From 887b7a4bb6a43efa09a6c1183061b50a32c18f17 Mon Sep 17 00:00:00 2001 From: sunlizhou <296190577@qq.com> Date: Fri, 8 Sep 2023 17:34:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E8=97=8F=E5=88=97=E8=A1=A8=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.ts | 6 +- src/pages/preview/collect/collect.tsx | 118 +++++++++--------- .../preview/search/search/components/list.tsx | 15 +-- 3 files changed, 66 insertions(+), 73 deletions(-) diff --git a/src/api/user.ts b/src/api/user.ts index 29e129b..1a11691 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -100,6 +100,10 @@ export const userApi = { // } /** 收藏列表 */ collectList(owner_type: number, page: number, page_size: number) { - return request<{ data: any[], total: number }>('/api/v1/collect/list', "GET", {owner_type, page, page_size}) + return request<{ list: any[], total: number }>('/api/v1/collect/list', "GET", {owner_type, page, page_size}) }, + /** 收藏 */ + create(data: Create) { + return request("/api/v1/collect/create", "POST", data) + } } diff --git a/src/pages/preview/collect/collect.tsx b/src/pages/preview/collect/collect.tsx index 02420bc..e68e3db 100644 --- a/src/pages/preview/collect/collect.tsx +++ b/src/pages/preview/collect/collect.tsx @@ -1,6 +1,6 @@ import {Image, ScrollView, Swiper, SwiperItem, View} from "@tarojs/components"; -import {HomeApi, userApi} from "@/api"; -import {useEffect, useState} from "react"; +import {userApi} from "@/api"; +import {useCallback, useEffect, useState} from "react"; import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; import Empty from "@/components/empty/empty"; import Taro from "@tarojs/taro"; @@ -11,7 +11,7 @@ import {rfc33392time} from "@/utils/day"; import play from "@/static/img/play.png"; interface KillData { - data: Kill[] + data: any[] total: number page: number } @@ -37,20 +37,20 @@ const Profession = () => { } try { - const res = await userApi.collectList(categoryId!, page, 10) - const dataList = res.data.reduce((pre, cur) => { - const index = pre.findIndex(d => d.id === cur.id) - if (index === -1) { - pre.push(cur) - } else { - pre.splice(index, 1, cur) - } - return pre - }, categoryData?.data || []) + const data = await userApi.collectList(categoryId!, page, 10) + // const dataList = data.list.reduce((pre, cur) => { + // const index = pre.findIndex(d => d.id === cur.id) + // if (index === -1) { + // pre.push(cur) + // } else { + // pre.splice(index, 1, cur) + // } + // return pre + // }, categoryData?.data || []) oldData.delete(categoryId) oldData.set(categoryId, { - data: dataList, - total: res.total, + data: data.list, + total: data.total, page: page }) setData(oldData) @@ -58,6 +58,19 @@ const Profession = () => { } } + Taro.useDidShow(useCallback(() => { + if(categoryId){ + let tempMap = new Map() + tempMap.set(categoryId, { + data: [], + total: undefined, + page: 1 + }) + setData(tempMap) + getData() + } + },[data])) + useEffect(() => { categoryId && getData() }, [categoryId]) @@ -76,33 +89,17 @@ const Profession = () => { function tabsChange(tab: OnChangOpt) { setCategoryId(tab.tab?.value as number) } - - // function jump(kill: Kill) { - // HomeApi.skillSetPlay(kill.id) - // Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?url=${kill.resource.url}&poster=${kill.url_path}&title=${kill.resource.name}`}) - // } - - function jumpInfo(id: number,type:string,health:any) { - console.log(type,'type') - let url = '' - switch (type){ - case 'brand': - url = '/pages/preview/brand/info/info'; - break; - case 'illness': - url = '/pages/preview/illness/list/list'; - break; - case 'article': - url = '/pages/preview/illness/article/article' - break - case 'video_records': - return Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?url=${health.resources.url}&poster=${health.url_path}&title=${health.title}`}) - case 'courses': - url = '/pages/business/videoInfo/videoInfo' - break + function jumpInfo(info: any) { + console.log(info,'info') + if(info.article){ + Taro.navigateTo({url: `/pages/preview/brand/article/article?id=${info.owner_id}`}) + }else if(info.course){ + Taro.navigateTo({url: `/pages/business/videoInfo/videoInfo?id=${info.owner_id}`}) + }else if(info.video_records){ + Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?id=${info.owner_id}`}) + }else if(info.brand){ + Taro.navigateTo({url: `/pages/preview/brand/info/info?id=${info.owner_id}`}) } - Taro.navigateTo({url: `${url}?id=${id}`}) - } function swiperChange(e) { @@ -123,53 +120,50 @@ const Profession = () => { className={styles.height}> { data.data.map(d => - jumpInfo(d.data.id,d.data.table,d.data['@data'])} className={styles.box} key={d.data.id}> + jumpInfo(d)} className={styles.box} key={d.id}> { - d.data.table === 'brand' && + d.brand && <> - + - {d.data.title} - {d.data.content || '暂无品牌简介'} + {d.brand.name} + {d.brand.graphic_introduction || '暂无品牌简介'} } { - d.data.table === 'article' && + d.article && <> - {d.data['@data'].title} - {rfc33392time(d.data['@data'].created_at)} {d.data['@data'].page_view}阅读 + {d.article.title} + {rfc33392time(d.article.created_at)} {d.article.page_view}阅读 - + } { - d.data.table === 'video_records' && + d.video_records && <> - + - {d.data['@data'].title} - {d.data['@data'].introduction} - 播放量: {d.data['@data'].video_view} + {d.video_records.title} + {d.video_records.introduction} + 播放量: {d.video_records.video_view} } { - d.data.table === 'courses' && + d.course && <> - + - {d.data['@data'].title} - 课时:{d.data['@data'].class_hour}节 销量:{d.data['@data'].charge} + {d.course.title} + 课时:{d.course.class_hour}节 销量:{d.course.charge} } - - - ) } diff --git a/src/pages/preview/search/search/components/list.tsx b/src/pages/preview/search/search/components/list.tsx index 75bab39..01ce6e1 100644 --- a/src/pages/preview/search/search/components/list.tsx +++ b/src/pages/preview/search/search/components/list.tsx @@ -60,21 +60,19 @@ const SearchList: FC = ({name,clear}) => { }, [page,name]) - function jumpInfo(id: number,type:string,health:any) { + function jumpInfo(id: number,type:string) { console.log(type,'type') let url = '' switch (type){ case 'brand': url = '/pages/preview/brand/info/info'; break; - case 'illness': - url = '/pages/preview/illness/list/list'; - break; case 'article': - url = '/pages/preview/illness/article/article' + url = '/pages/preview/brand/article/article' break case 'video_records': - return Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?url=${health.resources.url}&poster=${health.url_path}&title=${health.title}`}) + url = '/pages/preview/videoFull/videoFull' + break case 'courses': url = '/pages/business/videoInfo/videoInfo' break @@ -105,7 +103,7 @@ const SearchList: FC = ({name,clear}) => { brands.length >= 1 && !loading && <> {brands.map((d) => - jumpInfo(d.data.id,d.data.table,d.data['@data'])} className={styles.box} key={d.data.id}> + jumpInfo(d.data.id,d.data.table)} className={styles.box} key={d.data.id}> { d.data.table === 'brand' && <> @@ -149,9 +147,6 @@ const SearchList: FC = ({name,clear}) => { } - - - ) }