1.热门推荐-准备工作

在这里插入图片描述

// 用defineProps获取页面参数,query
const query = defineProps<{type: string
}>()
const currHot = hotMap.find((v) => v.type === query.type)
// 动态设置标题
uni.setNavigationBarTitle({ title: currHot!.title })
</script>

2.获取热门推荐数据

PageParams & { subType: string } 交叉类型,基于原有类型上进行扩展,再作为当前数据类型

  1. 封装通用接口
import type { PageParams } from '@/types/global'
import { http } from '@/utils/http'// 拓展类型
type HotParams = PageParams & { subType: string }
export const getHotRecommendAPI = (url: string, data: HotParams) => {return http({method: 'GET',url,data,})
}
  1. 初始化调用
// 获取热门推荐数据
const getHotRecommendData = async () => {const res = await getHotRecommendAPI(currHot!.url)
}
// 页面加载时调用
onLoad(() => {getHotRecommendData()
})

3.类型定义

类型的复用

export type GuessItem = GoodsItemimport type { PageResult, GoodsItem } from './global'
/** 热门推荐 */
export type HotResult = {/** id信息 */id: string/** 活动图片 */bannerPicture: string/** 活动标题 */title: string/** 子类选项 */subTypes: SubTypeItem[]
}/** 热门推荐-子类选项 */
export type SubTypeItem = {/** 子类id */id: string/** 子类标题 */title: string/** 子类对应的商品集合 */goodsItems: PageResult<GoodsItem>
}type HotParams = PageParams & { subType: string }
export const getHotRecommendAPI = (url: string, data?: HotParams) => {return http<HotResult>({method: 'GET',url,data,})
}
4.渲染页面和Tab交互
  1. 渲染页面
// 推荐封面图
const bannnerPicture = ref('')
// 推荐选项
const subTypes = ref<SubTypeItem[]>([])
// 获取下标
const activeIndex = ref(0)
// 获取热门推荐数据
const getHotRecommendData = async () => {const res = await getHotRecommendAPI(currHot!.url)bannnerPicture.value = res.result.bannerPicturesubTypes.value = res.result.subTypes
}
  1. Tab交互
<textv-for="(item, index) in subTypes":key="item.id"class="text":class="{ active: index === activeIndex }"@tap="activeIndex = index">{{ item.title }}</text>

用v-show反复的切换更好而不用v-if 耗费性能

<!-- 推荐列表 --><scroll-viewv-for="(item, index) in subTypes":key="item.id"v-show="activeIndex === index"scroll-yclass="scroll-view"><view class="goods"><navigatorhover-class="none"class="navigator"v-for="goods in item.goodsItems.items":key="goods.id":url="`/pages/goods/goods?id=${goods.id}`"><image class="thumb" :src="goods.picture"></image><view class="name ellipsis">{{ goods.name }}</view><view class="price"><text class="symbol">¥</text><text class="number">{{ goods.price }}</text></view></navigator></view><view class="loading-text">正在加载...</view></scroll-view></view>
</template>

5.分页加载

  1. 滚动触底
  2. 获取当前选项
  3. 当前页码累加
  4. 调用API传参
  5. 当前数据追加

实现效果:

// 滚动触底
const onScrolltolower = async () => {//获取当前选项const currsubTypes = subTypes.value[activeIndex.value]// 当前页码累加currsubTypes.goodsItems.page++// 调用API传参const res = await getHotRecommendAPI(currHot!.url, {subType: currsubTypes.id,page: currsubTypes.goodsItems.page,pageSize: currsubTypes.goodsItems.pageSize,})// 新的列表选项const newSubTypes = res.result.subTypes[activeIndex.value]// 数组追加currsubTypes.goodsItems.items.push(...newSubTypes.goodsItems.items)
}

6.分页结束条件

在这里插入图片描述
分页条件

 // 分页条件if (currsubTypes.goodsItems.page < currsubTypes.goodsItems.pages) {// 当前页码累加currsubTypes.goodsItems.page++} else {// 标志已结束currsubTypes.finish = truereturn uni.showToast({ title: '已经到底了' })}

标记已结束

修改一下:
// 给SubTypeItem 再加一个类型,可有可无加?
const subTypes = ref<(SubTypeItem & { finish?: boolean })[]>([])// 获取热门推荐数据
const getHotRecommendData = async () => {const res = await getHotRecommendAPI(currHot!.url, {subType: '912000341',// 技巧: 环境变量,开发环境,修改初始页面方便测试分页结果page: import.meta.env.DEV ? 30 : 1,pageSize: 10,})bannnerPicture.value = res.result.bannerPicturesubTypes.value = res.result.subTypes
}// 标志已结束currsubTypes.finish = truereturn uni.showToast({ title: '已经到底了' })

页面底部提示

 <view class="loading-text">{{ item.finish ? '已经到底了' : '正在加载中...' }}</view>

技巧:
环境变量,开发环境,修改初始页面方便测试分页结果
page: import.meta.env.DEV ? 30 : 1,

7.准备工作

静态数据=>获取轮播图数据=>渲染轮播图

<script setup lang="ts">
import { getHomeBannerAPI } from '@/services/home'
import { BannerItem } from '@/types/home'
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
const bannerList = ref<BannerItem[]>([])
//获取轮播图数据
const getHomeBannerData = async () => {const res = await getHomeBannerAPI()
}
// 页面加载时调用
onLoad(() => {getHomeBannerData()
})
</script>

8.渲染一级分类和Tab交互

  1. 封装API
import { http } from '@/utils/http'
import { CategoryTopItem } from '@/types/category'export const getCategoryTopAPI = () => {return http<CategoryTopItem[]>({method: 'GET',url: '/category/top',})
}
  1. 初始化调用
// 获取分类列表数据
const getCategoryTopData = async () => {const res = await getCategoryTopAPI()
}// 页面加载时调用
onLoad(() => {getHomeBannerData()getCategoryTopData()
})
  1. 定义类型
// 获取分类列表数据
const cayegoryList = ref<CategoryTopItem[]>([])
const getCategoryTopData = async () => {const res = await getCategoryTopAPI()cayegoryList.value = res.result
}
  1. 渲染一级分类
 <scroll-view class="primary" scroll-y><viewv-for="(item, index) in cayegoryList":key="item.id"class="item":class="{ active: index === activeIndex }">
  1. Tab交互
// 获取分类列表数据
const cayegoryList = ref<CategoryTopItem[]>([])
const activeIndex = ref(0)
const getCategoryTopData = async () => {const res = await getCategoryTopAPI()cayegoryList.value = res.result
}<scroll-view class="primary" scroll-y><viewv-for="(item, index) in cayegoryList":key="item.id"class="item":class="{ active: index === activeIndex }"@tap="activeIndex = index">

9.二级分类和商品渲染

  1. 提取当前二级分类数据
// 提取当前二级分类数据
const subCategoryList = computed(() => {return cayegoryList.value[activeIndex.value]?.children || []
})
  1. 渲染二级分类
  2. 渲染商品
 <view class="panel" v-for="item in subCategoryList" :key="item.id"><view class="title"><text class="name">{{ item.name }}</text><navigator class="more" hover-class="none">全部</navigator></view><view class="section"><navigatorv-for="goods in item.goods":key="goods.id"class="goods"hover-class="none":url="`/pages/goods/goods?id=${goods.id}`"><image class="image" :src="goods.picture"></image><view class="name ellipsis">{{ goods.name }}</view><view class="price"><text class="symbol">¥</text><text class="number">{{ goods.price }}</text></view></navigator></view></view>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/90795.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/90795.shtml
英文地址,请注明出处:http://en.pswp.cn/bicheng/90795.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

基于动态增强的 LLM 置信度方法研究

基于动态增强的 LLM 置信度方法研究 一、引言(Introduction) 大型语言模型(LLM)的性能提升高度依赖于对模型内部表征的精准调控 —— 表征工程通过优化模型中间层隐藏状态的传递规律,能够在不改变模型参数的前提下显著提升任务适应性(Wei et al., 2022)。当前主流方法中…

ComfyUI中运行Wan 2.1工作流,电影级视频,兼容Mac Windows

魔当(LM Downloader)是一个大模型应用下载工具 &#xff0c;目前 魔当 已经支持ComfyUI下载Wan 2.1视频模型。 魔当下载地址 https://seemts.com/ 先看生成效果 原始图片&#xff0c;你可以保存到自己电脑上测试 生成视频&#xff1a; 推荐提示词&#xff1a; A futurist…

CentOS 7 Linux 用 yum 安装 Docker,含 Docker 镜像无法拉取问题(即 docker pull 失败)的解决方案

CentOS 7 Linux 用 yum 安装 Docker,含 Docker 镜像无法拉取问题(即 docker pull 失败)的解决方案 本文对应的讲解视频链接:https://www.bilibili.com/video/BV1C48wzqE6T/ 文章目录 CentOS 7 Linux 用 yum 安装 Docker,含 Docker 镜像无法拉取问题(即 docker pull 失败…

XML的简略知识点

文章目录1. 基本概念2. 基本语法3. 示例4. 相关技术5. 应用场景XML&#xff08;可扩展标记语言&#xff09;是一种用于存储和传输数据的标记语言&#xff0c;核心特点是可扩展性和自我描述性。以下是其核心知识点&#xff1a; 1. 基本概念 用途&#xff1a;主要用于数据的存储…

RustDesk 完整部署教程:支持 Web 管理后台和网页客户端远程,保姆级教学来了!

RustDesk API本项目使用 Go 实现了 RustDesk 的 API&#xff0c;并包含了 Web Admin 和 Web 客户端。RustDesk是一个远程桌面软件&#xff0c;提供了自托管的解决方案&#xff0c;官方API是收费的&#xff0c;这次咱们用到的是Github开源的第三方API源码。✅特性PC端API支持 …

​​GOFLY LIVE CHAT:Golang製オープンソース・ライブチャットシステム​

以下是为日本技术受众优化的日语版介绍文章&#xff0c;采用IT行业惯用术语和简洁表达&#xff1a; ​​GOFLY LIVE CHAT&#xff1a;Golang製オープンソース・ライブチャットシステム​​ ​​現代的なカスタマーサポートのための高性能ソリューション​​ GOFLY LIVE CHATは…

ISIS GR实验案例

一、实验拓扑路由器R1和R2都为双主控设备&#xff0c;主用板和备用板间形成备份关系。路由器间通过IS-IS协议实现网络互连&#xff0c;并提供GR机制。要求当R1通过GR方式重启IS-IS进程或者进行主备倒换时转发不中断。1、基础配置AR1 system sysname AR1 int g 0/0/0 ip add 10.…

智慧农业病虫害识别准确率↑32%:陌讯多模态融合算法实战解析

原创声明本文为原创技术解析&#xff0c;核心技术参数与架构设计引用自《陌讯技术白皮书》&#xff0c;禁止未经授权的转载与篡改。一、行业痛点&#xff1a;智慧农业的识别困境智慧农业中&#xff0c;作物病虫害的精准识别是实现精准植保的核心&#xff0c;但田间复杂环境始终…

# JsSIP 从入门到实战:构建你的第一个 Web 电话

前言 欢迎来到实时通信&#xff08;Real-Time Communication, RTC&#xff09;的世界&#xff01;如果你是一名 JavaScript 开发者&#xff0c;渴望让你的 Web 应用拥有语音通话、视频聊天甚至即时消息的能力&#xff0c;那么你来对地方了。这本书是为你量身打造的指南&#x…

【RHCSA 问答题】第 12 章 安装和更新软件包

目录什么是 RPM&#xff1f;dnf 是什么&#xff0c;它和 rpm 有什么联系和区别&#xff1f;如何设置禁止直接远程登录 root 账户&#xff1f;RHEL 中如何做才能启用对第三方存储库的支持&#xff1f;怎么理解 RHEL9 中的应用流(Application Streams)和模块(Modules)&#xff1f…

GEO优化实战:如何在DeepSeek、豆包等AI平台抢占推荐位?

在当今竞争激烈的 AI 领域&#xff0c;GEO 优化在抢占 AI 平台推荐位上的重要性日益凸显。各大平台都在为优质内容和企业争取更好的展示机会&#xff0c;与此同时&#xff0c;一个现象引发了众人关注&#xff1a;众多企业大力推荐天津诚智未来公司&#xff0c;这背后究竟隐藏着…

机器学习——随机森林算法分类问题案例解析(sklearn)

1. 集成学习&#xff1a;三个臭皮匠&#xff0c;如何赛过诸葛亮&#xff1f;我们之前学习的线性回归、决策树等算法&#xff0c;就像是团队里的某一位“专家”。这位专家可能在某个领域很擅长&#xff0c;但单凭他一人&#xff0c;要解决复杂多变的问题&#xff0c;总会遇到瓶颈…

Mermaid流程图

手动画流程图太复杂了&#xff0c;用极少的字符生成图表是人生的梦想。 Mermaid Chart - Create complex, visual diagrams with text. A smarter way of creating diagrams. Linux开始菜单流程图 flowchartA(["StartMenu"]) --> B["/usr/share/applicati…

Compose笔记(三十八)--CompositionLocal

这一节主要了解一下CompositionLocal&#xff0c;CompositionLocal是Jetpack Compose中用于组件树内隐式数据传递的核心机制&#xff0c;其设计初衷是解决跨多层组件的数据共享问题&#xff0c;避免通过函数参数逐层传递数据。简单总结:API: (1)compositionLocalOf<T>创建…

解决uniapp 使用uview生成小程序包太大无法上传的问题

直接打包的插件内容优化后完美上传&#xff0c; 相信眼尖的小伙伴已经发现了问题的关键 uview 会在每个组件里重复引css。导致包太大。 并且 它的格式是 data-v-哈希 没法简单的处理 需要压缩通用规则。然后 再引用压缩后的规则例如是然后 成功上传

在线工具+网页平台来学习和操作Python与Excel相关技能

&#x1f517;一、在线平台推荐&#xff08;免安装&#xff09; ✅Python平台&#xff08;直接写代码、跑结果&#xff09;&#xff1a; 平台 优点 地址 Google Colab 免费&#xff0c;支持图表和文件操作&#xff0c;最推荐 https://colab.research.google.com …

R Excel 文件处理指南

R Excel 文件处理指南 引言 R语言作为一种强大的统计计算和图形展示工具&#xff0c;在数据分析领域有着广泛的应用。而Excel作为办公软件的佼佼者&#xff0c;在数据记录和计算中也扮演着重要的角色。本文旨在介绍如何使用R语言处理Excel文件&#xff0c;包括读取、写入以及数…

亿级流量短剧平台架构演进:高并发场景下的微服务设计与性能调优

一、短剧系统概述与市场背景短剧作为一种新兴的内容形式&#xff0c;近年来在移动互联网领域迅速崛起。根据最新市场数据显示&#xff0c;2023年中国短剧市场规模已突破300亿元&#xff0c;用户规模达到4.5亿&#xff0c;平均每日观看时长超过60分钟。这种爆发式增长催生了对专…

4G手机控车模块的核心功能与应用价值

4G手机控车模块是基于4G无线通信技术实现车辆远程监控、控制及数据交互的嵌入式设备。其核心功能包括通过4G网络实现高速数据传输&#xff08;支持TCP/IP协议&#xff09;、远程参数配置与设备管理、多网络制式兼容&#xff0c;集成GPS/北斗定位功能&#xff0c;可实时获取车辆…

【leetGPU】1. Vector Addition

问题 link: https://leetgpu.com/challenges/vector-addition Implement a program that performs element-wise addition of two vectors containing 32-bit floating point numbers on a GPU. The program should take two input vectors of equal length and produce a si…