refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范

这个提交包含在:
wikiboss
2026-09-20 17:05:22 +08:00
父节点 de3cf8b870
当前提交 9fa1d1fbd0
共有 1679 个文件被更改,包括 204798 次插入 和 16817 次删除

查看文件

@@ -0,0 +1,17 @@
<template>
<text class="child-text">child-text<text style="color: #007aff;">嵌套</text></text>
</template>
<script setup lang="uts">
</script>
<style>
.child-text {
font-size: 16px;
color: #007aff;
border: 1px solid #007aff;
padding: 10px;
margin: 10px;
text-align: center;
}
</style>

查看文件

@@ -0,0 +1,29 @@
describe('text-layout', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase();
const isIos = platformInfo.startsWith('ios');
const isHarmony = platformInfo.startsWith('harmony');
const isWeb = platformInfo.startsWith('web');
const isMP = platformInfo.startsWith('mp');
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true';
const isDom2 = process.env.UNI_APP_X_DOM2 == 'true';
if (isIos || isHarmony || isWeb || isMP || isAppWebView || isDom2) {
it('other platform', () => {
expect(1).toBe(1);
});
return;
}
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/text/text-layout');
await page.waitFor(500);
});
it('screenshot', async () => {
const image = await program.screenshot({
fullPage: true
});
expect(image).toSaveImageSnapshot();
});
});

查看文件

@@ -0,0 +1,149 @@
<template>
<scroll-view class="uni-flex-item uni-padding-wrap">
<!-- #ifdef APP-ANDROID -->
<page-head :title="title"></page-head>
<view class="uni-title">
<text class="uni-subtitle-text">无约束宽高</text>
<text class="uni-subtitle-text">{{info}}</text>
</view>
<view>
<text id="text" class="text"></text>
</view>
<view class="uni-title">
<text class="uni-subtitle-text">约束宽高-多行</text>
<text class="uni-subtitle-text">{{info2}}</text>
</view>
<view class="text-box">
<text id="text2" class="text"></text>
</view>
<view class="uni-title">
<text class="uni-subtitle-text">约束宽高-单行</text>
<text class="uni-subtitle-text">{{info3}}</text>
</view>
<view class="text-box">
<text id="text3" class="text"></text>
</view>
<view class="uni-title">
<text class="uni-subtitle-text">嵌套</text>
<text class="uni-subtitle-text">{{info4}}</text>
</view>
<view class="text-box">
<text id="text4" class="text"></text>
</view>
<!-- #endif -->
</scroll-view>
</template>
<script setup>
const title = 'text-layout';
// #ifdef APP-ANDROID
const info = ref('');
const info2 = ref('');
const info3 = ref('');
const info4 = ref('');
const setTextLayout = () => {
const element = uni.getElementById('text') as UniTextElement;
const layout = new UniTextLayout();
layout.setText('HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言;');
layout.setColor('red');
layout.setFontFamily('AlimamaDaoLiTiTTF');
layout.setFontSize('30px');
layout.setFontStyle('italic');
layout.setFontWeight('bold');
layout.setLineHeight('3');
layout.setTextShadow('2px 4px rgba(202,207,17,0.5)');
layout.setTextDecorationLine('underline');
const measureSize = layout.measure({} as UniLayoutConstraintSize);
element.style.setProperty('width', measureSize.width);
element.style.setProperty('height', measureSize.height);
element.setTextLayout(layout);
const size = element.getContentSize();
info.value = 'width: ' + size.width + 'px height: ' + size.height + 'px';
};
const setTextLayout2 = () => {
const element = uni.getElementById('text2') as UniTextElement;
const layout = new UniTextLayout();
layout.setText('HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言;')
layout.setColor('red');
layout.setLineHeight('3');
layout.setTextAlign('center');
const measureSize = layout.measure({
maxWidth: 300,
minHeight: 100
} as UniLayoutConstraintSize);
element.style.setProperty('width', measureSize.width);
element.style.setProperty('height', measureSize.height);
element.setTextLayout(layout);
const size = element.getContentSize();
info2.value = 'width: ' + size.width + 'px height: ' + size.height + 'px';
};
const setTextLayout3 = () => {
const element = uni.getElementById('text3') as UniTextElement;
const layout = new UniTextLayout();
layout.setText('HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言;')
layout.setColor('red');
layout.setLineHeight('30px');
layout.setTextOverflow('ellipsis');
layout.setWhiteSpace("nowrap");
const measureSize = layout.measure({
maxWidth: 300
} as UniLayoutConstraintSize);
element.style.setProperty('width', measureSize.width);
element.style.setProperty('height', measureSize.height);
element.setTextLayout(layout);
const size = element.getContentSize();
info3.value = 'width: ' + size.width + 'px height: ' + size.height + 'px';
};
const setTextLayout4 = () => {
const element = uni.getElementById('text4') as UniTextElement;
const layout = new UniTextLayout();
layout.setText('HBuilderX,轻巧、极速,极客编辑器;uts,大一统语言;');
layout.setColor('red');
layout.setFontSize('25px');
const child = new UniTextLayout();
child.setText("uni-app x,终极跨平台方案;");
layout.append(child);
const child2 = new UniTextLayout();
child2.setText('uts,大一统语言;');
child2.setColor("blue");
child2.setFontSize("20px");
layout.append(child2);
const measureSize = layout.measure({
maxWidth: 300
} as UniLayoutConstraintSize);
element.style.setProperty('width', measureSize.width);
element.style.setProperty('height', measureSize.height);
element.setTextLayout(layout);
const size = element.getContentSize();
info4.value = 'width: ' + size.width + 'px height: ' + size.height + 'px';
};
onLoad(() => {
uni.loadFontFace({
family: 'AlimamaDaoLiTiTTF',
source: "url('/static/font/AlimamaDaoLiTi.otf')"
});
});
onReady(() => {
setTextLayout();
setTextLayout2();
setTextLayout3();
setTextLayout4();
});
// #endif
</script>
<style>
.text-box {
align-items: center;
}
.text {
background-color: #ffffff;
}
</style>

查看文件

@@ -0,0 +1,106 @@
const PAGE_PATH = '/pages/component/text/text-props'
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
const isDom2 = process.env.UNI_APP_X_DOM2 === "true"
describe('text-props', () => {
if (isMP) {
it('skip', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(1000)
})
async function setPageData(newData) {
return await page.setData({ data: newData });
}
it('screenshot', async () => {
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
})
it('empty text', async () => {
await setPageData({ autoTest: true })
const element = await page.$('#empty-text')
if (element != null) {
const { width, height } = await element.size()
expect(width).toBe(0)
expect(height).toBe(0)
}
await page.callMethod("setEmptyText")
await page.waitFor(100)
const element2 = await page.$('#empty-text2')
if (element2 != null) {
expect(await element2.text()).toBe('')
const { width, height } = await element2.size()
expect(width).toBe(0)
expect(height).toBe(0)
}
const element3 = await page.$('#empty-text3')
if (element3 != null) {
expect(await element3.text()).toBe('')
}
await setPageData({ autoTest: false })
})
it('nested text', async () => {
await setPageData({ autoTest: true })
await page.callMethod("setNestedText")
await page.waitFor(100)
const element = await page.$('#nested-text')
if (!isMP && element != null) {
if(isDom2){
//Dom2为多线程等render之后再获取值
await page.waitFor('view');
}
// TODO 微信小程序端疑似自动化测试框架Bug,此处text方法会返回`"修改三级节点文本修改三级节点文本"`,手动测试未发现问题
expect(await element.text()).toBe("修改三级节点文本")
}
if(isMP || isWeb) {
// 不支持 program.tap
expect(1).toBe(1)
return
}
const rect = await page.callMethod("getBoundingClientRectForTest")
const windowInfo = await program.callUniMethod('getWindowInfo');
await program.tap({
x: Math.ceil(rect.left + rect.width / 2),
y: Math.ceil(windowInfo.statusBarHeight + 44 + rect.top + rect.height / 2)
})
await page.waitFor(300)
expect(await page.data('data.isNestedText1TapTriggered')).toBe(true)
expect(await page.data('data.isNestedText2TapTriggered')).toBe(true)
await setPageData({ autoTest: false })
})
it('height text', async () => {
await setPageData({ autoTest: true })
await page.callMethod("setHeightText")
await page.waitFor(100)
const element = await page.$('#height-text')
if (element != null) {
expect(await element.text()).toBe("修改设置高度文本")
}
await setPageData({ autoTest: false })
})
it('test attr decode', async () => {
await setPageData({ decode: false });
await page.waitFor(100);
const image = await program.screenshot({ fullPage: true });
expect(image).toSaveImageSnapshot();
await setPageData({ decode: true });
});
})

查看文件

@@ -0,0 +1,398 @@
<template>
<!-- #ifdef APP && !VUE3-VAPOR -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view style="background-color: #EEE;">
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">
<text class="uni-title-text">text相关属性示例</text>
</view>
<view class="uni-title">
<text class="uni-subtitle-text">根据宽度自动折行</text>
</view>
<view class="text-box">
<text>{{ multiLineText }}</text>
</view>
<text class="uni-subtitle-text">根据宽度自动折行,拍平测试</text>
<view class="text-box">
<text flatten>{{ multiLineText }}</text>
</view>
<view class="uni-title">
<text class="uni-subtitle-text">\\n换行</text>
</view>
<view class="text-box">
<text>\n 换行</text>
<text>\\n 换行</text>
<text>\\\n 换行</text>
<text>\n 换行 \\n 换行 \\\n 换行 \\\\n 换行 \\\\\n 换行</text>
<text>\n\n连续换行\n\n连续换行\n\n连续换行</text>
</view>
<text class="uni-subtitle-text">\\n换行,拍平测试</text>
<view class="text-box">
<text flatten>\n 换行</text>
<text flatten>\\n 换行</text>
<text flatten>\\\n 换行</text>
<text flatten>\n 换行 \\n 换行 \\\n 换行 \\\\n 换行 \\\\\n 换行</text>
<text flatten>\n\n连续换行\n\n连续换行\n\n连续换行</text>
</view>
<view class="uni-title">
<text class="uni-subtitle-text">selectable属性(鸿蒙蒸汽暂不支持)</text>
</view>
<view class="text-box">
<!-- #ifdef APP-HARMONY -->
<text>{{ singleLineText }}</text>
<!-- #endif -->
<!-- #ifndef APP-HARMONY -->
<text :selectable="true">{{ singleLineText }}</text>
<!-- #endif -->
</view>
<view class="uni-title">
<text class="uni-subtitle-text">space属性(App平台蒸汽模式不支持,推荐改用css white-space)</text>
<text class="uni-subtitle-text">依次为nbsp ensp emsp效果</text>
</view>
<view class="text-box">
<!-- #ifndef VUE3-VAPOR && APP -->
<text space="nbsp">{{ singleLineText }}</text>
<text space="ensp">{{ singleLineText }}</text>
<text space="emsp">{{ singleLineText }}</text>
<!-- #endif -->
<!-- #ifdef VUE3-VAPOR && APP -->
<text>{{ singleLineText }}</text>
<text>{{ singleLineText }}</text>
<text>{{ singleLineText }}</text>
<!-- #endif -->
</view>
<view class="uni-title">
<text class="uni-subtitle-text">decode属性(App平台蒸汽模式不支持)</text>
<text class="uni-subtitle-text">依次为lt gt amp apos nbsp ensp emsp效果</text>
</view>
<view class="text-box">
<!-- #ifndef VUE3-VAPOR && APP -->
<text :decode="data.decode">{{ decodeStr }}</text>
<text :decode="data.decode">uni-app&nbsp;x,终极跨平台方案</text>
<text :decode="data.decode">uni-app&ensp;x,终极跨平台方案</text>
<text :decode="data.decode">uni-app&emsp;x,终极跨平台方案</text>
<!-- #endif -->
<!-- #ifdef VUE3-VAPOR && APP -->
<text>{{ decodeStr }}</text>
<text>uni-app&nbsp;x,终极跨平台方案</text>
<text>uni-app&ensp;x,终极跨平台方案</text>
<text>uni-app&emsp;x,终极跨平台方案</text>
<!-- #endif -->
</view>
<view class="uni-title">
<text class="uni-subtitle-text">嵌套1</text>
</view>
<view class="text-box">
<text @tap="nestedText1Tap">一级节点黑色
<text style="color: red;background-color: yellow;" @tap="nestedText2Tap">二级节点红色且背景色黄色
<text style="text-decoration-line:underline;color:blue;" @tap="nestedText3Tap">App三级节点不继承二级的颜色</text>
</text>
<text style="font-size: 50px">二级节点大字体</text>
</text>
</view>
<text class="uni-subtitle-text">嵌套1,拍平测试</text>
<view class="text-box">
<text flatten @tap="nestedText1Tap">一级节点黑色
<text style="color: red;background-color: yellow;" @tap="nestedText2Tap">二级节点红色且背景色黄色
<text style="text-decoration-line:underline;color:blue;" @tap="nestedText3Tap">App三级节点不继承二级的颜色</text>
</text>
<text style="font-size: 50px">二级节点大字体</text>
</text>
</view>
<text class="uni-subtitle-text">动态text嵌套</text>
<text>
<text v-for="n in textArr" :key="n">{{ n }}</text>
</text>
<view class="uni-title">
<text class="uni-subtitle-text">空嵌套测试</text>
</view>
<view class="text-box">
<text>
<text>
文字应居中显示<text></text>
</text>
</text>
</view>
<text class="uni-subtitle-text">空嵌套测试(根拍平)</text>
<view class="text-box">
<text flatten>
<text>
文字应居中显示<text></text>
</text>
</text>
</view>
<view class="uni-title">
<text class="uni-subtitle-text">含换行符的多行文本(3行),但不自动换行,可横向滚动</text>
</view>
<scroll-view class="text-container" direction="horizontal">
<text style="white-space: nowrap;align-self: flex-start;">HBuilderX,轻巧、极速,极客编辑器;\nuni-app x,是下一代 uni-app,是一个跨平台应用开发引擎。uni-app x 是一个庞大的工程,它包括uts语言、uvue渲染引擎、uni的组件和API、以及扩展机制。\nuts是一门类ts的、跨平台的、新语言。</text>
</scroll-view>
<text class="uni-subtitle-text">含换行符的多行文本(3行),但不自动换行,可横向滚动【拍平测试】</text>
<scroll-view class="text-container" direction="horizontal">
<text flatten style="white-space: nowrap;align-self: flex-start;">HBuilderX,轻巧、极速,极客编辑器;\nuni-app x,是下一代 uni-app,是一个跨平台应用开发引擎。uni-app x 是一个庞大的工程,它包括uts语言、uvue渲染引擎、uni的组件和API、以及扩展机制。\nuts是一门类ts的、跨平台的、新语言。</text>
</scroll-view>
<!-- #ifdef APP -->
<view class="uni-title">
<text class="uni-subtitle-text">点击事件测试</text>
</view>
<view class="text-box" style="flex-direction: row;">
<text class="text-icon" style="background-color: aqua;" @tap="iconTap">{{String.fromCharCode(parseInt('E650',16))}}</text>
<text class="text-icon" style="background-color: yellow;" @tap="iconTap2">{{String.fromCharCode(parseInt('EA08',16))}}</text>
</view>
<!-- #endif -->
<!-- #ifdef VUE3-VAPOR -->
<view class="uni-title">
<text class="uni-title-text">hover-class 测试</text>
</view>
<text id="text-hover-parent" class="text-hover-main"
:hover-class="hoverData.hover_class ? 'is-parent-hover' : 'none'"
:class="isDarkMode ? 'theme-dark' : 'theme-light'"
:hover-start-time="hoverData.start_time"
:hover-stay-time="hoverData.stay_time"
>
点击测试 hover-class
</text>
<view class="uni-common-mb">
<boolean-data :defaultValue="false" title="是否指定按下去的样式类" @change="change_hover_class_boolean"></boolean-data>
<enum-data :items="hoverData.start_time_enum" title="按住后多久出现点击态" @change="radio_change_start_time_enum"></enum-data>
<enum-data :items="hoverData.stay_time_enum" title="手指松开后点击态保留时间" @change="radio_change_stay_time_enum"></enum-data>
</view>
<!-- #endif -->
<view v-if="data.autoTest">
<view class="uni-row">
<text id="empty-text"></text>
</view>
<view class="uni-row">
<text id="empty-text2">{{data.emptyText}}</text>
</view>
<view class="uni-row">
<text id="empty-text3" style="width: 100px;height: 100px;">{{data.emptyText}}</text>
</view>
<text>一级节点文本
<text>二级节点文本
<text id="nested-text">{{data.nestedText}}</text>
</text>
</text>
<text id="height-text" style="height: 50px;">{{data.heightText}}</text>
<text style="position: fixed;" id="nested-text2" @tap="nestedText1TapForTest">1
<text @tap="nestedText2TapForTest">2
<text>3</text>
</text>
</text>
</view>
</view>
</view>
<!-- #ifdef APP && !VUE3-VAPOR -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
import { ItemType } from '@/components/enum-data/enum-data-types'
import { state } from '@/store/index.uts'
const decodeStr = ref('&lt; &gt; &amp; &apos;')
const title = ref('text-props')
const multiLineText = ref('HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言;HBuilderX,轻巧、极速,极客编辑器;uni-app x,终极跨平台方案;uts,大一统语言')
const singleLineText = ref('uni-app x,终极跨平台方案')
const textArr= ref(["嵌套 text 1 ","嵌套 text 2 ","嵌套 text 3 "])
// #ifdef VUE3-VAPOR
type HoverDataType = {
hover_class: boolean;
start_time: number;
stay_time: number;
start_time_enum: ItemType[];
stay_time_enum: ItemType[];
}
// 使用reactive解决ref数据在自动化测试中无法访问
const hoverData = reactive({
hover_class: false,
start_time: 50,
stay_time: 400,
start_time_enum: [{ "value": 400, "name": "400毫秒" }, { "value": 1000, "name": "1000毫秒" }],
stay_time_enum: [{ "value": 600, "name": "600毫秒" }, { "value": 1000, "name": "1000毫秒" }]
} as HoverDataType)
const isDarkMode = computed((): boolean => {
return state.isDarkMode
})
const change_hover_class_boolean = (checked: boolean) => {
hoverData.hover_class = checked
}
const radio_change_start_time_enum = (time: number) => {
hoverData.start_time = time
}
const radio_change_stay_time_enum = (time: number) => {
hoverData.stay_time = time
}
// #endif
type DataType = {
autoTest: boolean,
nestedText: string,
emptyText: string,
heightText: string,
isNestedText1TapTriggered: boolean,
isNestedText2TapTriggered: boolean,
decode: boolean
}
// 自动化测试
const data = reactive({
autoTest: false,
nestedText: '三级节点文本',
emptyText: '空文本',
heightText: '设置高度文本',
isNestedText1TapTriggered: false,
isNestedText2TapTriggered: false,
decode: true
} as DataType)
function nestedText1Tap() {
uni.showModal({
title: '点击了',
content: '一级节点黑色',
showCancel: false
});
}
function nestedText2Tap(e : UniPointerEvent) {
e.stopPropagation();
uni.showModal({
title: '点击了',
content: '二级节点红色且背景色黄色',
showCancel: false
});
}
function nestedText3Tap(e : UniPointerEvent) {
e.stopPropagation();
uni.showModal({
title: '点击了',
content: 'App三级节点不继承二级的颜色',
showCancel: false
});
}
function iconTap() {
uni.showModal({
title: '点击了',
content: '字体图标1',
showCancel: false
});
}
function iconTap2() {
uni.showModal({
title: '点击了',
content: '字体图标2',
showCancel: false
});
}
// 自动化测试
function setNestedText() {
data.nestedText = "修改三级节点文本";
}
function setEmptyText() {
data.emptyText = "";
}
function setHeightText() {
data.heightText = "修改设置高度文本";
}
function getBoundingClientRectForTest() : DOMRect | null {
return uni.getElementById('nested-text2')?.getBoundingClientRect();
}
function nestedText1TapForTest() {
data.isNestedText1TapTriggered = true;
}
function nestedText2TapForTest() {
data.isNestedText2TapTriggered = true;
}
defineExpose({
data,
setNestedText,
setEmptyText,
setHeightText,
getBoundingClientRectForTest,
nestedText1TapForTest,
nestedText2TapForTest
})
</script>
<style>
.text-box {
margin-bottom: 20px;
padding: 20px 0;
background-color: #ffffff;
justify-content: center;
align-items: center;
}
.text-container {
width: 100%;
background-color: #ffffff;
padding: 10px;
}
.text {
font-size: 15px;
color: #353535;
line-height: 27px;
text-align: center;
}
.text-icon {
font-family: uni-icon;
font-size: 100px;
}
/* #ifdef VUE3-VAPOR && APP-HARMONY */
.harmony-unsupported-tip {
font-size: 12px;
color: #999999;
margin-top: 10px;
text-align: center;
}
/* #endif */
.text-hover-main {
padding: 5px 0;
flex-direction: row;
justify-content: center;
background-color: #ffffff;
}
.is-parent-hover {
background-color: #aa0000;
}
</style>

查看文件

@@ -0,0 +1,332 @@
<template>
<view class="page-container">
<!-- #ifndef MP -->
<fps></fps>
<!-- #endif -->
<!-- 打字机效果区域 -->
<view class="typewriter-container">
<view class="typewriter-title">
<text class="title-text">打字机效果演示</text>
</view>
<view class="typewriter-box">
<text v-for="(segment, index) in displayedSegments" :key="index"
:class="segment.className">{{ segment.text }}</text>
<text :class="showCursor ? 'typewriter-cursor' : 'typewriter-cursor-hidden'">|</text>
</view>
<text class="uni-title">【拍平测试】</text>
<view class="typewriter-box">
<text flatten v-for="(segment, index) in displayedSegments" :key="index"
:class="segment.className">{{ segment.text }}</text>
<text flatten :class="showCursor ? 'typewriter-cursor' : 'typewriter-cursor-hidden'">|</text>
</view>
</view>
</view>
</template>
<script setup lang="uts">
// 打字机效果相关 - 富文本片段定义
type TextSegment = {
text : string
className : string
}
// 定义富文本内容,每个片段有不同的样式
const textSegments : TextSegment[] = [
{ text: '欢迎使用 ', className: 'text-normal' },
{ text: 'uni-app x', className: 'text-brand-large' },
{ text: '!', className: 'text-exclaim-large' },
{ text: '这是一个', className: 'text-small-gray' },
{ text: '炫酷', className: 'text-fancy-bold' },
{ text: '的', className: 'text-small-gray' },
{ text: '打字机效果', className: 'text-orange-italic' },
{ text: '演示。', className: 'text-normal-small' },
{ text: '文字会像 ', className: 'text-small-light' },
{ text: 'AI', className: 'text-ai-highlight' },
{ text: ' 回复一样', className: 'text-normal-small' },
{ text: '逐字', className: 'text-purple-bold' },
{ text: '显示出来~ ', className: 'text-normal-small' },
{ text: 'HBuilderX ', className: 'text-orange-bold-wide' },
{ text: '是', className: 'text-small-gray' },
{ text: '轻巧', className: 'text-blue-italic' },
{ text: '、', className: 'text-small-light' },
{ text: '极速', className: 'text-green-italic' },
{ text: '、', className: 'text-small-light' },
{ text: '极客', className: 'text-pink-italic' },
{ text: '的编辑器;', className: 'text-normal-small' },
{ text: 'uni-app x', className: 'text-brand-underline' },
{ text: ' 是', className: 'text-small-gray' },
{ text: '终极', className: 'text-red-bold-italic' },
{ text: '跨平台方案', className: 'text-purple-highlight' },
{ text: '!', className: 'text-exclaim-pink' },
{ text: 'UTS', className: 'text-green-bold-wide' },
{ text: ' 让你使用', className: 'text-normal-small' },
{ text: '大一统语言', className: 'text-orange-italic-underline' },
{ text: '进行开发~', className: 'text-small-gray-15' }
]
const showCursor = ref(true)
const displayedSegments = ref<TextSegment[]>([])
let typingTimer : number | null = null
let cursorTimer : number | null = null
let currentSegmentIndex = ref(0)
let currentCharIndex = ref(0)
// 开始光标闪烁
function startCursorBlink() {
cursorTimer = setInterval(() => {
showCursor.value = !showCursor.value
}, 500) // 每0.1秒切换光标显示状态
}
// 开始打字机效果
function startTyping() {
currentSegmentIndex.value = 0
currentCharIndex.value = 0
displayedSegments.value = []
typingTimer = setInterval(() => {
if (currentSegmentIndex.value < textSegments.length) {
const currentSegment = textSegments[currentSegmentIndex.value]
if (currentCharIndex.value < currentSegment.text.length) {
// 更新当前片段的显示文字
const displayedChar = currentSegment.text.substring(0, currentCharIndex.value + 1)
// 更新 displayedSegments
const newSegments : TextSegment[] = []
for (let i = 0; i < currentSegmentIndex.value; i++) {
newSegments.push(textSegments[i])
}
newSegments.push({
text: displayedChar,
className: currentSegment.className
})
displayedSegments.value = newSegments
currentCharIndex.value++
} else {
// 当前片段完成,移动到下一个片段
currentSegmentIndex.value++
currentCharIndex.value = 0
}
} else {
// 所有片段完成,等待2秒重新开始
if (typingTimer != null) {
clearInterval(typingTimer!)
}
setTimeout(() => {
startTyping()
}, 1500)
}
}, 50)
}
// 组件挂载时开始打字和光标闪烁
onMounted(() => {
startTyping()
startCursorBlink()
})
// 组件卸载时清理定时器
onUnmounted(() => {
if (typingTimer != null) {
clearInterval(typingTimer)
}
if (cursorTimer != null) {
clearInterval(cursorTimer)
}
})
</script>
<style>
.page-container {
background-color: #F8F8F8;
flex: 1;
position: relative;
}
.typewriter-container {
margin: 20px;
padding: 30px 20px;
background-color: #ffffff;
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.typewriter-title {
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 2px solid #f0f0f0;
}
.title-text {
font-size: 20px;
font-weight: bold;
color: #333333;
}
.typewriter-box {
flex-direction: row;
flex-wrap: wrap;
align-items: flex-start;
}
.typewriter-cursor {
font-size: 16px;
line-height: 24px;
color: #3333ff;
margin-left: 2px;
}
.typewriter-cursor-hidden {
font-size: 16px;
line-height: 24px;
color: transparent;
margin-left: 2px;
}
/* 文本样式类 */
.text-normal {
font-size: 16px;
color: #333333;
}
.text-brand-large {
font-size: 20px;
color: #007aff;
font-weight: bold;
letter-spacing: 1px;
}
.text-exclaim-large {
font-size: 22px;
color: #ff3b30;
}
.text-small-gray {
font-size: 14px;
color: #666666;
}
.text-fancy-bold {
font-size: 19px;
color: #ff2d55;
font-weight: bold;
font-style: italic;
/* #ifdef WEB */
text-decoration: underline;
/* #endif */
}
.text-orange-italic {
font-size: 18px;
color: #ff9500;
font-style: italic;
letter-spacing: 0.5px;
}
.text-normal-small {
font-size: 15px;
color: #333333;
}
.text-small-light {
font-size: 14px;
color: #999999;
}
.text-ai-highlight {
font-size: 20px;
color: #34c759;
font-weight: bold;
background-color: #f0f9ff;
padding-left: 4px;
padding-right: 4px;
}
.text-purple-bold {
font-size: 17px;
color: #5856d6;
font-weight: bold;
/* #ifdef WEB */
text-decoration: underline;
/* #endif */
}
.text-orange-bold-wide {
font-size: 18px;
color: #ff9500;
font-weight: bold;
letter-spacing: 1.5px;
}
.text-blue-italic {
font-size: 16px;
color: #007aff;
font-style: italic;
}
.text-green-italic {
font-size: 16px;
color: #34c759;
font-style: italic;
}
.text-pink-italic {
font-size: 16px;
color: #ff2d55;
font-style: italic;
}
.text-brand-underline {
font-size: 19px;
color: #007aff;
font-weight: bold;
/* #ifdef WEB */
text-decoration: underline;
/* #endif */
letter-spacing: 0.8px;
}
.text-red-bold-italic {
font-size: 20px;
color: #ff3b30;
font-weight: bold;
font-style: italic;
}
.text-purple-highlight {
font-size: 17px;
color: #5856d6;
font-weight: bold;
background-color: #fff3e0;
padding-left: 3px;
padding-right: 3px;
}
.text-exclaim-pink {
font-size: 22px;
color: #ff2d55;
}
.text-green-bold-wide {
font-size: 18px;
color: #34c759;
font-weight: bold;
letter-spacing: 2px;
}
.text-orange-italic-underline {
font-size: 17px;
color: #ff9500;
font-style: italic;
/* #ifdef WEB */
text-decoration: underline;
/* #endif */
}
.text-small-gray-15 {
font-size: 15px;
color: #666666;
}
</style>

查看文件

@@ -0,0 +1,214 @@
<template>
<!-- #ifdef APP && !VUE3-VAPOR -->
<scroll-view style="flex: 1">
<!-- #endif -->
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<!-- 单行文本测试 -->
<text class="uni-title-text">单行文本</text>
<view class="text-box">
<text class="styled-text single-line">{{ singleLineText }}</text>
</view>
<text class="uni-subtitle-text">单行文本 - 拍平</text>
<view class="text-box" flatten>
<text class="styled-text single-line" flatten>{{ singleLineText }}</text>
</view>
<!-- 多行文本测试 -->
<text class="uni-title-text">多行文本</text>
<view class="text-box">
<text class="styled-text">{{ multiLineText }}</text>
</view>
<text class="uni-subtitle-text">多行文本 - 拍平</text>
<view class="text-box" flatten>
<text class="styled-text" flatten>{{ multiLineText }}</text>
</view>
<text class="uni-title-text">嵌套的text样式合集</text>
<text class="uni-common-mt uni-common-mb">
<text class="styled-text">text嵌套text的内容:</text>
<text class="styled-text">{{multiLineText}}</text>
</text>
<!-- 自定义组件拍平 -->
<text class="uni-title-text">自定义组件:右边拍平</text>
<view class="view-row">
<child></child>
<child flatten></child>
</view>
<!-- 动态文本测试 -->
<text class="uni-title-text">动态文本</text>
<view class="dynamic-text-box">
<text class="text">{{ text }}</text>
</view>
<text class="uni-subtitle-text">动态文本 - 拍平</text>
<view class="dynamic-text-box" flatten>
<text class="text" flatten>{{ text }}</text>
</view>
<view class="uni-btn-v">
<button class="uni-btn" type="primary" :disabled="!canAdd" @click="add">
add line
</button>
<button class="uni-btn" type="warn" :disabled="!canRemove" @click="remove">
remove line
</button>
<button class="uni-btn" type="primary" @click="textProps">
更多属性示例
</button>
<!-- #ifdef WEB || VUE3-VAPOR -->
<button class="uni-btn" type="primary" @click="textWriter">
打字机效果示例
</button>
<!-- #endif -->
<!-- #ifdef APP-ANDROID && !VUE3-VAPOR -->
<button class="uni-btn" type="primary" @click="textLayout">
文本测量
</button>
<!-- #endif -->
</view>
<!-- #ifdef VUE3-VAPOR -->
<navigator url="/pages/template/4050/4050">
<button class="uni-btn uni-common-mb">组件性能测试</button>
</navigator>
<!-- #endif -->
</view>
<!-- #ifdef APP && !VUE3-VAPOR -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
import Child from './child.uvue'
const title = ref('text')
// 单行文本
const singleLineText = ref('单行文本:16px字体、500粗细、斜体、下划线、1px字间距、1.8行高、文本阴影、居中对齐、不换行溢出省略、带边框圆角、内外边距、背景色')
// 多行文本
const multiLineText = ref('多行文本:字体(16px/500粗细/斜体)、装饰(下划线/阴影)、间距(1px字间距/1.8行高)、对齐(左对齐)、盒模型(边框/圆角/内外边距/背景色)。\n 第二行:展示自动换行效果及所有CSS样式的渲染表现。')
// 动态文本测试数据
const texts: string[] = [
'HBuilderX,轻巧、极速,极客编辑器',
'uni-app x,终极跨平台方案',
'uniCloud,js serverless云服务',
'uts,大一统语言',
'uniMPSdk,让你的App具备小程序能力',
'uni-admin,开源、现成的全端管理后台',
'uni-id,开源、全端的账户中心',
'uni-pay,开源、云端一体、全平台的支付',
'uni-ai,聚合ai能力',
'uni-cms,开源、云端一体、全平台的内容管理平台',
'uni-im,开源、云端一体、全平台的im即时消息',
'uni统计,开源、完善、全平台的统计报表',
'......'
]
const text = ref('')
const canAdd = ref(true)
const canRemove = ref(false)
let extraLine: string[] = []
const add = () => {
extraLine.push(texts[extraLine.length % 12])
text.value = extraLine.join('\n')
canAdd.value = extraLine.length < 12
canRemove.value = extraLine.length > 0
}
const remove = () => {
if (extraLine.length > 0) {
extraLine.pop()
text.value = extraLine.join('\n')
canAdd.value = extraLine.length < 12
canRemove.value = extraLine.length > 0
}
}
const textProps = () => {
uni.navigateTo({
url: '/pages/component/text/text-props'
})
}
const textWriter = () => {
uni.navigateTo({
url: '/pages/component/text/text-writer'
})
}
const textLayout = () => {
uni.navigateTo({
url: '/pages/component/text/text-layout'
})
}
</script>
<style>
.view-row {
flex-direction: row;
background: #fff;
justify-content: space-around;
}
.text-box {
margin-bottom: 15px;
padding: 10px;
display: flex;
min-height: 60px;
background-color: #ffffff;
justify-content: center;
align-items: center;
}
/* 包含所有文字和排版CSS的综合样式 */
.styled-text {
/* 文字专用CSS */
/* 字体相关 */
font-size: 16px;
font-weight: 500;
font-style: italic;
color: #1a1a1a;
/* 行高与字间距 */
line-height: 1.8;
letter-spacing: 1px;
/* 对齐 */
text-align: left;
/* 文字装饰 */
text-decoration-line: underline;
/* 文本阴影 */
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
/* 排版CSS */
width: 100%;
margin: 5px 0;
padding: 8px 12px;
border: 1px solid #e0e0e0;
border-radius: 4px;
background-color: #f9f9f9;
}
/* 单行文本特定样式 */
.single-line {
white-space: nowrap;
text-overflow: ellipsis;
text-align: center;
}
.dynamic-text-box {
margin-bottom: 15px;
padding: 10px;
display: flex;
min-height: 50px;
background-color: #ffffff;
border: 1px solid #dddddd;
border-radius: 5px;
justify-content: center;
align-items: center;
}
.text {
font-size: 14px;
color: #353535;
line-height: 22px;
text-align: center;
}
</style>