From bc0682351e655cb61af369ccf3458e00362a5f7c Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Tue, 12 Sep 2023 16:07:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=96=87=E7=AB=A0=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +- src/api/brand.ts | 2 +- .../articlesBox/articlesBox.module.scss | 40 +++++++++++++++++ src/components/articlesBox/articlesBox.tsx | 45 +++++++++++++++++++ src/components/image/image.tsx | 2 +- src/components/videoCover/videoCover.tsx | 2 +- src/components/videoList/videoList.tsx | 15 ++++--- src/pages/home/components/curRecommended.tsx | 32 ++++--------- src/pages/home/components/search.tsx | 2 +- src/pages/index/index.tsx | 19 ++------ src/pages/manage/depAdmin/depAdmin.scss | 2 +- src/pages/manage/depAdmin/depAdmin.tsx | 2 - src/pages/manage/selectDep/selectDep.tsx | 1 - src/pages/preview/brand/article/article.tsx | 11 +++-- src/pages/preview/brand/info/info.module.scss | 3 ++ src/pages/preview/brand/info/info.tsx | 33 +++----------- src/pages/preview/illness/list/list.tsx | 31 ++----------- types/articles.d.ts | 11 +++++ 18 files changed, 142 insertions(+), 115 deletions(-) create mode 100644 src/components/articlesBox/articlesBox.module.scss create mode 100644 src/components/articlesBox/articlesBox.tsx create mode 100644 types/articles.d.ts diff --git a/.env b/.env index 86e2b46..3852d45 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ -#TARO_APP_API=https://yjx.dev.yaojiankang.top -TARO_APP_API=https://mooc.yaojiankang.top +TARO_APP_API=https://yjx.dev.yaojiankang.top +#TARO_APP_API=https://mooc.yaojiankang.top #TARO_APP_API=https://shopfix.yaojiankang.top #TARO_APP_API=https://playedu.yaojiankang.top TARO_APP_LGOIN=true diff --git a/src/api/brand.ts b/src/api/brand.ts index aee7e9d..9967ddb 100644 --- a/src/api/brand.ts +++ b/src/api/brand.ts @@ -40,7 +40,7 @@ export const brandApi = { /** 文章列表 */ articleList(owner_id: number, page: number) { return request<{ - list: ArticleRecord[], + list: Articles[], total: number }>(`/home/v1/article/list?owner_id=${owner_id}&page=${page}&page_size=10`, "GET") }, diff --git a/src/components/articlesBox/articlesBox.module.scss b/src/components/articlesBox/articlesBox.module.scss new file mode 100644 index 0000000..0838d96 --- /dev/null +++ b/src/components/articlesBox/articlesBox.module.scss @@ -0,0 +1,40 @@ +.artcles { + padding: 30rpx 0; + border-bottom: 1px solid #F5F8F7; +} + +.outside { + display: flex; + justify-content: space-between; + + + .title { + font-size: 28rpx; + font-family: PingFang SC-Bold, PingFang SC; + font-weight: bold; + color: #323635; + } + + .intro { + font-size: 24rpx; + font-family: PingFang SC-Medium, PingFang SC; + font-weight: 500; + color: #909795; + margin-top: 10rpx; + } +} + +.img { + overflow: hidden; + border-radius: 10rpx; +} + +.pageView { + font-size: 22rpx; + font-family: PingFang SC-Medium, PingFang SC; + font-weight: 500; + color: #909795; + margin-top: 20rpx; +} + + diff --git a/src/components/articlesBox/articlesBox.tsx b/src/components/articlesBox/articlesBox.tsx new file mode 100644 index 0000000..d446f6f --- /dev/null +++ b/src/components/articlesBox/articlesBox.tsx @@ -0,0 +1,45 @@ +import {FC, useEffect, useState} from "react"; +import {Text, View} from "@tarojs/components"; +import Taro from "@tarojs/taro"; +import styles from './articlesBox.module.scss' +import Img from "@/components/image/image"; +import {beforeTime} from "@/utils/time"; + +interface Props { + data: Articles +} + +const ArticlesBox: FC = (props) => { + const [data, setData] = useState(props.data) + + useEffect(() => { + setData(props.data) + }, [props.data]) + + const toArticlePage = () => { + Taro.navigateTo({ + url: `/pages/preview/brand/article/article?id=${data.id}` + }) + } + + return ( + + + + {data.title} + {data.intro} + + {beforeTime(data.created_at)}· + {data.page_view || 0}阅读 + + + + + + ) +} +export default ArticlesBox diff --git a/src/components/image/image.tsx b/src/components/image/image.tsx index 1bffc13..b68cc44 100644 --- a/src/components/image/image.tsx +++ b/src/components/image/image.tsx @@ -81,7 +81,7 @@ const Img: FC = ({src, mode = 'aspectFill', width, fallback = shard, ...p overflow: 'hidden', width: width ? `${width}rpx` : "100%", height: height ? `${height}rpx` : "100%", - backgroundColor: (isError || !loading) ? 'transparent' : '#F8F8F8' + backgroundColor: (isError || !loading) ? 'transparent' : '#F8F8F8', }}> {!isError && diff --git a/src/components/videoCover/videoCover.tsx b/src/components/videoCover/videoCover.tsx index cc93e0d..c816fb3 100644 --- a/src/components/videoCover/videoCover.tsx +++ b/src/components/videoCover/videoCover.tsx @@ -29,7 +29,7 @@ const VideoCover: FC = (opt: VideoCoverProps) => { - + {opt.marker && {opt.marker}} {opt.content && {opt.content}} diff --git a/src/components/videoList/videoList.tsx b/src/components/videoList/videoList.tsx index 560e056..8a19b30 100644 --- a/src/components/videoList/videoList.tsx +++ b/src/components/videoList/videoList.tsx @@ -1,4 +1,4 @@ -import {FC, useState} from "react"; +import {FC, useEffect, 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"; @@ -11,25 +11,28 @@ interface Props { errorType?: ImgErrType } -const VideoList: FC = ({data, errorType}) => { - const [frequency, setFrequency] = useState(0) +const VideoList: FC = (props) => { + const [data, setData] = useState(props.data) + + useEffect(() => { + setData(props.data) + }, [props.data]) function jump() { Taro.preload(data) - setFrequency(frequency + 1) Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?id=${data.id}`}) } return ( - + {data.title} {data.introduction} {formatDate(new Date(data.publish_time), "YY-MM-dd")} - {(data.video_view || 1) + frequency}观看 + {(data.video_view || 0)}观看 ) diff --git a/src/pages/home/components/curRecommended.tsx b/src/pages/home/components/curRecommended.tsx index 4c875c5..a081971 100644 --- a/src/pages/home/components/curRecommended.tsx +++ b/src/pages/home/components/curRecommended.tsx @@ -1,24 +1,17 @@ import {FC, ReactNode, useEffect, useState} from "react"; import {Image, View} from "@tarojs/components"; import {HomeApi} from "@/api"; -import Taro, {useReachBottom} from "@tarojs/taro"; +import {useReachBottom} from "@tarojs/taro"; import styles from "../home.module.scss"; import VideoCover from "@/components/videoCover/videoCover"; import courseTag from '@/static/img/courseTag.png' -import Img from "@/components/image/image"; -import {beforeTime} from "@/utils/time"; - -const toArticlePage = (d: any) => { - Taro.navigateTo({ - url: `/pages/preview/brand/article/article?id=${d.id}` - }) -} +import ArticlesBox from "@/components/articlesBox/articlesBox"; const CurRecommended: FC = () => { const [page, setPage] = useState(1) const [data, setData] = useState([]) const [total, setTotal] = useState(0) - const [articles, setArticles] = useState([]) + const [articles, setArticles] = useState([]) async function getData() { const res = await HomeApi.course(page, 4) @@ -48,20 +41,11 @@ const CurRecommended: FC = () => { if (articles.length > 0) { examines = ( - 推荐文章 - - {articles.map((d, i) => toArticlePage(d)}> - {i > 0 && } - {d.title} - {(d.intro || '').length > 40 && ( - {d.intro} - {d.cover && } - )} - - {beforeTime(d.created_at)} - 阅读 {d.page_view || 0} - - )} + + 推荐文章 + { + articles.map(d => ) + } ) diff --git a/src/pages/home/components/search.tsx b/src/pages/home/components/search.tsx index fae43f7..5aebd88 100644 --- a/src/pages/home/components/search.tsx +++ b/src/pages/home/components/search.tsx @@ -13,7 +13,7 @@ export const Search: FC = () => { return ( - + 点击搜索 ) diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index c0c4323..18a74ed 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -6,10 +6,8 @@ import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; import {CoursesKey, publicApi} from "@/api/public"; import NavigationBar from "@/components/navigationBar/navigationBar"; 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"; +import ArticlesBox from "@/components/articlesBox/articlesBox"; const category: TabList[] = [ {title: "企选课程", value: 'is_required'}, @@ -56,20 +54,9 @@ const AuditMode: FC = () => { auditMode ? <> - + { - articles.map((d, i) => Taro.navigateTo({url: "/pages/preview/brand/article/article?id=" + d.id})}> - {i > 0 && } - {d.title} - {(d.intro || '').length > 40 && ( - {d.intro} - {d.cover && } - )} - - {beforeTime(d.created_at)} - 阅读 {d.page_view || 0} - - ) + articles.map(d => ) } 暂无更多 diff --git a/src/pages/manage/depAdmin/depAdmin.scss b/src/pages/manage/depAdmin/depAdmin.scss index 7c5d848..a2608c4 100644 --- a/src/pages/manage/depAdmin/depAdmin.scss +++ b/src/pages/manage/depAdmin/depAdmin.scss @@ -1,7 +1,7 @@ .content { margin-top: 20rpx; background: white; - min-height: calc(100vh - 20rpx); + min-height: calc(100vh - 20rpx - env(safe-area-inset-bottom)); box-sizing: border-box; padding-bottom: calc(env(safe-area-inset-bottom) + 80rpx); } diff --git a/src/pages/manage/depAdmin/depAdmin.tsx b/src/pages/manage/depAdmin/depAdmin.tsx index 4e4b966..b9b2d0f 100644 --- a/src/pages/manage/depAdmin/depAdmin.tsx +++ b/src/pages/manage/depAdmin/depAdmin.tsx @@ -160,8 +160,6 @@ const DepAdmin: FC = () => { content={['学员', '管理员', '超级管理员'][d.role_type]} />) } - {manages.length > 0 || users.length > 0 && 暂无更多} - {!manages.length && !users.length && } diff --git a/src/pages/manage/selectDep/selectDep.tsx b/src/pages/manage/selectDep/selectDep.tsx index cf1e907..8a34de9 100644 --- a/src/pages/manage/selectDep/selectDep.tsx +++ b/src/pages/manage/selectDep/selectDep.tsx @@ -59,7 +59,6 @@ const SelectDep: FC = () => { leftImage={folder}/> )} - 暂无更多 确定 diff --git a/src/pages/preview/brand/article/article.tsx b/src/pages/preview/brand/article/article.tsx index a02b485..0663ec9 100644 --- a/src/pages/preview/brand/article/article.tsx +++ b/src/pages/preview/brand/article/article.tsx @@ -22,7 +22,6 @@ const article: FC = () => { const [ultra, setUltra] = useState(true) const [show, setShow] = useState(false) const globalData = Taro.getApp().globalData - const pageHeight = globalData.windowHeight - globalData.textBarHeight - globalData.statusBarHeight const {children, headings} = useMemo(() => parse(articleInfo?.content || ''), [articleInfo]) const query = Taro.createSelectorQuery() const [maoId, setMaoId] = useState('') @@ -33,7 +32,7 @@ const article: FC = () => { query.select('#childrenNode').boundingClientRect((res) => { if (!Array.isArray(res)) { console.log({childrenNode: res}) - setUltra(pageHeight * .45 <= res.height) + setUltra(globalData.pageHeight * .45 <= res.height) } }).exec() }, 300) @@ -51,7 +50,6 @@ const article: FC = () => { Taro.nextTick(() => { query.select(`#${id}`).boundingClientRect() query.exec((res) => { - console.log({res}) if (res.length) { Taro.pageScrollTo({ scrollTop: res[res.length - 1].top, @@ -92,7 +90,7 @@ const article: FC = () => { { {articleInfo?.title} diff --git a/src/pages/preview/brand/info/info.module.scss b/src/pages/preview/brand/info/info.module.scss index f92c90d..abc218a 100644 --- a/src/pages/preview/brand/info/info.module.scss +++ b/src/pages/preview/brand/info/info.module.scss @@ -40,6 +40,9 @@ page{ background-color: #fff; border-radius: 32rpx 32rpx 0 0; width: 100%; + padding: 0 30rpx; + width: 100%; + box-sizing: border-box; .box { display: flex; background-color: #fff; diff --git a/src/pages/preview/brand/info/info.tsx b/src/pages/preview/brand/info/info.tsx index 0d754fb..2c43491 100644 --- a/src/pages/preview/brand/info/info.tsx +++ b/src/pages/preview/brand/info/info.tsx @@ -1,14 +1,14 @@ import {FC, useCallback, useEffect, useState} from "react"; import {Swiper, SwiperItem, Text, Video, View} from "@tarojs/components"; -import {ArticleRecord, brandApi, BrandRecord} from "@/api"; +import { brandApi, BrandRecord} from "@/api"; import styles from './info.module.scss' import Taro, {useReachBottom, useRouter} from "@tarojs/taro"; import LineEllipsis from "@/components/textCollapse/collapse"; import Empty from "@/components/empty/empty"; import Img from "@/components/image/image"; -import {rfc33392time} from "@/utils/day"; import Spin from "@/components/spinner"; import Collect from "@/components/collect/collect"; +import ArticlesBox from "@/components/articlesBox/articlesBox"; type Params = { id: number @@ -16,7 +16,7 @@ type Params = { const BrandInfo: FC = () => { const {id} = useRouter().params as unknown as Params const [brandInfo, setBrandInfo] = useState() - const [articleList, setArticleList] = useState([]) + const [articleList, setArticleList] = useState([]) const [curIndex, setCurIndex] = useState(1) const [page, setPage] = useState(1) const [total, setTotal] = useState(0) @@ -64,15 +64,6 @@ 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 ( @@ -106,7 +97,7 @@ const BrandInfo: FC = () => { (brandInfo?.brand_album?.length || 0) > 0 && brandInfo?.brand_album?.split(',').map((d) => - + ) } @@ -123,23 +114,13 @@ const BrandInfo: FC = () => { {brandInfo?.name} - + { articleList?.length ? <>{ - articleList.map((i, index) => jump(i, index)}> - - - {i.title} - {rfc33392time(i.created_at)} {i.page_view || 1}阅读 - - - - - - )} - 暂无更多 + articleList.map(d => )} + 暂无更多 : } diff --git a/src/pages/preview/illness/list/list.tsx b/src/pages/preview/illness/list/list.tsx index b74e758..3902939 100644 --- a/src/pages/preview/illness/list/list.tsx +++ b/src/pages/preview/illness/list/list.tsx @@ -4,8 +4,7 @@ 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"; +import ArticlesBox from "@/components/articlesBox/articlesBox"; const BrandList: FC = () => { const params = useRouter().params as unknown as { id: number } @@ -32,17 +31,6 @@ const BrandList: FC = () => { Taro.hideLoading() }, [page]) - 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) - } - - useReachBottom(useCallback(() => { if (articles?.length < total) { setPage(page + 1) @@ -51,25 +39,14 @@ const BrandList: FC = () => { return ( - + { articles.length > 0 ? <> - + { - articles.map((d, i) => jump(d, i)}> - {i > 0 && } - {d.title} - {(d.intro || '').length > 40 && ( - {d.intro} - {d.cover && } - )} - - {beforeTime(d.created_at)} - 阅读 {d.page_view || 0} - - ) + articles.map(d => ) } 暂无更多 diff --git a/types/articles.d.ts b/types/articles.d.ts new file mode 100644 index 0000000..7d63827 --- /dev/null +++ b/types/articles.d.ts @@ -0,0 +1,11 @@ +interface Articles { + id: number + title: string + /** 封面 */ + cover?: string + created_at: string + page_view: number + /** 描述 */ + intro: string + owner_type:number +}