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

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

查看文件

@@ -0,0 +1,162 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
const isHarmony = platformInfo.startsWith('harmony')
const isDom2 = process.env.UNI_APP_X_DOM2 === "true"
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
const PAGE_PATH = '/pages/component/picker-view/picker-view'
let page, pickerViewEl;
describe('PickerView.uvue', () => {
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(1000)
await page.callMethod('setEventCallbackNumTest', 0)
pickerViewEl = await page.$('.picker-view')
})
async function toScreenshot(imgName) {
const image = await program.screenshot({
fullPage: true
});
expect(image).toSaveImageSnapshot({
customSnapshotIdentifier() {
return imgName
}
})
await page.waitFor(500);
}
async function getPickerViewValue() {
const value = await pickerViewEl.property('value')
return value == null ? await page.data('data.value') : value
}
function stringifyPickerViewValue(value) {
return Array.isArray(value) ? value.join(',') : String(value)
}
it('value', async () => {
await page.callMethod('setValue')
await page.waitFor(1500)
const newValue1 = await getPickerViewValue()
// TODO
expect(stringifyPickerViewValue(newValue1)).toEqual('0,1,30')
// 仅在App端,setValue可触发change事件
if ((isAndroid && !isDom2) || (isIOS && !isDom2)) {
const res = await page.data('data.result')
await page.waitFor(500)
expect(res).toEqual([ 0, 1, 30 ])
}
await page.callMethod('setValue1')
await page.waitFor(1500)
const newValue2 = await getPickerViewValue()
// TODO
expect(stringifyPickerViewValue(newValue2)).toEqual('10,10,10')
if ((isAndroid && !isDom2) || (isIOS && !isDom2)) {
const res = await page.data('data.result')
await page.waitFor(500)
expect(res).toEqual([10, 10, 10])
}
})
it('length', async () => {
const els = await page.$$('.picker-view')
expect(els.length).toBe(1)
const els1 = await page.$$('.picker-view-column')
expect(els1.length).toBe(3)
})
// indicatorStyle 属性在编译时被解析成了对象,在获取时和用户设置的值格式不一样 [object Object]
// app-ios 同上
if (!isHarmony && !isIOS) {
it('indicator-style', async () => {
const indicatorStyle = "height: 50px;border:#ff5500 solid 1px;background:rgba(182, 179, 255, 0.4);"
await page.callMethod('setIndicatorStyle',true)
await page.waitFor(500)
expect(await pickerViewEl.attribute(isMP ? 'indicator-style' : 'indicatorStyle')).toBe(indicatorStyle)
await toScreenshot('picker-view-indicator-style')
//清空indicatorStyle
await page.callMethod('setIndicatorStyle',false)
})
}
if (isWeb || isMP) {
// indicator-class、mask-style、mask-class 仅web和MP支持
it('indicator-class', async () => {
//设置indicator-class
await page.callMethod('setIndicatorClass',true)
expect(await pickerViewEl.attribute(isMP ? 'indicator-class': 'indicatorClass')).toBe("indicator-test")
await toScreenshot('picker-view-web-indicator-class')
//清空indicatorClass
await page.callMethod('setIndicatorClass',false)
})
it('mask-style', async () => {
const maskStyle = "background-image: linear-gradient(to bottom, #d8e5ff, rgba(216, 229, 255, 0));"
// 设置mask-style
await page.callMethod('setMaskStyle',true)
expect(await pickerViewEl.attribute(isMP ? 'mask-style' : 'maskStyle')).toBe(maskStyle)
await toScreenshot('picker-view-web-mask-style')
})
it('mask-class', async () => {
// 设置mask-class
await page.callMethod('setMaskClass',true)
expect(await pickerViewEl.attribute(isMP ? 'mask-class' : 'maskClass')).toBe("mask-test")
await toScreenshot('picker-view-web-mask-class')
})
return
}
if (!isAppWebView && !isMP && !isHarmony && !(isIOS && isDom2) && !(isAndroid && isDom2)) {
it('mask-top-bottom-style', async () => {
// mask-top-style、mask-bottom-style仅App端支持
const linearToTop = "background-image: linear-gradient(to bottom, #f4ff73, rgba(216, 229, 255, 0));"
const linearToBottom = "background-image: linear-gradient(to top, #f4ff73, rgba(216, 229, 255, 0));"
// 第一次激活:设置黄色渐变
await page.callMethod('setMaskTopStyle',true)
await page.callMethod('setMaskBottomStyle',true)
await page.waitFor(500)
expect(await pickerViewEl.attribute('mask-top-style')).toBe(linearToTop)
expect(await pickerViewEl.attribute('mask-bottom-style')).toBe(linearToBottom)
await page.waitFor(2000)
await toScreenshot('picker-view-app-mask-top-bottom-style')
// 第二次点击:切换回原始状态
await page.callMethod('setMaskTopStyle',false)
await page.callMethod('setMaskBottomStyle',false)
await page.waitFor(500)
expect(await pickerViewEl.attribute('mask-top-style')).toBe('')
expect(await pickerViewEl.attribute('mask-bottom-style')).toBe('')
await page.waitFor(1000)
await toScreenshot('picker-view-app-mask-top-bottom-style-cleared')
})
it('reopen-picker-view-page', async () => {
page = await program.switchTab('/pages/tabBar/component')
await page.waitFor(500)
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(500)
const {
year,
month,
day
} = await page.data('data')
expect(year).toEqual(2018)
expect(month).toEqual(1)
expect(day).toEqual(12)
})
it('trigger UniPickerViewChangeEvent', async () => {
await page.callMethod('setEventCallbackNumTest', 0)
await page.callMethod('setValue')
await page.waitFor(1500)
const eventCallbackNum = await page.callMethod('getEventCallbackNum')
// 年月日滚动三次,测试 e.tagName +1 和 e.type+2,正常为9
expect(eventCallbackNum).toBe(9)
})
}
})

查看文件

@@ -0,0 +1,219 @@
<template>
<view>
<page-head :title="data.title"></page-head>
<view class="uni-padding-wrap">
<view class="uni-title">
日期:{{data.year}}年{{data.month}}月{{data.day}}日
</view>
</view>
<picker-view class="picker-view" :value="data.value" @change="bindChange" :indicator-style="data.indicatorStyle"
:indicator-class="data.indicatorClass" :mask-style="data.maskStyle" :mask-class="data.maskClass" :mask-top-style="data.maskTopStyle"
:mask-bottom-style="data.maskBottomStyle">
<picker-view-column class="picker-view-column">
<view class="item" v-for="(item,index) in data.years" :key="index"><text class="text">{{item}}年</text></view>
</picker-view-column>
<picker-view-column class="picker-view-column">
<view class="item" v-for="(item,index) in data.months" :key="index"><text class="text">{{item}}月</text>
</view>
</picker-view-column>
<picker-view-column class="picker-view-column">
<view class="item" v-for="(item,index) in data.days" :key="index"><text class="text">{{item}}日</text></view>
</picker-view-column>
</picker-view>
<boolean-data :defaultValue="false" title="设置选择器中间选中框的样式" @change="setIndicatorStyle"></boolean-data>
<!-- #ifdef WEB || MP-WEIXIN -->
<boolean-data :defaultValue="false" title="设置选择器中间选中框的类名" @change="setIndicatorClass"></boolean-data>
<boolean-data :defaultValue="false" title="设置蒙层的样式" @change="setMaskStyle"></boolean-data>
<boolean-data :defaultValue="false" title="设置蒙层的类名" @change="setMaskClass"></boolean-data>
<!-- #endif -->
<!-- #ifdef APP -->
<boolean-data :defaultValue="false" title="设置蒙层上半部分的样式" @change="setMaskTopStyle"></boolean-data>
<boolean-data :defaultValue="false" title="设置蒙层下半部分的样式" @change="setMaskBottomStyle"></boolean-data>
<!-- #endif -->
</view>
</template>
<script setup lang="uts">
import { state, setEventCallbackNum } from '@/store/index.uts'
type DataType = {
title: string;
years: number[];
year: number;
months: number[];
month: number;
days: number[];
day: number;
value: number[];
result: number[];
indicatorStyle: string;
indicatorClass: string;
maskStyle: string;
maskClass: string;
maskTopStyle: string;
maskBottomStyle: string;
}
// 初始化数据
// 20180112 HBuilderX内测开始 :)
const _years : number[] = []
const _year = 2018
const _months : number[] = []
const _month : number = 1
const _days : number[] = []
const _day = 12
for (let i = 2000; i <= _year; i++) {
_years.push(i)
}
for (let i = 1; i <= 12; i++) {
_months.push(i)
}
for (let i = 1; i <= 31; i++) {
_days.push(i)
}
// 使用reactive避免ref数据在自动化测试中无法访问
const data = reactive({
title: 'picker-view',
years: _years,
year: _year,
months: _months,
month: _month,
days: _days,
day: _day,
value: [_year - 2000, _month - 1, _day - 1],
result: [],
indicatorStyle: 'height: 50px;',
indicatorClass: '',
maskStyle: '',
maskClass: '',
maskTopStyle: '',
maskBottomStyle: ''
} as DataType)
const setIndicatorStyle = (checked : boolean) => {
const extraStyle = 'height: 50px;border:#ff5500 solid 1px;background:rgba(182, 179, 255, 0.4);';
// #ifdef APP-HARMONY
data.indicatorStyle = checked ? extraStyle : "height: 50px;border:none;background:transparent;";
// #endif
// #ifndef APP-HARMONY
data.indicatorStyle = checked ? extraStyle : "height: 50px;";
// #endif
}
const setIndicatorClass = (checked : boolean) => {
data.indicatorClass = checked ? "indicator-test" : ""
}
const setMaskStyle = (checked : boolean) => {
const extraMaskStyle = "background-image: linear-gradient(to bottom, #d8e5ff, rgba(216, 229, 255, 0));"
data.maskStyle = checked ? extraMaskStyle : ""
}
const setMaskClass = (checked : boolean) => {
data.maskClass = checked ? "mask-test" : ""
}
const setMaskTopStyle = (checked : boolean) => {
const linearToTop = "background-image: linear-gradient(to bottom, #f4ff73, rgba(216, 229, 255, 0));"
// #ifdef APP-HARMONY && !VUE3-VAPOR
data.maskTopStyle = checked ? linearToTop : "background-image: linear-gradient(to bottom, transparent, transparent);"
// #endif
// #ifdef APP-HARMONY && VUE3-VAPOR
data.maskTopStyle = checked ? linearToTop : ""
// #endif
// #ifndef APP-HARMONY
data.maskTopStyle = checked ? linearToTop : ""
// #endif
}
const setMaskBottomStyle = (checked : boolean) => {
const linearToBottom = "background-image: linear-gradient(to top, #f4ff73, rgba(216, 229, 255, 0));"
// #ifdef APP-HARMONY && !VUE3-VAPOR
data.maskBottomStyle = checked ? linearToBottom : "background-image: linear-gradient(to bottom, transparent, transparent);"
// #endif
// #ifdef APP-HARMONY && VUE3-VAPOR
data.maskBottomStyle = checked ? linearToBottom : ""
// #endif
// #ifndef APP-HARMONY
data.maskBottomStyle = checked ? linearToBottom : ""
// #endif
}
// 自动化测试
const getEventCallbackNum = () : number => {
return state.eventCallbackNum
}
// 自动化测试
const setEventCallbackNumTest = (num : number) => {
setEventCallbackNum(num)
}
const bindChange = (e : UniPickerViewChangeEvent) => {
// 自动化测试 触发事件元素、type 类型
// console.log(e.target?.tagName, e.type);
if ((e.target?.tagName ?? '').includes('PICKER-VIEW')) {
setEventCallbackNumTest(state.eventCallbackNum + 1)
}
if (e.type === 'change') {
setEventCallbackNumTest(state.eventCallbackNum + 2)
}
const val = e.detail.value
data.result = val
data.year = data.years[val[0]]
data.month = data.months[val[1]]
data.day = data.days[val[2]]
}
const setValue = () => {
data.value = [0, 1, 30] as number[]
}
const setValue1 = () => {
data.value = [10, 10, 10] as number[]
}
defineExpose({
data,
setIndicatorStyle,
setIndicatorClass,
setMaskStyle,
setMaskClass,
setMaskTopStyle,
setMaskBottomStyle,
getEventCallbackNum,
setEventCallbackNumTest,
setValue,
setValue1
})
</script>
<style>
.picker-view {
width: 100%;
height: 320px;
margin-top: 10px;
margin-bottom: 20px;
}
.item {
height: 50px;
}
.text {
line-height: 50px;
text-align: center;
}
/* 自动化测试 */
.indicator-test {
height: 50px;
border: #ff5500 solid 1px;
background:rgba(182, 179, 255, 0.4);
}
.mask-test {
background-image: linear-gradient(to bottom, #d8e5ff, rgba(216, 229, 255, 0));
}
</style>

查看文件

@@ -0,0 +1,28 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const PAGE_PATH = '/pages/component/picker-view/wrap-picker-view'
let page;
describe('wrap-picker-view', () => {
if (isMP) {
it('skip', () => {
expect(1).toBe(1)
})
return
}
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
// 此测试用例单独项目进行测试
it.skip('not crash', async () => {
// 测试应用正常渲染,可以正常查询元素不会崩溃丢失
const element = await page.$('.btn_toggle')
await element.tap()
await page.waitFor(1000)
const childExits = await page.$('.btn_toggle')
expect(!!childExits).toBe(true)
})
})

查看文件

@@ -0,0 +1,32 @@
<template>
<view>
<MyPickerView ref='pickerViewRef' v-if='visible'></MyPickerView>
<button class="btn_toggle" @click="toggle">btn</button>
</view>
</template>
<script setup lang="uts">
import MyPickerView from './picker-view.uvue'
const visible = ref(false)
const pickerViewRef = ref<ComponentPublicInstance | null>(null)
function setValue() {
if (pickerViewRef.value != null) {
pickerViewRef.value!.$callMethod('setValue')
}
}
function toggle() {
visible.value = !visible.value
if (visible.value) {
nextTick(() => {
setValue()
})
}
}
</script>
<style>
</style>