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

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

查看文件

@@ -0,0 +1,146 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isHarmony = platformInfo.includes('harmony')
const isMP = platformInfo.startsWith('mp')
const PAGE_PATH = '/pages/template/pull-refresh-custom-indicator/pull-refresh-custom-indicator'
const isVapor = process.env.UNI_APP_X_DOM2 === 'true'
describe('pull-refresh-custom-indicator', () => {
if (isVapor || isMP) {
it('not supported in vapor mode skip', () => {
expect(1).toBe(1)
})
return
}
let page
async function waitForRefreshState(matcher, timeout = 5000) {
const start = Date.now()
let matchedState = null
await page.waitFor(async () => {
const value = await page.callMethod('jest_getRefreshState')
if (matcher(value)) {
matchedState = value
return true
}
return Date.now() - start > timeout
})
if (matchedState != null) {
return matchedState
}
return await page.callMethod('jest_getRefreshState')
}
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
await page.waitFor(800)
})
beforeEach(async () => {
await page.callMethod('jest_applyPulling', 0)
await page.callMethod('jest_restoreRefresh')
await page.waitFor(100)
})
it('renders sticky header and content list', async () => {
const listView = await page.$('list-view')
const header = await page.$('.header')
const tipText = await page.$('.tip-text')
const items = await page.$$('.content-item-text')
expect(listView).not.toBeNull()
expect(tipText).not.toBeNull()
// 鸿蒙平台 sticky-header 组件只能作为 sticky-section 的子元素使用
if (!isHarmony) {
expect(header).not.toBeNull()
expect(await header.text()).toContain('sticky header')
}
expect(await tipText.text()).toBe('继续下拉执行刷新')
expect(items.length).toBe(20)
expect(await items[0].text()).toBe('item-1')
expect(await items[19].text()).toBe('item-20')
})
it('keeps initial hint before reaching threshold', async () => {
await page.callMethod('jest_applyPulling', 20)
await page.waitFor(100)
const state = await page.callMethod('jest_getRefreshState')
const tipText = await page.$('.tip-text')
expect(state.pullingDistance).toBe(20)
expect(state.state).toBe(0)
expect(await tipText.text()).toBe('继续下拉执行刷新')
})
it('switches to release hint after crossing threshold', async () => {
await page.callMethod('jest_applyPulling', 60)
await page.waitFor(100)
const state = await page.callMethod('jest_getRefreshState')
const tipText = await page.$('.tip-text')
expect(state.pullingDistance).toBe(60)
expect(state.state).toBe(1)
expect(await tipText.text()).toBe('释放立即刷新')
})
it('transitions through refreshing and restore states', async () => {
await page.callMethod('jest_applyPulling', 60)
await page.callMethod('jest_triggerRefresh')
let state = await waitForRefreshState((value) => value != null && value.state == 2 && value.refresherTriggered == true)
let tipText = await page.$('.tip-text')
let refreshIcons = await page.$$('.refresh-icon')
expect(state.state).toBe(2)
expect(state.refresherTriggered).toBe(true)
expect(await tipText.text()).toBe('刷新中')
expect(refreshIcons.length).toBe(1)
state = await waitForRefreshState((value) => {
if (value == null || value.refresherTriggered == true) {
return false
}
if (value.state == 3 && value.resetting == true) {
return true
}
return isHarmony && value.state == 0 && value.resetting == false
}, 3000)
expect(state.refresherTriggered).toBe(false)
// 鸿蒙端 restore 结束更快,可能观察到恢复中(state=3)或已恢复(state=0)。
if (isHarmony) {
expect([true, false]).toContain(state.resetting)
expect([3, 0]).toContain(state.state)
} else {
expect(state.resetting).toBe(true)
expect(state.state).toBe(3)
}
await page.callMethod('jest_restoreRefresh')
await page.waitFor(100)
state = await page.callMethod('jest_getRefreshState')
tipText = await page.$('.tip-text')
refreshIcons = await page.$$('.refresh-icon')
expect(state.pullingDistance).toBe(0)
expect(state.refresherTriggered).toBe(false)
expect(state.resetting).toBe(false)
expect(state.state).toBe(0)
expect(await tipText.text()).toBe('继续下拉执行刷新')
expect(refreshIcons.length).toBe(0)
})
})

查看文件

@@ -0,0 +1,142 @@
<template>
<!-- #ifdef WEB -->
<view>
<!-- #endif -->
<list-view class="list-view" :refresher-enabled="true" :refresher-triggered="data.refresherTriggered"
refresher-default-style="none" @refresherpulling="onRefresherpulling" @refresherrefresh="onRefresherrefresh"
@refresherrestore="onRefreshrestore" :refresher-threshold="data.refresherThreshold" refresher-max-drag-distance="200px">
<page-intro content="本页演示自定义下拉刷新:sticky header、列表项与自定义 refresher 插槽(refresh-box),下拉触发刷新。"></page-intro>
<sticky-header>
<view class="header">
<text>sticky header</text>
</view>
</sticky-header>
<list-item v-for="i in 20" :key="i" class="content-item">
<text class="content-item-text">item-{{i}}</text>
</list-item>
<refresh-box slot="refresher" :state="state" :pullingDistance="data.pullingDistance"></refresh-box>
</list-view>
<!-- #ifdef WEB -->
</view>
<!-- #endif -->
</template>
<script setup lang="uts">
/**
* @description: 支持为 list-view 提供自定义下拉刷新指示器,并同时演示 sticky header 与 refresher 插槽协同工作的页面。
* @logic: 页面监听下拉刷新过程中的 pulling、refresh、restore 事件,驱动自定义刷新状态变化,并通过 refresher 插槽展示刷新盒子。
* @optimization: 刷新状态统一收敛到 `state` 计算属性中,减少模板层对多种刷新状态的重复判断。
*/
import refreshBox from './refresh-box/refresh-box.uvue';
type PullRefreshIndicatorData = {
refresherTriggered: boolean
refresherThreshold: number
pullingDistance: number
resetting: boolean
}
type PullRefreshState = {
pullingDistance: number
refresherTriggered: boolean
resetting: boolean
state: number
}
const data = reactive<PullRefreshIndicatorData>({
refresherTriggered: false,
refresherThreshold: 40,
pullingDistance: 0,
resetting: false
})
const state = computed(() : number => {
if (data.resetting) {
return 3;
}
if (data.refresherTriggered) {
return 2
}
if (data.pullingDistance > data.refresherThreshold) {
return 1
} else {
return 0
}
})
function onRefresherpulling(e : RefresherEvent) {
// console.log('onRefresherpulling',e.detail.dy)
data.pullingDistance = e.detail.dy
}
function onRefresherrefresh() {
data.refresherTriggered = true
setTimeout(() => {
data.refresherTriggered = false
data.resetting = true
}, 1500)
}
function onRefreshrestore() {
data.pullingDistance = 0
data.resetting = false;
}
// 自动化测试
function jest_applyPulling(distance : number) : void {
data.pullingDistance = distance
}
function jest_triggerRefresh() : void {
onRefresherrefresh()
}
function jest_restoreRefresh() : void {
onRefreshrestore()
}
function jest_getRefreshState() : PullRefreshState {
return {
pullingDistance: data.pullingDistance,
refresherTriggered: data.refresherTriggered,
resetting: data.resetting,
state: state.value
}
}
defineExpose({
data,
jest_applyPulling,
jest_triggerRefresh,
jest_restoreRefresh,
jest_getRefreshState
})
</script>
<style>
.list-view {
flex: 1;
background-color: #f5f5f5;
}
.header {
justify-content: center;
height: 50px;
background-color: #f5f5f5;
padding: 15px;
}
.content-item {
}
.content-item-text {
margin: 5px 0;
padding: 15px;
background-color: #fff;
font-size: 14px;
color: #666;
line-height: 20px;
}
</style>

查看文件

@@ -0,0 +1,43 @@
<template>
<list-item slot="refresher" class="refresh-box">
<image v-if="state == 2" class="refresh-icon" src="https://web-ext-storage.dcloud.net.cn/hello-uni-app-x/refresh-box-run.gif" mode="widthFix"></image>
<text class="tip-text">{{text[state]}}</text>
</list-item>
</template>
<script setup lang="uts">
/**
* @description: 作为自定义下拉刷新页面的刷新指示器子组件,负责展示不同刷新状态下的图标与文案。
* @logic: 组件根据父页面传入的刷新状态,切换对应的提示文本和刷新动画展示。
* @optimization: 通过把刷新展示逻辑收敛到独立子组件中,避免父页面模板里重复处理多种刷新展示分支。
*/
type Props = {
state: number
}
const props = withDefaults(defineProps<Props>(), {
state: 0
})
const text = ['继续下拉执行刷新', '释放立即刷新', '刷新中', ""]
</script>
<style>
.refresh-box {
justify-content: center;
align-items: center;
flex-direction: row;
height: 30px;
}
.refresh-icon {
width: 20px;
height: 20px;
margin: 5px;
}
.tip-text {
color: #888;
font-size: 12px;
}
</style>