Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
80da005e
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
80da005e
编写于
8月 23, 2023
作者:
H
hdx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
long-list: 当 swiper item 首次可见时初始化数据
上级
216b6240
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
27 addition
and
11 deletion
+27
-11
pages/template/long-list/long-list-page.uvue
pages/template/long-list/long-list-page.uvue
+6
-2
pages/template/long-list/long-list.uvue
pages/template/long-list/long-list.uvue
+21
-9
未找到文件。
pages/template/long-list/long-list-page.uvue
浏览文件 @
80da005e
...
@@ -66,9 +66,13 @@
...
@@ -66,9 +66,13 @@
family: 'UtsIconsFontFamily',
family: 'UtsIconsFontFamily',
source: '/static/fonts/icon-star.ttf'
source: '/static/fonts/icon-star.ttf'
})
})
this.loadData()
},
},
methods: {
methods: {
init() {
if (this.dataList.length == 0) {
this.loadData()
}
},
loadData() {
loadData() {
if (this.loading || this.isEnded) {
if (this.loading || this.isEnded) {
return
return
...
@@ -94,7 +98,7 @@
...
@@ -94,7 +98,7 @@
this.dataList.push(item)
this.dataList.push(item)
})
})
if (responseData.data.length
<
= 0) {
if (responseData.data.length
=
= 0) {
this.isEnded = true
this.isEnded = true
} else {
} else {
this.$currentPage++
this.$currentPage++
...
...
pages/template/long-list/long-list.uvue
浏览文件 @
80da005e
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
<swiper class="swiper-view" ref="swiper" :current="swiperIndex" @change="onSwiperChange"
<swiper class="swiper-view" ref="swiper" :current="swiperIndex" @change="onSwiperChange"
@transition="onSwiperTransition" @animationfinish="onSwiperAnimationfinish">
@transition="onSwiperTransition" @animationfinish="onSwiperAnimationfinish">
<swiper-item class="swiper-item" v-for="(item, index) in swiperList" :key="index">
<swiper-item class="swiper-item" v-for="(item, index) in swiperList" :key="index">
<long-page :type="item.type"></long-page>
<long-page
ref="longPage"
:type="item.type"></long-page>
</swiper-item>
</swiper-item>
</swiper>
</swiper>
</view>
</view>
...
@@ -39,7 +39,8 @@
...
@@ -39,7 +39,8 @@
type SwiperViewItem = {
type SwiperViewItem = {
type : string,
type : string,
name : string
name : string,
init : Boolean,
}
}
// 测试数据
// 测试数据
...
@@ -98,19 +99,22 @@
...
@@ -98,19 +99,22 @@
this.setSwiperIndex(e.detail.current, false)
this.setSwiperIndex(e.detail.current, false)
},
},
onSwiperTransition(e : SwiperTransitionEvent) {
onSwiperTransition(e : SwiperTransitionEvent) {
const offsetX = e.detail.dx
;
const offsetX = e.detail.dx
let moveToIndex = offsetX > 0 ? this.$lastSwiperIndex + 1 : this.$lastSwiperIndex - 1
let moveToIndex = offsetX > 0 ? this.$lastSwiperIndex + 1 : this.$lastSwiperIndex - 1
if (moveToIndex < 0) { moveToIndex = 0 }
if (moveToIndex < 0) { moveToIndex = 0 }
if (moveToIndex > this.$swiperTabsRect.length - 1) { moveToIndex = this.$swiperTabsRect.length - 1 }
if (moveToIndex > this.$swiperTabsRect.length - 1) { moveToIndex = this.$swiperTabsRect.length - 1 }
const percentage = Math.abs(offsetX) / this.$swiperWidth;
const percentage = Math.abs(offsetX) / this.$swiperWidth
const currentSize = this.$swiperTabsRect[this.$lastSwiperIndex];
const currentSize = this.$swiperTabsRect[this.$lastSwiperIndex]
const moveToSize = this.$swiperTabsRect[moveToIndex];
const moveToSize = this.$swiperTabsRect[moveToIndex]
const indicatorlineL = currentSize.left + (moveToSize.left - currentSize.left) * percentage;
const indicatorlineL = currentSize.left + (moveToSize.left - currentSize.left) * percentage
const indicatorlineW = currentSize.width + (moveToSize.width - currentSize.width) * percentage;
const indicatorlineW = currentSize.width + (moveToSize.width - currentSize.width) * percentage
this.updateTabIndicator(indicatorlineL, indicatorlineW)
this.initSwiperItemPage(moveToIndex)
this.updateTabIndicator(indicatorlineL, indicatorlineW);
//console.log(this.$lastSwiperIndex, moveToIndex, offsetX, this.$swiperWidth, percentage);
//console.log(this.$lastSwiperIndex, moveToIndex, offsetX, this.$swiperWidth, percentage);
},
},
onSwiperAnimationfinish(e : SwiperAnimationFinishEvent) {
onSwiperAnimationfinish(e : SwiperAnimationFinishEvent) {
...
@@ -134,10 +138,18 @@
...
@@ -134,10 +138,18 @@
}
}
this.swiperIndex = index
this.swiperIndex = index
this.initSwiperItemPage(index)
if (updateIndicator) {
if (updateIndicator) {
this.updateTabIndicator(this.$swiperTabsRect[index].left, this.$swiperTabsRect[index].width)
this.updateTabIndicator(this.$swiperTabsRect[index].left, this.$swiperTabsRect[index].width)
}
}
},
},
initSwiperItemPage(index : Number) {
if (!this.swiperList[index].init) {
this.swiperList[index].init = true;
(this.$refs["longPage"] as ComponentPublicInstance[])[index].$callMethod('init')
}
},
updateTabIndicator(left : Number, width : Number) {
updateTabIndicator(left : Number, width : Number) {
this.swiperIndicatorLineLeft = left
this.swiperIndicatorLineLeft = left
this.swiperIndicatorLineWidth = width
this.swiperIndicatorLineWidth = width
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录