refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,11 @@
|
||||
## 2.0.1(2026-05-09)
|
||||
- 修复2.0.0版本插件内容错误
|
||||
## 2.0.0(2025-09-06)
|
||||
- 【重要】实现item复用,滚动更流畅,限制所有item高度必须一致。
|
||||
## 1.0.3(2025-03-12)
|
||||
- 修复 滚动且非加载期间偶尔出现空白区域的Bug
|
||||
- 修复 不定高item条目过少时部分情况下显示不全的Bug
|
||||
## 1.0.2(2025-03-04)
|
||||
- 修复 uni-recycle-view子项过少时显示数目不正确的Bug 感谢@鸿程
|
||||
## 1.0.1(2025-02-21)
|
||||
- 适配微信小程序
|
||||
@@ -0,0 +1,5 @@
|
||||
export type LayoutItem = {
|
||||
id : number,
|
||||
offset : number,
|
||||
item: any
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<view class="recycle-item" :style="{transform: 'translateY(' + props.offset + 'px)'}">
|
||||
<slot></slot>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
offset: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.recycle-item {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,248 @@
|
||||
<template>
|
||||
<scroll-view style="flex: 1;" :direction="props.direction" :scroll-into-view="props.scrollIntoView"
|
||||
<!-- #ifndef VUE3-VAPOR -->
|
||||
:type="props.type" :custom-nested-scroll="props.customNestedScroll" :nested-scroll-child="props.nestedScrollChild"
|
||||
<!-- #endif -->
|
||||
:associative-container="props.associativeContainer" :enable-back-to-top="props.enableBackToTop"
|
||||
:bounces="props.bounces"
|
||||
:upper-threshold="props.upperThreshold" :lower-threshold="props.lowerThreshold" :scroll-top="props.scrollTop"
|
||||
:scroll-left="props.scrollLeft" :scroll-with-animation="props.scrollWithAnimation"
|
||||
:refresher-enabled="props.refresherEnabled" :refresher-threshold="props.refresherThreshold"
|
||||
:refresher-max-drag-distance="props.refresherMaxDragDistance" :refresher-default-style="props.refresherDefaultStyle"
|
||||
:refresher-background="props.refresherBackground" :refresher-triggered="props.refresherTriggered"
|
||||
:show-scrollbar="props.showScrollbar"
|
||||
@scroll="onScroll" @scrollend="onScrollEnd" @scrolltolower="onScrollToLower" @scrolltoupper="onScrollToUpper"
|
||||
@refresherabort="onRefresherAbort" @refresherpulling="onRefresherPulling" @refresherrefresh="onRefresherRefresh"
|
||||
@refresherrestore="onRefresherRestore">
|
||||
<view class="placeholder" :style="{height: placeholderHeight + 'px'}">
|
||||
<slot :layoutItems="layoutItems" :items="items"></slot>
|
||||
</view>
|
||||
<slot name="load-more"></slot>
|
||||
</scroll-view>
|
||||
</template>
|
||||
<script setup>
|
||||
import {
|
||||
LayoutItem
|
||||
} from '../../common/types.uts'
|
||||
const props = defineProps({
|
||||
itemHeight: {
|
||||
type: Number,
|
||||
default: 40,
|
||||
required: true
|
||||
},
|
||||
list: {
|
||||
type: Array as PropType<any[]>,
|
||||
default: [] as any[]
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
direction: {
|
||||
type: String,
|
||||
default: 'vertical'
|
||||
},
|
||||
associativeContainer: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
enableBackToTop: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
bounces: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
upperThreshold: {
|
||||
type: Number,
|
||||
default: 50
|
||||
},
|
||||
lowerThreshold: {
|
||||
type: Number,
|
||||
default: 50
|
||||
},
|
||||
scrollTop: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
scrollLeft: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
scrollIntoView: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
scrollWithAnimation: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
refresherEnabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
refresherThreshold: {
|
||||
type: Number,
|
||||
default: 45
|
||||
},
|
||||
refresherMaxDragDistance: {
|
||||
type: Number
|
||||
},
|
||||
refresherDefaultStyle: {
|
||||
type: String,
|
||||
default: 'black'
|
||||
},
|
||||
refresherBackground: {
|
||||
type: String,
|
||||
default: 'transparent'
|
||||
},
|
||||
refresherTriggered: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
showScrollbar: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
customNestedScroll: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
nestedScrollChild: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
})
|
||||
const emit = defineEmits([
|
||||
'scroll',
|
||||
'scrollend',
|
||||
'scrolltolower',
|
||||
'scrolltoupper',
|
||||
'refresherabort',
|
||||
'refresherpulling',
|
||||
'refresherrefresh',
|
||||
'refresherrestore',
|
||||
])
|
||||
|
||||
const windowInfo = uni.getWindowInfo()
|
||||
|
||||
// TODO 规避鸿蒙平台过早取不到windowHeight的Bug
|
||||
// 使用窗口高度计算节省不少逻辑,通常也不会有滚动区域超出窗口大小的需求
|
||||
const windowHeight = windowInfo.windowHeight == 0 ? windowInfo.screenHeight : windowInfo.windowHeight
|
||||
const cachedCount = 10
|
||||
const renderItemCount = computed(() => {
|
||||
return Math.min(
|
||||
props.list.length,
|
||||
Math.ceil(
|
||||
windowHeight / props.itemHeight) + 1 + cachedCount
|
||||
)
|
||||
})
|
||||
|
||||
const placeholderHeight = computed(() => {
|
||||
return props.list.length * props.itemHeight
|
||||
})
|
||||
|
||||
const scrollTop = ref(0)
|
||||
|
||||
const startIndex = computed(() => {
|
||||
return Math.min(
|
||||
Math.max(
|
||||
Math.floor(scrollTop.value / props.itemHeight) - Math.floor(cachedCount / 2),
|
||||
0
|
||||
),
|
||||
props.list.length - renderItemCount.value
|
||||
);
|
||||
})
|
||||
const items = computed<any[]>(() => {
|
||||
return props.list.slice(startIndex.value, Math.min(props.list.length, startIndex.value + renderItemCount.value))
|
||||
})
|
||||
const layoutItems = ref<LayoutItem[]>([])
|
||||
|
||||
type ItemAndIndex = {
|
||||
item : any,
|
||||
index : number
|
||||
}
|
||||
watch([items, startIndex], () => {
|
||||
if (layoutItems.value.length !== items.value.length) {
|
||||
layoutItems.value.splice(0, layoutItems.value.length)
|
||||
items.value.forEach((item, index) => {
|
||||
layoutItems.value.push({
|
||||
id: index,
|
||||
offset: (startIndex.value + index) * props.itemHeight,
|
||||
item
|
||||
} as LayoutItem)
|
||||
})
|
||||
} else {
|
||||
// 仍存活的item仅更新offset,新生的item复用并更新死亡的item的layoutItem,注意id无论如何都不更新
|
||||
// TODO 当前方案在列表末尾向列表开头滚动时可能会命中if分支,导致所有item都触发更新
|
||||
const newItems : ItemAndIndex[] = []
|
||||
const aliveItems : ItemAndIndex[] = []
|
||||
for (let i = 0; i < items.value.length; i++) {
|
||||
const item = items.value[i]
|
||||
const layoutItemIndex = layoutItems.value.findIndex((layoutItem) => {
|
||||
return item == layoutItem.item
|
||||
})
|
||||
if (layoutItemIndex > -1) {
|
||||
aliveItems.push({
|
||||
item,
|
||||
index: i
|
||||
} as ItemAndIndex)
|
||||
} else {
|
||||
newItems.push({
|
||||
item,
|
||||
index: i
|
||||
} as ItemAndIndex)
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < layoutItems.value.length; i++) {
|
||||
const layoutItem = layoutItems.value[i]
|
||||
const aliveItemAndIndex = aliveItems.find((aliveItem) => {
|
||||
return aliveItem.item == layoutItem.item
|
||||
})
|
||||
if (aliveItemAndIndex != null) {
|
||||
layoutItem.offset = (startIndex.value + aliveItemAndIndex!.index) * props.itemHeight
|
||||
} else {
|
||||
const newItemAndIndex = newItems.pop()!
|
||||
layoutItem.item = newItemAndIndex.item
|
||||
layoutItem.offset = (startIndex.value + newItemAndIndex.index) * props.itemHeight
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layoutItems.value.sort((a, b) => {
|
||||
return items.value.indexOf(a.item) - items.value.indexOf(b.item)
|
||||
})
|
||||
}, {
|
||||
immediate: true
|
||||
})
|
||||
|
||||
function onScroll(e : UniScrollEvent) {
|
||||
const _scrollTop = e.detail.scrollTop
|
||||
scrollTop.value = _scrollTop < 0 ? 0 : _scrollTop
|
||||
emit('scroll', e)
|
||||
}
|
||||
function onScrollToLower(e : UniScrollToLowerEvent) {
|
||||
emit('scrolltolower', e)
|
||||
}
|
||||
function onScrollToUpper(e : UniScrollToUpperEvent) {
|
||||
emit('scrolltoupper', e)
|
||||
}
|
||||
function onScrollEnd(e : UniScrollEvent) {
|
||||
emit('scrollend', e)
|
||||
}
|
||||
function onRefresherAbort(e : UniRefresherEvent) {
|
||||
emit('refresherabort', e)
|
||||
}
|
||||
function onRefresherPulling(e : UniRefresherEvent) {
|
||||
emit('refresherpulling', e)
|
||||
}
|
||||
function onRefresherRefresh(e : UniRefresherEvent) {
|
||||
emit('refresherrefresh', e)
|
||||
}
|
||||
function onRefresherRestore(e : UniRefresherEvent) {
|
||||
emit('refresherrestore', e)
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
</style>
|
||||
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"id": "uni-recycle-view",
|
||||
"displayName": "uni-recycle-view",
|
||||
"version": "2.0.1",
|
||||
"description": "优化了加载速度及内存占用的长列表组件",
|
||||
"keywords": [
|
||||
"recycle-view",
|
||||
"长列表"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^4.0.0",
|
||||
"uni-app": "",
|
||||
"uni-app-x": "^4.76"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "component-vue",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "否",
|
||||
"data": "无",
|
||||
"permissions": "无"
|
||||
},
|
||||
"npmurl": "",
|
||||
"darkmode": "x",
|
||||
"i18n": "x",
|
||||
"widescreen": "x"
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "√",
|
||||
"aliyun": "√",
|
||||
"alipay": "√"
|
||||
},
|
||||
"client": {
|
||||
"uni-app": {
|
||||
"vue": {
|
||||
"vue2": "-",
|
||||
"vue3": "-"
|
||||
},
|
||||
"web": {
|
||||
"safari": "-",
|
||||
"chrome": "-"
|
||||
},
|
||||
"app": {
|
||||
"vue": "-",
|
||||
"nvue": "-",
|
||||
"android": "-",
|
||||
"ios": "-",
|
||||
"harmony": "-"
|
||||
},
|
||||
"mp": {
|
||||
"weixin": "-",
|
||||
"alipay": "-",
|
||||
"toutiao": "-",
|
||||
"baidu": "-",
|
||||
"kuaishou": "-",
|
||||
"jd": "-",
|
||||
"harmony": "-",
|
||||
"qq": "-",
|
||||
"lark": "-"
|
||||
},
|
||||
"quickapp": {
|
||||
"huawei": "-",
|
||||
"union": "-"
|
||||
}
|
||||
},
|
||||
"uni-app-x": {
|
||||
"web": {
|
||||
"safari": "√",
|
||||
"chrome": "√"
|
||||
},
|
||||
"app": {
|
||||
"android": {
|
||||
"extVersion": "",
|
||||
"minVersion": "21"
|
||||
},
|
||||
"ios": "√",
|
||||
"harmony": "√"
|
||||
},
|
||||
"mp": {
|
||||
"weixin": "√"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
## uni-recycle-view
|
||||
|
||||
> 此组件支持uni-app-x(web端、app端、小程序端),不支持非uni-app-x项目。此插件1.x版本最低支持HBuilderX 4.11,2.0及以上版本最低支持HBuilderX 4.81。
|
||||
|
||||
> 为了实现更流畅的滚动性能,自此插件2.0版本起,itemHeight为必传属性,既所有item高度一致才可以使用此组件。如果有动态item高度的需求可以下载1.x版本使用。
|
||||
|
||||
uni-recycle-view 组件是一个开源的、适用于展示超长列表的组件,它有2个优势:
|
||||
- 更快的初始化速度
|
||||
- 更低的内存占用
|
||||
|
||||
### 背景
|
||||
|
||||
uni-app x 的 list-view组件,在ui层面基于原生的recycle-view封装,对于长列表的渲染资源可以复用。
|
||||
|
||||
但在vue环境下,装载长列表会对列表所有数据都创建VNode,不管渲染层这些列表是否显示。创建大量VNode会影响初始化速度和内存占用。
|
||||
|
||||
uni-recycle-view 组件只创建了有限的VNode,循环复用这些VNode。uni-recycle-view组件内部通过计算决定哪些数据需要在界面展示,默认展示当前滚动位置的所在屏及上下各5屏的数据。
|
||||
|
||||
同时它也有一些限制和注意事项:
|
||||
1. uni-recycle-view 组件适用于仅使用一个for循环创建所有列表项的场景。
|
||||
2. 由于滚动过程中会计算哪些数据需要渲染,因此滚动流畅度略低于list-view组件。
|
||||
3. 2.0版本起限制所有item高度一致
|
||||
|
||||
所以uni-recycle-view 组件是对list-view组件的一个补充方案。如果list-view的初始化速度和内存占用满足你的需求,那么继续使用list-view即可。
|
||||
|
||||
一般联网的分页加载列表,仍然可以使用list-view。uni-recycle-view 组件常见的场景是本地一次性遍历了大量数据并需要立即渲染在界面上。
|
||||
|
||||
在hello uni-app x的模板->自定义虚拟长列表示例中可以看到演示。
|
||||
|
||||
### 基本用法
|
||||
|
||||
示例参考:[hello uni-app-x 虚拟长列表模板](https://gitcode.com/dcloud/hello-uni-app-x/blob/dev/pages/template/recycle-long-list/recycle-long-list.uvue)
|
||||
|
||||
uni-recycle-view组件传入通过绑定list属性`:list="list"`传入含所有数据的列表。经过组件内部计算,由作用域插槽返回真实要渲染的部分数据`v-slot:default="{items}"`。最终仅需渲染items而不是list,从而节省了大量的计算消耗及内存占用。
|
||||
|
||||
### 属性及事件
|
||||
|
||||
|属性名 |类型 |默认值 |说明 |
|
||||
|:-: |:-: |:-: |:-: |
|
||||
|list |any[] | [] |列表所有数据 |
|
||||
|itemHeight |number | 40 |每项占用高度(包括margin),此属性自2.0版本必传 |
|
||||
|其他 |- |- |其余属性及事件会透传给内部的scroll-view组件,参考: [scroll-view组件](https://doc.dcloud.net.cn/uni-app-x/component/scroll-view.html) |
|
||||
|
||||
|
||||
## uni-recycle-item
|
||||
|
||||
uni-recycle-item用于渲染uni-recycle-view筛选出的用于展示的数据。
|
||||
|
||||
### 属性及事件
|
||||
|
||||
|属性名 |类型 |默认值 |说明 |
|
||||
|:-: |:-: |:-: |:-: |
|
||||
|offset |number | - |由uni-recycle-view计算得来的组件偏移距离 |
|
||||
|
||||
## 注意事项
|
||||
|
||||
- uni-recycle-view和uni-recycle-item必须搭配使用
|
||||
在新工单中引用
屏蔽一个用户