refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,41 @@
|
||||
const PAGE_PATH = '/pages/component/swiper/swiper-anim'
|
||||
|
||||
describe('swiper-touch-test', () => {
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
// 仅测试Android平台
|
||||
if (!isAndroid) {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor(100);
|
||||
})
|
||||
|
||||
|
||||
it('swiper-anim-test', async () => {
|
||||
|
||||
await page.waitFor(1500);
|
||||
const res = await page.callMethod('jest_getWindowInfo')
|
||||
const windowHeight = res.windowHeight * res.pixelRatio;
|
||||
const windowWidth = res.windowWidth * res.pixelRatio;
|
||||
|
||||
const image = await program.screenshot({
|
||||
deviceShot: true,
|
||||
area: {
|
||||
x: 0,
|
||||
y: 60,
|
||||
height: windowHeight - 60,
|
||||
width:windowWidth
|
||||
},
|
||||
});
|
||||
expect(image).toSaveImageSnapshot();
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<view>
|
||||
<text>computed属性在设置duration=0的测试:</text>
|
||||
<swiper :current="current" :vertical="true" :duration="0" style="height: 100px; width: 100%;">
|
||||
<swiper-item v-for="item,index in data.list" :key="item.id">
|
||||
<view>
|
||||
当前实际渲染的值:{{index}},指定current的值:{{current}}
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<text>同时设置autoplay / circular / duration的测试:</text>
|
||||
<swiper id="swiper-view" :autoplay="true" :interval="3000" :circular="true" :duration="3000" :current="0" style="height: 100px; width: 100%;">
|
||||
<swiper-item >
|
||||
<text>0000000000000000000</text>
|
||||
</swiper-item>
|
||||
<swiper-item >
|
||||
<text>111111111111111111</text>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
export type ListType={
|
||||
id:number,
|
||||
content:string
|
||||
}
|
||||
|
||||
type DataType = {
|
||||
list: ListType[],
|
||||
}
|
||||
|
||||
// 使用reactive包装数据,便于自动化测试获取
|
||||
const data = reactive({
|
||||
list: [
|
||||
{id:1,content:"第一个"},
|
||||
{id:2,content:"第二个"},
|
||||
] as ListType[],
|
||||
} as DataType)
|
||||
|
||||
const current = computed(():number => {
|
||||
return 1
|
||||
})
|
||||
|
||||
//自动化测试例专用
|
||||
function jest_getWindowInfo() : GetWindowInfoResult {
|
||||
return uni.getWindowInfo();
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
jest_getWindowInfo
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,298 @@
|
||||
<template>
|
||||
<view class="swiper-list">
|
||||
<scroll-view ref="tabScroll" class="swiper-tabs" direction="horizontal" :show-scrollbar="false">
|
||||
<view class="flex-row">
|
||||
<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.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">
|
||||
<list-view style="height: 100%; width: 100%; border: 3px solid lime;">
|
||||
<list-item>
|
||||
<swiper :disable-bounce="true" style="height: 180px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #e74c3c; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">A</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #3498db; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">B</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #2ecc71; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">C</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</list-item>
|
||||
<list-item v-for="item in 100" :key="item">
|
||||
<text class="list-item">{{item}}</text>
|
||||
</list-item>
|
||||
</list-view>
|
||||
</swiper-item>
|
||||
<swiper-item class="swiper-item">
|
||||
<list-view style="height: 100%; width: 100%; border: 3px solid lime;">
|
||||
<list-item>
|
||||
<swiper :circular="true" style="height: 180px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #e74c3c; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">A</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #3498db; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">B</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #2ecc71; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">C</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</list-item>
|
||||
<list-item v-for="item in 100" :key="item">
|
||||
<text class="list-item">{{item}}</text>
|
||||
</list-item>
|
||||
</list-view>
|
||||
</swiper-item>
|
||||
<swiper-item class="swiper-item">
|
||||
<list-view style="height: 100%; width: 100%; border: 3px solid lime;">
|
||||
<list-item>
|
||||
<swiper :disable-bounce="true" style="height: 180px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #e74c3c; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">A</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #3498db; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">B</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #2ecc71; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">C</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</list-item>
|
||||
<list-item v-for="item in 100" :key="item">
|
||||
<text class="list-item">{{item}}</text>
|
||||
</list-item>
|
||||
</list-view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
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<SwiperViewItem[]>([])
|
||||
const swiperIndex = ref(0)
|
||||
const tabScroll = ref<UniScrollViewElement | null>(null)
|
||||
const indicator = ref<UniElement | null>(null)
|
||||
const swiper = ref<UniSwiperElement | null>(null)
|
||||
const swipertab = ref<UniTextElement[] | null>(null)
|
||||
const animationFinishIndex = ref(0)
|
||||
const swiperWidth = ref(0)
|
||||
const swiperTabsRect = ref<SwiperTabsItem[]>([])
|
||||
|
||||
function updateTabIndicator(current_index : number, move_to_index : number, percentage : number) {
|
||||
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)
|
||||
// #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
|
||||
// console.log('scroll_x', scroll_x);
|
||||
tabScroll.value!.scrollLeft = scroll_x
|
||||
// console.log('scrollLeft', scroll_x);
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
tabScroll.value!.scrollTo({
|
||||
left: scroll_x
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
|
||||
function setSwiperIndex(index : number, updateIndicator : boolean) {
|
||||
if (swiperIndex.value === index) {
|
||||
return
|
||||
}
|
||||
swiperIndex.value = 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.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)
|
||||
}
|
||||
}
|
||||
|
||||
function onSwiperAnimationfinish(e : SwiperAnimationFinishEvent) {
|
||||
setSwiperIndex(e.detail.current, true)
|
||||
animationFinishIndex.value = e.detail.current
|
||||
}
|
||||
|
||||
async function cacheTabItemsSize() {
|
||||
swiperTabsRect.value.length = 0;
|
||||
const tabs = swipertab.value as UniElement[]
|
||||
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)
|
||||
}
|
||||
// console.log('swiperTabsRect', swiperTabsRect);
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const space = " ".repeat(i)
|
||||
swiperList.value.push({
|
||||
title: "Tab " + space + i
|
||||
} as SwiperViewItem)
|
||||
}
|
||||
})
|
||||
|
||||
onReady(() => {
|
||||
(swiper.value as UniElement).getBoundingClientRectAsync()!.then((res : DOMRect) : Promise<void> => {
|
||||
swiperWidth.value = res.width
|
||||
console.log('swiper-width', res.width);
|
||||
return cacheTabItemsSize()
|
||||
}).then(() => {
|
||||
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;
|
||||
}
|
||||
|
||||
.swiper-item-text {
|
||||
font-size: 72px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
margin-top: 1px;
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,234 @@
|
||||
<template>
|
||||
<view class="swiper-list">
|
||||
<scroll-view ref="tabScroll" class="swiper-tabs" direction="horizontal" :show-scrollbar="false">
|
||||
<view class="flex-row">
|
||||
<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.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="swiper-item-text">{{index}}</text>
|
||||
<!-- 可以将上述text组件替换为list组件,实现可左右滑动的长列表 -->
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
||||
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<SwiperViewItem[]>([])
|
||||
const swiperIndex = ref(0)
|
||||
const tabScroll = ref<UniScrollViewElement | null>(null)
|
||||
const indicator = ref<UniElement | null>(null)
|
||||
const swiper = ref<UniSwiperElement | null>(null)
|
||||
const swipertab = ref<UniTextElement[] | null>(null)
|
||||
const animationFinishIndex = ref(0)
|
||||
const swiperWidth = ref(0)
|
||||
const swiperTabsRect = ref<SwiperTabsItem[]>([])
|
||||
|
||||
function updateTabIndicator(current_index : number, move_to_index : number, percentage : number) {
|
||||
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)
|
||||
// #ifdef APP
|
||||
const x = indicator_line_x + indicator_line_w / 2
|
||||
// console.log('transform', `translateX(${x}px) scaleX(${indicator_line_w})`);
|
||||
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
|
||||
// console.log('scroll_x', scroll_x);
|
||||
tabScroll.value!.scrollLeft = scroll_x
|
||||
// console.log('scrollLeft', scroll_x);
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
tabScroll.value!.scrollTo({
|
||||
left: scroll_x
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
|
||||
function setSwiperIndex(index : number, updateIndicator : boolean) {
|
||||
if (swiperIndex.value === index) {
|
||||
return
|
||||
}
|
||||
swiperIndex.value = 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.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)
|
||||
// console.log(current_index, move_to_index, percentage);
|
||||
}
|
||||
}
|
||||
|
||||
function onSwiperAnimationfinish(e : SwiperAnimationFinishEvent) {
|
||||
console.log('@animationfinish.current=', e.detail.current)
|
||||
setSwiperIndex(e.detail.current, true)
|
||||
animationFinishIndex.value = e.detail.current
|
||||
}
|
||||
|
||||
async function cacheTabItemsSize() {
|
||||
swiperTabsRect.value.length = 0;
|
||||
const tabs = swipertab.value as UniElement[]
|
||||
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)
|
||||
}
|
||||
// console.log('swiperTabsRect', swiperTabsRect);
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
swiperList.value.push({
|
||||
title: "Tab " + i
|
||||
} as SwiperViewItem)
|
||||
}
|
||||
})
|
||||
|
||||
onReady(() => {
|
||||
(swiper.value as UniElement).getBoundingClientRectAsync()!.then((res : DOMRect) : Promise<void> => {
|
||||
swiperWidth.value = res.width
|
||||
return cacheTabItemsSize()
|
||||
}).then(() => {
|
||||
updateTabIndicator(swiperIndex.value, swiperIndex.value, 1)
|
||||
});
|
||||
})
|
||||
|
||||
// #ifdef APP
|
||||
const instance = getCurrentInstance();
|
||||
const insPage = instance.proxy.$page;
|
||||
var startime = Date.now();
|
||||
insPage.onRenderChange(({ duration }) => {
|
||||
const endtime = Date.now();
|
||||
uni.showToast({
|
||||
title: `${endtime - startime}ms`,
|
||||
})
|
||||
});
|
||||
// #endif
|
||||
</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;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.swiper-item-text {
|
||||
font-size: 72px;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,39 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
|
||||
describe('component-swiper-list-view', () => {
|
||||
if (isMP) {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
let page
|
||||
beforeAll(async () => {
|
||||
//打开swiper-list-view测试页
|
||||
page = await program.reLaunch('/pages/component/swiper/swiper-list-view')
|
||||
await page.waitFor('list-view')
|
||||
})
|
||||
|
||||
async function setPageData(newData) {
|
||||
return await page.setData({ data: newData });
|
||||
}
|
||||
|
||||
it('check-sticky-header', async () => {
|
||||
await setPageData({scrollTop: 300})
|
||||
await page.waitFor(600)
|
||||
await setPageData({currentVal: 1})
|
||||
await page.waitFor(async () => {
|
||||
return await page.data('data.swiperCurrentIndex') === 1;
|
||||
});
|
||||
await page.waitFor(200)
|
||||
await setPageData({currentVal: 0})
|
||||
await page.waitFor(async () => {
|
||||
return await page.data('data.swiperCurrentIndex') === 0;
|
||||
});
|
||||
await page.waitFor(600)
|
||||
const image = await program.screenshot({fullPage: true});
|
||||
expect(image).toSaveImageSnapshot();
|
||||
})
|
||||
|
||||
})
|
||||
@@ -0,0 +1,84 @@
|
||||
<template>
|
||||
<view style="flex: 1;">
|
||||
<view class="content-item">
|
||||
<text class="text">左右滑动页面,体验swiper嵌套list-view效果。</text>
|
||||
</view>
|
||||
<swiper style="flex: 1;" :current="data.currentVal" @change="swiperChange">
|
||||
<swiper-item v-for="index in 3">
|
||||
<list-view :id="'list'+index" style="flex: 1; border: 3px solid lime;" refresher-enabled="true" @refresherrefresh="onRefresherrefresh"
|
||||
:refresher-triggered="data.refresherTriggeredArray[index-1]" :scroll-top="data.scrollTop">
|
||||
<sticky-section>
|
||||
<sticky-header>
|
||||
<text class="header">上下滑动体验吸顶效果 swiper-item{{index}}</text>
|
||||
</sticky-header>
|
||||
<list-item v-for="itemIndex in 40" :key="itemIndex" class="item">
|
||||
<text>item----------{{itemIndex}}</text>
|
||||
</list-item>
|
||||
</sticky-section>
|
||||
</list-view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
|
||||
type DataType = {
|
||||
swiperCurrentIndex: number,
|
||||
currentVal: number,
|
||||
scrollTop: number,
|
||||
refresherTriggeredArray: boolean[],
|
||||
}
|
||||
|
||||
// 使用reactive包装数据,便于自动化测试获取
|
||||
const data = reactive({
|
||||
swiperCurrentIndex: 0,
|
||||
currentVal: 0,
|
||||
scrollTop: 0,
|
||||
refresherTriggeredArray: [false, false, false] as boolean[],
|
||||
} as DataType)
|
||||
|
||||
// Methods
|
||||
function swiperChange(e : SwiperChangeEvent) {
|
||||
data.swiperCurrentIndex = e.detail.current
|
||||
}
|
||||
|
||||
function onRefresherrefresh() {
|
||||
data.refresherTriggeredArray[data.swiperCurrentIndex] = true
|
||||
setTimeout(() => {
|
||||
data.refresherTriggeredArray[data.swiperCurrentIndex] = false
|
||||
}, 100)
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.item {
|
||||
padding: 15px;
|
||||
margin: 0 0 5px 0;
|
||||
background-color: #fff;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.text {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.content-item {
|
||||
padding: 15px;
|
||||
margin-bottom: 10px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.header {
|
||||
background-color: #ffaa00;
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,482 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1;">
|
||||
<!-- #endif -->
|
||||
<view style="padding: 10px;">
|
||||
<text style="font-size: 18px; font-weight: bold; color: #333; margin-bottom: 10px;">Swiper组件演示</text>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">不等高slider测试(Auto Height)harmony 无效:</text>
|
||||
<text style="color: #999; font-size: 12px; margin-bottom: 5px;">容器高度随当前slider内容自动调整</text>
|
||||
<swiper auto-height>
|
||||
<swiper-item>
|
||||
<view style="background-color: #ff6b6b; padding: 20px;">
|
||||
<view style="background-color: white; padding: 15px; border-radius: 8px;">
|
||||
<text style="color: #333; font-size: 16px; line-height: 24px;">短内容 - 高度约100px</text>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="background-color: #4ecdc4; padding: 20px;">
|
||||
<view style="background-color: white; padding: 15px; border-radius: 8px;">
|
||||
<text style="color: #333; font-size: 16px; line-height: 24px;">中等内容 - 高度约150px
|
||||
这里有更多的文字来测试不同高度的slider是否能正常显示和切换。容器应该自动调整到这个高度。</text>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="background-color: #95e1d3; padding: 20px;">
|
||||
<view style="background-color: white; padding: 15px; border-radius: 8px;">
|
||||
<text style="color: #333; font-size: 16px; line-height: 24px;">长内容 - 高度约200px
|
||||
这是一个高度较大的内容。这里有很多文字来测试不同高度的slider。
|
||||
包含了更多的信息和描述内容,用于验证swiper在处理不等高内容时的表现。
|
||||
容器高度应该自动调整到这个slider的高度。</text>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">基础用法(横向滑动,测试指示器可见性):</text>
|
||||
<swiper style="height: 150px;" :indicator-dots="true">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #ff6b6b; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Item 1 红</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #fff; align-items: center; justify-content: center;">
|
||||
<text style="color: #333; font-size: 24px;">Item 2 白</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #000; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Item 3 黑</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">3D卡片(previousMargin + nextMargin + circular),应用层实现缩放:</text>
|
||||
<swiper
|
||||
circular
|
||||
previous-margin="40px"
|
||||
next-margin="40px"
|
||||
style="height: 120px;"
|
||||
@change="handleScaleChange1"
|
||||
>
|
||||
<swiper-item>
|
||||
<view class="scale-card" :class="{'scale-card-active': scaleCurrentIndex1 == 0}">
|
||||
<view style="width: 100%; height: 100%; background-color: #e74c3c; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">A</text>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view class="scale-card" :class="{'scale-card-active': scaleCurrentIndex1 == 1}">
|
||||
<view style="width: 100%; height: 100%; background-color: #3498db; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">B</text>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view class="scale-card" :class="{'scale-card-active': scaleCurrentIndex1 == 2}">
|
||||
<view style="width: 100%; height: 100%; background-color: #2ecc71; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">C</text>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">3D卡片(previousMargin + nextMargin + circular),应用层实现缩放:</text>
|
||||
<swiper
|
||||
circular
|
||||
previous-margin="40px"
|
||||
next-margin="40px"
|
||||
style="height: 120px;"
|
||||
@change="handleScaleChange2"
|
||||
>
|
||||
<swiper-item>
|
||||
<view class="scale-card" :class="{'scale-card-active': scaleCurrentIndex2 == 0}">
|
||||
<view style="width: 100%; height: 100%; background-color: #e74c3c; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">A</text>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view class="scale-card" :class="{'scale-card-active': scaleCurrentIndex2 == 1}">
|
||||
<view style="width: 100%; height: 100%; background-color: #3498db; align-items: center; justify-content: center; border-radius: 8px;">
|
||||
<text style="color: white; font-size: 20px;">B</text>
|
||||
</view>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">垂直滑动(vertical):</text>
|
||||
<swiper vertical style="height: 200px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #8e44ad; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #2c3e50; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #e67e22; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">垂直滑动(vertical)且开启 disable-rebound:</text>
|
||||
<swiper vertical :disable-bounce="true" style="height: 200px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #8e44ad; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #2c3e50; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #e67e22; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">垂直滑动(vertical)且开启 circular:</text>
|
||||
<swiper vertical circular style="height: 200px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #8e44ad; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #2c3e50; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #e67e22; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Vertical 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">自动播放 + 循环(autoplay + circular):</text>
|
||||
<swiper autoplay circular :interval="2000" style="height: 150px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #ee5a6f; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Auto 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #f368e0; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Auto 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #ff9ff3; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Auto 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">2卡片 + 循环circular:</text>
|
||||
<swiper circular :interval="2000" style="height: 150px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #ee5a6f; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">A</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #f368e0; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">B</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">指示器短横线样式(item-style):</text>
|
||||
<swiper style="height: 150px;" :indicator-dots="true" indicator-style="width: 20px; height: 3px; border-radius: 2px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #9b59b6; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Line 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #ffffff; align-items: center; justify-content: center;">
|
||||
<text style="color: black; font-size: 24px;">Line 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #000000; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Line 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">高亮指示器加长(item-active-style):</text>
|
||||
<swiper style="height: 150px;" :indicator-dots="true" indicator-style="width: 8px; height: 8px;" indicator-active-style="width: 12px; height: 8px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #e84118; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Scale 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #c23616; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Scale 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">指示器class定制(item-class + item-active-class):</text>
|
||||
<swiper style="height: 150px;" :indicator-dots="true" indicator-class="custom-item" indicator-active-class="custom-item-active">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #f39c12; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Class 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #d35400; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Class 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">指示器样式定制(item-style + item-active-style):</text>
|
||||
<swiper style="height: 150px;" :indicator-dots="true" indicator-style="width: 16px; height: 4px; border-radius: 2px; background-color: rgba(100, 100, 255, 0.5);" indicator-active-style="width: 24px; background-color: rgba(100, 100, 255, 1);">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #8e44ad; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Style 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #9b59b6; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Style 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">事件监听(@change、@transition、@animationfinish):</text>
|
||||
<text style="color: #999; font-size: 12px; margin-bottom: 5px;">当前索引: {{eventCurrentIndex}}</text>
|
||||
<text style="color: #999; font-size: 12px; margin-bottom: 5px;">上次触发: {{eventSource}}</text>
|
||||
<text style="color: #999; font-size: 12px; margin-bottom: 5px;">过渡位置: dx={{transitionDx}}, dy={{transitionDy}}</text>
|
||||
<swiper
|
||||
@change="handleChange"
|
||||
@transition="handleTransition"
|
||||
@animationfinish="handleAnimationFinish"
|
||||
style="height: 150px;"
|
||||
>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #2d3436; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Event 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #636e72; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Event 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #b2bec3; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Event 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">自定义数字指示器(slot):</text>
|
||||
<swiper @change="handleCustomIndicatorChange" style="height: 150px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #16a085; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Custom 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #ffffff; align-items: center; justify-content: center;">
|
||||
<text style="color: black; font-size: 24px;">Custom 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #000000; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Custom 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<template v-slot:indicator>
|
||||
<view style="position: absolute; bottom: 10px; right: 10px; background-color: rgba(0,0,0,0.6); padding: 4px 12px; border-radius: 12px;">
|
||||
<text style="color: white; font-size: 14px; font-weight: bold;">{{customIndicatorIndex + 1}}/{{customIndicatorTotal}}</text>
|
||||
</view>
|
||||
</template>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">自定义指示器并绑定点击事件(仅web支持点击):</text>
|
||||
<swiper :current='customIndicatorCurrent' style="height: 150px;" @change="handleCustomIndicatorHandleClickChange">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #16a085; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Custom 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #ffffff; align-items: center; justify-content: center;">
|
||||
<text style="color: black; font-size: 24px;">Custom 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #000000; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Custom 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<template v-slot:indicator>
|
||||
<view v-for="item in 3" style="margin: 0 10px;">
|
||||
<text class="custom-indicator-text" :class="{ 'active': customIndicatorCurrent == item - 1 }" @click="handleCustomIndicatorClick(item - 1)">{{item - 1}}</text>
|
||||
</view>
|
||||
</template>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<view style="margin-bottom: 20px;">
|
||||
<text style="color: #666; margin-bottom: 10px;">circular 和 disabled-bounce 同时设置:</text>
|
||||
<text style="color: #999; font-size: 12px; margin-bottom: 5px;">以circular为优先</text>
|
||||
<swiper :disable-bounce="false" :circular="true" style="height: 150px;">
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #3742fa; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Rebound 1</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #5352ed; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Rebound 2</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item>
|
||||
<view style="width: 100%; height: 100%; background-color: #a29bfe; align-items: center; justify-content: center;">
|
||||
<text style="color: white; font-size: 24px;">Rebound 3</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
const scaleCurrentIndex1 = ref<number>(0)
|
||||
const scaleCurrentIndex2 = ref<number>(0)
|
||||
|
||||
|
||||
const eventCurrentIndex = ref<number>(0)
|
||||
const eventSource = ref<string>('none')
|
||||
const transitionDx = ref<number>(0)
|
||||
const transitionDy = ref<number>(0)
|
||||
|
||||
const customIndicatorIndex = ref<number>(0)
|
||||
const customIndicatorTotal = ref<number>(3)
|
||||
const customIndicatorCurrent = ref<number>(0)
|
||||
|
||||
const handleScaleChange1 = (e: UniSwiperChangeEvent) => {
|
||||
scaleCurrentIndex1.value = e.detail.current
|
||||
}
|
||||
const handleScaleChange2 = (e: UniSwiperChangeEvent) => {
|
||||
scaleCurrentIndex2.value = e.detail.current
|
||||
}
|
||||
|
||||
const handleChange = (e: UniSwiperChangeEvent) => {
|
||||
eventCurrentIndex.value = e.detail.current
|
||||
eventSource.value = 'change-' + e.detail.source
|
||||
}
|
||||
|
||||
const handleTransition = (e: UniSwiperTransitionEvent) => {
|
||||
transitionDx.value = Math.round(e.detail.dx)
|
||||
transitionDy.value = Math.round(e.detail.dy)
|
||||
}
|
||||
|
||||
const handleAnimationFinish = (e: UniSwiperAnimationFinishEvent) => {
|
||||
eventSource.value = 'animationfinish-' + e.detail.source
|
||||
}
|
||||
|
||||
const handleCustomIndicatorChange = (e: UniSwiperChangeEvent) => {
|
||||
customIndicatorIndex.value = e.detail.current
|
||||
}
|
||||
const handleCustomIndicatorHandleClickChange = (e: UniSwiperChangeEvent) => {
|
||||
customIndicatorCurrent.value = e.detail.current
|
||||
}
|
||||
const handleCustomIndicatorClick = (index: number) => {
|
||||
customIndicatorCurrent.value = index
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.scale-card {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transform: scale(0.9);
|
||||
opacity: 0.7;
|
||||
transition: all 300ms ease;
|
||||
}
|
||||
|
||||
.scale-card-active {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.custom-item {
|
||||
width: 16px;
|
||||
height: 4px;
|
||||
border-radius: 2px;
|
||||
background-color: rgba(255, 165, 0, 0.5);
|
||||
}
|
||||
|
||||
.custom-item-active {
|
||||
width: 24px;
|
||||
background-color: rgba(255, 165, 0, 1);
|
||||
}
|
||||
.custom-indicator-text {
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
color: #ccc;
|
||||
}
|
||||
.custom-indicator-text.active {
|
||||
font-size: 18px;
|
||||
color: yellow;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,136 @@
|
||||
describe('test swiper', () => {
|
||||
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')
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isDom2 = process.env.UNI_APP_X_DOM2 === "true"
|
||||
|
||||
let page;
|
||||
const detailResWithCurrentItemId = {
|
||||
current: 1,
|
||||
currentItemId: 'B',//web端多了currentItemId
|
||||
source: 'autoplay' ,
|
||||
}
|
||||
const detailRes = {
|
||||
current: 1,
|
||||
source: 'autoplay' ,
|
||||
}
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch('/pages/component/swiper/swiper')
|
||||
await page.waitFor('view')
|
||||
})
|
||||
|
||||
if(!isMP) {
|
||||
it('check autoplay loop', async () => {
|
||||
await page.setData({
|
||||
data:{
|
||||
currentValChange: 0,
|
||||
autoplaySelect: true,
|
||||
}
|
||||
})
|
||||
const swiperChangeInterval = (isHarmony && !isDom2) ? 2700 : 2500
|
||||
await page.waitFor(swiperChangeInterval)
|
||||
expect(await page.data('data.currentValChange')).toEqual(1)
|
||||
await page.waitFor(swiperChangeInterval)
|
||||
expect(await page.data('data.currentValChange')).toEqual(2)
|
||||
await page.waitFor(swiperChangeInterval)
|
||||
expect(await page.data('data.currentValChange')).toEqual(0)
|
||||
|
||||
await page.setData({
|
||||
data:{autoplaySelect: false}
|
||||
})
|
||||
await page.waitFor(300)
|
||||
});
|
||||
}
|
||||
|
||||
it('check current', async () => {
|
||||
if(isMP) {
|
||||
// 微信小程序表现较为怪异,interval显式的设置非0的情况下,会无视autoplay属性。interval默认值5000
|
||||
await page.setData({
|
||||
data:{intervalSelect: 0,}
|
||||
})
|
||||
}
|
||||
await page.setData({
|
||||
data:{currentVal: 2,}
|
||||
})
|
||||
await page.waitFor(600)
|
||||
expect(await page.data('data.currentValChange')).toEqual(2)
|
||||
await page.setData({
|
||||
data:{currentVal: 0,}
|
||||
})
|
||||
await page.waitFor(600)
|
||||
expect(await page.data('data.currentValChange')).toEqual(0)
|
||||
|
||||
if(isMP) {
|
||||
await page.setData({
|
||||
data:{intervalSelect: 2000,}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
if (!isDom2) {
|
||||
it('check currentId', async () => {
|
||||
await page.setData({
|
||||
data:{currentItemIdVal: 'C',}
|
||||
})
|
||||
await page.waitFor(800)
|
||||
expect(await page.data('data.currentValChange')).toEqual(2)
|
||||
|
||||
await page.setData({
|
||||
data:{currentItemIdVal: 'A',}
|
||||
})
|
||||
await page.waitFor(800)
|
||||
expect(await page.data('data.currentValChange')).toEqual(0)
|
||||
});
|
||||
}
|
||||
|
||||
it('Trigger Event', async () => {
|
||||
await page.setData({
|
||||
data:{
|
||||
swiperChangeSelect: true,
|
||||
swiperTransitionSelect: true,
|
||||
swiperAnimationfinishSelect: true,
|
||||
autoplaySelect:true,
|
||||
}
|
||||
})
|
||||
await page.waitFor(2000)
|
||||
await page.waitFor(async()=>{
|
||||
return await page.data('data.currentValChange') == 1
|
||||
})
|
||||
await page.setData({
|
||||
data:{autoplaySelect:false}
|
||||
})
|
||||
});
|
||||
|
||||
it('Event transition', async () => {
|
||||
await page.waitFor(100)
|
||||
const transitionDetailInfo = await page.data('data.transitionDetailTest')
|
||||
expect(transitionDetailInfo.dy).toBe(0)
|
||||
expect(transitionDetailInfo.dx).not.toBe(0)
|
||||
expect(await page.data('data.isTransitionTest')).toBe('transition:Success')
|
||||
});
|
||||
|
||||
it('Event change', async () => {
|
||||
const changeDetailInfo = await page.data('data.changeDetailTest')
|
||||
if(isWeb || isMP || isHarmony || (isiOS && isDom2) || (isAndroid && isDom2)){
|
||||
expect(changeDetailInfo).toEqual(detailResWithCurrentItemId)
|
||||
}else{
|
||||
expect(changeDetailInfo).toEqual(detailRes)
|
||||
}
|
||||
expect(await page.data('data.isChangeTest')).toBe('change:Success')
|
||||
});
|
||||
|
||||
it('Event animationfinish', async () => {
|
||||
// 等待最后一个动画结束animationfinish
|
||||
await page.waitFor(2000)
|
||||
const animationfinishDetailInfo = await page.data('data.animationfinishDetailTest')
|
||||
if(isWeb || isMP || isHarmony || (isiOS && isDom2) || (isAndroid && isDom2)){
|
||||
expect(animationfinishDetailInfo).toEqual(detailResWithCurrentItemId)
|
||||
}else{
|
||||
expect(animationfinishDetailInfo).toEqual(detailRes)
|
||||
}
|
||||
expect(await page.data('data.isAnimationfinishTest')).toBe('animationfinish:Success')
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,413 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view class="page-scroll-view">
|
||||
<!-- #endif -->
|
||||
<view class="uni-common-mb uni-common-pb">
|
||||
<page-head title="swiper,可滑动视图"></page-head>
|
||||
<view>
|
||||
<!-- 微信小程序自身Bug,autoplay为false时更新interval会导致swiper启用自动播放 -->
|
||||
<swiper id="swiper-view" class="swiper" :vertical="data.verticalSelect" :indicator-dots="data.dotsSelect"
|
||||
:autoplay="data.autoplaySelect"
|
||||
<!-- #ifdef (APP && VUE3-VAPOR) -->
|
||||
:disable-bounce="data.disableBounceSelect"
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef (APP && VUE3-VAPOR) -->
|
||||
:bounces="!data.disableBounceSelect"
|
||||
<!-- #endif -->
|
||||
:interval="data.intervalSelect" :circular="data.circularSelect"
|
||||
:duration="data.durationSelect" :indicator-color="data.indicatorColor" :indicator-active-color="data.indicatorColorActive"
|
||||
:disable-touch="data.disableTouchSelect" :current="data.currentVal" :current-item-id="data.currentItemIdVal"
|
||||
@change="swiperChange" @transition="swiperTransition" @animationfinish="swiperAnimationfinish"
|
||||
@touchstart="swipertouchStart">
|
||||
<swiper-item item-id="A">
|
||||
<view class="swiper-item uni-bg-red"><text class="swiper-item-Text" @touchstart="viewtouchStart">A</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
<swiper-item item-id="B">
|
||||
<view class="swiper-item uni-bg-green"><text class="swiper-item-Text">B</text></view>
|
||||
</swiper-item>
|
||||
<swiper-item item-id="C">
|
||||
<view class="swiper-item uni-bg-blue"><text class="swiper-item-Text">C</text></view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
<view class="uni-list">
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">显示面板指示点</view>
|
||||
<switch :checked="data.dotsSelect" @change="dotsChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">定制指示器颜色</view>
|
||||
<switch :checked="data.indicatorColorSelect"
|
||||
<!-- #ifndef (APP && VUE3-VAPOR) -->
|
||||
:disabled="true"
|
||||
<!-- #endif -->
|
||||
@change="indicatorColorChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">禁止 touch 操作</view>
|
||||
<switch :checked="data.disableTouchSelect" @change="disableTouchChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">是否自动切换</view>
|
||||
<switch :checked="data.autoplaySelect" @change="autoplayChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">是否衔接滑动</view>
|
||||
<switch :checked="data.circularSelect" @change="circularChange" />
|
||||
</view>
|
||||
<view class="uni-title uni-list-cell-padding">间隔时间(毫秒)</view>
|
||||
<view class="uni-padding-wrap">
|
||||
<slider @change="sliderChange" :value="2000" :min="500" :max="5000" :show-value="true" />
|
||||
</view>
|
||||
<view class="uni-title uni-list-cell-padding">动画时长(毫秒)</view>
|
||||
<view class="uni-padding-wrap">
|
||||
<slider @change="durationSliderChange" :value="500" :min="50" :max="2000" :show-value="true" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">是否纵向滑动</view>
|
||||
<switch :checked="data.verticalSelect" @change="verticalChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">是否禁用回弹效果</view>
|
||||
<!-- 仅 android ios harmony 支持,web 微信小程序 bounces 为 true -->
|
||||
<switch :checked="data.disableBounceSelect" @change="disableBounceSelectChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">指定current为最后一个元素</view>
|
||||
<switch :checked="data.currentSelect" @change="currentChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">指定current-item-id为最后一个元素</view>
|
||||
<switch :checked="data.currentItemIdSelect" @change="currentItemIdChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">打印 swiperChange 日志</view>
|
||||
<switch :checked="data.swiperChangeSelect" @change="swiperChangeChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">打印 swiperTransition 日志</view>
|
||||
<switch :checked="data.swiperTransitionSelect" @change="swiperTransitionChange" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">打印 swiperAnimationfinish 日志</view>
|
||||
<switch :checked="data.swiperAnimationfinishSelect" @change="swiperAnimationfinishChange" />
|
||||
</view>
|
||||
|
||||
<view class="uni-list-cell-padding">测试 swiper 默认行为</view>
|
||||
<swiper class="swiper" :autoplay="data.autoplayForDefault" :circular="data.circularForDefault">
|
||||
<swiper-item item-id="A">
|
||||
<view class="swiper-item uni-bg-red"><text class="swiper-item-Text">A</text></view>
|
||||
</swiper-item>
|
||||
<swiper-item item-id="B">
|
||||
<view class="swiper-item uni-bg-green"><text class="swiper-item-Text">B</text></view>
|
||||
</swiper-item>
|
||||
<swiper-item item-id="C">
|
||||
<view class="swiper-item uni-bg-blue"><text class="swiper-item-Text">C</text></view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">是否自动切换</view>
|
||||
<switch :checked="data.autoplayForDefault" @change="() => {data.autoplayForDefault = !data.autoplayForDefault}" />
|
||||
</view>
|
||||
<view class="uni-list-cell uni-list-cell-padding">
|
||||
<view class="uni-list-cell-db">是否衔接滑动</view>
|
||||
<switch :checked="data.circularForDefault" @change="() => {data.circularForDefault = !data.circularForDefault}" />
|
||||
</view>
|
||||
<!-- #ifndef MP -->
|
||||
<navigator url="/pages/component/swiper/swiper-list-view">
|
||||
<button type="primary">
|
||||
swiper 嵌套 list-view 测试
|
||||
</button>
|
||||
</navigator>
|
||||
<navigator url="/pages/component/swiper/swiper-anim" style="margin-top: 10px;">
|
||||
<button type="primary">
|
||||
swiper 动画测试
|
||||
</button>
|
||||
</navigator>
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef (APP && VUE3-VAPOR) -->
|
||||
<navigator url="/pages/component/swiper/swiper-more" style="margin-top: 10px;">
|
||||
<button type="primary">
|
||||
更多 swiper
|
||||
</button>
|
||||
</navigator>
|
||||
<navigator url="/pages/component/swiper/swiper-in-swiper" style="margin-top: 10px;">
|
||||
<button type="primary">嵌套测试</button>
|
||||
</navigator>
|
||||
<navigator url="/pages/component/swiper/swiper-item-100" style="margin-top: 10px;">
|
||||
<button>组件性能测试</button>
|
||||
</navigator>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
type SwiperEventTest = {
|
||||
type : string;
|
||||
target : UniElement | null;
|
||||
currentTarget : UniElement | null;
|
||||
}
|
||||
|
||||
type DataType = {
|
||||
background: string[];
|
||||
dotsSelect: boolean;
|
||||
disableBounceSelect: boolean;
|
||||
autoplaySelect: boolean;
|
||||
circularSelect: boolean;
|
||||
indicatorColorSelect: boolean;
|
||||
verticalSelect: boolean;
|
||||
currentSelect: boolean;
|
||||
currentItemIdSelect: boolean;
|
||||
intervalSelect: number;
|
||||
durationSelect: number;
|
||||
indicatorColor: string;
|
||||
indicatorColorActive: string;
|
||||
currentVal: number;
|
||||
currentItemIdVal: string;
|
||||
disableTouchSelect: boolean;
|
||||
swiperTransitionSelect: boolean;
|
||||
swiperAnimationfinishSelect: boolean;
|
||||
swiperChangeSelect: boolean;
|
||||
currentValChange: number;
|
||||
autoplayForDefault: boolean;
|
||||
circularForDefault: boolean;
|
||||
// 自动化测试
|
||||
changeDetailTest: UniSwiperChangeEventDetail | null;
|
||||
transitionDetailTest: UniSwiperTransitionEventDetail | null;
|
||||
animationfinishDetailTest: UniSwiperAnimationFinishEventDetail | null;
|
||||
isChangeTest: string;
|
||||
isTransitionTest: string;
|
||||
isAnimationfinishTest: string;
|
||||
swipeX: number;
|
||||
swipeY: number;
|
||||
}
|
||||
|
||||
// 使用reactive避免ref数据在自动化测试中无法访问
|
||||
const data = reactive({
|
||||
background: ['color1', 'color2', 'color3'],
|
||||
dotsSelect: false,
|
||||
disableBounceSelect: false,
|
||||
autoplaySelect: false,
|
||||
circularSelect: false,
|
||||
indicatorColorSelect: false,
|
||||
verticalSelect: false,
|
||||
currentSelect: false,
|
||||
currentItemIdSelect: false,
|
||||
intervalSelect: 2000,
|
||||
durationSelect: 500,
|
||||
indicatorColor: "",
|
||||
indicatorColorActive: "",
|
||||
currentVal: 0,
|
||||
currentItemIdVal: "",
|
||||
disableTouchSelect: false,
|
||||
swiperTransitionSelect: false,
|
||||
swiperAnimationfinishSelect: false,
|
||||
swiperChangeSelect: false,
|
||||
currentValChange: 0,
|
||||
autoplayForDefault: false,
|
||||
circularForDefault: false,
|
||||
// 自动化测试
|
||||
changeDetailTest: null as UniSwiperChangeEventDetail | null,
|
||||
transitionDetailTest: null as UniSwiperTransitionEventDetail | null,
|
||||
animationfinishDetailTest: null as UniSwiperAnimationFinishEventDetail | null,
|
||||
isChangeTest: '',
|
||||
isTransitionTest: '',
|
||||
isAnimationfinishTest: '',
|
||||
swipeX: 0,
|
||||
swipeY: 0
|
||||
} as DataType)
|
||||
|
||||
onReady(() => {
|
||||
// #ifndef MP
|
||||
// 获取模拟滑动手势的起始点
|
||||
let ele = uni.getElementById("swiper-view")
|
||||
let eleRect = ele?.getBoundingClientRect()
|
||||
if (eleRect != null) {
|
||||
// 避开右侧边界,避免滑动行为响应为侧滑
|
||||
data.swipeX = eleRect.width - 40
|
||||
data.swipeY += eleRect.y + uni.getSystemInfoSync().safeArea.top + 44 + 35
|
||||
}
|
||||
// #endif
|
||||
})
|
||||
|
||||
const swipertouchStart = (e : UniTouchEvent) => {
|
||||
console.log("swiper touchstart")
|
||||
}
|
||||
|
||||
const viewtouchStart = (e : UniTouchEvent) => {
|
||||
console.log("view touchstart:")
|
||||
}
|
||||
|
||||
// 自动化测试专用(由于事件event参数对象中存在循环引用,在ios端JSON.stringify报错,自动化测试无法page.data获取)
|
||||
const checkEventTest = (e : SwiperEventTest, eventName : String) => {
|
||||
// #ifndef MP
|
||||
const isPass = e.type === eventName && e.target instanceof UniElement && e.currentTarget instanceof UniElement;
|
||||
// #endif
|
||||
// #ifdef MP
|
||||
const isPass = true;
|
||||
// #endif
|
||||
const result = isPass ? `${eventName}:Success` : `${eventName}:Fail`;
|
||||
switch (eventName) {
|
||||
case 'change':
|
||||
data.isChangeTest = result
|
||||
break;
|
||||
case 'transition':
|
||||
data.isTransitionTest = result
|
||||
break;
|
||||
case 'animationfinish':
|
||||
data.isAnimationfinishTest = result
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const swiperChange = (e : UniSwiperChangeEvent) => {
|
||||
data.changeDetailTest = e.detail
|
||||
checkEventTest({
|
||||
type: e.type,
|
||||
target: e.target,
|
||||
currentTarget: e.currentTarget
|
||||
} as SwiperEventTest, 'change')
|
||||
data.currentValChange = e.detail.current
|
||||
console.log(data.currentValChange)
|
||||
if (data.swiperChangeSelect) {
|
||||
console.log("swiperChange", e)
|
||||
}
|
||||
}
|
||||
|
||||
const swiperTransition = (e : UniSwiperTransitionEvent) => {
|
||||
data.transitionDetailTest = e.detail
|
||||
checkEventTest({
|
||||
type: e.type,
|
||||
target: e.target,
|
||||
currentTarget: e.currentTarget
|
||||
} as SwiperEventTest, 'transition')
|
||||
if (data.swiperTransitionSelect) {
|
||||
console.log("swiperTransition", e)
|
||||
}
|
||||
}
|
||||
|
||||
const swiperAnimationfinish = (e : UniSwiperAnimationFinishEvent) => {
|
||||
data.animationfinishDetailTest = e.detail
|
||||
checkEventTest({
|
||||
type: e.type,
|
||||
target: e.target,
|
||||
currentTarget: e.currentTarget
|
||||
} as SwiperEventTest, 'animationfinish')
|
||||
if (data.swiperAnimationfinishSelect) {
|
||||
console.log("swiperAnimationfinish", e)
|
||||
}
|
||||
}
|
||||
|
||||
//自动化测试例专用
|
||||
const jest_getSystemInfo = () : GetSystemInfoResult => {
|
||||
return uni.getSystemInfoSync();
|
||||
}
|
||||
|
||||
|
||||
const dotsChange = (e : UniSwitchChangeEvent) => {
|
||||
data.dotsSelect = e.detail.value
|
||||
}
|
||||
|
||||
const swiperTransitionChange = (e : UniSwitchChangeEvent) => {
|
||||
data.swiperTransitionSelect = e.detail.value
|
||||
}
|
||||
|
||||
const swiperChangeChange = (e : UniSwitchChangeEvent) => {
|
||||
data.swiperChangeSelect = e.detail.value
|
||||
}
|
||||
|
||||
const swiperAnimationfinishChange = (e : UniSwitchChangeEvent) => {
|
||||
data.swiperAnimationfinishSelect = e.detail.value
|
||||
}
|
||||
|
||||
const autoplayChange = (e : UniSwitchChangeEvent) => {
|
||||
data.autoplaySelect = e.detail.value
|
||||
}
|
||||
|
||||
const verticalChange = (e : UniSwitchChangeEvent) => {
|
||||
data.verticalSelect = e.detail.value
|
||||
}
|
||||
|
||||
const disableTouchChange = (e : UniSwitchChangeEvent) => {
|
||||
data.disableTouchSelect = e.detail.value
|
||||
}
|
||||
|
||||
const currentItemIdChange = (e : UniSwitchChangeEvent) => {
|
||||
data.currentItemIdSelect = e.detail.value
|
||||
if (data.currentItemIdSelect) {
|
||||
data.currentItemIdVal = 'C'
|
||||
} else {
|
||||
data.currentItemIdVal = 'A'
|
||||
}
|
||||
}
|
||||
|
||||
const currentChange = (e : UniSwitchChangeEvent) => {
|
||||
data.currentSelect = e.detail.value
|
||||
if (data.currentSelect) {
|
||||
data.currentVal = 2
|
||||
} else {
|
||||
data.currentVal = 0
|
||||
}
|
||||
}
|
||||
|
||||
const circularChange = (e : UniSwitchChangeEvent) => {
|
||||
data.circularSelect = e.detail.value
|
||||
console.log(data.circularSelect)
|
||||
}
|
||||
|
||||
const disableBounceSelectChange = (e : UniSwitchChangeEvent) => {
|
||||
data.disableBounceSelect = e.detail.value
|
||||
console.log(data.disableBounceSelect)
|
||||
}
|
||||
|
||||
const sliderChange = (e : UniSliderChangeEvent) => {
|
||||
data.intervalSelect = e.detail.value
|
||||
}
|
||||
|
||||
const durationSliderChange = (e : UniSliderChangeEvent) => {
|
||||
data.durationSelect = e.detail.value
|
||||
}
|
||||
|
||||
const indicatorColorChange = (e : UniSwitchChangeEvent) => {
|
||||
data.indicatorColorSelect = e.detail.value
|
||||
if (data.indicatorColorSelect) {
|
||||
// 选择了定制指示器颜色
|
||||
data.indicatorColor = "#ff00ff"
|
||||
data.indicatorColorActive = "#0000ff"
|
||||
} else {
|
||||
// 没有选择颜色
|
||||
data.indicatorColor = ""
|
||||
data.indicatorColorActive = ""
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
jest_getSystemInfo
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.swiper {
|
||||
height: 150px;
|
||||
}
|
||||
|
||||
.swiper-item {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
}
|
||||
|
||||
.swiper-item-Text {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
line-height: 150px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,50 @@
|
||||
// @Author-APP-ANDROID:DCloud_Android_DQQ
|
||||
const PAGE_PATH = '/pages/component/swiper/swiper'
|
||||
|
||||
|
||||
describe('swiper-touch-test', () => {
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isMP = platformInfo.startsWith('mp')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
let res;
|
||||
// 屏蔽 web & 小程序,不支持 program.swipe
|
||||
if (isWeb || isMP) {
|
||||
it('other platform', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view');
|
||||
res = await page.callMethod('jest_getSystemInfo')
|
||||
})
|
||||
|
||||
|
||||
it('滑动切换 swiper', async () => {
|
||||
let x = await page.data('data.swipeX')
|
||||
let y = await page.data('data.swipeY')
|
||||
// harmony onReady getBoundingClientRect 获取节点宽度不稳定,偶发错误
|
||||
if (isHarmony && x < 20) {
|
||||
x = 300
|
||||
}
|
||||
// program.swipe Android10以上不生效
|
||||
if(isAndroid && res.osAndroidAPILevel > 28){
|
||||
// 避免 android 10 侧滑影响
|
||||
x -= 20
|
||||
}
|
||||
await program.swipe({
|
||||
startPoint: {x, y},
|
||||
endPoint: {x: 10, y},
|
||||
duration: 200
|
||||
})
|
||||
|
||||
await page.waitFor(1000)
|
||||
let val = await page.data('data.currentValChange')
|
||||
expect(val).toEqual(1)
|
||||
})
|
||||
})
|
||||
在新工单中引用
屏蔽一个用户