From ce42bfd06fd7a2c2cb6f53e08e7e4889ea5f41ae Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Mon, 4 Sep 2023 14:01:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=AA=E4=BA=BA=E6=8A=98?= =?UTF-8?q?=E7=BA=BF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.ts | 2 +- .../learningRecord/learningRecord.tsx | 71 +++++++++++++++++++ src/components/lineChart/lineChart.tsx | 20 +++--- src/pages/manage/userInfo/userInfo.tsx | 58 ++------------- src/pages/my/components/header/service.tsx | 4 +- src/pages/my/components/header/time.tsx | 4 +- src/pages/my/my.module.scss | 56 +++++++++------ src/pages/my/my.tsx | 16 +++-- src/utils/{time.ts => time.tsx} | 40 +++++++++-- 9 files changed, 168 insertions(+), 103 deletions(-) create mode 100644 src/components/learningRecord/learningRecord.tsx rename src/utils/{time.ts => time.tsx} (81%) diff --git a/src/api/user.ts b/src/api/user.ts index 4c560c4..6d7996a 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -79,7 +79,7 @@ export const userApi = { return request(`/api/v1/statistics/${user_id}`, "GET") }, /**获取指定学员指定时间学习记录 */ - statistics(user_id: string, data: StatisticsParam) { + statistics(user_id: string | number, data: StatisticsParam) { return request<{ data: Record }>(`/api/v1/statistics/statistics/${user_id}?start_time=${data.start_time}&end_time=${data.end_time}`, "GET") diff --git a/src/components/learningRecord/learningRecord.tsx b/src/components/learningRecord/learningRecord.tsx new file mode 100644 index 0000000..b951a39 --- /dev/null +++ b/src/components/learningRecord/learningRecord.tsx @@ -0,0 +1,71 @@ +import {Text, View} from "@tarojs/components"; +import styles from "@/pages/manage/userInfo/userInfo.module.scss"; +import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; +import {everyDay, formatTime, getMonday, getSunday, monthEnd, monthFirst} from "@/utils/time"; +import LineChart from "@/components/lineChart/lineChart"; +import {FC, useEffect, useState} from "react"; +import {StatisticsParam, userApi} from "@/api"; + +const tabList: TabList[] = [ + { + title: '日', + value: { + start_time: new Date().setHours(0, 0, 0, 0), + end_time: new Date().setHours(24, 0, 0, 0) + } + }, + { + title: '周', value: { + start_time: getMonday(), + end_time: getSunday() + } + }, + { + title: '月', value: { + start_time: monthFirst(), + end_time: monthEnd() + } + }, +] + +interface Props { + userId: string | number +} + +/** + * 学习记录折线图 + */ +const LearningRecord: FC = ({userId}) => { + const [lineData, setLineData] = useState([]) + + async function getStatistics(data: StatisticsParam) { + try { + const res = await userApi.statistics(userId, data) + const everyDayValue = everyDay(data.start_time, Number(data.end_time), res.data) + setLineData(everyDayValue) + } catch (e) { + setLineData([]) + } + } + + function tabChange({tab}: OnChangOpt) { + getStatistics(tab?.value! as StatisticsParam) + } + + useEffect(() => { + userId && getStatistics(tabList[0].value) + }, [userId]) + + return ( + + + 总共学习 + + {formatTime(lineData.reduce((pre, cur) => pre + cur.value, 0) || 0)} + + + + ) +} + +export default LearningRecord diff --git a/src/components/lineChart/lineChart.tsx b/src/components/lineChart/lineChart.tsx index cc9b56f..d3e2a69 100644 --- a/src/components/lineChart/lineChart.tsx +++ b/src/components/lineChart/lineChart.tsx @@ -1,7 +1,7 @@ -import {ScrollView, View} from "@tarojs/components"; +import {ScrollView, Text, View} from "@tarojs/components"; import {FC, useEffect, useState} from "react"; import style from './lineChart.module.scss' -import {formatMinute} from "@/utils/time"; +import {formatDateTime, formatTime} from "@/utils/time"; export interface lineData { time: string @@ -24,21 +24,25 @@ const LineChart: FC = ({data}) => { return cur } return pre - }, {time: '', value: 0})) + }, {time: formatDateTime(new Date(), 'MM/dd'), value: 0})) }, [data]) return ( <> - - {maxHeight.time}日最努力,学习了{formatMinute(maxHeight.value)}分钟 + + {formatDateTime(new Date(maxHeight.time), 'MM月dd日')} + {maxHeight.value > 0 ? `日最努力` : `期间没有学习记录`},学习了{formatTime(maxHeight.value)} + + {!maxHeight.value && 暂无数据} { !!maxHeight.value && lineChartList.map(d => - - {d.value > 0 && {formatMinute(d.value)}} - + + {d.value > 0 && {formatTime(d.value, 0)}} + {d.time} ) diff --git a/src/pages/manage/userInfo/userInfo.tsx b/src/pages/manage/userInfo/userInfo.tsx index 608cbcc..a6cc1f7 100644 --- a/src/pages/manage/userInfo/userInfo.tsx +++ b/src/pages/manage/userInfo/userInfo.tsx @@ -1,42 +1,17 @@ -import {Text, View} from "@tarojs/components"; +import {View} from "@tarojs/components"; import {FC, useEffect, useState} from "react"; import styles from './userInfo.module.scss' import Taro from "@tarojs/taro"; import Info from "@/pages/manage/userInfo/components/info"; -import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; import MyButton from "@/components/button/MyButton"; -import {ManageApi, StatisticsParam, userApi} from "@/api"; +import {ManageApi, userApi} from "@/api"; import {Profile} from "@/store"; -import {everyDay, formatMinute, getMonday, getSunday, monthEnd, monthFirst} from "@/utils/time"; -import LineChart from "@/components/lineChart/lineChart"; +import LearningRecord from "@/components/learningRecord/learningRecord"; -const tabList: TabList[] = [ - { - title: '日', - value: { - start_time: new Date().setHours(0, 0, 0, 0), - end_time: new Date().setHours(24, 0, 0, 0) - } - }, - { - title: '周', value: { - start_time: getMonday(), - end_time: getSunday() - } - }, - { - title: '月', value: { - start_time: monthFirst(), - end_time: monthEnd() - } - }, -] - const UserInfo: FC = () => { const {userId} = Taro.getCurrentInstance().router?.params as { userId: string } const [data, setData] = useState(null) - const [lineData, setLineData] = useState([]) const router = Taro.useRouter() const {user} = Profile.useContainer() @@ -81,22 +56,9 @@ const UserInfo: FC = () => { }) } - async function getStatistics(data: StatisticsParam) { - try { - const res = await userApi.statistics(userId, data) - const everyDayValue = everyDay(data.start_time, Number(data.end_time), res.data) - setLineData(everyDayValue) - } catch (e) { - - } - } - - function tabChange({tab}: OnChangOpt) { - getStatistics(tab?.value! as StatisticsParam) - } useEffect(() => { - getStatistics(tabList[0].value) + userApi.info(userId).then(res => { setData(res) }) @@ -114,17 +76,7 @@ const UserInfo: FC = () => { - - - - 总共学习 - - {formatMinute(lineData.reduce((pre, cur) => pre + cur.value, 0) || 0)} - - 分钟 - - - + diff --git a/src/pages/my/components/header/service.tsx b/src/pages/my/components/header/service.tsx index 4575009..c6347fd 100644 --- a/src/pages/my/components/header/service.tsx +++ b/src/pages/my/components/header/service.tsx @@ -57,9 +57,9 @@ const Service = () => { } return ( - + 工具服务 - + { list.map(d => { return ( diff --git a/src/pages/my/components/header/time.tsx b/src/pages/my/components/header/time.tsx index ef2e98c..f2fe81a 100644 --- a/src/pages/my/components/header/time.tsx +++ b/src/pages/my/components/header/time.tsx @@ -57,14 +57,14 @@ const Time: FC = () => { return ( - + { list.map(d => { return ( jump(d.type)}> - {d.title} + {d.title} {token && {d.time}} diff --git a/src/pages/my/my.module.scss b/src/pages/my/my.module.scss index d4667f3..ae5c8cc 100644 --- a/src/pages/my/my.module.scss +++ b/src/pages/my/my.module.scss @@ -1,13 +1,17 @@ page { background: #F2F8F6 !important; - width:750rpx; - overflow: hidden; + width: 750rpx; + overflow-x: hidden; } .content { background: linear-gradient(180deg, #45D4A8 0%, rgba(69, 212, 168, 0) 100%) no-repeat; background-size: 100% 458rpx; position: relative; + padding: 0 10rpx; + width: 750rpx; + box-sizing: border-box; + overflow: hidden; &:after { content: ''; @@ -37,7 +41,7 @@ page { } .header { - padding: 130px 20px 0; + padding: 130px 10rpx 0; font-size: 10rpx; .avatar { @@ -50,9 +54,9 @@ page { .timeBox { width: 50%; - line-height: 1.7; - margin-bottom: 20px; - padding: 0 10rpx; + height: 124rpx; + margin-bottom: 15rpx; + padding: 12rpx 10rpx; box-sizing: border-box; } @@ -71,10 +75,10 @@ page { } .service { + margin-top: 44rpx; display: grid; - margin-top: 48rpx; grid-template-columns:1fr 1fr 1fr 1fr; - grid-auto-rows: 100px 100px 100px 100px; + grid-auto-rows: 80px 80px 80px 80px; grid-gap: 60px; font-size: 28px; text-align: center; @@ -87,9 +91,9 @@ page { .tool { background: #fff; - border-radius: 20px; - padding: 30rpx 20px; - margin: 20rpx; + border-radius: 20rpx; + padding: 30rpx 20px 46rpx; + margin-top: 30rpx; } .box { @@ -99,17 +103,20 @@ page { padding: 16rpx 0; box-sizing: border-box; border-bottom: 2rpx solid #F5F8F7; - &.noBorder{ - border:none; + + &.noBorder { + border: none; } - .image{ + + .image { width: 68rpx; - height:68rpx; + height: 68rpx; background-color: #eee; border-radius: 8rpx; overflow: hidden; } - .innerBox{ + + .innerBox { height: 68rpx; align-items: center; margin-left: 24rpx; @@ -117,7 +124,8 @@ page { flex: 1; display: flex; justify-content: space-between; - .title{ + + .title { font-size: 32rpx; font-weight: 500; color: #323635; @@ -125,14 +133,16 @@ page { display: -webkit-box; text-overflow: ellipsis; overflow: hidden; - -webkit-box-orient:vertical; - -webkit-line-clamp:1; + -webkit-box-orient: vertical; + -webkit-line-clamp: 1; } - .icon{ + + .icon { margin-left: 24rpx; - width:24rpx; - height:24rpx; - &.hide{ + width: 24rpx; + height: 24rpx; + + &.hide { background: none; } } diff --git a/src/pages/my/my.tsx b/src/pages/my/my.tsx index b9c09e4..90c72eb 100644 --- a/src/pages/my/my.tsx +++ b/src/pages/my/my.tsx @@ -9,10 +9,11 @@ import {Profile} from "@/store"; import Img from "@/components/image/image"; import GreenNike from "@/static/img/greenNike.png" import {userApi} from "@/api"; +import LearningRecord from "@/components/learningRecord/learningRecord"; const My: FC = () => { const globalData = Taro.getApp().globalData - const {token, company, setCompany} = Profile.useContainer() + const {token, company, setCompany, user} = Profile.useContainer() const [companyShow, setCompanyShow] = useState(false) const [companyList, setCompanyList] = useState([]) Taro.useDidShow(() => { @@ -26,7 +27,12 @@ const My: FC = () => {
companyList.length >= 2 && setCompanyShow(true)}/>