From 7f4092cc8a4c93c8ffb0f38a6941c44f0b520c07 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Fri, 28 Jul 2023 17:39:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/curriculum.ts | 1 + src/api/manage.ts | 3 + src/app.config.ts | 2 + src/hooks/eventsIndex.ts | 18 ++ src/pages/business/videoInfo/videoInfo.tsx | 4 + src/pages/index/components/videoList.tsx | 57 ++----- src/pages/index/index.tsx | 4 +- src/pages/manage/bingUser/bingUser.config.ts | 3 + src/pages/manage/bingUser/bingUser.tsx | 49 ++++++ src/pages/manage/offline/offline.config.ts | 4 + src/pages/manage/offline/offline.module.scss | 11 ++ src/pages/manage/offline/offline.tsx | 168 +++++++++++++++++++ src/pages/my/components/header/service.tsx | 1 + src/utils/time.ts | 19 +++ types/user.d.ts | 11 +- 15 files changed, 307 insertions(+), 48 deletions(-) create mode 100644 src/hooks/eventsIndex.ts create mode 100644 src/pages/manage/bingUser/bingUser.config.ts create mode 100644 src/pages/manage/bingUser/bingUser.tsx create mode 100644 src/pages/manage/offline/offline.config.ts create mode 100644 src/pages/manage/offline/offline.module.scss create mode 100644 src/pages/manage/offline/offline.tsx diff --git a/src/api/curriculum.ts b/src/api/curriculum.ts index 56ce566..8f76a45 100644 --- a/src/api/curriculum.ts +++ b/src/api/curriculum.ts @@ -66,6 +66,7 @@ export interface CurEndParam { } export const curriculum = { + /** 部门all */ department() { return request<{ data: Manage[] }>('/api/v1/department/index', 'GET') }, diff --git a/src/api/manage.ts b/src/api/manage.ts index 398e06a..d79541a 100644 --- a/src/api/manage.ts +++ b/src/api/manage.ts @@ -120,5 +120,8 @@ export const ManageApi = { /** 学员学习记录 */ userRecord(curId: number) { return request(`/api/v1/course/${curId}/user/index?page=1&size=10000`, "GET") + }, + offline(data: Offline) { + return request('/wechat/link', "GET", data) } } diff --git a/src/app.config.ts b/src/app.config.ts index d66a073..7daf7bf 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -58,6 +58,8 @@ export default defineAppConfig({ 'addStudent/addStudent', 'depCur/depCur', 'addCur/addCur', + 'offline/offline', + 'bingUser/bingUser', ] } ], diff --git a/src/hooks/eventsIndex.ts b/src/hooks/eventsIndex.ts new file mode 100644 index 0000000..643c28f --- /dev/null +++ b/src/hooks/eventsIndex.ts @@ -0,0 +1,18 @@ +import Taro from "@tarojs/taro"; + +/** 首页全局事件 */ +const KEY = 'REFRESHINDEX' + +function on(fn: (arg: any) => void) { + Taro.eventCenter.on(KEY, fn) +} + +function trigger(data:any){ + Taro.eventCenter.trigger(KEY, data) +} + +export default { + on, + trigger +} + diff --git a/src/pages/business/videoInfo/videoInfo.tsx b/src/pages/business/videoInfo/videoInfo.tsx index a1939cc..1cc66ea 100644 --- a/src/pages/business/videoInfo/videoInfo.tsx +++ b/src/pages/business/videoInfo/videoInfo.tsx @@ -6,6 +6,7 @@ import {Profile} from '@/store' import Catalogue from "./components/catalogue"; import Course from "./components/course"; import Taro from "@tarojs/taro"; +import eventsIndex from "@/hooks/eventsIndex"; const VideoInfo: FC = () => { @@ -14,6 +15,9 @@ const VideoInfo: FC = () => { const [playId, setPlayId] = useState(null) const [preview, setPreview] = useState(false) + eventsIndex.trigger(12) + + async function getData() { const res = await curriculum.courseDep(id, depId) if (res) { diff --git a/src/pages/index/components/videoList.tsx b/src/pages/index/components/videoList.tsx index 941fa79..ae0abab 100644 --- a/src/pages/index/components/videoList.tsx +++ b/src/pages/index/components/videoList.tsx @@ -7,6 +7,7 @@ import styles from '../index.module.scss' import {formatMinute} from "@/utils/time"; import {userApi} from "@/api"; import Empty from "@/components/empty/empty"; +// import eventsIndex from "@/hooks/eventsIndex"; interface Props { categoryKey: CoursesKey @@ -23,51 +24,11 @@ export const VideoList: FC = ({categoryKey}) => { const [page, setPage] = useState(1) const [records, setRecords] = useState([]) + async function getData() { try { - const res = await publicApi.course({page: page, pageSize: 10}) - const oldData: Courses = JSON.parse(JSON.stringify(data)) - oldData.is_finished = res.is_finished.reduce((pre, cur) => { - const index = pre.findIndex(d => d.id === cur.id) - if (index === -1) { - pre.push(cur) - } else { - pre.splice(index, 1, cur) - } - return pre - }, oldData.is_finished) - - oldData.is_required = res.is_required.reduce((pre, cur) => { - const index = pre.findIndex(d => d.id === cur.id) - if (index === -1) { - pre.push(cur) - } else { - pre.splice(index, 1, cur) - } - return pre - }, oldData.is_required) - - oldData.is_not_finished = res.is_not_finished.reduce((pre, cur) => { - const index = pre.findIndex(d => d.id === cur.id) - if (index === -1) { - pre.push(cur) - } else { - pre.splice(index, 1, cur) - } - return pre - }, oldData.is_not_finished) - - oldData.is_not_required = res.is_not_required.reduce((pre, cur) => { - const index = pre.findIndex(d => d.id === cur.id) - if (index === -1) { - pre.push(cur) - } else { - pre.splice(index, 1, cur) - } - return pre - }, oldData.is_not_required) - - setData(oldData) + const res = await publicApi.course({page: 1, pageSize: 10 * page}) + setData(res) } catch (e) { } } @@ -85,13 +46,15 @@ export const VideoList: FC = ({categoryKey}) => { switch (categoryKey) { case "is_required": case "is_not_required": + case "is_not_finished": const find = records.find(d => d?.course_id === id) if (find) { + if(class_hour === find.finished_count){ + return 已完成 + } return ({`共${class_hour}节/已学${find.finished_count}节`}) } return ({`共${class_hour}节/已学0节`}) - case "is_not_finished": - return ({`共${class_hour}节/已学0节`}) case "is_finished": return ({`共${class_hour}节/已学${class_hour}节`}) } @@ -102,6 +65,10 @@ export const VideoList: FC = ({categoryKey}) => { setPage(page + 1) }) + // eventsIndex.on(()=>{ + // getRecords() + // }) + Taro.useDidShow(() => { if (init) { getData() diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 119045b..0a465e1 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,12 +1,12 @@ import {FC, useState} from "react"; import {View} from "@tarojs/components"; -import Taro from "@tarojs/taro"; import styles from './index.module.scss' import {Profile} from '@/store' // import {Search} from "@/pages/index/components/search"; import {VideoList} from "@/pages/index/components/videoList"; import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; import {CoursesKey} from "@/api/public"; +import Taro from '@tarojs/taro' const Index: FC = () => { @@ -19,6 +19,8 @@ const Index: FC = () => { ] const [categoryKey, setCategoryKey] = useState('is_required') + + function tabChange(data: OnChangOpt) { setCategoryKey(data.tab?.value as CoursesKey) } diff --git a/src/pages/manage/bingUser/bingUser.config.ts b/src/pages/manage/bingUser/bingUser.config.ts new file mode 100644 index 0000000..a71090b --- /dev/null +++ b/src/pages/manage/bingUser/bingUser.config.ts @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: '注册', +}) diff --git a/src/pages/manage/bingUser/bingUser.tsx b/src/pages/manage/bingUser/bingUser.tsx new file mode 100644 index 0000000..dae2448 --- /dev/null +++ b/src/pages/manage/bingUser/bingUser.tsx @@ -0,0 +1,49 @@ +import {FC} from "react"; +import {Button, Form, Input, View} from "@tarojs/components"; +import {getCurrentInstance} from "@tarojs/runtime"; +import Taro from "@tarojs/taro"; + +const BingUser: FC = () => { + const {company_id, department_id, start_time, end_time} = getCurrentInstance()?.router?.params as unknown as Offline + + Taro.useLoad(() => { + const time = Date.now() + if (!company_id + || !department_id + || !start_time + || !end_time + || time > new Date(end_time).getTime() + || time < new Date(start_time).getTime()) { + Taro.showModal({ + title: '二维码已过期', + success() { + Taro.reLaunch({url: '/pages/login/login'}) + } + }) + return + } + + }) + + + return ( + +
+ + + 用户名 + + + + + 手机号 + + + + +
+
+ ) +} + +export default BingUser diff --git a/src/pages/manage/offline/offline.config.ts b/src/pages/manage/offline/offline.config.ts new file mode 100644 index 0000000..3f286c6 --- /dev/null +++ b/src/pages/manage/offline/offline.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '见面会', + enableShareAppMessage: true +}) diff --git a/src/pages/manage/offline/offline.module.scss b/src/pages/manage/offline/offline.module.scss new file mode 100644 index 0000000..5d68914 --- /dev/null +++ b/src/pages/manage/offline/offline.module.scss @@ -0,0 +1,11 @@ +.page { + background: #fff; + min-height: 100vh; + padding: 20px; +} + +.time { + border-bottom: 1px solid #ddd; + padding: 30px 15px; + border-radius: 10px; +} diff --git a/src/pages/manage/offline/offline.tsx b/src/pages/manage/offline/offline.tsx new file mode 100644 index 0000000..22a7a8d --- /dev/null +++ b/src/pages/manage/offline/offline.tsx @@ -0,0 +1,168 @@ +import {FC, useCallback, useState} from "react"; +import {Button, Image, Picker, View} from "@tarojs/components"; +import styles from './offline.module.scss' +import Taro from "@tarojs/taro"; +import {curriculum} from "@/api"; +import {formatDate} from "@/utils/time"; +import {getSetting, authorize} from "@tarojs/taro"; +import PopPut from "@/components/popPut/popPut"; + + +const Offline: FC = () => { + const [manages, setManages] = useState([]) + const [start, setStart] = useState(formatDate(new Date(), "YY-MM-dd")) + const [end, setEnd] = useState(formatDate(new Date(), "YY-MM-dd")) + const [tempFilePath, setTempFilePath] = useState(null); + + + Taro.useLoad(() => { + curriculum.department().then(res => { + setManages(res.data) + }) + }) + + async function change(e) { + const depName = e.detail.value + if (!depName) { + Taro.showToast({title: '请选择部门', icon: 'error'}) + return null + } + + const startTime = new Date(start).getTime() + const endTime = new Date(end).getTime() + const depid = manages.find(d => d.name === depName)?.id + const path = encodeURIComponent("/pages/meeting/index") + + const qrcodeUrl = `${process.env.TARO_APP_API}/wechat/link?depid=${depid}&start_time=${startTime}&end_time=${endTime}&path=${path}` + + Taro.downloadFile({ + url: qrcodeUrl, + success(res) { + setTempFilePath(res.tempFilePath) + }, + fail() { + Taro.showToast({title: '二维码生产失败', icon: 'error'}) + } + } + ) + } + + + // const paintingCanvas = () => { + // Taro.showLoading() + // try { + // Taro.createSelectorQuery().select('#canvasId').fields({node: true, size: true}).exec((res) => { + // const width = res[0].width + // const height = res[0].height + // + // const canvas = res[0].node + // + // Mycanvas = canvas + // const ctx = canvas.getContext('2d') + // + // const dpr = Taro.getSystemInfoSync().pixelRatio + // canvas.width = width * dpr + // canvas.height = height * dpr + // ctx.scale(dpr, dpr) + // + // ctx.fillStyle = '#ffffff' + // ctx.fillRect(0, 0, width, height) + // + // ctx.font = '16px Microsoft YaiHei' + // ctx.fillStyle = 'black' + // ctx.textAlign = 'center'; + // ctx.fillText(`${start === end ? `有效期${start}` : `开始:${start} 结束:${end}`}`, width / 2, 280) + // + // Taro.getImageInfo({ + // src: 'http://81.69.44.74:39200/kynyxd/images/ILBNTCk3PhC3xEV1zCDAsggudZzkiHJi.png', + // success(res) { + // const img = canvas.createImage() + // img.src = res.path + // img.onload = () => { + // ctx.drawImage(img, (width - 200) / 2, 20, 200, 200) + // } + // } + // }) + // }) + // } catch (e) { + // Taro.showToast({title: '二维码生成失败', icon: 'error'}) + // } + // Taro.hideLoading() + // } + + + const handleWriteFile = useCallback(() => { + if (tempFilePath) { + Taro.saveImageToPhotosAlbum({ + filePath: tempFilePath, + success() { + Taro.showModal({title: '下载成功'}) + }, + fail() { + Taro.showToast({title: '下载失败', icon: 'error'}) + } + }) + } else { + Taro.showToast({title: '下载失败', icon: 'error'}) + } + }, [tempFilePath]) + + + // function handleWriteFile() { + // + // } + + const handleSaveCode = useCallback(() => { + getSetting({ + success: function ({authSetting}) { + //没有权限则申请 + if (!authSetting["scope.writePhotosAlbum"]) { + authorize({ + scope: "scope.writePhotosAlbum", + success: () => { + //存储二维码 + handleWriteFile() + }, + }); + } else { + handleWriteFile() + } + }, + }); + }, [tempFilePath]); + + + return ( + + + + setStart(e.detail.value)} name='start'> + + {start} + + + + + + setEnd(e.detail.value)} name='end'> + + {end} + + + + + + + + + + + {tempFilePath && + + + } + + ) +} + +export default Offline diff --git a/src/pages/my/components/header/service.tsx b/src/pages/my/components/header/service.tsx index f3ef642..016ebf8 100644 --- a/src/pages/my/components/header/service.tsx +++ b/src/pages/my/components/header/service.tsx @@ -27,6 +27,7 @@ const Service = () => { oldList.unshift(...[ {title: '部门管理', src: dep, router: '/pages/manage/depAdmin/depAdmin'}, {title: '课程购买', src: buy, router: '/pages/manage/curriculum/curriculum'}, + {title: '见面会', src: buy, router: '/pages/manage/offline/offline'}, ]) setList(oldList) } diff --git a/src/utils/time.ts b/src/utils/time.ts index bb6f726..7a3a857 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -43,3 +43,22 @@ export function formatDateTime(date, format) { } return format; } + +export function formatDate(date, format) { + const year = date.getFullYear(), + month = date.getMonth() + 1,//月份是从0开始的 + day = date.getDate(), + hour = date.getHours(), + min = date.getMinutes(), + sec = date.getSeconds(); + const preArr = Array.apply(null, Array(10)).map(function (_elem, index) { + return '0' + index; + }); + + return format.replace(/YY/g, year) + .replace(/MM/g, preArr[month] || month) + .replace(/dd/g, preArr[day] || day) + .replace(/hh/g, preArr[hour] || hour) + .replace(/mm/g, preArr[min] || min) + .replace(/ss/g, preArr[sec] || sec); +} diff --git a/types/user.d.ts b/types/user.d.ts index e5d1247..e961b9a 100644 --- a/types/user.d.ts +++ b/types/user.d.ts @@ -76,8 +76,7 @@ interface CueStats { } - -interface userRecord{ +interface userRecord { id: number; duration: number; course: Curriculum; @@ -91,3 +90,11 @@ interface userRecord{ total_hour_count: number; finished_count: number; } + + +interface Offline { + depid: number + start_time: number + end_time: number + path:string +}