From adc5d17a5d28771fae0fe5c586b18f482c852534 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Wed, 6 Sep 2023 18:22:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +- src/api/home.ts | 8 +++- src/api/public.ts | 13 ++++--- .../learningRecord/learningRecord.module.scss | 1 - .../lineChart/lineChart.module.scss | 14 ++++++- src/components/lineChart/lineChart.tsx | 17 ++++++--- .../navigationBar/navigationBar.tsx | 4 +- src/pages/home/components/curRecommended.tsx | 25 ++++++++++--- .../home/components/feature_recommended.tsx | 2 +- src/pages/home/home.module.scss | 14 ------- src/pages/index/components/videoList.tsx | 4 +- src/pages/index/index.tsx | 37 +++++++++++++++++-- src/pages/my/my.tsx | 10 ++--- src/pages/preview/brand/list/list.tsx | 4 +- src/pages/preview/health/health.tsx | 13 ++++--- src/utils/time.tsx | 4 +- types/home.d.ts | 1 + 17 files changed, 117 insertions(+), 58 deletions(-) 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/home.ts b/src/api/home.ts index 70ee5e3..701819b 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -41,12 +41,18 @@ export interface HomeData { } } +interface Course { + articles:any[] + audit_mode:boolean + course:{ data: Curriculum[], total: number } +} + export const HomeApi = { advert(only_flag: string) { return request("/home/v1/advert/unique?only_flag=" + only_flag, "GET") }, course(page: number, page_size: number) { - return request<{ data: Curriculum[], total: number }>('/home/v1/course/course', "GET", {page, page_size}) + return request('/home/v1/course/course', "GET", {page, page_size}) }, /** 健康管理 */ healthTop(count: number) { diff --git a/src/api/public.ts b/src/api/public.ts index cd4acc1..bb20e62 100644 --- a/src/api/public.ts +++ b/src/api/public.ts @@ -13,11 +13,14 @@ interface CategoryList { categories: Record } +export interface CoursesMode { + articles: any[] + audit_mode: boolean + course: Courses +} + export interface Courses { - /** 已完成 */ - // is_finished: Curriculum[] - /** 未完成 */ - // is_not_finished: Curriculum[] + /** 选秀 */ is_not_required: Curriculum[] /** 必修 */ @@ -36,6 +39,6 @@ export const publicApi = { }, /** 课程 */ course(data: { page: number, pageSize: number }) { - return request('/api/v1/category/course/index', "GET", data) + return request('/api/v1/category/course/index', "GET", data) } } diff --git a/src/components/learningRecord/learningRecord.module.scss b/src/components/learningRecord/learningRecord.module.scss index 99b7e1e..a8d083e 100644 --- a/src/components/learningRecord/learningRecord.module.scss +++ b/src/components/learningRecord/learningRecord.module.scss @@ -1,7 +1,6 @@ .box { background: #fff; border-radius: 20rpx; - padding: 40rpx; display: flex; align-items: center; box-sizing: border-box; diff --git a/src/components/lineChart/lineChart.module.scss b/src/components/lineChart/lineChart.module.scss index be146bc..eb02c83 100644 --- a/src/components/lineChart/lineChart.module.scss +++ b/src/components/lineChart/lineChart.module.scss @@ -3,7 +3,7 @@ align-items: flex-end; justify-content: left; flex-wrap: nowrap; - height: 420px; + height: 380px; position: relative; } @@ -13,12 +13,22 @@ bottom: 0; left: 0; right: 0; - border-radius: 10rpx; color: #00D6AC; display: flex; justify-content: center; align-items: center; background: rgba(#fff, .9); + + view{ + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + display: flex; + justify-content: center; + align-items: center; + } } .records { diff --git a/src/components/lineChart/lineChart.tsx b/src/components/lineChart/lineChart.tsx index 7f0cc3f..31d8b2a 100644 --- a/src/components/lineChart/lineChart.tsx +++ b/src/components/lineChart/lineChart.tsx @@ -1,7 +1,8 @@ -import {ScrollView, Text, View} from "@tarojs/components"; +import {Image, ScrollView, Text, View} from "@tarojs/components"; import {FC, useEffect, useState} from "react"; import style from './lineChart.module.scss' import {formatDateTime, formatTime} from "@/utils/time"; +import emptyLineChart from '@/static/img/emptyLineChart.png' export interface lineData { time: string @@ -12,7 +13,7 @@ interface Props { data: lineData[] } -const height = 180 +const height = 150 const LineChart: FC = ({data}) => { const [maxHeight, setMaxHeight] = useState({time: '', value: 0}) const [lineChartList, setLineChartList] = useState(data) @@ -31,17 +32,21 @@ const LineChart: FC = ({data}) => { <> {formatDateTime(new Date(maxHeight.time), 'MM月dd日')} - {maxHeight.value > 0 ? `日最努力` : `期间没有学习记录`},学习了{formatTime(maxHeight.value)} + {maxHeight.value > 0 ? `日最努力` : `期间没有学习记录`},学习了{formatTime(maxHeight.value, 0)} - {!maxHeight.value && 暂无学习记录} + { + !maxHeight.value && + 暂无学习记录 + + + } { !!maxHeight.value && lineChartList.map(d => - + { d.value > 0 && {formatTime(d.value, 0)} } diff --git a/src/components/navigationBar/navigationBar.tsx b/src/components/navigationBar/navigationBar.tsx index 433803c..a4ac5e0 100644 --- a/src/components/navigationBar/navigationBar.tsx +++ b/src/components/navigationBar/navigationBar.tsx @@ -1,5 +1,5 @@ import {Image, View} from "@tarojs/components"; -import React, {FC, ReactNode, useMemo} from "react"; +import React, {CSSProperties, FC, ReactNode, useMemo} from "react"; import styles from './navigationBar.module.scss' import Taro from "@tarojs/taro"; import leftArrow from '@/static/img/leftArrow.png' @@ -19,6 +19,7 @@ interface Props { // 跟随页面滚动 inherit?: boolean className?: string + style?: CSSProperties } const NavigationBar: FC = (props) => { @@ -29,6 +30,7 @@ const NavigationBar: FC = (props) => { paddingTop: globalData.statusBarHeight + 'px', height: globalData.textBarHeight + globalData.statusBarHeight + 'px', boxSizing: 'border-box', + ...props.style }), [props]) diff --git a/src/pages/home/components/curRecommended.tsx b/src/pages/home/components/curRecommended.tsx index 8f42c20..a1a124f 100644 --- a/src/pages/home/components/curRecommended.tsx +++ b/src/pages/home/components/curRecommended.tsx @@ -1,7 +1,7 @@ import {FC, useEffect, useState} from "react"; import {Image, View} from "@tarojs/components"; import {HomeApi} from "@/api"; -import {useReachBottom} from "@tarojs/taro"; +import Taro, {useReachBottom} from "@tarojs/taro"; import styles from "../home.module.scss"; import VideoCover from "@/components/videoCover/videoCover"; import courseTag from '@/static/img/courseTag.png' @@ -10,11 +10,19 @@ const CurRecommended: FC = () => { const [page, setPage] = useState(1) const [data, setData] = useState([]) const [total, setTotal] = useState(0) + const [examine, setExamine] = useState(false) + const [articles, setArticles] = useState([]) async function getData() { const res = await HomeApi.course(page, 4) - setTotal(res.total) - const newData = res.data.reduce((pre, cut) => { + if (res.audit_mode) { + Taro.setTabBarItem({index: 1, text: '文章'}) + setArticles(res.articles) + setExamine(res.audit_mode) + return + } + setTotal(res.course.total) + const newData = res.course.data.reduce((pre, cut) => { const index = pre.findIndex(d => d.id === cut.id) if (index === -1) { pre.push(cut) @@ -37,7 +45,14 @@ const CurRecommended: FC = () => { return ( <> { - data.length > 0 && + examine ? + <> + 推荐文章 + { + articles.map(d => {d.title}) + } + + : data.length > 0 && { @@ -53,7 +68,7 @@ const CurRecommended: FC = () => { } - - 暂无更多 - + - 暂无更多 - ) } diff --git a/src/pages/home/components/feature_recommended.tsx b/src/pages/home/components/feature_recommended.tsx index 009a9fd..443ff6b 100644 --- a/src/pages/home/components/feature_recommended.tsx +++ b/src/pages/home/components/feature_recommended.tsx @@ -153,7 +153,7 @@ const FeatureRecommended: FC = (props) => { { - data.map(d => + data.filter(d=>d.data.length === 3).map(d => = ({categoryKey, setCategoryKey}) => { const res = await publicApi.course({page: page, pageSize: 10}) const old: Courses = JSON.parse(JSON.stringify(data)) setData({ - is_required: screen(old.is_required, res.is_required || []), - is_not_required: screen(old.is_not_required, res.is_not_required || []), + is_required: screen(old.is_required, res.course.is_required || []), + is_not_required: screen(old.is_not_required, res.course.is_not_required || []), }) } catch (e) { } diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index ce10e38..5cb819b 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,10 +1,11 @@ -import {FC, useState} from "react"; +import {FC, useEffect, useState} from "react"; import {View} from "@tarojs/components"; import styles from './index.module.scss' import {VideoList} from "@/pages/index/components/videoList"; import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; -import {CoursesKey} from "@/api/public"; +import {CoursesKey, publicApi} from "@/api/public"; import NavigationBar from "@/components/navigationBar/navigationBar"; +import Taro from "@tarojs/taro"; const category: TabList[] = [ {title: "企选课程", value: 'is_required'}, @@ -33,4 +34,34 @@ const Index: FC = () => { ) } -export default Index +const AuditMode: FC = () => { + const [auditMode, setAuditMode] = useState(false) + const [articles, setArticles] = useState([]) + useEffect(() => { + publicApi.course({page: 1, pageSize: 10}).then(res => { + setAuditMode(res.audit_mode) + setArticles(res.articles) + if(res.audit_mode){ + Taro.setTabBarItem({index: 1, text: '文章'}) + } + }) + }, []) + return ( + <> + { + auditMode ? + <> + + + { + articles.map(d => {d.title}) + } + + + : + } + + ) +} + +export default AuditMode diff --git a/src/pages/my/my.tsx b/src/pages/my/my.tsx index fca8ec4..e0f8ec3 100644 --- a/src/pages/my/my.tsx +++ b/src/pages/my/my.tsx @@ -39,8 +39,6 @@ const My: FC = () => { const [navbarOpacity, setNavbarOpacity] = useState('0') const navbarHeight = globalData.statusBarHeight + globalData.textBarHeight; - console.log(globalData) - Taro.useDidShow(() => { token && userApi.companyList().then(res => { setCompanyList(res as Company[]) @@ -48,7 +46,7 @@ const My: FC = () => { }) Taro.usePageScroll((e) => { - const v = (Math.min(e.scrollTop / navbarHeight, 1) * 0.9).toFixed(6) + const v = (Math.min(e.scrollTop / navbarHeight, 1)).toFixed(6) if (v != navbarOpacity) { setNavbarOpacity(v) } @@ -73,8 +71,9 @@ const My: FC = () => { return ( { errorType='avatar'/> {token ? user?.name : '请登录'} - } - /> + }/> diff --git a/src/pages/preview/brand/list/list.tsx b/src/pages/preview/brand/list/list.tsx index 00dd5c4..006230e 100644 --- a/src/pages/preview/brand/list/list.tsx +++ b/src/pages/preview/brand/list/list.tsx @@ -48,7 +48,7 @@ const BrandItem: FC<{ data: BrandRecord; onClick: VoidFunction }> = ({data, onCl {formatDate(new Date(data.created_at), "YY-MM-dd hh:mm:ss")} - 文章:{data.article_count} + 文章:{data.article_count || 0} 点赞:{(Math.random() * 100).toFixed(0)} @@ -72,7 +72,7 @@ const BrandList: FC = () => { const res = await brandApi.list(page, 10) if (page === 1) { if (res.list.length < 10) { - setText('没有更多了~') + setText('- 暂无更多 -') } else { setText('上拉加载更多~') } diff --git a/src/pages/preview/health/health.tsx b/src/pages/preview/health/health.tsx index 510d523..84b4f7a 100644 --- a/src/pages/preview/health/health.tsx +++ b/src/pages/preview/health/health.tsx @@ -1,12 +1,13 @@ import {FC, useEffect, useState} from "react"; -import {Image, View} from "@tarojs/components"; +import {Image, Text, View} from "@tarojs/components"; import {HomeApi} from "@/api"; import Taro, {useReachBottom} from "@tarojs/taro"; import styles from './health.module.scss' -import play from '@/static/img/play.png' +import play from '@/static/img/play-back.png' import Empty from "@/components/empty/empty"; import Spin from "@/components/spinner"; import Img from "@/components/image/image"; +import {formatDate} from "@/utils/time"; const Health: FC = () => { const [page, setPage] = useState(1) @@ -42,14 +43,16 @@ const Health: FC = () => { { - data.length > 0 - ? <> + data.length > 0 ? <> {data.map(d => jump(d)}> {d.title} - {d.video_view}观看 + + {formatDate(new Date(d.publish_time), "YY-MM-dd")} + {d.video_view}观看 + )} 没有更多了 diff --git a/src/utils/time.tsx b/src/utils/time.tsx index 21ef571..4759388 100644 --- a/src/utils/time.tsx +++ b/src/utils/time.tsx @@ -33,12 +33,12 @@ export function formatTime(time: number, padding = 10): JSX.Element { ) } else if (time >= 60 && time < 3600) { return (<> - {(time / 60).toFixed(2)} + {(time / 60).toFixed(1)} 分钟 ) } else if (time >= 3600) { return (<> - {(time / 3600).toFixed(2)} + {(time / 3600).toFixed(1)} 小时 ) } diff --git a/types/home.d.ts b/types/home.d.ts index 1c9ce4e..8cf33ef 100644 --- a/types/home.d.ts +++ b/types/home.d.ts @@ -6,6 +6,7 @@ interface Health { resource: Resource /** 播放量 */ video_view: number + publish_time:string } interface Brand {