收藏列表调整

v2
一杯沧海 1 year ago
parent e4acf12d87
commit 887b7a4bb6
  1. 6
      src/api/user.ts
  2. 120
      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) {
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 {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
}
Taro.navigateTo({url: `${url}?id=${id}`})
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}`})
}
}
function swiperChange(e) {
@ -123,53 +120,50 @@ const Profession = () => {
className={styles.height}>
{
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='font-weight mb-2 font-28'>{d.data.title}</View>
<View className={styles.desc}>{d.data.content || '暂无品牌简介'}</View>
<View className='font-weight mb-2 font-28'>{d.brand.name}</View>
<View className={styles.desc}>{d.brand.graphic_introduction || '暂无品牌简介'}</View>
</View>
</>
}
{
d.data.table === 'article' &&
d.article &&
<>
<View className={styles.articleLeftBox}>
<View className='font-weight mb-2 font-28 lh-40'>{d.data['@data'].title}</View>
<View className={styles.desc}>{rfc33392time(d.data['@data'].created_at)} {d.data['@data'].page_view}</View>
<View className='font-weight mb-2 font-28 lh-40'>{d.article.title}</View>
<View className={styles.desc}>{rfc33392time(d.article.created_at)} {d.article.page_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'/>
<View className={styles.videoRightBox}>
<View className='font-weight mb-2 font-28 lh-40'>{d.data['@data'].title}</View>
<View className={styles.desc}>{d.data['@data'].introduction}</View>
<View className={`${styles.desc} mt-2`}>: {d.data['@data'].video_view}</View>
<View className='font-weight mb-2 font-28 lh-40'>{d.video_records.title}</View>
<View className={styles.desc}>{d.video_records.introduction}</View>
<View className={`${styles.desc} mt-2`}>: {d.video_records.video_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='font-weight mb-2 font-28 lh-40'>{d.data['@data'].title}</View>
<View className={styles.desc}>:{d.data['@data'].class_hour} {d.data['@data'].charge}</View>
<View className='font-weight mb-2 font-28 lh-40'>{d.course.title}</View>
<View className={styles.desc}>:{d.course.class_hour} {d.course.charge}</View>
</View>
</>
}
</View>
)
}

@ -60,21 +60,19 @@ const SearchList: FC<Props> = ({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<Props> = ({name,clear}) => {
brands.length >= 1 && !loading &&
<>
{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' &&
<>
@ -149,9 +147,6 @@ const SearchList: FC<Props> = ({name,clear}) => {
</>
}
</View>
)
}

Loading…
Cancel
Save