From b7c28ebfbcc2a4f1383591664f1155662c261962 Mon Sep 17 00:00:00 2001 From: as6325400 Date: Thu, 18 Jan 2024 16:46:54 +0800 Subject: [PATCH] fix race condition --- src/components/pages/main/courseCard.vue | 7 ++++--- src/components/pages/main/inputArea.vue | 6 ++++-- src/components/pages/main/search_box.vue | 2 +- src/components/pages/main/serach_modes/department.vue | 5 +++-- src/store/course.ts | 8 ++++---- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/pages/main/courseCard.vue b/src/components/pages/main/courseCard.vue index 05a948f..cd07268 100644 --- a/src/components/pages/main/courseCard.vue +++ b/src/components/pages/main/courseCard.vue @@ -21,7 +21,7 @@
- 刪除 + 刪除 修改顏色 文字樣式 查看評價 @@ -101,8 +101,9 @@ // if(color != ) } - let delete_course_card = function(item){ - console.log(item); + let delete_course_card = async function(item){ + await setConflictState(1) + await setConflictState(2) if(item.getCredit() != null){ decreaseCredit(item.getCredit()) } diff --git a/src/components/pages/main/inputArea.vue b/src/components/pages/main/inputArea.vue index e5938d4..12cd72f 100644 --- a/src/components/pages/main/inputArea.vue +++ b/src/components/pages/main/inputArea.vue @@ -60,7 +60,7 @@ {{ item.getStartTime() }} @@ -148,9 +148,11 @@ watch(toggleActive1, (inputValue) => { } }) -var delete_course = function(item) +var delete_course = async function(item) { // 刪除課程 + await setConflictState(1); + await setConflictState(2); if(item.getCredit() != null){ decreaseCredit(item.getCredit()) } diff --git a/src/components/pages/main/search_box.vue b/src/components/pages/main/search_box.vue index 1a4389b..3b05db6 100644 --- a/src/components/pages/main/search_box.vue +++ b/src/components/pages/main/search_box.vue @@ -87,7 +87,7 @@ const setConflictState = (state) => store.dispatch("setrunConflictState", state) watch(runConflictState, async (state) => { - if(state){ + if(state == 2){ data.value = data.value.map(temp => { temp['conflict'] = classconflict(temp); return temp; diff --git a/src/components/pages/main/serach_modes/department.vue b/src/components/pages/main/serach_modes/department.vue index 5d1a925..723c3d9 100644 --- a/src/components/pages/main/serach_modes/department.vue +++ b/src/components/pages/main/serach_modes/department.vue @@ -86,7 +86,7 @@ const classClick = (item) => { }; watch(runConflictState, async (state) => { - if(state){ + if(state == 1){ courseList.value = courseList.value.map(temp => { temp['conflict'] = classconflict(temp); temp['click'] = false; @@ -123,7 +123,8 @@ async function clickDepartment() }); let coursedata = await getCourseByDepartment(departmentInput.value); courseList.value = coursedata; - setConflictState(true); + // department 給 1 + setConflictState(1) show_search_list.value = true; } diff --git a/src/store/course.ts b/src/store/course.ts index 1de76c0..e01ab16 100644 --- a/src/store/course.ts +++ b/src/store/course.ts @@ -18,7 +18,7 @@ interface State { searchTime_status: boolean; timeSearchMode: boolean; timeSearchArgument: Array; - runConflict: boolean; + runConflict: number; } function Transfer(data : any) @@ -58,7 +58,7 @@ const store: Module = { searchTime_status: false, timeSearchMode: false, timeSearchArgument: [0, 0, 0], - runConflict: false + runConflict: 0 }, mutations: { display(state: State) { @@ -172,7 +172,7 @@ const store: Module = { settimeSearchArgument(state: State, arg: Array){ state.timeSearchArgument = arg; }, - setrunConflictState(state: State, arg: boolean){ + setrunConflictState(state: State, arg: number){ state.runConflict = arg; } }, @@ -251,7 +251,7 @@ const store: Module = { settimeSearchArgument(context: any, arg: Array){ context.commit("settimeSearchArgument", arg); }, - setrunConflictState(context: any, arg: boolean){ + setrunConflictState(context: any, arg: number){ context.commit("setrunConflictState", arg); } }