浏览量本地增加

v2
king 2 years ago
parent a004bceaf9
commit 22e012e711
  1. 2
      src/api/brand.ts
  2. 7
      src/components/videoList/videoList.tsx
  3. 2
      src/pages/preview/brand/article/article.tsx
  4. 15
      src/pages/preview/brand/info/info.tsx
  5. 14
      src/pages/preview/illness/list/list.tsx

@ -15,12 +15,14 @@ export type BrandRecord = {
collect: boolean
}
export type ArticleRecord = {
id: number;
title: string
page_view: number
created_at: string
content: string
brands: BrandRecord[]
collect: boolean
cover:string
}
export const brandApi = {

@ -1,4 +1,4 @@
import {FC} from "react";
import {FC, useState} from "react";
import styles from "@/pages/preview/health/health.module.scss";
import {Image, Text, View} from "@tarojs/components";
import Img from "@/components/image/image";
@ -12,8 +12,11 @@ interface Props {
}
const VideoList: FC<Props> = ({data, errorType}) => {
const [frequency, setFrequency] = useState(0)
function jump() {
Taro.preload(data)
setFrequency(frequency + 1)
Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?id=${data.id}`})
}
@ -26,7 +29,7 @@ const VideoList: FC<Props> = ({data, errorType}) => {
<View className='text-ellipsis-2 mt-1 font-26 text-secondary'>{data.introduction}</View>
<View className='font-24 text-muted my-2 flex justify-between'>
<Text>{formatDate(new Date(data.publish_time), "YY-MM-dd")}</Text>
<Text>{data.video_view}</Text>
<Text>{(data.video_view || 1) + frequency}</Text>
</View>
</View>
</View>)

@ -124,7 +124,7 @@ const article: FC = () => {
<View>{d?.name}</View>
<View className='flex mt-1 text-muted font-24'>
<View className='mr-2'>{beforeTime(articleInfo?.created_at)} . </View>
<View> {articleInfo.page_view || 0}</View>
<View> {articleInfo.page_view || 1}</View>
</View>
</View>
</View>

@ -64,6 +64,16 @@ const BrandInfo: FC = () => {
setCurIndex(+e.detail.current + 1)
}
function jump(data: ArticleRecord, index: number) {
Taro.navigateTo({url: `/pages/preview/brand/article/article?id=${data.id}`})
const oldArticle: ArticleRecord[] = JSON.parse(JSON.stringify(articleList))
oldArticle.splice(index, 1, {
...data,
page_view: (data.page_view || 1) + 1
})
setArticleList(oldArticle)
}
return (
<View className='flex flex-column' style={{display: 'flex'}}>
<Spin enable={enable} overlay/>
@ -118,12 +128,11 @@ const BrandInfo: FC = () => {
<View className={styles['bottom']}>
{
articleList?.length ? <>{
articleList.map((i: any) => <View className={styles.box}
onClick={() => Taro.navigateTo({url: `/pages/preview/brand/article/article?id=${i.id}`})}>
articleList.map((i, index) => <View className={styles.box} onClick={() => jump(i, index)}>
<View className={styles.inner}>
<View className={styles.leftBox}>
<View className='font-weight mb-2 font-28 lh-40'>{i.title}</View>
<View className={styles.desc}>{rfc33392time(i.created_at)} {i.page_view}</View>
<View className={styles.desc}>{rfc33392time(i.created_at)} {i.page_view || 1}</View>
</View>
<View className={styles.image}>
<Img width={172} height={128} src={i.cover} errorType='brand'/>

@ -11,7 +11,6 @@ const BrandList: FC = () => {
const params = useRouter().params as unknown as { id: number }
const [page, setPage] = useState(1)
const [articles, setArticles] = useState<any[]>([])
// const [illness, setIllness] = useState<{ name: string; description: string; resource: any; album: string[] }>()
const [total, setTotal] = useState(0)
const [fetchDone, setFetchDone] = useState(false)
const [enable, setEnable] = useState(true)
@ -24,7 +23,6 @@ const BrandList: FC = () => {
try {
const data = await illnessApi.articleInfo(params.id, page, 20)
Taro.setNavigationBarTitle({title: data?.illness?.name || '暂无文章'})
// setIllness(data.illness)
setTotal(data.list.total)
setArticles([...articles, ...data.list.list])
} catch (e) {
@ -34,8 +32,14 @@ const BrandList: FC = () => {
Taro.hideLoading()
}, [page])
function jump(id: number) {
Taro.navigateTo({url: '/pages/preview/brand/article/article?id=' + id})
function jump(data: any, index: number) {
Taro.navigateTo({url: '/pages/preview/brand/article/article?id=' + data.id})
const oldArticles: any[] = JSON.parse(JSON.stringify(articles))
oldArticles.splice(index, 1, {
...data,
page_view: data.page_view + 1
})
setArticles(oldArticles)
}
@ -54,7 +58,7 @@ const BrandList: FC = () => {
<>
<View className='bg-white rounded-20 clip'>
{
articles.map((d, i) => <View className='p-3 relative' onClick={() => jump(d.id)}>
articles.map((d, i) => <View className='p-3 relative' onClick={() => jump(d, i)}>
{i > 0 && <View className='absolute top left right divided ml-3 mr-3'/>}
<View className="font-34 text-black">{d.title}</View>
{(d.intro || '').length > 40 && (<View className='flex mt-1'>

Loading…
Cancel
Save