diff --git a/pages.json b/pages.json index 6f767fb..228de21 100644 --- a/pages.json +++ b/pages.json @@ -17,6 +17,7 @@ "style": { // "navigationBarTitleText": "custom", "navigationStyle": "custom", + "enablePullDownRefresh": true, // "navigationStyle": "default", // "navigationBarBackgroundColor": "#298DFF", // "navigationBarTextStyle": "white" @@ -60,6 +61,7 @@ "path": "pages/cate/index", "style": { "navigationBarTitleText": "健康资讯", + "enablePullDownRefresh": true, // 主包异步引用分包 ListSkeleton "componentPlaceholder": { "list-skeleton": "view" @@ -78,6 +80,7 @@ "path": "pages/index/index", "style": { "navigationBarTitleText": "消息", + "enablePullDownRefresh": true, // 主包异步引用分包 ListSkeleton "componentPlaceholder": { "list-skeleton": "view" diff --git a/pages/cate/index.vue b/pages/cate/index.vue index d8db7c3..9a910d3 100644 --- a/pages/cate/index.vue +++ b/pages/cate/index.vue @@ -5,7 +5,8 @@ + @search="toSearch" + @clear="clearSearch"> @@ -88,9 +89,18 @@ }, methods: { - // 搜索 + // 搜索:按当前分类 + 标题关键词拉文章(不再误调分类接口) toSearch() { - this.getList() + this.infoList = [] + this.articleFetchingEmpty = true + this.getArticleList() + }, + // 清空搜索词后重新拉当前分类文章 + clearSearch() { + this.keyword = '' + this.infoList = [] + this.articleFetchingEmpty = true + this.getArticleList() }, /*切换需要*/ changeStyle(id) { @@ -102,16 +112,17 @@ url: '/pages/cate/info-detail?id=' + e }) }, - //点击药品一级分类e:不清空 infoList,有旧数据则保留到新结果返回 + // 切分类:立即清空文章出骨架 handleCategory1(e, index) { this.num = e this.cid = e + this.infoList = [] + this.articleFetchingEmpty = true this.getArticleList() }, - - //获取药品分类:成功后再覆盖,失败保留旧分类 + // 获取分类:返回 Promise 供下拉刷新等待 getList() { - categoriesList({ + return categoriesList({ method: "post", data: { store_id: uni.getStorageSync('store_id') || '11001', @@ -129,23 +140,28 @@ const firstId = list[0].id this.num = firstId this.cid = firstId - this.getArticleList() + return this.getArticleList() } }).finally(() => { this.categoryInitialLoading = false }) }, - // 文章列表:请求前不清空;仅当当前无文章可展示时打骨架标记 + // 文章列表:可选 keyword 标题搜索 getArticleList() { if (!this.infoList || this.infoList.length === 0) { this.articleFetchingEmpty = true } - articleList({ + const data = { + store_id: uni.getStorageSync('store_id') || '11001', + cid: this.cid + } + const kw = (this.keyword || '').trim() + if (kw) { + data.keyword = kw + } + return articleList({ method: "get", - data: { - store_id: uni.getStorageSync('store_id') || '11001', - cid: this.cid - } + data }).then((res) => { if (res.data.code == 0) { this.infoList = (res.data.result && res.data.result.list) || [] @@ -154,6 +170,19 @@ this.articleInitialLoading = false this.articleFetchingEmpty = false }) + }, + /** + * 下拉刷新:清空分类/文章并重走开骨架 + */ + onPullDownRefresh() { + this.categoryLists = [] + this.infoList = [] + this.categoryInitialLoading = true + this.articleInitialLoading = true + this.articleFetchingEmpty = false + Promise.resolve(this.getList()).finally(() => { + uni.stopPullDownRefresh() + }) } }, mounted() { diff --git a/pages/home/home.vue b/pages/home/home.vue index cb5387d..5ce3641 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -86,14 +86,20 @@ - + 预约购药 正品保障 · 种类齐全 · 快速配送 - + + + @@ -200,7 +206,7 @@ 更多 - +