From d19b02a97d6bcb9a2fa9701f871e8806bf295003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lemon=E6=A9=AA?= <17633066053@163.com> Date: Fri, 30 Jul 2021 16:29:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=83=AD=E9=97=A8=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=96=B9=E6=A1=88=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=86=E5=90=8E=E7=AB=AF=E6=9C=80=E6=96=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E8=AF=B7pull=E4=B8=8B=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/home.js | 4 +-- pages/navigation/search/searchPage.vue | 42 +++++++++++++++++++------- pages/order/complain/complainInfo.vue | 4 ++- utils/storage.js | 8 +++++ 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/api/home.js b/api/home.js index 7e055dd..fc94bcc 100644 --- a/api/home.js +++ b/api/home.js @@ -30,12 +30,12 @@ export function getCategory(parent_id = 0) { * 获取热门关键词 * @param num */ -export function getHotKeywords(start = 0, end = 10) { +export function getHotKeywords(count) { return http.request({ url: "/goods/hot-words", method: Method.GET, loading: false, - params: { start, end }, + params: { count }, }); } diff --git a/pages/navigation/search/searchPage.vue b/pages/navigation/search/searchPage.vue index ff405d2..b6b8d8c 100644 --- a/pages/navigation/search/searchPage.vue +++ b/pages/navigation/search/searchPage.vue @@ -274,7 +274,7 @@ import { getGoodsList, getGoodsRelated } from "@/api/goods.js"; import { getHotKeywords } from "@/api/home.js"; import mSearch from "@/components/m-search-revision/m-search-revision.vue"; - +import storage from "@/utils/storage"; export default { data() { return { @@ -594,15 +594,38 @@ export default { }, }); }, - //加载热门搜索 + + /** + * 加载热门搜索 + * 1.30分钟之后更新缓存 + * 2.如果有缓存热门关键字则去请求缓存 + */ async loadHotKeyword() { this.hotKeywordList = []; - let res = await getHotKeywords(); - let keywords = res.data.result; + if ( + !storage.getHotWords().time || + storage.getHotWords().time <= new Date().getTime() / 1000 + ) { + // 没有缓存或者第一次进入请求接口保存缓存 + let res = await getHotKeywords(10); + let keywords = res.data.result; - keywords.forEach((item) => { - this.hotKeywordList.push(item); - }); + keywords.forEach((item) => { + this.hotKeywordList.push(item); + }); + + let hotData = { + time: new Date().getTime() / 1000 + 30 * 60, + keywords: keywords, + }; + storage.setHotWords(hotData); + } else { + let keywords = storage.getHotWords().keywords; + + keywords.forEach((item) => { + this.hotKeywordList.push(item); + }); + } }, //加载商品 ,带下拉刷新和上滑加载 async loadData(type, loading) { @@ -612,7 +635,7 @@ export default { } //没有更多直接返回 let goodsList = await getGoodsList(this.params); - + if (goodsList.data.result.content.length < 10) { this.loadingType = "noMore"; } @@ -663,7 +686,6 @@ export default { content: "确定清除历史搜索记录?", success: (res) => { if (res.confirm) { - this.oldKeywordList = []; uni.removeStorage({ key: "OldKeys", @@ -694,7 +716,6 @@ export default { }, //保存关键字到历史记录 saveKeyword(keyword) { - if (!keyword) return false; uni.getStorage({ key: "OldKeys", @@ -715,7 +736,6 @@ export default { data: JSON.stringify(OldKeys), }); this.oldKeywordList = OldKeys; //更新历史搜索 - }, fail: (e) => { var OldKeys = [keyword]; diff --git a/pages/order/complain/complainInfo.vue b/pages/order/complain/complainInfo.vue index 6b92738..51b7027 100644 --- a/pages/order/complain/complainInfo.vue +++ b/pages/order/complain/complainInfo.vue @@ -103,7 +103,9 @@ export default { .row { display: flex; flex-wrap: wrap; + padding: 26rpx 32rpx; } + .speak-msg { padding: 26rpx 32rpx; > span { @@ -120,6 +122,6 @@ export default { padding: 16rpx; } .tips { - margin: 40rpx 0; + margin: 40rpx 32rpx; } diff --git a/utils/storage.js b/utils/storage.js index d3f0f4a..ed2aa35 100644 --- a/utils/storage.js +++ b/utils/storage.js @@ -9,6 +9,14 @@ const FACE_LOGIN = isDev ? "face_login_dev" : "face_login"; const FINGER_LOGIN = isDev ? "finger_login_dev" : "finger_login"; const CART_BACKBTN = isDev ? "cart_backbtn_dev" : "cart_backbtn"; export default { + // 写入热门搜索时间戳 + setHotWords(val) { + uni.setStorageSync("hotWords", val); + }, + // 获取热门搜索时间戳 + getHotWords() { + return uni.getStorageSync(`hotWords`); + }, // 获取face id登录 getFaceLogin() {