From 54e581f2aedcd9f84ac46783c1cb307bc38e0e12 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Mon, 4 Sep 2023 10:23:45 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E4=B8=AA=E4=BA=BA=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E6=89=8B=E6=9C=BA=E5=8F=B7=E5=92=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A4=B4=E5=83=8F=202.=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=99=BB=E5=BD=95=E5=90=8E=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=203.=E5=88=87=E6=8D=A2=E5=85=AC=E5=8F=B8?= =?UTF-8?q?=E4=BB=85=E5=8F=AA=E6=9C=89=E4=B8=80=E4=B8=AA=E5=85=AC=E5=8F=B8?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E8=BF=9B=E8=A1=8C=E6=93=8D=E4=BD=9C=204.?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A6=96=E9=A1=B5=E5=88=87=E6=8D=A2=E5=92=8C?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=9B=B4=E5=A4=9A=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +- src/api/user.ts | 4 + .../navigationBar/navigationBar.module.scss | 1 + src/components/popPut/popPut.tsx | 2 +- src/hooks/eventsIndex.ts | 25 ------ src/pages/business/courType/courType.tsx | 11 --- src/pages/business/userInfo/userInfo.tsx | 59 ++++++++++++-- src/pages/business/videoInfo/videoInfo.tsx | 2 - src/pages/index/components/videoList.tsx | 35 +++----- src/pages/index/index.tsx | 2 - src/pages/my/components/header/header.tsx | 43 +++++----- src/pages/my/components/header/service.tsx | 36 +++++---- src/pages/my/my.tsx | 81 +++++++++---------- 13 files changed, 149 insertions(+), 156 deletions(-) delete mode 100644 src/hooks/eventsIndex.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/user.ts b/src/api/user.ts index bfdc66c..4c560c4 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -94,4 +94,8 @@ export const userApi = { companyReplace(id: number) { return request(`/api/v1/company/replace/${id}`, "PATCH") }, + // /** 上传头像 */ + // putAvatar(file: string) { + // return request('/api/v1/user/avatar', "PUT", {file}) + // } } diff --git a/src/components/navigationBar/navigationBar.module.scss b/src/components/navigationBar/navigationBar.module.scss index 1fe8856..0279392 100644 --- a/src/components/navigationBar/navigationBar.module.scss +++ b/src/components/navigationBar/navigationBar.module.scss @@ -15,6 +15,7 @@ left: 0; bottom: 0; align-items: center; + z-index: 1; } .text { diff --git a/src/components/popPut/popPut.tsx b/src/components/popPut/popPut.tsx index ed2f6dc..8465ab1 100644 --- a/src/components/popPut/popPut.tsx +++ b/src/components/popPut/popPut.tsx @@ -52,8 +52,8 @@ const PopPut: FC = ({title, chevron, content, image, isProp, children, sh {content} - {!chevron && } {image && } + {!chevron && } { diff --git a/src/hooks/eventsIndex.ts b/src/hooks/eventsIndex.ts deleted file mode 100644 index fa11c9e..0000000 --- a/src/hooks/eventsIndex.ts +++ /dev/null @@ -1,25 +0,0 @@ -import Taro from "@tarojs/taro"; - -/** - * 首页全局事件 - * 当某个课程看完-触发未完成移动已完成 - */ -const KEY = 'REFRESH_INDEX' - -interface RefreshIndex { - id: number -} - -function on(fn: (arg: RefreshIndex) => void) { - Taro.eventCenter.on(KEY, fn) -} - -function trigger(data: RefreshIndex) { - Taro.eventCenter.trigger(KEY, data) -} - -export default { - on, - trigger -} - diff --git a/src/pages/business/courType/courType.tsx b/src/pages/business/courType/courType.tsx index 40de350..cc7cba0 100644 --- a/src/pages/business/courType/courType.tsx +++ b/src/pages/business/courType/courType.tsx @@ -5,7 +5,6 @@ import {courseApi} from "@/api"; import VideoCover from "@/components/videoCover/videoCover"; import {formatMinute} from "@/utils/time"; import Empty from "@/components/empty/empty"; -import eventsIndex from "@/hooks/eventsIndex"; const CourType: FC = () => { const params = useRouter().params @@ -46,16 +45,6 @@ const CourType: FC = () => { } } - eventsIndex.on(({id}) => { - if (id == null && params.type === "4") return; - for (const [index, notFinished] of data.entries()) { - if (notFinished.id === id) { - data.splice(index, 1) - return - } - } - }) - useEffect(() => { getData() diff --git a/src/pages/business/userInfo/userInfo.tsx b/src/pages/business/userInfo/userInfo.tsx index e517b85..77f38a5 100644 --- a/src/pages/business/userInfo/userInfo.tsx +++ b/src/pages/business/userInfo/userInfo.tsx @@ -1,6 +1,5 @@ import {useState} from "react"; import {Profile} from '@/store' -import avatar from "@/static/img/avatar.png" import PopPut from "@/components/popPut/popPut"; import {Input, View} from "@tarojs/components"; import Taro from "@tarojs/taro"; @@ -10,7 +9,7 @@ import MyButton from "@/components/button/MyButton"; const List = () => { - const {empty, user, setUser} = Profile.useContainer() + const {empty, user, setUser, token} = Profile.useContainer() const [show, setShow] = useState(false) const [name, setName] = useState(user?.name || '') @@ -45,17 +44,67 @@ const List = () => { Taro.showModal({ title: '是否确定退出登录', success({confirm}) { - confirm && empty(true,true) + confirm && empty(true, true) } }) } + function putAvatar(filePath: string) { + Taro.showLoading({title: "正在上传图片"}) + Taro.uploadFile({ + url: process.env.TARO_APP_API + '/api/v1/user/avatar', + filePath, + name: 'file', + header: { + 'Authorization': `Bearer ${token}` + }, + success(res) { + Taro.hideLoading() + if (res.statusCode === 200) { + const data: User = JSON.parse(res.data).data + setUser(data) + Taro.showToast({title: "图片上传成功"}) + } else { + Taro.showToast({title: "图片上传失败", icon: 'error'}) + } + }, + fail() { + Taro.showToast({title: "图片上传失败", icon: 'error'}) + } + }) + } + + function selectAvatar() { + Taro.chooseImage({ + count: 1, + sizeType: ['original', 'compressed'], + sourceType: ['album', 'camera'], + success: async (res) => { + if (!res.tempFiles.length) return; + const file = res.tempFiles[0] + if (file.size > 40960000) { + Taro.compressImage({ + src: file.path, + quality: 50, + compressedWidth: 50, + compressHeight: 50, + success(res) { + putAvatar(res.tempFilePath) + } + }) + } else { + putAvatar(file.path) + } + } + }) + } return ( <> - - + + 修改昵称 diff --git a/src/pages/business/videoInfo/videoInfo.tsx b/src/pages/business/videoInfo/videoInfo.tsx index 4bc8d59..517cc04 100644 --- a/src/pages/business/videoInfo/videoInfo.tsx +++ b/src/pages/business/videoInfo/videoInfo.tsx @@ -5,7 +5,6 @@ import './videoInfo.scss' import Catalogue from "./components/catalogue"; import Course from "./components/course"; import Taro from "@tarojs/taro"; -import eventsIndex from "@/hooks/eventsIndex"; import {formatMinute} from "@/utils/time"; import videoEvents from "@/hooks/videoEvents"; import unique_ident from "@/hooks/unique_ident"; @@ -52,7 +51,6 @@ const VideoInfo: FC = () => { const flats: Hour[] = Object.values(data?.hours || {}).flat(Infinity) as Hour[] if (playId === flats?.[flats.length - 1]?.id && !preview) { Taro.showModal({title: '当前课程结束'}) - eventsIndex.trigger({id: Number(id)}) return; } for (const [index, flat] of flats.entries()) { diff --git a/src/pages/index/components/videoList.tsx b/src/pages/index/components/videoList.tsx index 5fba1bb..6913e08 100644 --- a/src/pages/index/components/videoList.tsx +++ b/src/pages/index/components/videoList.tsx @@ -19,8 +19,6 @@ export const VideoList: FC = ({categoryKey, setCategoryKey}) => { const [data, setData] = useState({ is_required: [], is_not_required: [], - // is_finished: [], - // is_not_finished: [], }) const [page, setPage] = useState(1) const [records, setRecords] = useState([]) @@ -45,8 +43,6 @@ export const VideoList: FC = ({categoryKey, setCategoryKey}) => { setData({ is_required: screen(old.is_required, res.is_required || []), is_not_required: screen(old.is_not_required, res.is_not_required || []), - // is_finished: screen(old.is_finished, res.is_finished || []), - // is_not_finished: screen(old.is_not_finished, res.is_not_finished || []), }) } catch (e) { } @@ -76,16 +72,6 @@ export const VideoList: FC = ({categoryKey, setCategoryKey}) => { } } - // eventsIndex.on(({id}) => { - // if (id == null) return; - // for (const [index, notFinished] of data.is_not_finished.entries()) { - // if (notFinished.id === id) { - // data.is_finished.push(notFinished) - // data.is_not_finished.splice(index, 1) - // return - // } - // } - // }) const fetchData = () => { getData().then() @@ -114,12 +100,11 @@ export const VideoList: FC = ({categoryKey, setCategoryKey}) => { Object.entries(data).map(([key, value]) => setPage(page + 1)} enhanced showScrollbar={false}> - - { - !token - && key === 'is_required' - ? : value?.length ? - <> + { + !token && key === 'is_required' + ? : value?.length ? + <> + { value?.map(c => = ({categoryKey, setCategoryKey}) => { content={rateOfLearning(c.id, c.class_hour)} />) } - 暂无更多 - - : - } - + + 暂无更多 + + : + } ) } diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 3f77848..f5000dc 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -10,8 +10,6 @@ const Index: FC = () => { const category: TabList[] = [ {title: "必修", value: 'is_required'}, {title: "选修", value: 'is_not_required'}, - // {title: "已完成", value: 'is_finished'}, - // {title: "未完成", value: 'is_not_finished'}, ] const [categoryKey, setCategoryKey] = useState('is_required') diff --git a/src/pages/my/components/header/header.tsx b/src/pages/my/components/header/header.tsx index 0235cbf..369433e 100644 --- a/src/pages/my/components/header/header.tsx +++ b/src/pages/my/components/header/header.tsx @@ -3,39 +3,32 @@ import {Image, Text, View} from "@tarojs/components"; import styles from "@/pages/my/my.module.scss"; import avatar from "@/static/img/avatar.png" import blacktriang from "@/static/img/blacktriangle.png" +import {FC} from "react"; -const Header = ({showCompany}:{showCompany:()=> void}) => { - const {token,user,company,empty} = Profile.useContainer() +interface Props { + companyList: Company[] + showCompany: () => void +} + +const Header: FC = ({companyList, showCompany}) => { + const {token, user, company, empty} = Profile.useContainer() return ( + { - token ? - : - - } - { token ? - - {user?.name} - - { - showCompany() - }}> - {company?.name} - + token ? + {user?.name} + + {company?.name} + {companyList.length > 2 && } + + + : + empty()}>请登录 - : - - { - empty() - }}>请登录 - } - - {/**/} - {/* 手机号:{user?.phone_number}*/} - {/**/} ) diff --git a/src/pages/my/components/header/service.tsx b/src/pages/my/components/header/service.tsx index d652b8f..4575009 100644 --- a/src/pages/my/components/header/service.tsx +++ b/src/pages/my/components/header/service.tsx @@ -1,4 +1,4 @@ -import {useEffect, useState} from "react"; +import {useState} from "react"; import {Image, View} from "@tarojs/components"; import Taro from "@tarojs/taro"; import {Profile} from '@/store/profile' @@ -22,7 +22,7 @@ const Service = () => { {title: '个人中心', src: userInfo, router: '/pages/business/userInfo/userInfo'}, ]) - const {token,user, setUser} = Profile.useContainer() + const {token, user, setUser} = Profile.useContainer() Taro.useDidShow(async () => { if (user?.id) { @@ -31,24 +31,26 @@ const Service = () => { } }) - useEffect(() => { - const oldList: List[] = JSON.parse(JSON.stringify(list)) - if(token){ - if ([1, 2].includes(user?.role_type || 0)) { - oldList.unshift(...[ - {title: '部门管理', src: dep, router: '/pages/manage/depAdmin/depAdmin'}, - // {title: '课程市场', src: buy, router: '/pages/manage/curriculum/curriculum'}, - {title: '现场会', src: spotMeeting, router: '/pages/manage/spotMeeting/spotMeeting'}, - {title: '课程管理', src: course, router: '/pages/manage/courseAdmin/courseAdmin'}, - ]) - setList(oldList) - } + Taro.useDidShow(() => { + if ([1, 2].includes(user?.role_type || 0)) { + setList([ + {title: '部门管理', src: dep, router: '/pages/manage/depAdmin/depAdmin'}, + {title: '现场会', src: spotMeeting, router: '/pages/manage/spotMeeting/spotMeeting'}, + {title: '课程管理', src: course, router: '/pages/manage/courseAdmin/courseAdmin'}, + {title: '个人中心', src: userInfo, router: '/pages/business/userInfo/userInfo'}, + {title: '历史记录', src: cur, router: '/pages/business/history/history'}, + ]) + } else { + setList([ + {title: '历史记录', src: cur, router: '/pages/business/history/history'}, + {title: '个人中心', src: userInfo, router: '/pages/business/userInfo/userInfo'}, + ]) } - }, []) + }) function jump(url: string) { - if(!token){ - Taro.navigateTo({url:'/pages/login/login'}) + if (!token) { + Taro.navigateTo({url: '/pages/login/login'}) return } Taro.navigateTo({url}) diff --git a/src/pages/my/my.tsx b/src/pages/my/my.tsx index 9561e3c..b9c09e4 100644 --- a/src/pages/my/my.tsx +++ b/src/pages/my/my.tsx @@ -16,58 +16,57 @@ const My: FC = () => { const [companyShow, setCompanyShow] = useState(false) const [companyList, setCompanyList] = useState([]) Taro.useDidShow(() => { - if(token){ - try { - userApi.companyList().then(res => { - setCompanyList(res as Company[]) - }) - } catch (e) { - } - } - + token && userApi.companyList().then(res => { + setCompanyList(res as Company[]) + }) }) return ( -
{ - companyList.length >= 2 && setCompanyShow(true) - }}/> -