From ebaefb2331e42d5e3d4be19d621262cd2fba8e75 Mon Sep 17 00:00:00 2001 From: hdx Date: Sat, 2 Sep 2023 11:37:54 +0800 Subject: [PATCH] =?UTF-8?q?long-list:=20request=20=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E6=B3=9B=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/template/long-list/long-list-page.uvue | 7 +++---- pages/template/long-list/long-list.uvue | 22 +++++++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pages/template/long-list/long-list-page.uvue b/pages/template/long-list/long-list-page.uvue index b32aa795..4feed08b 100644 --- a/pages/template/long-list/long-list-page.uvue +++ b/pages/template/long-list/long-list-page.uvue @@ -103,16 +103,15 @@ this.loading = true // TODO request data 没有拼接到 url 中,暂时手动拼接 - uni.request({ + uni.request({ url: `${SERVER_URL}?type=${this.type}&page=${this.$currentPage}&page_size=${PAGE_SIZE}`, data: { type: this.type, page: this.$currentPage, page_size: PAGE_SIZE }, - dataType: '', success: (res) => { - const responseData = JSON.parse(res.data as string) + const responseData = res.data if (responseData == null) { return } @@ -238,4 +237,4 @@ text-align: center; background-color: #f8f8f8; } - \ No newline at end of file + diff --git a/pages/template/long-list/long-list.uvue b/pages/template/long-list/long-list.uvue index 93439183..42fec78a 100644 --- a/pages/template/long-list/long-list.uvue +++ b/pages/template/long-list/long-list.uvue @@ -40,6 +40,18 @@ preload : Boolean, } + /** + * 根据权重在两个值之间执行线性插值. + * @constructor + * @param {number} value1 - 第一个值,该值应为下限. + * @param {number} value2 - 第二个值,该值应为上限. + * @param {number} amount - 应介于 0 和 1 之间,指示内插的权重. + * @returns {number} 内插值 + */ + function lerpNumber(value1 : number, value2 : number, amount : number) : number { + return (value1 + (value2 - value1) * amount) + } + export default { components: { longPage @@ -148,14 +160,14 @@ // 计算指示线 const current_size = this.$swiperTabsRect[current_index] const move_to_size = this.$swiperTabsRect[move_to_index] - const indicator_line_l = current_size.x + (move_to_size.x - current_size.x) * percentage - const indicator_line_w = current_size.w + (move_to_size.w - current_size.w) * percentage + 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) // 更新指示线 - const x = indicator_line_l + indicator_line_w / 2 + const x = indicator_line_x + indicator_line_w / 2 this.$indicatorNode?.style?.setProperty('transform', `translateX(${x}px) scaleX(${indicator_line_w})`) - // 将指示线滚动到水平中心位置 + // 滚动到水平中心位置 const scroll_x = x - this.$swiperWidth / 2 this.$tabScrollView?.setAttribute('scrollLeft', scroll_x) }, @@ -214,4 +226,4 @@ .swiper-item { flex: 1; } - + \ No newline at end of file -- GitLab