From e6ca8a8d5b6bf1af394ad5b748c5464b7d91478d Mon Sep 17 00:00:00 2001 From: yuping <82253452@qq.com> Date: Mon, 20 Feb 2023 04:23:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E9=99=A2=E6=AE=B5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/CONST.js | 55 +- src/api/useCommon.js | 55 + src/store/index.js | 86 +- src/views/liveBroadcast/LiveBroadcast.vue | 1325 +++++++++++---------- src/views/project/ProjectDetails.vue | 207 +--- src/views/roadmap/PathDetails.vue | 124 +- 6 files changed, 938 insertions(+), 914 deletions(-) create mode 100644 src/api/useCommon.js diff --git a/src/api/CONST.js b/src/api/CONST.js index d8d0693..e07e4bb 100644 --- a/src/api/CONST.js +++ b/src/api/CONST.js @@ -1,3 +1,56 @@ export const PROJECT = 1; export const ROUTER = 2; -export const COURSE = 3; \ No newline at end of file +export const COURSE = 3; + +export const TASK_TYPES ={ + typeName: { + 1: "在线", + 2: "面授", + 3: "案例", + 4: "作业", + 5: "考试", + 6: "直播", + 7: "外链", + 8: "讨论", + 9: "活动", + 10: "测评", + 11: "评估", + 12: "投票", + 13: "项目", + }, + toName: { + 1: "去上课", + 2: "去上课", + 3: "去阅读", + 4: "去完成", + 5: "去完成", + 6: "去观看", + 7: "去查看", + 8: "去讨论", + 9: "去签到", + 10: "去完成", + 11: "去完成", + 12: "去投票", + 13: "去完成", + }, + path: { + 1: window.location.protocol + import.meta.env.VITE_BOE_ONLINE_CLASS_URL, //在线 + 2: ({courseId}) => window.open(`${location.protocol}//${location.host}${import.meta.env.VITE_BASE_API}/stu/project/redirectDetail?courseId=${courseId}`, '_top'), + 3: window.location.protocol + import.meta.env.VITE_BOE_CASS_DETAIL_URL, //案例 + 4: "/homeworkpage", + 5: window.location.protocol + import.meta.env.VITE_BOE_EXAM_DETAIL_URL, //考试 + 6: "/livebroadcast", + 7: ({targetId}) => window.open(targetId, '_top'), //外联 + 8: "/discusspage", + 9: "/moreactive", + 10: ({evaType, targetId}) => + window.open( + evaType == 0 + ? window.location.protocol + import.meta.env.VITE_BOE_TEST_DETAIL_URL + targetId + : window.location.protocol + import.meta.env.VITE_BOE_TEST_OUT_DETAIL_URL + targetId + `&quizTaskKid=${routerId}&channelCode=learningpath` + , '_top'), //测评 + 11: "/surveydetail", + 12: "/ballotpage", + 13: "/projectdetails", + }, +} \ No newline at end of file diff --git a/src/api/useCommon.js b/src/api/useCommon.js new file mode 100644 index 0000000..55bfcda --- /dev/null +++ b/src/api/useCommon.js @@ -0,0 +1,55 @@ +import {useRoute, useRouter} from "vue-router/dist/vue-router"; +import {useStore} from "vuex"; +import {PROJECT, TASK_TYPES} from "@/api/CONST"; +import {computed, onMounted} from "vue"; + +export function useTaskPage() { + const router = useRouter() + const {query: {id: taskId, type, infoId}} = useRoute() + const {state, dispatch} = useStore() + const info = computed(() => type == 1 ? state.projectInfo : state.routerInfo) + + const taskList = computed(() => type == 1 ? info.value.stageProcessList.flatMap(t => t.taskProcessList.map(s => ({ + ...s, + stageId: t.id, + stageName: t.name + }))) : info.value.taskBoList) + const index = computed(() => taskList.value?.findIndex(t => t.id == taskId)) + const hasPrev = computed(() => index.value - 1 > 0) + const hasNext = computed(() => taskList.value.length > index) + + onMounted(() => { + dispatch('getProjectInfo', {projectId:infoId}) + }) + + function nextPage() { + toPage(taskList.value[index.value + 1]) + } + + function prevPage() { + toPage(taskList.value[index.value - 1]) + } + + function toPage(d) { + if (typeof TASK_TYPES.path[d.type] === "string") { + TASK_TYPES.path[d.type] && TASK_TYPES.path[d.type].startsWith("http") && window.open(TASK_TYPES.path[d.type] + d.targetId, '_top'); + TASK_TYPES.path[d.type] && TASK_TYPES.path[d.type].startsWith("/") && router.push({ + path: TASK_TYPES.path[d.type], + query: { + id: d.id, + type: type, + infoId: info.id, + courseId: d.courseId, + pName: info.name, + sName:d.stageName, + chapterOrStageId: d.stageId, + btype: type + }, + }); + } else if (typeof TASK_TYPES.path[d.type] === "function") { + TASK_TYPES.path[d.type](d); + } + } + + return {hasPrev, hasNext, nextPage, prevPage} +} \ No newline at end of file diff --git a/src/store/index.js b/src/store/index.js index 5b3df40..efdd06d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,15 +1,95 @@ import {createStore} from 'vuex' +import {PROJECT_PROCESS, ROUTER_PROCESS} from "@/api/api"; +import {request} from "@/api/request"; +import {TASK_TYPES} from "@/api/CONST"; export default createStore({ state: { - userInfo: {} + userInfo: {}, + projectInfo: {}, + routerInfo: {} + }, + getters: { + }, - getters: {}, mutations: { SET_USER(state, userInfo) { state.userInfo = userInfo }, + SET_PROJECT_INFO(state, info) { + state.projectInfo = info + }, + INIT_PROJECT_INFO(state) { + if (state.projectInfo.status === -1) { + state.projectInfo.stageProcessList.forEach((t) => { + t.statusName = '已结束'; + t.taskProcessList?.forEach((s) => s.statusName = '已结束') + }) + return + } + if (state.projectInfo.unlockMode === 1) { + state.projectInfo.stageProcessList.forEach((t) => { + t.statusName = '进行中' + const stageState = t.taskProcessList?.every((s) => { + s.statusName = s.status === 1 ? '已完成' : TASK_TYPES.toName[s.type] + return s.status === 1 + }) + stageState && (t.statusName = '已完成') + }) + return + } + state.projectInfo.stageProcessList?.some((t) => { + t.statusName = '已完成' + const stageState = t.taskProcessList?.some((s) => { + s.unlock = true + s.statusName = '已完成' + s.status !== 1 && (s.statusName = TASK_TYPES.toName[s.type]) + return state.projectInfo.unlockMode === 2 ? s.status !== 1 : (s.status !== 1 && s.flag) + }) + stageState && (t.statusName = '进行中'); + return stageState + }) + }, + SET_ROUTER_INFO(state, info) { + state.routerInfo = info + }, + INIT_ROUTER_INFO(state) { + // state.routerInfo.unlockMode 1自由模式 2闯关模式 3 闯关模式 必修 flag true + if (state.routerInfo.status === -1) { + state.routerInfo.statusName = '已结束' + state.routerInfo.taskBoList.forEach((t) => t.statusName = '已结束') + return + } + state.routerInfo.statusName = '进行中' + if (state.routerInfo.unlockMode === 1) { + state.routerInfo.taskBoList?.every((s) => { + s.statusName = s.status === 1 ? '已完成' : TASK_TYPES.toName[s.type] + return s.status === 1 + }) && (state.routerInfo.statusName = '已完成') + return + } + state.routerInfo.statusName = '已完成' + state.routerInfo.taskBoList?.some((s) => { + s.unlock = true + s.statusName = '已完成' + s.status !== 1 && (s.statusName = TASK_TYPES.toName[s.type]) + return state.routerInfo.unlockMode === 2 ? s.status !== 1 : (s.status !== 1 && s.flag) + }) && (state.routerInfo.statusName = '进行中') + }, + }, + actions: { + getProjectInfo(content, {projectId}) { + content.state.projectInfo.projectId || request(PROJECT_PROCESS, {projectId}).then(res => { + content.commit('SET_PROJECT_INFO', res.data) + content.commit('INIT_PROJECT_INFO') + }) + }, + getRouterInfo(content, {routerId}) { + content.state.routerInfo.routerId || request(ROUTER_PROCESS, {routerId}).then(res => { + content.commit('SET_ROUTER_INFO', res.data) + content.commit('INIT_ROUTER_INFO') + }) + }, }, - actions: {}, modules: {} }) diff --git a/src/views/liveBroadcast/LiveBroadcast.vue b/src/views/liveBroadcast/LiveBroadcast.vue index 1ed0d61..03b15b1 100644 --- a/src/views/liveBroadcast/LiveBroadcast.vue +++ b/src/views/liveBroadcast/LiveBroadcast.vue @@ -1,42 +1,46 @@ diff --git a/src/views/project/ProjectDetails.vue b/src/views/project/ProjectDetails.vue index aa6d8f6..f043f85 100644 --- a/src/views/project/ProjectDetails.vue +++ b/src/views/project/ProjectDetails.vue @@ -14,7 +14,6 @@
- {{ loading.close() }}
{{ i.stageName }}
@@ -34,7 +33,7 @@
{ return a.id - b.id; })).filter( (e) => !whiteTypes(e.type) )" :key="index"> @@ -90,7 +89,7 @@
-
{{ value.statusName || (data.unlockMode === 1 ? types.toName[value.type] : '未解锁') }}
@@ -404,72 +403,28 @@