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

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

查看文件

@@ -0,0 +1,157 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
const isHarmony = platformInfo.startsWith('harmony')
const isIOS = platformInfo.startsWith('ios')
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
const isDom2 = process.env.UNI_APP_X_DOM2 === "true"
const PAGE_PATH = '/pages/component/rich-text/rich-text-complex'
async function screenshot(name) {
const image = await program.screenshot({
fullPage: true
})
expect(image).toSaveImageSnapshot({
customSnapshotIdentifier() {
return name
}
})
}
describe('rich-text-complex', () => {
if (isMP || isWeb || process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
it('skip', () => {
expect(1).toBe(1)
})
return
}
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view');
await page.waitFor(2000);
await setPageData({
autoTest: true
});
})
let page
async function testItemClickEvent() {
await setPageData({
imageClicked: false
});
const rect = await page.callMethod("getBoundingClientRectForRichtext")
const windowInfo = await program.callUniMethod('getWindowInfo');
const tapOption = {
x: Math.ceil(rect.left + 30),
y: Math.ceil(windowInfo.statusBarHeight + 44 + rect.top + 60),
duration: 100
}
await program.tap(tapOption)
await page.waitFor(500);
// 关闭弹窗逻辑各平台需要适配不同机型
if (isIOS) {
// 关闭弹窗 iPhone Pro 机型
await program.tap({
x: 200,
y: 433,
duration: 100
})
// 关闭弹窗 iPhone ProMax 机型
await program.tap({
x: 220,
y: 476,
duration: 100
})
// 关闭弹窗 iPhone plus 机型
await program.tap({
x: 220,
y: 526,
duration: 100
})
// 关闭弹窗 iPhone mini 机型
await program.tap({
x: 186,
y: 400,
duration: 100
})
}
const imageClicked = await page.data('data.imageClicked')
expect(imageClicked).toBe(true)
}
async function setPageData(newData) {
return await page.setData({
data: newData
});
}
/**
* 1. mode=web 截图,点击事件
* 2. mode=native 截图,点击事件
* 3. 安卓或鸿蒙(vapor) mode=native 切换回 mode=web 截图
*/
it("rich-text-web-snapshot", async () => {
await page.waitFor(1000);
await screenshot('rich-text-mode-web')
});
it('itemclick-event-web', async () => {
await testItemClickEvent()
})
if ((isAndroid || (isHarmony && isDom2)) && !isAppWebView) {
it("rich-text-native", async () => {
await setPageData({
mode: 'native'
});
await page.waitFor(1000);
await screenshot('rich-text-mode-native')
});
it('itemclick-event-native', async () => {
await testItemClickEvent()
})
it("rich-text-native-change-web", async () => {
await setPageData({
mode: 'web'
});
await page.waitFor(1000);
await screenshot('rich-text-mode-native-change-web')
});
}
// TODO: dom1 仅iOS支持rich-text组件响应自身click和父链的click事件,dom2 目前通道有问题,暂时屏蔽
if (isDom2) {
return
}
it('click-event', async () => {
const rect = await page.callMethod("getBoundingClientRectForRichtext")
const windowInfo = await program.callUniMethod('getWindowInfo');
await program.tap({
x: Math.ceil(rect.left + rect.width * 0.7),
y: Math.ceil(windowInfo.statusBarHeight + 44 + rect.top + 100),
duration: 100
})
await page.waitFor(1000);
const fViewClicked = await page.data('data.fViewClicked')
const selfClicked = await page.data('data.selfClicked')
expect(fViewClicked).toBe(true)
expect(selfClicked).toBe(true)
})
})

查看文件

@@ -0,0 +1,94 @@
<template>
<!-- #ifdef APP && !VUE3-VAPOR -->
<scroll-view style="flex: 1;">
<!-- #endif -->
<view>
<page-head title="rich-text-complex"></page-head>
<page-intro content="本页演示 rich-text 渲染复杂 HTML:富文本内容、selectable、itemclick 与 click 事件、父 view 与自身点击区分。"></page-intro>
<enum-data title="设置mode(仅Android平台支持,默认值为web)" :disabled="data.disabledEnum" :items="modeItemTypes" @change="onModeChange"></enum-data>
<view class="uni-padding-wrap uni-common-mt" @click="fViewClick('触发父 view click 事件')">
<rich-text id="richtext" :nodes="htmlString" :selectable="true" @itemclick="itemClick" @click="selfClick('触发 richtext click 事件')" :mode="data.mode"/>
</view>
</view>
<!-- #ifdef APP && !VUE3-VAPOR -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
import { ItemType } from '@/components/enum-data/enum-data-types';
type DataType = {
mode: string,
imageClicked: boolean,
fViewClicked: boolean,
selfClicked: boolean,
autoTest: boolean,
disabledEnum: boolean
}
const htmlString = ref('<p><a href="https://www.dcloud.io/hbuilderx.html">HBuilderX</a><br/><img src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png"></img><h1>HBuilderX,轻巧、极速,极客编辑器</h1><p style="color:red;"><small>HBuilderX,轻巧、极速,极客编辑器 </small><big>HBuilderX,轻巧、极速,极客编辑器</big><strong>HBuilderX,轻巧、极速,极客编辑器</strong><i>HBuilderX,轻巧、极速,极客编辑器 </i><u>HBuilderX,轻巧、极速,极客编辑器</u><del>HBuilderX,轻巧、极速,极客编辑器</del></p><h2>uni-app x,终极跨平台方案</h2>、<p style="background-color: yellow;"><small>uni-app x,终极跨平台方案 </small><big>uni-app x,终极跨平台方案</big><strong>uni-appx,终极跨平台方案 </strong><i>uni-app x,终极跨平台方案 </i><u>uni-app x,终极跨平台方案 </u><del>uni-appx,终极跨平台方案</del></p><h3>uniCloud,js serverless云服务</h3><p style="text-decoration: line-through;"><small>uniCloud,js serverless云服务 </small><big>uniCloud,jsserverless云服务</big><strong>uniCloud,js serverless云服务 </strong><i>uniCloud,js serverless云服务 </i><u>uniCloud,jsserverless云服务</u><del>uniCloud,js serverless云服务</del></p><h4>uts,大一统语言</h4><p style="text-align: center;"><small>uts,大一统语言 </small><big>uts,大一统语言 </big><strong>uts,大一统语言</strong><i>uts,大一统语言</i><u>uts,大一统语言 </u><del>uts,大一统语言</del></p><h5>uniMPSdk,让你的App具备小程序能力</h5><h6>uni-admin,开源、现成的全端管理后台</h6><ul><li style="color: red; text-align: left;">uni-app x,终极跨平台方案</li><li style="color: green; text-align: center;">uni-app x,终极跨平台方案</li><li style="color: blue; text-align: right;">uni-app x,终极跨平台方案</li></ul><a href="https://uniapp.dcloud.net.cn">uni-app</a><br/><img src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png"></img></p>')
const modeItems = ['web', 'native']
const modeItemTypes = ref([{ 'value': 0, 'name': 'web', 'checked': true }, { 'value': 1, 'name': 'native' }] as ItemType[])
const data = reactive({
mode: 'web',
imageClicked: false,
fViewClicked: false,
selfClicked: false,
autoTest: false,
disabledEnum: true
} as DataType)
// #ifdef APP-ANDROID || (APP-HARMONY && VUE3-VAPOR) || (APP-IOS && VUE3-VAPOR)
data.disabledEnum = false
// #endif
watch((): string => data.mode, (mode: string): void => {
modeItemTypes.value.forEach((item: ItemType): void => {
item.checked = item.name == mode
})
})
function itemClick(e : UniRichTextItemClickEvent) {
console.log(JSON.stringify(e.detail));
let clicktext = '';
if (e.detail.src != null) {
clicktext = '点击了图片,src = ' + e.detail.src;
data.imageClicked = true
} else if (e.detail.href != null) {
clicktext = '点击了链接,href = ' + e.detail.href;
}
if (data.autoTest) {
return;
}
uni.showModal({
content: clicktext,
showCancel: false
});
}
function fViewClick(e : string) {
console.log(e)
data.fViewClicked = true
}
function selfClick(e : string) {
console.log(e)
data.selfClicked = true
}
function onModeChange(value : number) {
data.mode = modeItems[value];
}
function getBoundingClientRectForRichtext() : DOMRect | null {
return uni.getElementById('richtext')?.getBoundingClientRect();
}
defineExpose({
data,
getBoundingClientRectForRichtext
})
</script>

查看文件

@@ -0,0 +1,93 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
const isHarmony = platformInfo.startsWith('harmony')
const isIOS = platformInfo.startsWith('ios')
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
const PAGE_PATH = '/pages/component/rich-text/rich-text-highlight'
const CASE_SNAPSHOT_NAMES = [
'highlight-bg-text-color',
'highlight-bg-text-background',
'handle-color-text-color',
'handle-color-text-background',
'text-color-text-background',
'text-highlight-bg-background-handle-color',
'text-handle-color-background-highlight-bg',
'text-background-highlight-bg',
'text-background-handle-color',
'normal-control'
]
describe('rich-text-highlight', () => {
if (isMP || process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
it('skip', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
await page.waitFor(1500)
})
async function setPageData(newData) {
return await page.setData({
data: newData
})
}
async function setMode(mode) {
const currentMode = await page.data('data.mode')
if (currentMode == mode) {
return
}
await setPageData({
mode
})
await page.waitFor(1000)
expect(await page.data('data.mode')).toBe(mode)
}
async function setCase(index) {
await page.callMethod('setCase', index)
await page.waitFor(500)
expect(await page.data('data.currentCaseIndex')).toBe(index)
}
async function screenshot(name) {
const image = await program.screenshot({
fullPage: true
})
expect(image).toSaveImageSnapshot({
customSnapshotIdentifier() {
return name
}
})
}
CASE_SNAPSHOT_NAMES.forEach((name, index) => {
it(`rich-text-highlight-web-${name}`, async () => {
await setMode('web')
await setCase(index)
await screenshot(`rich-text-highlight-web-${name}`)
})
})
if ((isAndroid || ((isHarmony || isIOS) && isDom2)) && !isAppWebView && !isWeb) {
CASE_SNAPSHOT_NAMES.forEach((name, index) => {
it(`rich-text-highlight-native-${name}`, async () => {
await setMode('native')
await setCase(index)
await screenshot(`rich-text-highlight-native-${name}`)
})
})
}
})

查看文件

@@ -0,0 +1,279 @@
<template>
<!-- #ifdef APP && !VUE3-VAPOR -->
<scroll-view style="flex: 1;">
<!-- #endif -->
<page-head title="rich-text-highlight"></page-head>
<page-intro content="本页用于测试 rich-text 手动选择文本时,高亮背景色、操作手柄色与文字颜色、文字背景色相同或交叉组合时的显示效果。"></page-intro>
<!-- #ifdef APP-ANDROID || (APP-HARMONY && VUE3-VAPOR) || (APP-IOS && VUE3-VAPOR) -->
<enum-data title="设置mode(iOS和鸿蒙平台仅蒸汽模式支持,默认值为web)" :items="modeItemTypes" @change="onModeChange"></enum-data>
<!-- #endif -->
<view class="uni-padding-wrap uni-common-mt">
<view class="toolbar">
<view class="toolbar-row">
<text class="toolbar-label">当前模式:{{ data.mode }}</text>
<text class="toolbar-label">当前用例:{{ data.caseName }}</text>
</view>
<view class="color-reference">
<text class="reference-text">高亮背景色:{{ highlightBackgroundColor }}</text>
<text class="reference-text">操作手柄色:{{ highlightHandleColor }}</text>
</view>
<view class="case-grid">
<button v-for="(item, index) in highlightCases" :key="item.name" :class="data.currentCaseIndex == index ? 'case-button case-button-active' : 'case-button'" @click="setCase(index)">{{ item.name }}</button>
</view>
<text class="tip-text">操作方式:切换用例后,长按下方 rich-text 文本并拖动选择范围,观察选区背景和左右操作手柄在同色、近色、交叉配色下是否仍然清晰可见。</text>
</view>
<view class="content-card">
<rich-text id="highlight-rich-text" class="rich-text-content" :nodes="htmlString" :selectable="true" :mode="data.mode"></rich-text>
</view>
<view class="legend">
<text class="legend-text">观察点:</text>
<text class="legend-text">1. 高亮背景色固定为 #33B5E566,操作手柄色固定为 #4285F4FF。</text>
<text class="legend-text">2. 每个用例只改变目标文本的 color 和 background-color。</text>
<text class="legend-text">3. 重点检查高亮背景、操作手柄、文字颜色、文字背景色两两相同或交叉时是否互相遮挡。</text>
<text class="legend-text">4. 切换 web/native mode 后重复手动划选,比较不同渲染模式的覆盖效果。</text>
</view>
</view>
<!-- #ifdef APP && !VUE3-VAPOR -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
import { ItemType } from '@/components/enum-data/enum-data-types';
type DataType = {
mode : string,
currentCaseIndex : number,
caseName : string,
caseDescription : string,
textColor : string,
textBackgroundColor : string
}
type HighlightCase = {
name : string,
description : string,
textColor : string,
textBackgroundColor : string
}
const highlightBackgroundColor = '#33B5E566'
const highlightHandleColor = '#4285F4FF'
const normalTextColor = '#202124FF'
const normalTextBackgroundColor = '#FFFFFFFF'
const contrastTextColor = '#111111FF'
const contrastTextBackgroundColor = '#FFE082FF'
const highlightCases = [
{
name: '高亮背景=文字色',
description: '文字颜色使用高亮背景色,文字背景保持白色。',
textColor: highlightBackgroundColor,
textBackgroundColor: normalTextBackgroundColor
},
{
name: '高亮背景=文字背景',
description: '文字背景使用高亮背景色,文字颜色保持普通深色。',
textColor: normalTextColor,
textBackgroundColor: highlightBackgroundColor
},
{
name: '手柄色=文字色',
description: '文字颜色使用操作手柄色,文字背景保持白色。',
textColor: highlightHandleColor,
textBackgroundColor: normalTextBackgroundColor
},
{
name: '手柄色=文字背景',
description: '文字背景使用操作手柄色,文字颜色保持普通深色。',
textColor: normalTextColor,
textBackgroundColor: highlightHandleColor
},
{
name: '文字色=文字背景',
description: '文字颜色与文字背景色相同,用于验证选择后文字是否能被高亮区分。',
textColor: contrastTextBackgroundColor,
textBackgroundColor: contrastTextBackgroundColor
},
{
name: '文字色=高亮背景 背景=手柄色',
description: '文字颜色等于高亮背景色,文字背景等于操作手柄色。',
textColor: highlightBackgroundColor,
textBackgroundColor: highlightHandleColor
},
{
name: '文字色=手柄色 背景=高亮背景',
description: '文字颜色等于操作手柄色,文字背景等于高亮背景色。',
textColor: highlightHandleColor,
textBackgroundColor: highlightBackgroundColor
},
{
name: '文字/背景=高亮背景',
description: '文字颜色与文字背景色都等于高亮背景色。',
textColor: highlightBackgroundColor,
textBackgroundColor: highlightBackgroundColor
},
{
name: '文字/背景=手柄色',
description: '文字颜色与文字背景色都等于操作手柄色。',
textColor: highlightHandleColor,
textBackgroundColor: highlightHandleColor
},
{
name: '普通对照',
description: '文字颜色和文字背景色都避开高亮背景色与操作手柄色。',
textColor: contrastTextColor,
textBackgroundColor: contrastTextBackgroundColor
}
] as HighlightCase[]
const modeItems = ['web', 'native']
const modeItemTypes = ref([{ 'value': 0, 'name': 'web', 'checked': true }, { 'value': 1, 'name': 'native' }] as ItemType[])
const data = reactive({
mode: 'web',
currentCaseIndex: 0,
caseName: highlightCases[0].name,
caseDescription: highlightCases[0].description,
textColor: highlightCases[0].textColor,
textBackgroundColor: highlightCases[0].textBackgroundColor
} as DataType)
const htmlString = ref('')
watch(() : string => data.mode, (mode : string) : void => {
modeItemTypes.value.forEach((item : ItemType) : void => {
item.checked = item.name == mode
})
})
function buildHtml() : string {
const targetStyle = 'color: ' + data.textColor + '; background-color: ' + data.textBackgroundColor + ';'
const highlightBackgroundStyle = 'color: #202124FF; background-color: ' + highlightBackgroundColor + ';'
const highlightHandleStyle = 'color: #FFFFFF; background-color: ' + highlightHandleColor + ';'
return '<p><span>当前用例:</span><span style="' + targetStyle + '">' + data.caseName + '</span></p>' +
'<p><span>用例说明:</span><span>' + data.caseDescription + '</span></p>' +
'<p><span>高亮背景色参考:</span><span style="' + highlightBackgroundStyle + '">' + highlightBackgroundColor + '</span><span> 操作手柄色参考:</span><span style="' + highlightHandleStyle + '">' + highlightHandleColor + '</span></p>' +
'<p><span>目标配置:</span><span>文字颜色 ' + data.textColor + ',文字背景色 ' + data.textBackgroundColor + '</span></p>' +
'<p><span>选择目标:</span><span style="' + targetStyle + '">长按并拖动选择这一段文字,检查高亮背景是否覆盖原文字色与文字背景色,操作手柄是否仍然容易辨认。</span></p>' +
'<p><span style="' + targetStyle + '">这是一段更长的目标文本,用于扩大选区;请从句首拖动到句尾,观察选区边界、半透明高亮背景、操作手柄和文字背景之间的叠加效果。</span></p>' +
'<p><span style="color: #444444; background-color: #FFFFFFFF;">普通文本区域:用于对比无特殊颜色组合时的默认选择效果。</span></p>'
}
function updateHtmlString() {
htmlString.value = buildHtml()
}
function setCase(index : number) {
if (index < 0 || index >= highlightCases.length) {
return
}
const item = highlightCases[index]
data.currentCaseIndex = index
data.caseName = item.name
data.caseDescription = item.description
data.textColor = item.textColor
data.textBackgroundColor = item.textBackgroundColor
updateHtmlString()
}
function onModeChange(value : number) {
data.mode = modeItems[value]
}
updateHtmlString()
defineExpose({
data,
highlightCases,
setCase
})
</script>
<style>
.toolbar {
padding: 12px;
background-color: #ffffff;
border-radius: 8px;
}
.toolbar-row {
flex-direction: row;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
}
.toolbar-label {
font-size: 14px;
color: #333333;
}
.color-reference {
flex-direction: row;
flex-wrap: wrap;
margin-bottom: 8px;
}
.reference-text {
margin-right: 12px;
margin-bottom: 4px;
font-size: 13px;
color: #555555;
line-height: 20px;
}
.case-grid {
flex-direction: row;
flex-wrap: wrap;
margin-bottom: 8px;
}
.case-button {
width: 31%;
margin-right: 6px;
margin-bottom: 8px;
font-size: 12px;
}
.case-button-active {
background-color: #4285F4;
color: #ffffff;
}
.tip-text {
font-size: 13px;
color: #666666;
line-height: 20px;
}
.content-card {
margin-top: 12px;
padding: 16px;
background-color: #ffffff;
border-width: 1px;
border-style: solid;
border-color: #d8d8d8;
border-radius: 8px;
}
.rich-text-content {
width: 100%;
min-height: 240px;
}
.legend {
margin-top: 12px;
padding: 12px;
background-color: #ffffff;
border-radius: 8px;
}
.legend-text {
font-size: 13px;
color: #555555;
line-height: 22px;
}
</style>

查看文件

@@ -0,0 +1,24 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const PAGE_PATH = '/pages/component/rich-text/rich-text-list'
describe('rich-text-list', () => {
if (isMP) {
it('skip', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(1500);
})
// 覆盖iOS平台bug,list 中使用 rich-text 时会引起崩溃
it('richt-text-in-list', async () => {
expect(1).toBe(1)
})
})

查看文件

@@ -0,0 +1,20 @@
<template>
<view style="flex: 1;">
<list-view style="flex: 1;">
<list-item v-for="index in 5" :key="index" type=1 :name="index">
<rich-text :nodes="text"></rich-text>
<text style="height: 150px;">{{ index }}</text>
</list-item>
</list-view>
</view>
</template>
<script setup lang="uts">
const text = ref("<h2>uni-app x,终极跨平台方案</h2>")
</script>
<style>
</style>

查看文件

@@ -0,0 +1,45 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isAndroid = platformInfo.startsWith('android');
const isHarmony = platformInfo.startsWith('harmony')
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
async function screenshot(name) {
const image = await program.screenshot({
fullPage: true
})
expect(image).toSaveImageSnapshot({
customSnapshotIdentifier() {
return name
}
})
}
describe("rich-text-tags", () => {
if (isMP || isAppWebView) {
it('skip', () => {
expect(1).toBe(1)
})
return
}
let page;
it("screenshot", async () => {
page = await program.reLaunch('/pages/component/rich-text/rich-text-tags');
await page.waitFor('view');
await page.waitFor(4000)
await screenshot('rich-text-tags-web')
})
if (isAndroid) {
it("test attr mode", async () => {
await page.setData({
modeData: {
mode: 'native'
}
});
await page.waitFor(1000);
await screenshot('rich-text-tags-native')
});
}
});

查看文件

@@ -0,0 +1,383 @@
<template>
<!-- #ifdef APP && !VUE3-VAPOR -->
<scroll-view style="flex: 1;">
<!-- #endif -->
<page-head title="单tag测试(web模式时页面中有较多web-view)"></page-head>
<!-- #ifdef APP-ANDROID || (APP-HARMONY && VUE3-VAPOR) || (APP-IOS && VUE3-VAPOR)-->
<enum-data title="设置mode(仅Android和鸿蒙蒸汽模式支持,默认值为web)" :items="modeItemTypes" @change="onModeChange"></enum-data>
<!-- #endif -->
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">
<text class="uni-title-text">支持的HTML标签</text>
</view>
<view class="uni-common-mt" v-for="(item,index) in data" :key="index">
<text class="uni-subtitle-text">{{item.name}}</text>
<view style="background:#FFFFFF;">
<rich-text :nodes="item.html" @itemclick="itemClick" :mode="modeData.mode"></rich-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';
type TagInfo = {
name : string,
html : Array<UTSJSONObject>
}
const data = ref<Array<TagInfo>>([
{
name: '<br/>',
html: [
{
name: 'br'
},
{
type: 'text',
text: 'hello uni-app x'
},
{
name: 'br'
},
{
type: 'text',
text: 'hello uni-app x'
}
] as Array<UTSJSONObject>
},
{
name: '<p/>',
html: [
{
name: 'p',
attrs: {
style: 'text-align: center; text-decoration: line-through;'
},
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
},
{
name: 'p',
attrs: {
style: 'background-color: green; color: red;'
},
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<ul/> <li/>',
html: [
{
name: 'ul',
children: [
{
name: 'li',
attrs: {
style: 'text-decoration: line-through; text-align: center;'
},
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
},
{
name: 'li',
attrs: {
style: 'color: red; background-color: green; text-align: center;'
},
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
],
}
] as Array<UTSJSONObject>
},
{
name: '<span/>',
html: [
{
name: 'span',
attrs: {
style: 'color: red; background-color: green; text-decoration: line-through;'
},
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<strong/>',
html: [
{
name: 'strong',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<i/>',
html: [
{
name: 'i',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<big/>',
html: [
{
name: 'big',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<small/>',
html: [
{
name: 'small',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<a/>',
html: [
{
name: 'a',
attrs: {
href: 'https://www.baidu.com'
},
children: [
{
type: 'text',
text: '百度'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<u/>',
html: [
{
name: 'u',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<del/>',
html: [
{
name: 'del',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<h1/> <h2/> <h3/> <h4/> <h5/> <h6/>',
html: [
{
name: 'h1',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
},
{
name: 'h2',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
},
{
name: 'h3',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
},
{
name: 'h4',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
},
{
name: 'h5',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
},
{
name: 'h6',
children: [
{
type: 'text',
text: 'hello uni-app x'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '带 # 内容',
html: [
{
name: 'span',
attrs: {
style: "color: #42b983;"
},
children: [
{
type: 'text',
text: 'span 标签 style 中使用 16 进制颜色 # 正常显示'
}
]
}
] as Array<UTSJSONObject>
},
{
name: '<img/>',
html: [
{
name: 'img',
attrs: {
src: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png',
width: '100',
height: '100'
}
}
] as Array<UTSJSONObject>
},
{
name: '超长链接是否换行测试,rich-text组件应该适当位置换行',
html: [
{
name: "p",
attrs: {
style: "font-family: PingFang-SC, PingFang-SC; font-weight: 500; font-size: 28rpx; color: #333333; line-height: 40rpx; letter-spacing: 1px; margin-bottom: 16rpx;"
},
children: [
{
name: "span",
attrs: {
style: "font-size:16px"
},
children: [
{
text: "uni-app x超长链接换行测试:https://doc.dcloud.net.cn/uni-app-x/testlonglonglonglonglonglonglonglongltlonglonglonglonglonglonglonglonglononglink.com"
}
]
}
]
}
] as Array<UTSJSONObject>
},
] as Array<TagInfo>)
type ModeDataType = {
mode: string
}
const modeData = reactive({
mode: 'web'
} as ModeDataType)
const modeItems = ref(['web', 'native'])
const modeItemTypes = ref<ItemType[]>([{ 'value': 0, 'name': 'web', 'checked': true }, { 'value': 1, 'name': 'native' }] as ItemType[])
function itemClick(e : UniRichTextItemClickEvent) {
console.log(JSON.stringify(e.detail));
let clicktext = '';
if (e.detail.src != null) {
clicktext = '点击了图片,src = ' + e.detail.src;
} else if (e.detail.href != null) {
clicktext = '点击了链接,href = ' + e.detail.href;
}
uni.showModal({
content: clicktext,
showCancel: false
});
}
function onModeChange(value : number) {
modeData.mode = modeItems.value[value];
}
defineExpose({
modeData
})
</script>

查看文件

@@ -0,0 +1,225 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
const isIos = platformInfo.startsWith('ios')
const isHarmony = platformInfo.startsWith('harmony')
const isAndroid = platformInfo.startsWith('android')
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
const PAGE_PATH = '/pages/component/rich-text/rich-text'
describe('rich-text-test', () => {
if (isMP) {
it('skip', () => {
expect(1).toBe(1)
})
return
}
let page
let deviceShotOptions = { fullPage: true }
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(1500);
if (!isWeb) {
const windowInfo = await program.callUniMethod('getWindowInfo');
let topSafeArea = windowInfo.safeAreaInsets.top;
if (isAppWebView) {
if (isIos) {
topSafeArea = 59
if (platformInfo.includes('26')) {
topSafeArea = 62
}
} else if (isAndroid) {
topSafeArea = 24
windowInfo.safeArea.bottom = 867
if (platformInfo.startsWith('android 5')) {
topSafeArea = 25
}if (platformInfo.startsWith('android 6')) {
windowInfo.safeArea.bottom = 592
}if (platformInfo.startsWith('android 8')) {
windowInfo.safeArea.bottom = 534
} else if (platformInfo.startsWith('android 11')) {
topSafeArea = 52
} else if (platformInfo.startsWith('android 12')) {
topSafeArea = 24
windowInfo.safeArea.bottom = 716
} else if (platformInfo.startsWith('android 13') || platformInfo.startsWith('android 15')) {
topSafeArea = 49
windowInfo.safeArea.bottom = 891
} else if (platformInfo.startsWith('android 14')) {
windowInfo.safeArea.bottom = 891
}
} else if (isHarmony) {
topSafeArea = 39
if (platformInfo.includes('nova_12')) {
topSafeArea = 35
}
}
}
const top = topSafeArea + 44
const bottom = Math.min(top + windowInfo.windowHeight, windowInfo.safeArea.bottom)
const left = windowInfo.safeArea.left
const right = windowInfo.safeArea.right - 10
deviceShotOptions = {
deviceShot: true,
area: {
x: left,
y: top,
width: right - left,
height: bottom - top
},
}
}
})
async function setPageData(newData) {
return await page.setData({ data: newData });
}
it('richt-text-height', async () => {
let beforeValue = await page.data('data.richTextHeight')
if (beforeValue < 10) {
await page.waitFor(2000)
beforeValue = await page.data('data.richTextHeight')
if (beforeValue < 10) {
await page.waitFor(2000)
beforeValue = await page.data('data.richTextHeight')
}
}
await page.callMethod('changeText')
await page.waitFor(2000)
await page.callMethod('changeText')
await page.waitFor(2000)
let afterValue = await page.data('data.richTextHeight')
console.log('beforeValue:', beforeValue)
console.log('afterValue:', afterValue)
expect(Math.abs(beforeValue - afterValue) < 0.1).toBe(true)
})
it('rich-text parent click', async () => {
const element = await page.$('#rich-text-parent')
await element.tap()
await page.waitFor(500)
const element2 = await page.$('#rich-text-str')
expect(await element2.text()).toBe("true")
})
it('test style font-size-12px', async () => {
await page.callMethod('changeFontSize')
await page.waitFor(500)
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
})
it('test style font-size-16px', async () => {
await page.callMethod('changeFontSize')
await page.waitFor(500)
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
// 重置为默认
await setPageData({
currentFontSize: "默认",
currentColor: "默认",
currentLineHeight: "默认",
currentFontFamily: "默认",
fontSizeIndex: 0,
colorIndex: 0,
lineHeightIndex: 0,
fontFamilyIndex: 0,
richTextStyle: 'border: 1px; border-style: solid; border-color: red;'
})
await page.waitFor(300)
})
it('test style color-red', async () => {
await page.callMethod('changeColor')
await page.waitFor(500)
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
})
it('test style color-blue', async () => {
await page.callMethod('changeColor')
await page.waitFor(500)
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
// 重置为默认
await setPageData({
currentFontSize: "默认",
currentColor: "默认",
currentLineHeight: "默认",
currentFontFamily: "默认",
fontSizeIndex: 0,
colorIndex: 0,
lineHeightIndex: 0,
fontFamilyIndex: 0,
richTextStyle: 'border: 1px; border-style: solid; border-color: red;'
})
await page.waitFor(300)
})
it('test style line-height-1', async () => {
await page.callMethod('changeLineHeight')
await page.waitFor(500)
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
})
it('test style line-height-1.5', async () => {
await page.callMethod('changeLineHeight')
await page.waitFor(500)
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
// 重置为默认
await setPageData({
currentFontSize: "默认",
currentColor: "默认",
currentLineHeight: "默认",
currentFontFamily: "默认",
fontSizeIndex: 0,
colorIndex: 0,
lineHeightIndex: 0,
fontFamilyIndex: 0,
richTextStyle: 'border: 1px; border-style: solid; border-color: red;'
})
await page.waitFor(300)
})
it('test style font-family-serif', async () => {
await page.callMethod('changeFontFamily')
await page.waitFor(500)
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
})
it('test style font-family-sans-serif', async () => {
await page.callMethod('changeFontFamily')
await page.waitFor(500)
const image = await program.screenshot({ fullPage: true })
expect(image).toSaveImageSnapshot()
// 重置为默认
await setPageData({
currentFontSize: "默认",
currentColor: "默认",
currentLineHeight: "默认",
currentFontFamily: "默认",
fontSizeIndex: 0,
colorIndex: 0,
lineHeightIndex: 0,
fontFamilyIndex: 0,
richTextStyle: 'border: 1px; border-style: solid; border-color: red;'
})
await page.waitFor(300)
})
it('test dialogPage', async () => {
await page.callMethod('testOpenDialogPage');
await page.waitFor(1000);
const image = await program.screenshot(deviceShotOptions);
expect(image).toSaveImageSnapshot();
await page.callMethod('testCloseDialogPage');
})
})

查看文件

@@ -0,0 +1,214 @@
<template>
<!-- #ifdef APP && !VUE3-VAPOR -->
<scroll-view style="flex: 1;">
<!-- #endif -->
<view class="uni-padding-wrap uni-common-mt">
<navigator url="/pages/component/rich-text/rich-text-tags" class="uni-btn-v">
<button>rich-text渲染单个HTML标签示例</button>
</navigator>
<navigator url="/pages/component/rich-text/rich-text-complex" class="uni-btn-v">
<button>rich-text渲染复杂HTML示例</button>
</navigator>
<navigator url="/pages/component/rich-text/rich-text-highlight" class="uni-btn-v">
<button>rich-text高亮覆盖测试</button>
</navigator>
<navigator url="/pages/template/long-rich-text/long-rich-text" class="uni-btn-v">
<button class="uni-btn">组件性能测试</button>
</navigator>
<view class="uni-title">
<button type="default" @click="changeText">修改文本内容</button>
</view>
<view class="uni-title">
<button type="default" @click="changeFontSize">切换 font-size ({{ data.currentFontSize }})</button>
</view>
<view class="uni-title">
<button type="default" @click="changeColor">切换 color ({{ data.currentColor }})</button>
</view>
<view class="uni-title">
<button type="default" @click="changeLineHeight">切换 line-height ({{ data.currentLineHeight }})</button>
</view>
<view class="uni-title">
<button type="default" @click="changeFontFamily">切换 font-family ({{ data.currentFontFamily }})</button>
</view>
<view class="text-box" id="rich-text-parent" @click="richTextParentClick">
<rich-text id='rich-text' :style="data.richTextStyle" :nodes="data.text" mode="native">
</rich-text>
<view>
<text>rich-text-parent</text>
<text id='rich-text-str'>{{ data.richTextStr }}</text>
</view>
</view>
<view class="uni-title">
<text class="uni-subtitle-text">selectable</text>
</view>
<view class="text-box2">
<rich-text style="height: 80px;" :selectable="true" :nodes="data.text"></rich-text>
</view>
</view>
<!-- #ifdef APP && !VUE3-VAPOR -->
</scroll-view>
<!-- #endif -->
</template>
<script setup lang="uts">
type DataType = {
text : string;
richTextHeight : number;
richTextElement : UniElement | null;
richTextStr : boolean;
richTextStyle : string;
currentFontSize : string;
currentColor : string;
currentLineHeight : string;
currentFontFamily : string;
fontSizeIndex : number;
colorIndex : number;
lineHeightIndex : number;
fontFamilyIndex : number;
}
// 定义各属性的可选值
const fontSizeList : string[] = ["默认", "12px", "16px", "20px", "24px", "32px"]
const colorList : string[] = ["默认", "red", "blue", "green", "#ff9800", "#8e44ad"]
const lineHeightList : string[] = ["默认", "1", "1.5", "2", "2.5", "3"]
const fontFamilyList : string[] = ["默认", "serif", "sans-serif", "monospace", "cursive"]
// 使用reactive避免ref数据在自动化测试中无法访问
const data = reactive({
text: "<span>hello uni-app x!</span><br/><span>uni-app x,终极跨平台方案</span>",
richTextHeight: 0,
richTextElement: null,
richTextStr: false,
richTextStyle: "border: 1px; border-style: solid; border-color: red;",
currentFontSize: "默认",
currentColor: "默认",
currentLineHeight: "默认",
currentFontFamily: "默认",
fontSizeIndex: 0,
colorIndex: 0,
lineHeightIndex: 0,
fontFamilyIndex: 0
} as DataType)
const updateRichTextHeight = () => {
if (data.richTextElement != null) {
data.richTextElement!.getBoundingClientRectAsync()!.then((elRect : DOMRect) => {
data.richTextHeight = elRect.height
console.log('richTextHeight:', data.richTextHeight)
})
}
}
onReady(() => {
data.richTextElement = uni.getElementById('rich-text') as UniElement
console.log("onReady 加载完成,richTextElement= ", data.richTextElement?.tagName)
setTimeout(() => {
updateRichTextHeight()
}, 2500)
})
const changeText = () => {
if (data.text === "<span>hello uni-app x!</span><br/><span>uni-app x,终极跨平台方案</span>") {
data.text = "<h1>hello uni-app x!</h1><br/><h2>uni-app x,终极跨平台方案</h2>"
} else {
data.text = "<span>hello uni-app x!</span><br/><span>uni-app x,终极跨平台方案</span>"
}
nextTick(() => {
setTimeout(() => {
console.log("修改文本内容: ", data.text)
updateRichTextHeight()
}, 1000)
})
}
// 更新组合样式
const updateRichTextStyle = () => {
let style = "border: 1px; border-style: solid; border-color: red;"
if (data.currentFontSize != "默认") {
style += " font-size: " + data.currentFontSize + ";"
}
if (data.currentColor != "默认") {
style += " color: " + data.currentColor + ";"
}
if (data.currentLineHeight != "默认") {
style += " line-height: " + data.currentLineHeight + ";"
}
if (data.currentFontFamily != "默认") {
style += " font-family: " + data.currentFontFamily + ";"
}
data.richTextStyle = style
console.log("更新样式:", data.richTextStyle)
}
const changeFontSize = () => {
data.fontSizeIndex = (data.fontSizeIndex + 1) % fontSizeList.length
data.currentFontSize = fontSizeList[data.fontSizeIndex]
console.log("切换 font-size:", data.currentFontSize)
updateRichTextStyle()
}
const changeColor = () => {
data.colorIndex = (data.colorIndex + 1) % colorList.length
data.currentColor = colorList[data.colorIndex]
console.log("切换 color:", data.currentColor)
updateRichTextStyle()
}
const changeLineHeight = () => {
data.lineHeightIndex = (data.lineHeightIndex + 1) % lineHeightList.length
data.currentLineHeight = lineHeightList[data.lineHeightIndex]
console.log("切换 line-height:", data.currentLineHeight)
updateRichTextStyle()
}
const changeFontFamily = () => {
data.fontFamilyIndex = (data.fontFamilyIndex + 1) % fontFamilyList.length
data.currentFontFamily = fontFamilyList[data.fontFamilyIndex]
console.log("切换 font-family:", data.currentFontFamily)
updateRichTextStyle()
}
const getBoundingClientRectForTest = () : DOMRect => {
return uni.getElementById('test-rich-text')?.getBoundingClientRect()!;
}
const richTextParentClick = () => {
data.richTextStr = true;
}
const testOpenDialogPage = () => {
uni.openDialogPage({
url: '/pages/API/dialog-page/rich-text-in-dialog-page'
});
}
const testCloseDialogPage = () => {
uni.closeDialogPage();
}
defineExpose({
data,
changeText,
changeFontSize,
changeColor,
changeLineHeight,
changeFontFamily,
getBoundingClientRectForTest,
testOpenDialogPage,
testCloseDialogPage
})
</script>
<style>
.text-box {
padding: 20px 0;
background-color: white;
}
.text-box2 {
top: 20px;
background-color: white;
}
</style>