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

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

查看文件

@@ -0,0 +1,300 @@
<template>
<view class="swiper-list">
<scroll-view ref="tabScroll" class="swiper-tabs" direction="horizontal" :show-scrollbar="false">
<view class="flex-row">
<text :ref="setSwiperTabRef" class="swiper-tabs-item"
:class="swiperIndex==index ? 'swiper-tabs-item-active' : ''" v-for="(item, index) in swiperList" :key="index"
@click="onTabClick(index)">
{{item.title}}
</text>
</view>
<view ref="indicator" class="swiper-tabs-indicator"></view>
</scroll-view>
<swiper ref="swiper" class="swiper-view" :current="swiperIndex" @transition="onSwiperTransition"
@animationfinish="onSwiperAnimationfinish">
<swiper-item class="swiper-item" v-for="(_, index) in swiperList" :key="index">
<text class="uni-title">显示当前value</text>
<slider :value="50" :show-value="true" />
<text class="uni-title">设置步进:step=10跳动</text>
<slider :value="60" :step="10" />
<text class="uni-title">浮点步进:step=0.01跳动</text>
<slider :value="0.5" :min="0" :max="1" :step="0.01" :show-value="true" />
<text class="uni-title">设置最小/最大值</text>
<slider :value="100" :min="50" :max="200" :show-value="true" />
<text class="uni-title">不同颜色和大小的滑块</text>
<slider id="slider-custom-color-and-size" :value="sliderValue" :backgroundColor="sliderBackgroundColor"
:activeColor="sliderActiveColor" :activeBackgroundColor="sliderActiveColor" :blockColor="sliderBlockColor"
:foreColor="sliderBlockColor" :block-size="sliderBlockSize" track-active-class="track-active-class" track-class="track-class" thumb-class="thumb-class"/>
</swiper-item>
</swiper>
</view>
</template>
<script setup lang="uts">
type SwiperTabsItem = {
x : number,
w : number
}
type SwiperViewItem = {
title : string,
}
/**
* 根据权重在两个值之间执行线性插值.
* @constructor
* @param {number} value1 - 第一个值,该值应为下限.
* @param {number} value2 - 第二个值,该值应为上限.
* @param {number} amount - 应介于 0 和 1 之间,指示内插的权重.
* @returns {number} 内插值
*/
function lerpNumber(value1 : number, value2 : number, amount : number) : number {
return (value1 + (value2 - value1) * amount)
}
const swiperList = ref([] as SwiperViewItem[])
const swiperIndex = ref(0)
const tabScroll = ref<UniElement | null>(null)
const indicator = ref<UniElement | null>(null)
const swiper = ref<UniElement | null>(null)
const animationFinishIndex = ref(0)
const swiperWidth = ref(0)
const swiperTabsRect = ref([] as SwiperTabsItem[])
const swiperTabRefs = ref<UniElement[]>([])
const sliderValue = ref(50)
const sliderBlockSize = ref(20)
const sliderBackgroundColor = ref("#000000")
const sliderActiveColor = ref("#FFCC33")
const sliderBlockColor = ref("#8A6DE9")
// Function to set tab refs in v-for
function setSwiperTabRef(el : UniElement | null) {
if (el != null) {
swiperTabRefs.value.push(el)
}
}
/**
* 更新页签指示线的位置和宽度.
* @constructor
* @param {number} current_index - 当前索引,该值应介于 0 和 最大数量之间.
* @param {number} move_to_index - 目标索引,该值应介于 0 和 最大数量之间.
* @param {number} percentage - 偏移百分比,应介于 0 和 1 之间,用于计算在移动过程中的线性值.
*/
function updateTabIndicator(current_index : number, move_to_index : number, percentage : number) {
// Check if indices are valid
if (current_index < 0 || current_index >= swiperTabsRect.value.length ||
move_to_index < 0 || move_to_index >= swiperTabsRect.value.length) {
return
}
const current_size = swiperTabsRect.value[current_index]
const move_to_size = swiperTabsRect.value[move_to_index]
// 计算指示线 位置 和 宽度 在移动过程中的线性值
const indicator_line_x = lerpNumber(current_size.x, move_to_size.x, percentage)
const indicator_line_w = lerpNumber(current_size.w, move_to_size.w, percentage)
// 通过 transform 更新指示线,避免重排版
// #ifdef APP
const x = indicator_line_x + indicator_line_w / 2
indicator.value?.style?.setProperty('transform', `translateX(${x}px) scaleX(${indicator_line_w})`)
// #endif
// #ifdef WEB || MP
// TODO chrome windows系统 transform scaleX渲染bug
const x = indicator_line_x
indicator.value?.style?.setProperty('width', `${indicator_line_w}px`)
indicator.value?.style?.setProperty('transform', `translateX(${x}px)`)
// #endif
// 滚动到水平中心位置
const scroll_x = x - swiperWidth.value / 2
// app 平台后续支持 scrollTo()
// #ifndef MP-WEIXIN
if (tabScroll.value != null) {
tabScroll.value!.scrollLeft = scroll_x
}
// #endif
// #ifdef MP-WEIXIN
if (tabScroll.value != null) {
tabScroll.value!.scrollTo({
left: scroll_x
})
}
// #endif
}
/**
* 设置当前 swiper 选中的索引值.
* @constructor
* @param {number} index - 当前索引,该值应介于 0 和 最大数量之间.
* @param {boolean} updateIndicator - 是否更新指示线.
*/
function setSwiperIndex(index : number, updateIndicator : boolean) {
if (swiperIndex.value === index) {
return
}
swiperIndex.value = index
if (updateIndicator) {
updateTabIndicator(index, index, 1)
}
}
/**
* 每个页签的点击事件,点击后设置当前 swiper.
* @constructor
* @param {number} index - 当前索引,该值应介于 0 和 最大数量之间.
*/
function onTabClick(index : number) {
setSwiperIndex(index, false)
}
function onSwiperTransition(e : SwiperTransitionEvent) {
// 微信 skyline 每项完成触发 Animationfinish,偏移值重置
// 微信 webview 全部完成触发 Animationfinish,偏移值累加
// 在滑动到下一个项的过程中,再次反向滑动,偏移值递减
// uni-app-x 和 微信 webview 行为一致
const offset_x = e.detail.dx
// 计算当前索引并重置差异
const current_offset_x = offset_x % swiperWidth.value
const current_offset_i = offset_x / swiperWidth.value
const current_index = animationFinishIndex.value + parseInt(current_offset_i + '')
// 计算目标索引及边界检查
let move_to_index = current_index
if (current_offset_x > 0 && move_to_index < swiperList.value.length - 1) {
move_to_index += 1
} else if (current_offset_x < 0 && move_to_index > 0) {
move_to_index -= 1
}
// 计算偏移百分比
const percentage = Math.abs(current_offset_x) / swiperWidth.value
// 通知更新指示线
if (current_index != move_to_index) {
updateTabIndicator(current_index, move_to_index, percentage)
}
}
/**
* Swiper滑动动画结束事件.
*/
function onSwiperAnimationfinish(e : SwiperAnimationFinishEvent) {
setSwiperIndex(e.detail.current, true)
// 记录上次的索引位置
animationFinishIndex.value = e.detail.current
}
/**
* 缓存所有页签的左边距和宽度,用于计算指示线在移动过程中的线性变化.
*/
async function cacheTabItemsSize() {
swiperTabsRect.value.length = 0;
const tabs = swiperTabRefs.value
for (let i = 0; i < tabs.length; i++) {
const element = tabs[i];
// #ifdef MP
const rect = await element.getBoundingClientRectAsync()!
const x = rect.left
const w = rect.width
// #endif
// #ifndef MP
const x = element.offsetLeft
const w = element.offsetWidth
// #endif
swiperTabsRect.value.push({
x,
w
} as SwiperTabsItem)
}
}
onBeforeUpdate(() => {
// Clear refs array before update to prevent duplicates
swiperTabRefs.value = []
})
onLoad(() => {
// 初始化 5 个页签,宽度依次递增,用于演示在滑动 swiper 过程中指示线宽度的线性变化
for (let i = 0; i < 3; i++) {
const space = " ".repeat(i)
swiperList.value.push({
title: "Tab " + space + i
} as SwiperViewItem)
}
})
onReady(() => {
if (swiper.value != null) {
swiper.value!.getBoundingClientRectAsync()!.then((res : DOMRect) : Promise<void> => {
swiperWidth.value = res.width
return cacheTabItemsSize()
}).then(() => {
if (swiperTabsRect.value.length > 0) {
updateTabIndicator(swiperIndex.value, swiperIndex.value, 1)
}
});
}
})
</script>
<style>
.flex-row {
flex-direction: row;
align-self: flex-start;
}
.swiper-list {
flex: 1;
}
.swiper-tabs {
background-color: #ffffff;
}
.swiper-tabs-item {
color: #555;
font-size: 16px;
padding: 12px 25px;
white-space: nowrap;
}
.swiper-tabs-item-active {
color: #007AFF;
}
.swiper-tabs-indicator {
width: 1px;
height: 2px;
background-color: #007AFF;
}
.swiper-view {
flex: 1;
}
.swiper-item {
flex: 1;
padding: 15px;
}
.track-class {
background-color: #000000;
}
.track-active-class {
background-color: #FFCC33;
}
.thumb-class {
width: 20px;
height: 20px;
background-color: #8A6DE9;
border-radius: 10px;
}
</style>

查看文件

@@ -0,0 +1,56 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
const PAGE_PATH = '/pages/component/slider/slider-maxValue'
describe('touch-events-test', () => {
if (isAndroid || isWeb || isMP || process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
it('not support', () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500);
})
it('test-slider-max-value', async () => {
const pageData = await page.data('data')
const sliderX = pageData.sliderX
const sliderY = pageData.sliderY
const x = sliderX + 25
const y = sliderY + 15
// 滑动事件
await program.swipe({
startPoint: {x, y},
endPoint: {x: x + 1000, y},
duration: 300
})
await page.waitFor(600);
const ret = await page.data('data.sliderValue')
expect(ret).toBe(10)
})
it('test-slider-click', async () => {
const pageData = await page.data('data')
const sliderX = pageData.sliderX
const sliderY = pageData.sliderY
const sliderHeight = pageData.sliderHeight
const x = sliderX + 100
const y = sliderY + sliderHeight / 2.0
// 点击事件
await program.tap({x, y})
await page.waitFor(600);
const ret = await page.data('data.sliderValue')
expect(ret).toBeLessThan(10)
})
})

查看文件

@@ -0,0 +1,50 @@
<template>
<view class="uni-padding-wrap">
<view class="uni-title">最大值溢出测试(不能滑动到最右侧)</view>
<view>
<slider id="slider" :value="0" :min="0" :max="10.5" :step="1" :show-value="true" @change="valueChange"/>
</view>
</view>
</template>
<script setup lang="uts">
type DataType = {
sliderX: number,
sliderY: number,
sliderHeight: number,
sliderValue: number,
}
const data = reactive({
sliderX: 0,
sliderY: 0,
sliderHeight: 0,
sliderValue: 0,
} as DataType)
function valueChange(e: UniSliderChangeEvent) {
console.log('valueChange', e.detail.value)
data.sliderValue = e.detail.value
}
onReady(() => {
// #ifdef APP-IOS || APP-HARMONY
const sliderEle = uni.getElementById("slider")
const sliderRect = sliderEle?.getBoundingClientRect()
if (sliderRect != null) {
data.sliderX = sliderRect.x
data.sliderY = sliderRect.y
data.sliderHeight = sliderRect.height
}
// 加上导航栏及状态栏高度
const systemInfo = uni.getSystemInfoSync()
data.sliderY += systemInfo.safeAreaInsets.top + 44
// #endif
})
defineExpose({
data
})
</script>

查看文件

@@ -0,0 +1,104 @@
const PAGE_PATH = '/pages/component/slider/slider'
describe('slider', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
if (isMP) {
it('skip', () => {
expect(1).toBe(1)
})
return
}
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isHarmony = platformInfo.startsWith('harmony')
const isDom2 = process.env.UNI_APP_X_DOM2 == 'true'
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
async function setPageData(newData) {
return await page.setData({ data: newData });
}
it('value', async () => {
const slider = await page.$('#slider-custom-color-and-size')
const sliderValue = 80
await setPageData({
sliderValue: sliderValue
})
await page.waitFor(100)
// TODO
const newValue = await slider.property('value')
expect(newValue.toString()).toBe(sliderValue + '')
})
it('color', async () => {
if (isHarmony && isDom2) {
console.log('Slider Harmony Dom2 not support props backgroundColor、activeColor、blockColor、activeBackgroundColor、foreColor')
expect(1).toBe(1)
return
}
if (isIOS && isDom2) {
console.log('Slider Harmony Dom2 not support props backgroundColor、activeColor、blockColor、activeBackgroundColor、foreColor')
expect(1).toBe(1)
return
}
const slider = await page.$('#slider-custom-color-and-size')
expect(await slider.attribute('backgroundColor')).toBe('#000000')
expect(await slider.attribute('activeColor')).toBe('#FFCC33')
expect(await slider.attribute('blockColor')).toBe('#8A6DE9')
expect(await slider.attribute('activeBackgroundColor')).toBe('#FFCC33')
expect(await slider.attribute('foreColor')).toBe('#8A6DE9')
const backgroundColor = '#008000'
const activeColor = '#00FF00'
const blockColor = '#0000A0'
await setPageData({
sliderBackgroundColor: backgroundColor,
sliderActiveColor: activeColor,
sliderBlockColor: blockColor
})
await page.waitFor(100)
expect(await slider.attribute('backgroundColor')).toBe(backgroundColor)
expect(await slider.attribute('activeColor')).toBe(activeColor)
expect(await slider.attribute('activeBackgroundColor')).toBe(activeColor)
expect(await slider.attribute('blockColor')).toBe(blockColor)
expect(await slider.attribute('foreColor')).toBe(blockColor)
})
it('block-size', async () => {
if (isHarmony && isDom2) {
console.log('Slider Harmony Dom2 not support props block-size')
expect(1).toBe(1)
return
}
if (isIOS && isDom2) {
console.log('Slider iOS Dom2 not support props block-size')
expect(1).toBe(1)
return
}
if (isAndroid && isDom2) {
console.log('Slider Android Dom2 not support props block-size')
expect(1).toBe(1)
return
}
const slider = await page.$('#slider-custom-color-and-size')
expect(await slider.attribute('blockSize')).toBe(20 + '')
const blockSize = 18
await setPageData({
sliderBlockSize: blockSize
})
await page.waitFor(100)
expect(await slider.attribute('blockSize')).toBe(blockSize + '')
})
})

查看文件

@@ -0,0 +1,258 @@
<script setup lang="uts">
type DataType = {
sliderValue: number;
sliderBlockSize: number;
sliderBackgroundColor: string;
sliderActiveColor: string;
sliderBlockColor: string;
// 组件属性 autotest
show_value_boolean: boolean;
disabled_boolean: boolean;
min_input: number;
max_input: number;
step_input: number;
value_input: number;
activeColor_input: string;
backgroundColor_input: string;
block_size_input: number;
block_color_input: string;
valueColor: string;
}
// 使用reactive避免ref数据在自动化测试中无法访问
const data = reactive({
sliderValue: 50,
sliderBlockSize: 20,
sliderBackgroundColor: "#000000",
sliderActiveColor: "#FFCC33",
sliderBlockColor: "#8A6DE9",
// 组件属性 autotest
show_value_boolean: false,
disabled_boolean: false,
min_input: 0,
max_input: 100,
step_input: 1,
value_input: 0,
activeColor_input: "#007aff",
backgroundColor_input: "#e9e9e9",
block_size_input: 28,
block_color_input: "#ffffff",
valueColor: "#888888"
} as DataType)
const sliderChange = (e: UniSliderChangeEvent) => {
console.log("value 发生变化:" + e.detail.value);
}
const slider_click = () => {
console.log("组件被点击时触发");
}
const slider_touchstart = () => {
console.log("手指触摸动作开始");
}
const slider_touchmove = () => {
console.log("手指触摸后移动");
}
const slider_touchcancel = () => {
console.log("手指触摸动作被打断,如来电提醒,弹窗");
}
const slider_touchend = () => {
console.log("手指触摸动作结束");
}
const slider_tap = () => {
console.log("手指触摸后马上离开");
}
const slider_longpress = () => {
console.log(
"如果一个组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。"
);
}
const slider_change = () => {
console.log("完成一次拖动后触发的事件,event.detail = {value: value}");
}
const slider_changing = () => {
console.log("拖动过程中触发的事件,event.detail = {value: value}");
}
const change_show_value_boolean = (checked: boolean) => {
data.show_value_boolean = checked;
}
const change_disabled_boolean = (checked: boolean) => {
data.disabled_boolean = checked;
}
const confirm_min_input = (value: number) => {
data.min_input = value;
}
const confirm_max_input = (value: number) => {
data.max_input = value;
}
const confirm_step_input = (value: number) => {
data.step_input = value;
}
const confirm_value_input = (value: number) => {
data.value_input = value;
}
const confirm_activeColor_input = (value: string) => {
data.activeColor_input = value;
}
const confirm_backgroundColor_input = (value: string) => {
data.backgroundColor_input = value;
}
const confirm_block_size_input = (value: number) => {
data.block_size_input = value;
}
const confirm_block_color_input = (value: string) => {
data.block_color_input = value;
}
const confirm_value_color_input = (value: string) => {
data.valueColor = value;
}
defineExpose({
data
})
</script>
<template>
<view class="main">
<slider :disabled="data.disabled_boolean" :min="data.min_input" :max="data.max_input" :step="data.step_input" :value="data.value_input"
:activeColor="data.activeColor_input" :backgroundColor="data.backgroundColor_input" :block-size="data.block_size_input"
:block-color="data.block_color_input" :show-value="data.show_value_boolean" :valueColor="data.valueColor" @click="slider_click"
@touchstart="slider_touchstart" @touchmove="slider_touchmove" @touchcancel="slider_touchcancel"
@touchend="slider_touchend" @tap="slider_tap" @longpress="slider_longpress" @change="slider_change"
@changing="slider_changing" style="width: 90%;margin-left: 10px;"></slider>
</view>
<scroll-view style="flex: 1">
<view class="content">
<page-head title="组件属性"></page-head>
<boolean-data :defaultValue="false" title="是否显示当前 value" @change="change_show_value_boolean"></boolean-data>
<boolean-data :defaultValue="false" title="是否禁用" @change="change_disabled_boolean"></boolean-data>
<input-data defaultValue="0" title="最小值(min)" type="number" @confirm="confirm_min_input"></input-data>
<input-data defaultValue="100" title="最大值(max)" type="number" @confirm="confirm_max_input"></input-data>
<input-data defaultValue="1" title="步长(step),取值必须大于 0,并且可被(max - min)整除" type="number"
@confirm="confirm_step_input"></input-data>
<input-data defaultValue="0" title="当前取值(value)" type="number" @confirm="confirm_value_input"></input-data>
<!-- #ifndef VUE3-VAPOR -->
<input-data defaultValue="#007aff" title="滑块左侧已选择部分的线条颜色(active-color)" type="text"
@confirm="confirm_activeColor_input"></input-data>
<input-data defaultValue="#e9e9e9" title="背景条的颜色(background-color)" type="text"
@confirm="confirm_backgroundColor_input"></input-data>
<input-data defaultValue="28" title="滑块的大小(block-size),取值范围为 12 - 28" type="number"
@confirm="confirm_block_size_input"></input-data>
<input-data defaultValue="#ffffff" title="滑块颜色(block-color)" type="text"
@confirm="confirm_block_color_input"></input-data>
<input-data defaultValue="#888888" title="Value颜色(value-color)" type="text"
@confirm="confirm_value_color_input"></input-data>
<!-- #endif -->
</view>
<view class="uni-padding-wrap">
<page-head title="默认及使用"></page-head>
<view class="uni-title">显示当前value</view>
<view>
<slider style="padding: 5px 0;margin-left: 10px;" @change="sliderChange" :value="50" :show-value="true" />
</view>
<view class="uni-title">设置步进:step=10跳动</view>
<view>
<view class="uni-row">
<text>0</text>
<text class="m-l-a">100</text>
</view>
<slider style="padding: 5px 0;margin-left: 10px;" @change="sliderChange" :value="60" :step="10" />
</view>
<view class="uni-title">浮点步进:step=0.01跳动</view>
<view>
<slider style="padding: 5px 0;margin-left: 10px" :value="0.5" :min="0" :max="1" :step="0.01" :show-value="true" />
</view>
<view class="uni-title">设置最小/最大值</view>
<view>
<slider style="padding: 5px 0;margin-left: 10px" @change="sliderChange" :value="100" :min="50" :max="200" :show-value="true" />
</view>
<view class="uni-title">不同颜色和大小的滑块</view>
<view>
<!-- vapor 模式不支持 activeColor、blockColor 等属性,需要使用 track-class、track-active-class、thumb-class -->
<slider style="padding: 5px 0;margin-left: 10px" id="slider-custom-color-and-size" @change="sliderChange" :value="data.sliderValue"
:backgroundColor="data.sliderBackgroundColor" :activeColor="data.sliderActiveColor"
:activeBackgroundColor="data.sliderActiveColor" :blockColor="data.sliderBlockColor" :foreColor="data.sliderBlockColor"
:block-size="data.sliderBlockSize"
track-class="custom-track" track-active-class="custom-track-active" thumb-class="custom-thumb"/>
</view>
<view class="uni-title">暗黑模式</view>
<view>
<slider style="padding: 5px 0;margin-left: 10px" :show-value="true" backgroundColor="rgba(32,32,32,0.5)" valueColor="#555" track-class="dark-track" thumb-class="dark-thumb"/>
</view>
<navigator class="uni-common-mb" url="/pages/template/slider-100/slider-100">
<button>组件性能测试</button>
</navigator>
<navigator class="uni-common-mb" url="./slider-in-swiper">
<button>slider in swiper</button>
</navigator>
<navigator class="uni-common-mb" url="./slider-maxValue">
<button>slider maxValue</button>
</navigator>
</view>
</scroll-view>
</template>
<style>
.main {
padding: 5px 0;
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
flex-direction: row;
justify-content: center;
}
.m-l-a {
margin-left: auto;
}
/* 自定义样式示例 */
.custom-track {
background-color: #000000;
}
.custom-track-active {
background-color: #FFCC33;
}
.custom-thumb {
width: 20px;
height: 20px;
background-color: #8A6DE9;
border-radius: 10px;
}
/* 暗黑模式样式 */
.dark-track {
background-color: rgba(32, 32, 32, 0.5);
}
.dark-thumb {
background-color: #555;
}
</style>