mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-18 15:26:51 +08:00
学院段修改
This commit is contained in:
55
src/api/useCommon.js
Normal file
55
src/api/useCommon.js
Normal file
@@ -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}
|
||||
}
|
||||
Reference in New Issue
Block a user