|
@@ -54,7 +54,9 @@ import {
|
|
|
getCourseScheduleDateByMonth_gyt,
|
|
|
getCourseSchedulesWithDate_gyt
|
|
|
} from "@/api/curriculum.api"
|
|
|
-import { httpAjaxErrMsg, httpAjax } from "@/plugin/httpAjax"
|
|
|
+import { httpAjax } from "@/plugin/httpAjax"
|
|
|
+import { CODE_ERR_CANCELED } from "@/libs/auth"
|
|
|
+import { ElMessage } from "element-plus"
|
|
|
|
|
|
const userStoreHook = userStore()
|
|
|
const navs = [
|
|
@@ -71,6 +73,8 @@ const curriculumByMonth = shallowRef<string[]>([])
|
|
|
const curriculumByDay = shallowRef<any[]>([])
|
|
|
const dateValue = ref(new Date())
|
|
|
const loading = ref(false)
|
|
|
+let monthController: AbortController
|
|
|
+let dayController: AbortController
|
|
|
watch(dateValue, () => {
|
|
|
handleDayChange(dateValue.value)
|
|
|
})
|
|
@@ -84,33 +88,60 @@ function handleDayChange(date: Date) {
|
|
|
getCurriculumByDay(format(date, "yyyy-mm-dd"))
|
|
|
}
|
|
|
function getCurriculumByDay(day: string) {
|
|
|
+ if (dayController) {
|
|
|
+ dayController.abort()
|
|
|
+ }
|
|
|
+ dayController = new AbortController()
|
|
|
if (userStoreHook.roles === "GYM") {
|
|
|
loading.value = true
|
|
|
- httpAjaxErrMsg(getCourseSchedulesWithDate_gym, day).then(res => {
|
|
|
+ httpAjax(getCourseSchedulesWithDate_gym, day, dayController).then(res => {
|
|
|
+ // 自己关闭的时候不取消加载
|
|
|
+ if (res.code === CODE_ERR_CANCELED) {
|
|
|
+ return
|
|
|
+ }
|
|
|
loading.value = false
|
|
|
if (res.code === 200) {
|
|
|
curriculumByDay.value = res.data?.rows || []
|
|
|
+ } else {
|
|
|
+ ElMessage({
|
|
|
+ showClose: true,
|
|
|
+ message: res.message,
|
|
|
+ type: "error"
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
loading.value = true
|
|
|
- httpAjaxErrMsg(getCourseSchedulesWithDate_gyt, day).then(res => {
|
|
|
+ httpAjax(getCourseSchedulesWithDate_gyt, day, dayController).then(res => {
|
|
|
+ if (res.code === CODE_ERR_CANCELED) {
|
|
|
+ return
|
|
|
+ }
|
|
|
loading.value = false
|
|
|
if (res.code === 200) {
|
|
|
curriculumByDay.value = res.data?.rows || []
|
|
|
+ } else {
|
|
|
+ ElMessage({
|
|
|
+ showClose: true,
|
|
|
+ message: res.message,
|
|
|
+ type: "error"
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
function getCurriculumByMonth(month: string) {
|
|
|
+ if (monthController) {
|
|
|
+ monthController.abort()
|
|
|
+ }
|
|
|
+ monthController = new AbortController()
|
|
|
if (userStoreHook.roles === "GYM") {
|
|
|
- httpAjax(getCourseScheduleDateByMonth_gym, month).then(res => {
|
|
|
+ httpAjax(getCourseScheduleDateByMonth_gym, month, monthController).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
curriculumByMonth.value = res.data || []
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
- httpAjax(getCourseScheduleDateByMonth_gyt, month).then(res => {
|
|
|
+ httpAjax(getCourseScheduleDateByMonth_gyt, month, monthController).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
curriculumByMonth.value = res.data || []
|
|
|
}
|