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

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

查看文件

@@ -0,0 +1,36 @@
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
const isHarmony = platformInfo.startsWith('harmony')
const isIOS = platformInfo.startsWith('ios')
describe('banner-waterfall-nested-scroll', () => {
if (isWeb || isMP || isHarmony || isIOS || process.env.UNI_TEST_DEVICES_DIRECTION == 'landscape') {
it('dummyTest', async () => {
expect(1).toBe(1)
})
return
}
let page
beforeAll(async () => {
//打开list-view测试页
page = await program.reLaunch('/pages/template/banner-waterfall-nested-scroll/banner-waterfall-nested-scroll')
await page.waitFor(600)
})
//测试验证Waterflow下拉刷新是否闪退问题
it('check_refresherabort', async () => {
//部分安卓设备需要延迟一段时间swipe才生效 此处暂时延迟1秒
await page.waitFor(1000);
// 仅App端支持手势下拉刷新
await program.swipe({
startPoint: {x: 100,y: 300},
endPoint: {x: 100,y: 600},
duration: 100
})
await page.waitFor(1500)
expect(page.path).toBe('pages/template/banner-waterfall-nested-scroll/banner-waterfall-nested-scroll')
});
})

查看文件

@@ -0,0 +1,273 @@
<template>
<scroll-view ref="pageScrollView" class="page" :bounces="false" type="nested"
:refresher-triggered="refresherTriggered" refresher-enabled="true" @refresherrefresh="onRefresherrefresh">
<nested-scroll-header>
<swiper ref="header" indicator-dots="true" circular="true">
<swiper-item v-for="i in 3" :item-id="''+i">
<image src="/static/shuijiao.jpg" style="width:100% ;height: 240px;"></image>
<text style="position: absolute;">{{i}}</text>
</swiper-item>
</swiper>
</nested-scroll-header>
<nested-scroll-body style="height: 100%;">
<view style="flex: 1;">
<scroll-view ref="tabScrollView" class="swiper-tabs" direction="horizontal" :show-scrollbar="false">
<view class="flex-row" style="align-self: flex-start;">
<text ref="swipertab" class="swiper-tabs-item" :class="swiperIndex==index ? 'swiper-tabs-item-active' : ''"
v-for="(item, index) in swiperList" :key="index" @click="onTabClick(index)">
{{item.name}}
</text>
</view>
<view ref="indicatorNode" 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="(item, index) in swiperList" :key="index">
<long-page ref="longPageRef" :id="item.id" :type="item.type" :preload="item.preload"></long-page>
</swiper-item>
</swiper>
</view>
</nested-scroll-body>
</scroll-view>
</template>
<script setup lang="uts">
/**
* @description: 支持顶部 Banner、横向标签栏和瀑布流内容联动切换的嵌套滚动页面。
* @logic: 页面顶部先展示 Banner,下面通过标签切换不同瀑布流数据源,在嵌套滚动容器中完成头部与内容区的联动滚动。
* @optimization: 标签内容按首次可见时才触发加载,并缓存标签尺寸用于复用指示器动画,减少瀑布流页面切换时的布局计算。
*/
import longPage from './long-waterflow-page.uvue';
type SwiperTabsItem = {
x : number,
w : number
}
type SwiperViewItem = {
type : string,
name : string,
id : string,
preload : boolean,
}
/**
* 根据权重在两个值之间执行线性插值.
* @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([
{
type: 'UpdatedDate',
name: '最新上架',
id: "list-id-1",
preload: true
} as SwiperViewItem,
{
type: 'FreeHot',
name: '免费热榜',
id: "list-id-2",
preload: false
} as SwiperViewItem,
{
type: 'PaymentHot',
name: '付费热榜',
id: "list-id-3",
preload: false
} as SwiperViewItem,
{
type: 'HotList',
name: '热门总榜',
id: "list-id-4",
preload: false
} as SwiperViewItem
] as SwiperViewItem[]);
const swiperIndex = ref(0);
const pageScrollView = ref<UniScrollViewElement | null>(null);
let headerHeight = 0;
let animationFinishIndex = 0;
const tabScrollView = ref<UniScrollViewElement | null>(null);
const indicatorNode = ref<UniElement | null>(null);
let swiperWidth = 0;
let swiperTabsRect: SwiperTabsItem[] = [];
let nestedScrollChildId = "";
const header = ref<UniSwiperElement | null>(null);
const swipertab = ref<UniElement[]>([]);
const swiper = ref<UniSwiperElement | null>(null);
const longPageRef = ref<ComponentPublicInstance[]>([]);
function cacheTabItemsSize() {
swiperTabsRect.length = 0
swipertab.value.forEach((node) => {
swiperTabsRect.push({
x: node.offsetLeft,
w: node.offsetWidth
} as SwiperTabsItem)
})
}
function initSwiperItemData(index : number) {
if (!swiperList.value[index].preload) {
swiperList.value[index].preload = true;
longPageRef.value[index].$callMethod('loadData', null)
}
//swiper页面切换需要重新赋值嵌套滚动子元素的id
nestedScrollChildId = swiperList.value[index].id
}
function updateTabIndicator(current_index : number, move_to_index : number, percentage : number) {
const current_size = swiperTabsRect[current_index]
const move_to_size = swiperTabsRect[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)
// 更新指示线
// #ifdef APP
const x = indicator_line_x + indicator_line_w / 2
indicatorNode.value?.style?.setProperty('transform', `translateX(${x}px) scaleX(${indicator_line_w})`)
// #endif
// #ifdef WEB
// TODO chrome windows系统 transform scaleX渲染bug
const x = indicator_line_x
indicatorNode.value?.style?.setProperty('width', `${indicator_line_w}px`)
indicatorNode.value?.style?.setProperty('transform', `translateX(${x}px)`)
// #endif
// 滚动到水平中心位置
const scroll_x = x - swiperWidth / 2
if (tabScrollView.value !== null) {
tabScrollView.value!.scrollLeft = scroll_x
}
}
function setSwiperIndex(index : number, updateIndicator : boolean) {
if (swiperIndex.value === index) {
return
}
swiperIndex.value = index
initSwiperItemData(index)
if (updateIndicator) {
updateTabIndicator(index, index, 1)
}
}
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
const current_offset_i = offset_x / swiperWidth
const current_index = animationFinishIndex + 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
// 通知更新指示线
if (current_index != move_to_index) {
updateTabIndicator(current_index, move_to_index, percentage)
}
// 首次可见时初始化数据
initSwiperItemData(move_to_index)
}
function onSwiperAnimationfinish(e : SwiperAnimationFinishEvent) {
setSwiperIndex(e.detail.current, true)
animationFinishIndex = e.detail.current
}
onReady(() => {
headerHeight = header.value!.offsetHeight
swiperWidth = swiper.value!.getBoundingClientRect().width
cacheTabItemsSize()
updateTabIndicator(swiperIndex.value, swiperIndex.value, 1)
});
const refresherTriggered = ref(false);
function onRefresherrefresh(e : UniRefresherEvent) {
refresherTriggered.value = true;
longPageRef.value[swiperIndex.value].$callMethod('refreshData', () => {
refresherTriggered.value = false;
})
}
</script>
<style>
.flex-row {
flex-direction: row;
}
.page {
flex: 1;
}
.search-bar {
padding: 10px;
}
.swiper-list {
height: 100%;
/* #ifdef WEB */
flex: 1;
/* #endif */
}
.swiper-tabs {
background-color: #ffffff;
flex-direction: column;
}
.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;
}
</style>

查看文件

@@ -0,0 +1,217 @@
<template>
<waterflow :id="id" class="grid" :bounces="false" :scroll-y="true" :custom-nested-scroll="true"
main-axis-gap="8px" cross-axis-gap="8px" cross-axis-count=2
@scrolltolower="loadData(null)" associative-container="nested-scroll-view">
<flow-item class="flow-item" v-for="(item, _) in datagrid" :key="item.plugin_id" type=1>
<view class="flow-item-icon">
<image class="flow-item-icon-image" :src="item.plugin_img_link" mode="aspectFit"></image>
</view>
<view class="flow-item-fill">
<view class="flex-row">
<text class="title">{{item.plugin_name}}</text>
</view>
<view>
<text class="description-text">{{item.plugin_intro}}</text>
</view>
<uni-rate :value="(item.score as number) / 10" :full="true" :readonly="true"></uni-rate>
<view class="tag-grid">
<text class="tag-item" v-for="(item2, index2) in (item.tags as Array<string>).slice(0,1)" :key="index2">{{item2}}</text>
</view>
<view class="flex-row update-date">
<text class="author">{{item.author_name}}</text>
</view>
<view class="flex-row update-date">
<text class="update-date-text">更新日期</text>
<text class="update-date-value">{{item.update_date}}</text>
</view>
</view>
</flow-item type="20">
<flow-item slot="load-more" class="loading" type=6>
<!-- <uni-loading :loading="loading" color="#999" :text="loadingText"></uni-loading> -->
<loading v-if="loadingRef" style="color: #999"></loading>
<text v-if="isEnded" style="color: #999">到底了</text>
</flow-item>
</waterflow>
</template>
<script setup lang="uts">
/**
* @description: 作为瀑布流内容页,支持按分类加载卡片数据并在滚动到底部后继续追加内容。
* @logic: 页面根据父级传入的分类参数请求瀑布流接口,首次显示时按需预加载,触底后继续请求下一页并更新瀑布流数据源。
* @optimization: 通过 `preload` 控制首次请求时机,避免所有标签页同时加载;瀑布流列表采用分页追加方式,降低首屏数据量和布局压力。
*/
const SERVER_URL = "https://unidemo.dcloud.net.cn/plugin/uniappx-plugin-list"
const PAGE_SIZE = 10; // 最大值 10
type flowItem = {
plugin_id : number,
plugin_img_link : string,
plugin_name : string,
plugin_intro : string,
score : number,
tags : Array<string>,
update_date : string,
author_name : string,
}
type ResponseDataType = {
code : number,
data : flowItem[]
}
const props = defineProps({
type: { type: String, default: '' },
preload: { type: Boolean, default: false },
id: { type: String, default: '' }
})
const loadingRef = ref(false);
const datagrid = ref([] as flowItem[]);
const isEnded = ref(false);
const loadingError = ref('');
const currentPage = ref(1);
const loadingText = computed(() : string => {
if (loadingRef.value) {
return "加载中..."
} else if (isEnded.value) {
return "没有更多了"
} else if (loadingError.value.length > 0) {
return loadingError.value
} else {
return ""
}
});
function loadData(loadComplete : (() => void) | null) {
if (loadingRef.value || isEnded.value) {
return
}
loadingRef.value = true
uni.request<ResponseDataType>({
url: SERVER_URL,
data: {
type: props.type,
page: currentPage.value,
page_size: PAGE_SIZE
},
success: (res) => {
const responseData = res.data
if (responseData == null) {
return
}
datagrid.value.push(...responseData.data)
if (responseData.data.length == 0) {
isEnded.value = true
} else {
currentPage.value++
}
},
fail: (err) => {
loadingError.value = err.errMsg
},
complete: () => {
loadingRef.value = false
if (loadComplete != null) {
loadComplete()
}
}
})
}
function refreshData(loadComplete : (() => void) | null) {
datagrid.value.length = 0
currentPage.value = 1
loadData(loadComplete)
}
onMounted(() => {
if (props.preload) {
loadData(null)
}
});
defineExpose({
refreshData,
loadData
});
</script>
<style>
.grid {
flex: 1;
background-color: #f7f7f7;
}
.flow-item {
flex-direction: column;
border-radius: 5px;
background-color: #ffffff;
}
.flow-item-icon {
position: relative;
}
.flow-item-icon-image {
width: 100%;
}
.flow-item-fill {
flex: 1;
padding: 5px;
}
.description-text {
font-size: 13px;
color: #666;
line-height: 19px;
}
.tag-grid {
flex-direction: row;
margin-top: 5px;
}
.tag-item {
font-size: 12px;
background-color: #EFF9F0;
color: #639069;
border-radius: 20px;
margin-right: 5px;
padding: 2px 5px;
}
.update-date {
margin-top: 10px;
}
.update-date-text {
font-size: 12px;
color: #888888;
}
.update-date-value {
font-size: 12px;
color: #777777;
margin-left: 5px;
}
.author {
font-size: 12px;
color: #008000;
}
.loading {
padding: 30px;
align-items: center;
height: 80px;
}
.flex-row {
flex-direction: row;
}
</style>