收藏列表调整

v2
一杯沧海 1 year ago
parent e4acf12d87
commit 887b7a4bb6
  1. 6
      src/api/user.ts
  2. 118
      src/pages/preview/collect/collect.tsx
  3. 15
      src/pages/preview/search/search/components/list.tsx

@ -100,6 +100,10 @@ export const userApi = {
// } // }
/** 收藏列表 */ /** 收藏列表 */
collectList(owner_type: number, page: number, page_size: number) { 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)
}
} }

@ -1,6 +1,6 @@
import {Image, ScrollView, Swiper, SwiperItem, View} from "@tarojs/components"; import {Image, ScrollView, Swiper, SwiperItem, View} from "@tarojs/components";
import {HomeApi, userApi} from "@/api"; import {userApi} from "@/api";
import {useEffect, useState} from "react"; import {useCallback, useEffect, useState} from "react";
import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs";
import Empty from "@/components/empty/empty"; import Empty from "@/components/empty/empty";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
@ -11,7 +11,7 @@ import {rfc33392time} from "@/utils/day";
import play from "@/static/img/play.png"; import play from "@/static/img/play.png";
interface KillData { interface KillData {
data: Kill[] data: any[]
total: number total: number
page: number page: number
} }
@ -37,20 +37,20 @@ const Profession = () => {
} }
try { try {
const res = await userApi.collectList(categoryId!, page, 10) const data = await userApi.collectList(categoryId!, page, 10)
const dataList = res.data.reduce((pre, cur) => { // const dataList = data.list.reduce((pre, cur) => {
const index = pre.findIndex(d => d.id === cur.id) // const index = pre.findIndex(d => d.id === cur.id)
if (index === -1) { // if (index === -1) {
pre.push(cur) // pre.push(cur)
} else { // } else {
pre.splice(index, 1, cur) // pre.splice(index, 1, cur)
} // }
return pre // return pre
}, categoryData?.data || []) // }, categoryData?.data || [])
oldData.delete(categoryId) oldData.delete(categoryId)
oldData.set(categoryId, { oldData.set(categoryId, {
data: dataList, data: data.list,
total: res.total, total: data.total,
page: page page: page
}) })
setData(oldData) 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(() => { useEffect(() => {
categoryId && getData() categoryId && getData()
}, [categoryId]) }, [categoryId])
@ -76,33 +89,17 @@ const Profession = () => {
function tabsChange(tab: OnChangOpt) { function tabsChange(tab: OnChangOpt) {
setCategoryId(tab.tab?.value as number) setCategoryId(tab.tab?.value as number)
} }
function jumpInfo(info: any) {
// function jump(kill: Kill) { console.log(info,'info')
// HomeApi.skillSetPlay(kill.id) if(info.article){
// Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?url=${kill.resource.url}&poster=${kill.url_path}&title=${kill.resource.name}`}) 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}`})
function jumpInfo(id: number,type:string,health:any) { }else if(info.video_records){
console.log(type,'type') Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?id=${info.owner_id}`})
let url = '' }else if(info.brand){
switch (type){ Taro.navigateTo({url: `/pages/preview/brand/info/info?id=${info.owner_id}`})
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
} }
Taro.navigateTo({url: `${url}?id=${id}`})
} }
function swiperChange(e) { function swiperChange(e) {
@ -123,53 +120,50 @@ const Profession = () => {
className={styles.height}> className={styles.height}>
{ {
data.data.map(d => data.data.map(d =>
<View onClick={() => jumpInfo(d.data.id,d.data.table,d.data['@data'])} className={styles.box} key={d.data.id}> <View onClick={() => jumpInfo(d)} className={styles.box} key={d.id}>
{ {
d.data.table === 'brand' && d.brand &&
<> <>
<Img width={128} height={128} src={d.data?.logo} mode='aspectFill' className={styles.image}/> <Img width={128} height={128} src={d.brand.logo} mode='aspectFill' className={styles.image}/>
<View className={styles.rightBox}> <View className={styles.rightBox}>
<View className='font-weight mb-2 font-28'>{d.data.title}</View> <View className='font-weight mb-2 font-28'>{d.brand.name}</View>
<View className={styles.desc}>{d.data.content || '暂无品牌简介'}</View> <View className={styles.desc}>{d.brand.graphic_introduction || '暂无品牌简介'}</View>
</View> </View>
</> </>
} }
{ {
d.data.table === 'article' && d.article &&
<> <>
<View className={styles.articleLeftBox}> <View className={styles.articleLeftBox}>
<View className='font-weight mb-2 font-28 lh-40'>{d.data['@data'].title}</View> <View className='font-weight mb-2 font-28 lh-40'>{d.article.title}</View>
<View className={styles.desc}>{rfc33392time(d.data['@data'].created_at)} {d.data['@data'].page_view}</View> <View className={styles.desc}>{rfc33392time(d.article.created_at)} {d.article.page_view}</View>
</View> </View>
<Img width={172} height={128} src={d.data['@data'].logo} mode='aspectFill' className={styles.image}/> <Img width={172} height={128} src={d.article.logo} mode='aspectFill' className={styles.image}/>
</> </>
} }
{ {
d.data.table === 'video_records' && d.video_records &&
<> <>
<Img width={192} height={192} src={d.data['@data'].url_path} mode='aspectFill' className={styles.image}/> <Img width={192} height={192} src={d.video_records.url_path} mode='aspectFill' className={styles.image}/>
<Image src={play} className={styles.play} mode='aspectFit'/> <Image src={play} className={styles.play} mode='aspectFit'/>
<View className={styles.videoRightBox}> <View className={styles.videoRightBox}>
<View className='font-weight mb-2 font-28 lh-40'>{d.data['@data'].title}</View> <View className='font-weight mb-2 font-28 lh-40'>{d.video_records.title}</View>
<View className={styles.desc}>{d.data['@data'].introduction}</View> <View className={styles.desc}>{d.video_records.introduction}</View>
<View className={`${styles.desc} mt-2`}>: {d.data['@data'].video_view}</View> <View className={`${styles.desc} mt-2`}>: {d.video_records.video_view}</View>
</View> </View>
</> </>
} }
{ {
d.data.table === 'courses' && d.course &&
<> <>
<Img width={192} height={138} src={d.data['@data'].thumb} mode='aspectFill' className={styles.image}/> <Img width={192} height={138} src={d.course.thumb} mode='aspectFill' className={styles.image}/>
<View className={styles.courseRightBox}> <View className={styles.courseRightBox}>
<View className='font-weight mb-2 font-28 lh-40'>{d.data['@data'].title}</View> <View className='font-weight mb-2 font-28 lh-40'>{d.course.title}</View>
<View className={styles.desc}>:{d.data['@data'].class_hour} {d.data['@data'].charge}</View> <View className={styles.desc}>:{d.course.class_hour} {d.course.charge}</View>
</View> </View>
</> </>
} }
</View> </View>
) )
} }

@ -60,21 +60,19 @@ const SearchList: FC<Props> = ({name,clear}) => {
}, [page,name]) }, [page,name])
function jumpInfo(id: number,type:string,health:any) { function jumpInfo(id: number,type:string) {
console.log(type,'type') console.log(type,'type')
let url = '' let url = ''
switch (type){ switch (type){
case 'brand': case 'brand':
url = '/pages/preview/brand/info/info'; url = '/pages/preview/brand/info/info';
break; break;
case 'illness':
url = '/pages/preview/illness/list/list';
break;
case 'article': case 'article':
url = '/pages/preview/illness/article/article' url = '/pages/preview/brand/article/article'
break break
case 'video_records': 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': case 'courses':
url = '/pages/business/videoInfo/videoInfo' url = '/pages/business/videoInfo/videoInfo'
break break
@ -105,7 +103,7 @@ const SearchList: FC<Props> = ({name,clear}) => {
brands.length >= 1 && !loading && brands.length >= 1 && !loading &&
<> <>
{brands.map((d) => {brands.map((d) =>
<View onClick={() => jumpInfo(d.data.id,d.data.table,d.data['@data'])} className={styles.box} key={d.data.id}> <View onClick={() => jumpInfo(d.data.id,d.data.table)} className={styles.box} key={d.data.id}>
{ {
d.data.table === 'brand' && d.data.table === 'brand' &&
<> <>
@ -149,9 +147,6 @@ const SearchList: FC<Props> = ({name,clear}) => {
</> </>
} }
</View> </View>
) )
} }

Loading…
Cancel
Save