refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,102 @@
|
||||
const PAGE_PATH = '/pages/template/scroll-view-sticky-section/scroll-view-sticky-section'
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isIos = platformInfo.startsWith('ios')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
const isApp = isAndroid || isIos || isHarmony
|
||||
describe('template-scroll-view-sticky-section', () => {
|
||||
if (!isApp) {
|
||||
it('not support', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
let page
|
||||
|
||||
async function waitForStickyTransform(expectedSticky) {
|
||||
const start = Date.now()
|
||||
await page.waitFor(async () => {
|
||||
const sticky = await page.$('.search')
|
||||
const transform = await sticky.style('transform')
|
||||
const isSticky = transform.includes('translateY(')
|
||||
return isSticky == expectedSticky || Date.now() - start > 3000
|
||||
})
|
||||
|
||||
const sticky = await page.$('.search')
|
||||
const transform = await sticky.style('transform')
|
||||
const isSticky = transform.includes('translateY(')
|
||||
expect(isSticky).toBe(expectedSticky)
|
||||
}
|
||||
|
||||
async function scrollTo(scrollTop) {
|
||||
const scrollView = await page.$('.page')
|
||||
expect(scrollView).not.toBeNull()
|
||||
|
||||
if (typeof scrollView.scrollTo == 'function') {
|
||||
await scrollView.scrollTo(0, scrollTop)
|
||||
} else {
|
||||
await program.pageScrollTo(scrollTop)
|
||||
}
|
||||
await page.waitFor(400)
|
||||
}
|
||||
|
||||
async function getStickyThreshold() {
|
||||
const sticky = await page.$('.search')
|
||||
const scrollView = await page.$('.page')
|
||||
const stickyRect = await sticky.offset()
|
||||
const scrollRect = await scrollView.offset()
|
||||
const threshold = Math.round(stickyRect.top - scrollRect.top)
|
||||
return threshold
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
await page.waitFor('scroll-view')
|
||||
await page.waitFor(800)
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await scrollTo(0)
|
||||
await waitForStickyTransform(false)
|
||||
})
|
||||
|
||||
it('renders sticky search section and list content', async () => {
|
||||
const sticky = await page.$('.search')
|
||||
const firstContent = await page.$('.content-item')
|
||||
const searchTip = await page.$('.search-tip-text')
|
||||
const searchBtn = await page.$('.search-btn')
|
||||
|
||||
expect(sticky).not.toBeNull()
|
||||
expect(firstContent).not.toBeNull()
|
||||
expect(searchTip).not.toBeNull()
|
||||
expect(searchBtn).not.toBeNull()
|
||||
expect(await searchTip.text()).toBe('请输入你要搜索的内容')
|
||||
expect(await searchBtn.text()).toBe('搜索')
|
||||
await waitForStickyTransform(false)
|
||||
})
|
||||
|
||||
it('keeps sticky section in normal flow before reaching threshold', async () => {
|
||||
const threshold = await getStickyThreshold()
|
||||
const beforeThreshold = threshold > 20 ? threshold - 20 : 0
|
||||
|
||||
await scrollTo(beforeThreshold)
|
||||
await waitForStickyTransform(false)
|
||||
})
|
||||
|
||||
it('sticks search section after scrolling beyond threshold', async () => {
|
||||
const threshold = await getStickyThreshold()
|
||||
|
||||
await scrollTo(threshold + 30)
|
||||
await waitForStickyTransform(true)
|
||||
})
|
||||
|
||||
it('restores sticky section after scrolling back to top', async () => {
|
||||
const threshold = await getStickyThreshold()
|
||||
|
||||
await scrollTo(threshold + 30)
|
||||
await waitForStickyTransform(true)
|
||||
await scrollTo(0)
|
||||
await waitForStickyTransform(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,130 @@
|
||||
<template>
|
||||
<scroll-view ref="scroll" @scroll="onScroll" class="page" bounces="false">
|
||||
<view class="content-item">
|
||||
<text class="text">向上滑动页面,体验元素吸顶效果。</text>
|
||||
</view>
|
||||
<view v-for="(item,index) in list" :key="index" class="content-item">
|
||||
<text class="text">first content-{{item}}</text>
|
||||
</view>
|
||||
|
||||
<view ref="sticky" class="search">
|
||||
<view style="flex-direction: row;">
|
||||
<image src="/static/template/scroll-fold-nav/search.png" style="width: 15px;" mode="widthFix"></image>
|
||||
<text class="search-tip-text">请输入你要搜索的内容</text>
|
||||
</view>
|
||||
<text class="search-btn">搜索</text>
|
||||
</view>
|
||||
|
||||
<view v-for="(item,index) in list" :key="index" class="content-item">
|
||||
<text class="text">second content-{{item}}</text>
|
||||
</view>
|
||||
|
||||
<view v-for="(item,index) in list" :key="index" class="content-item">
|
||||
<text class="text">second content-{{item}}</text>
|
||||
</view>
|
||||
|
||||
</scroll-view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
/**
|
||||
* @description: 支持在 scroll-view 中让搜索栏吸附到顶部的分段列表页面。
|
||||
* @logic: 页面在初次渲染时计算吸顶元素相对滚动容器的位置,滚动过程中根据 scrollTop 动态更新搜索栏的 translateY,实现吸顶效果。
|
||||
* @optimization: 吸顶逻辑只维护一个当前偏移值并直接更新目标元素 transform,避免滚动过程中重复创建或销毁节点。
|
||||
*/
|
||||
|
||||
const list = ref(['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15'])
|
||||
let stickyTop = 0
|
||||
let stickyTran = 0
|
||||
const scrollTop = ref(0)
|
||||
const sticky = ref<UniElement | null>(null)
|
||||
const scroll = ref<UniElement | null>(null)
|
||||
|
||||
function onScroll(e : ScrollEvent) {
|
||||
if (e.detail.scrollTop > stickyTop) {
|
||||
let stickyTran_ = e.detail.scrollTop - stickyTop;
|
||||
if (stickyTran_ != stickyTran) {
|
||||
sticky.value?.style?.setProperty('transform', 'translateY(' + stickyTran_ + 'px)');
|
||||
}
|
||||
stickyTran = stickyTran_;
|
||||
} else {
|
||||
sticky.value?.style?.setProperty('transform', '');
|
||||
stickyTran = 0;
|
||||
}
|
||||
}
|
||||
function back() {
|
||||
uni.navigateBack({
|
||||
success(result) {
|
||||
console.log('navigateBack success', result.errMsg)
|
||||
},
|
||||
fail(error) {
|
||||
console.log('navigateBack fail', error.errMsg)
|
||||
},
|
||||
complete(result) {
|
||||
console.log('navigateBack complete', result.errMsg)
|
||||
},
|
||||
})
|
||||
}
|
||||
async function calcStickyTop() {
|
||||
if (sticky.value != null && scroll.value != null) {
|
||||
const stickyRect = await sticky.value!.getBoundingClientRectAsync()!;
|
||||
const scrollRect = await scroll.value!.getBoundingClientRectAsync()!;
|
||||
stickyTop = stickyRect.top - scrollRect.top;
|
||||
console.log(stickyRect, scrollRect);
|
||||
}
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
})
|
||||
onReady(() => {
|
||||
calcStickyTop()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
flex: 1;
|
||||
padding: 0 15px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.content-item {
|
||||
padding: 15px;
|
||||
margin: 5px 0;
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
|
||||
}
|
||||
|
||||
.text {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.search {
|
||||
background-color: #FFFFFF;
|
||||
border: 1px solid #fbdf0d;
|
||||
height: 35px;
|
||||
border-radius: 100px;
|
||||
margin: 0 12px;
|
||||
padding: 8px;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.search-tip-text {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
font-size: 12px;
|
||||
background-color: #ff6900;
|
||||
color: #FFF;
|
||||
padding: 5px 8px;
|
||||
border-radius: 100px;
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户