From c2f29333dc86ed1e125be531559daad1776cf984 Mon Sep 17 00:00:00 2001 From: owen Date: Thu, 11 Jan 2024 00:25:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5=E6=88=91=E7=9A=84=E8=B6=B3?= =?UTF-8?q?=E8=BF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/user/goods-log.vue | 151 +++++++++++++++++++---------------- sheep/api/product/history.js | 35 ++++++++ sheep/hooks/useGoods.js | 4 +- 3 files changed, 120 insertions(+), 70 deletions(-) create mode 100644 sheep/api/product/history.js diff --git a/pages/user/goods-log.vue b/pages/user/goods-log.vue index 76043db7..04d77ff6 100644 --- a/pages/user/goods-log.vue +++ b/pages/user/goods-log.vue @@ -31,32 +31,32 @@ @@ -78,13 +78,23 @@ 全选 - + + @@ -95,7 +105,7 @@ :content-text="{ contentdown: '上拉加载更多', }" - @tap="loadmore" + @tap="loadMore" /> { - if (!state.selectedCollectList.includes(id)) { - state.selectedCollectList.push(id); + if (!state.selectedSpuIdList.includes(id)) { + state.selectedSpuIdList.push(id); } else { - state.selectedCollectList.splice(state.selectedCollectList.indexOf(id), 1); + state.selectedSpuIdList.splice(state.selectedSpuIdList.indexOf(id), 1); } - state.selectAll = state.selectedCollectList.length === state.pagination.data.length; + state.selectAll = state.selectedSpuIdList.length === state.pagination.list.length; }; // 全选 const onSelectAll = () => { state.selectAll = !state.selectAll; if (!state.selectAll) { - state.selectedCollectList = []; + state.selectedSpuIdList = []; } else { - state.pagination.data.forEach((item) => { - if (state.selectedCollectList.includes(item.goods_id)) { - state.selectedCollectList.splice(state.selectedCollectList.indexOf(item.goods_id), 1); + state.pagination.list.forEach((item) => { + if (state.selectedSpuIdList.includes(item.spuId)) { + state.selectedSpuIdList.splice(state.selectedSpuIdList.indexOf(item.spuId), 1); } - state.selectedCollectList.push(item.goods_id); + state.selectedSpuIdList.push(item.spuId); }); } }; - async function onCancel() { - if (state.selectedCollectList) { - state.selectedCollectList = state.selectedCollectList.toString(); - const { error } = await sheep.$api.user.view.delete({ - goods_id: state.selectedCollectList, - }); - if (error === 0) { - state.editMode = false; - state.selectedCollectList = []; - state.selectAll = false; - state.pagination = pagination; - getData(); - } + // 删除足迹 + async function onDelete() { + if (state.selectedSpuIdList.length <= 0) { + return; + } + + const { code } = await SpuHistoryApi.deleteBrowseHistory(state.selectedSpuIdList); + if (code === 0) { + reload(); } } + // 清空 + async function onClean() { + const { code } = await SpuHistoryApi.cleanBrowseHistory(); + if (code === 0) { + reload(); + } + } + + function reload() { + state.editMode = false; + state.selectedSpuIdList = []; + state.selectAll = false; + state.pagination = pagination; + getList(); + } + // 加载更多 - function loadmore() { + function loadMore() { if (state.loadStatus !== 'noMore') { - getData(state.pagination.current_page + 1); + state.pagination.pageNo += 1; + getList(); } } onReachBottom(() => { - loadmore(); + loadMore(); }); onLoad(() => { - getData(); + getList(); }); diff --git a/sheep/api/product/history.js b/sheep/api/product/history.js new file mode 100644 index 00000000..1f026642 --- /dev/null +++ b/sheep/api/product/history.js @@ -0,0 +1,35 @@ +import request from '@/sheep/request'; + +const SpuHistoryApi = { + // 删除商品浏览记录 + deleteBrowseHistory: (spuIds) => { + return request({ + url: '/app-api/product/browse-history/delete', + method: 'DELETE', + data: { spuIds }, + }); + }, + // 清空商品浏览记录 + cleanBrowseHistory: () => { + return request({ + url: '/app-api/product/browse-history/clean', + method: 'DELETE', + }); + }, + // 获得商品浏览记录分页 + getBrowseHistoryPage: (data) => { + return request({ + url: '/app-api/product/browse-history/page', + method: 'GET', + data + }); + }, + // 获得商品浏览记录数量 + getBrowseHistoryCount: () => { + return request({ + url: '/app-api/product/browse-history/get-count', + method: 'GET', + }); + } +}; +export default SpuHistoryApi; diff --git a/sheep/hooks/useGoods.js b/sheep/hooks/useGoods.js index b35c37d3..2d290aff 100644 --- a/sheep/hooks/useGoods.js +++ b/sheep/hooks/useGoods.js @@ -74,12 +74,12 @@ const VIDEO_SUFFIX_LIST = ['.avi', '.mp4'] * @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表 */ export function formatGoodsSwiper(urlList) { - return urlList.filter(url => url).map((url, key) => { + return urlList?.filter(url => url).map((url, key) => { const isVideo = VIDEO_SUFFIX_LIST.some(suffix => url.includes(suffix)); const type = isVideo ? 'video' : 'image' const src = $url.cdn(url); return { type, src } - }); + }) || []; } /**