From 93064963a71e5894b2d6dfc1817e2f6dfd35777b Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Fri, 8 Sep 2023 19:21:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E4=BF=AE=E6=94=B9=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/collect/collect.tsx | 3 + src/components/icon/index.tsx | 7 +- src/pages/home/components/curRecommended.tsx | 4 +- src/pages/home/home.tsx | 2 +- src/pages/index/index.tsx | 3 +- .../preview/brand/article/article.module.scss | 2 +- src/pages/preview/brand/article/article.tsx | 112 ++++++++++++------ src/pages/preview/illness/list/list.tsx | 18 ++- src/static/img/catalogue-inactive.png | Bin 0 -> 411 bytes 9 files changed, 108 insertions(+), 43 deletions(-) create mode 100644 src/static/img/catalogue-inactive.png diff --git a/src/components/collect/collect.tsx b/src/components/collect/collect.tsx index 78c90fc..1e7ba86 100644 --- a/src/components/collect/collect.tsx +++ b/src/components/collect/collect.tsx @@ -15,6 +15,7 @@ interface Props { owner_id: number owner_type: CreateOwnerType textHidden?: boolean + onUpdate?: (v: boolean) => void } /** 收藏 */ @@ -37,7 +38,9 @@ const Collect: FC = (props) => { console.log(select) setSelect(!select) setLoading(true) + // fixme: 动画逻辑不对,应该是先 loading, 然后只有操作成功之后才是 select 动画 await userApi.create({owner_id: props.owner_id, owner_type: props.owner_type}) + props.onUpdate?.(!select) setTimeout(() => { setLoading(false) }, 300) diff --git a/src/components/icon/index.tsx b/src/components/icon/index.tsx index 3428b86..0190a32 100644 --- a/src/components/icon/index.tsx +++ b/src/components/icon/index.tsx @@ -213,12 +213,17 @@ export interface IconProps { size?: string | number color?: string onClick?: (event: ITouchEvent) => void + bold?: boolean } const Icon: FC = (props) => { const size = typeof props.size === 'string' ? props.size : `${props.size ?? 16}px` const color = props.color ?? 'currentColor' - const fontStyle: CSSProperties = {fontSize: size, color} + const fontStyle: CSSProperties = { + fontSize: size, + color, + fontWeight: props.bold ? 'bold' : undefined, + } return ( diff --git a/src/pages/home/components/curRecommended.tsx b/src/pages/home/components/curRecommended.tsx index 700786d..4c875c5 100644 --- a/src/pages/home/components/curRecommended.tsx +++ b/src/pages/home/components/curRecommended.tsx @@ -24,7 +24,7 @@ const CurRecommended: FC = () => { const res = await HomeApi.course(page, 4) setArticles(res.articles) setTotal(res.course.total) - const newData = res.course.data.reduce((pre, cut) => { + const newData = res.course.data?.reduce((pre, cut) => { const index = pre.findIndex(d => d.id === cut.id) if (index === -1) { pre.push(cut) @@ -33,7 +33,7 @@ const CurRecommended: FC = () => { } return pre }, JSON.parse(JSON.stringify(data)) as Curriculum[]) - setData(newData) + setData(newData ?? []) } useEffect(() => { diff --git a/src/pages/home/home.tsx b/src/pages/home/home.tsx index db3454d..2514196 100644 --- a/src/pages/home/home.tsx +++ b/src/pages/home/home.tsx @@ -52,7 +52,7 @@ const Home: FC = () => { leftNode={ <> - 医学道 + 信桂 } > diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 65c7e62..c0c4323 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -9,6 +9,7 @@ import Spin from "@/components/spinner"; import Img from "@/components/image/image"; import {beforeTime} from "@/utils/time"; import {isBoolean} from "@tarojs/shared"; +import Taro from "@tarojs/taro"; const category: TabList[] = [ {title: "企选课程", value: 'is_required'}, @@ -57,7 +58,7 @@ const AuditMode: FC = () => { { - articles.map((d, i) => + articles.map((d, i) => Taro.navigateTo({url: "/pages/preview/brand/article/article?id=" + d.id})}> {i > 0 && } {d.title} {(d.intro || '').length > 40 && ( diff --git a/src/pages/preview/brand/article/article.module.scss b/src/pages/preview/brand/article/article.module.scss index 9b0d9ed..6f0e96f 100644 --- a/src/pages/preview/brand/article/article.module.scss +++ b/src/pages/preview/brand/article/article.module.scss @@ -65,7 +65,7 @@ page{ .article { font-size: 30rpx; display: flex; - margin-bottom: 40rpx; + //margin-bottom: 40rpx; } .articleImag { diff --git a/src/pages/preview/brand/article/article.tsx b/src/pages/preview/brand/article/article.tsx index 9b41257..ca1e76e 100644 --- a/src/pages/preview/brand/article/article.tsx +++ b/src/pages/preview/brand/article/article.tsx @@ -11,8 +11,8 @@ import Spin from "@/components/spinner"; import {beforeTime} from "@/utils/time"; import Img from "@/components/image/image"; import Collect from "@/components/collect/collect"; -import catalogue from "@/static/img/catalogue.png"; - +import catalogue from "@/static/img/catalogue-inactive.png"; +import Icon from "@/components/icon"; const article: FC = () => { const {token} = Profile.useContainer() @@ -25,7 +25,7 @@ const article: FC = () => { const pageHeight = globalData.windowHeight - globalData.textBarHeight - globalData.statusBarHeight const {children, headings} = useMemo(() => parse(articleInfo?.content || ''), [articleInfo]) const query = Taro.createSelectorQuery() - + const [maoId, setMaoId] = useState('') useEffect(() => { setTimeout(() => { @@ -39,11 +39,19 @@ const article: FC = () => { }, 300) }, [children]) + useEffect(() => { + if (!maoId && headings.length) { + setMaoId(headings[0].id) + } + }, [headings]) + function mao(id: string) { + setMaoId(id) setShow(false) Taro.nextTick(() => { query.select(`#${id}`).boundingClientRect() query.exec((res) => { + console.log({res}) if (res.length) { Taro.pageScrollTo({ scrollTop: res[res.length - 1].top, @@ -55,6 +63,10 @@ const article: FC = () => { }) } + const onCollect = (v: boolean | undefined) => { + setArticleInfo((s) => ({...s, collect: v} as ArticleRecord)) + } + Taro.useReady(() => { getData().then() }) @@ -82,13 +94,17 @@ const article: FC = () => { styles={{flexDirection: 'column', justifyContent: 'center', padding: '20rpx'}} stylesImage={{margin: '0 0 8rpx 0'}} owner_id={Number(id)} - owner_type={1}/> + owner_type={1} + onUpdate={onCollect} + /> { - headings.length > 0 && setShow(true)}> - - 目录 - + headings.length > 0 && ( + setShow(true)}> + + 目录 + + ) } @@ -102,22 +118,35 @@ const article: FC = () => { {articleInfo?.title} { - children.length > 0 ? - - { - articleInfo?.brands.map(d => - - - {d?.name} - - {beforeTime(articleInfo?.created_at)} . - 阅读 {articleInfo.page_view || 1} - + articleInfo?.brands.map(d => ( + + + + + {d?.name} + + {beforeTime(articleInfo?.created_at)} . + 阅读 {articleInfo.page_view || 0} - ) - } - {children} + + + + + + )) + } + { + children.length > 0 + ? {children} : } @@ -138,20 +167,36 @@ const article: FC = () => { } setShow(false)} + onAfterLeave={() => setShow(false)} show={show} round overlay - overlayStyle={'background:rgba(0,0,0,0.3)'}> - - { - headings.length > 0 && headings.map((d) => mao(d.id)}> - {d.text} - - ) - } + overlayStyle={'background:rgba(0,0,0,0.3)'} + > + + + setShow(false)}> + + + 目录 + + + + { + headings.length > 0 && headings.map((d) => mao(d.id)}> + {d.text} + + ) + } + @@ -160,4 +205,5 @@ const article: FC = () => { return helloWorld() } + export default article diff --git a/src/pages/preview/illness/list/list.tsx b/src/pages/preview/illness/list/list.tsx index 7089638..bdc5663 100644 --- a/src/pages/preview/illness/list/list.tsx +++ b/src/pages/preview/illness/list/list.tsx @@ -1,10 +1,11 @@ import {FC, useCallback, useEffect, useState} from "react"; import {View} from "@tarojs/components"; -import styles from './list.module.scss' import Taro, {useReachBottom, useRouter} from "@tarojs/taro"; import {illnessApi} from "@/api/illness"; import Empty from "@/components/empty/empty"; import Spin from "@/components/spinner"; +import Img from "@/components/image/image"; +import {beforeTime} from "@/utils/time"; const BrandList: FC = () => { const params = useRouter().params as unknown as { id: number } @@ -51,10 +52,19 @@ const BrandList: FC = () => { { articles.length > 0 ? <> - + { - articles.map((d, index) => jump(d.id)}> - {index + 1} . {d.title} + articles.map((d, i) => jump(d.id)}> + {i > 0 && } + {d.title} + {(d.intro || '').length > 40 && ( + {d.intro} + {d.cover && } + )} + + {beforeTime(d.created_at)} + 阅读 {d.page_view || 0} + ) } diff --git a/src/static/img/catalogue-inactive.png b/src/static/img/catalogue-inactive.png new file mode 100644 index 0000000000000000000000000000000000000000..901617c39a7ba5987a443ef6e0bf7914304c2c1d GIT binary patch literal 411 zcmV;M0c8G(P)Px$RY^oaR9Hvtmp@9xKorKm=emWk+NgzMZD}KT0uNy41+*9@hO8E{7qFA;hGbHS zx3KdBdI5V2!DT_$N=%;E3F5^0b3sg( zAS}5iH_l%9E?_x*sbZmc3K002ovPDHLk FV1n#=x{&|? literal 0 HcmV?d00001