From d8c1e84622b510bb97c3c3b8ad71a18cb3614724 Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Fri, 9 Aug 2024 16:07:08 +0800 Subject: [PATCH] fix: #327 add needed await keyword --- src/stores/acctMgmt.ts | 1 - src/stores/loading.js | 7 +++- .../AccountAdmin/AccountAdmin.vue | 34 ++++--------------- .../AccountManagement/ModalDeleteAlert.vue | 4 +-- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/stores/acctMgmt.ts b/src/stores/acctMgmt.ts index 2f18e84..6c0979e 100644 --- a/src/stores/acctMgmt.ts +++ b/src/stores/acctMgmt.ts @@ -62,7 +62,6 @@ export default defineStore('acctMgmtStore', { */ setCurrentViewingUser(username: string) { const userFind: User | undefined = this.allUserAccoutList.find(user => user.username === username); - console.log('userFind', userFind); this.currentViewingUser = userFind || { username: '', detail: {} }; }, /** diff --git a/src/stores/loading.js b/src/stores/loading.js index 6cafe6b..5bf5c33 100644 --- a/src/stores/loading.js +++ b/src/stores/loading.js @@ -3,5 +3,10 @@ import { defineStore } from "pinia"; export default defineStore('loadingStore', { state: () => ({ isLoading: true, - }) + }), + actions: { + setIsLoading(isLoadingBoolean) { + this.isLoading = isLoadingBoolean; + } + }, }); diff --git a/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue b/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue index 84844d8..c4f6939 100644 --- a/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue +++ b/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue @@ -135,30 +135,12 @@ import { import iconDetailOn from '@/assets/icon-detail-on.svg'; import iconDetailOff from '@/assets/icon-detail-card.svg'; -// 這是製作假資料,在正式環境不會用到 -function repeatAccountList(accountList, N) { - const repeatedList = []; - - for (let i = 0; i < N; i++) { - accountList.forEach(account => { - const newAccount = { ...account, id: account.id + i }; - repeatedList.push(newAccount); - }); - } - - return repeatedList; -} - -// 這是製作假資料,在正式環境不會用到 -// const repeatedAccountList = repeatAccountList(accountList, 20); - export default { setup() { const toast = useToast(); const acctMgmtStore = useAcctMgmtStore(); const loadingStore = LoadingStore(); const modalStore = useModalStore(); - const { isLoading } = storeToRefs(loadingStore); const loginStore = piniaLoginStore(); const infiniteStart = ref(0); @@ -256,13 +238,14 @@ export default { watch(shouldUpdateList, async(newShouldUpdateList) => { if (newShouldUpdateList) { - await acctMgmtStore.getAllUserAccounts(); - acctMgmtStore.setShouldUpdateList(false); - + await acctMgmtStore.getAllUserAccounts(); // 當夾帶有infiniteStart.value,就表示依然考慮到無限捲動的需求 - infiniteAcctData.value = allAccountResponsive.value.slice(0, infiniteStart.value + ONCE_RENDER_NUM_OF_DATA); + infiniteAcctData.value = acctMgmtStore.allUserAccoutList.slice(0, infiniteStart.value + ONCE_RENDER_NUM_OF_DATA); moveJustCreateUserToFirstRow(); + accountSearchResults.value = infiniteAcctData.value; + } + acctMgmtStore.setShouldUpdateList(false); }); const onSearchAccountButtonClick = (inputQueryString) => { @@ -302,7 +285,8 @@ export default { toast.success(i18next.t("AcctMgmt.MsgAccountEdited")); } - onMounted(async () => { + onMounted(async () => { + loadingStore.setIsLoading(false); await fetchLoginUserData(); await acctMgmtStore.getAllUserAccounts(); }); @@ -344,7 +328,6 @@ export default { return { accountSearchResults, - isLoading, modalStore, loginUserData, infiniteAcctData, @@ -413,14 +396,11 @@ export default { * 無限滾動: 滾到底後,要載入數據 */ async fetchMoreDataVue2() { - this.isLoading = true; this.infiniteFinish = false; this.infiniteStart += ONCE_RENDER_NUM_OF_DATA; this.infiniteAcctDataVue2 = await [...this.infiniteAcctDataVue2, ...this.allUserAccoutList.slice( this.infiniteStart, this.infiniteStart + ONCE_RENDER_NUM_OF_DATA)]; this.isInfiniteFinish = true; - this.isLoading = false; - }, onDetailBtnClick(dataKey){ this.openModal(MODAL_ACCT_INFO); diff --git a/src/views/AccountManagement/ModalDeleteAlert.vue b/src/views/AccountManagement/ModalDeleteAlert.vue index 89ee549..ca24757 100644 --- a/src/views/AccountManagement/ModalDeleteAlert.vue +++ b/src/views/AccountManagement/ModalDeleteAlert.vue @@ -43,11 +43,11 @@ export default defineComponent({ const router = useRouter(); const onDeleteConfirmBtnClick = async() => { - if(acctMgmtStore.deleteAccount(acctMgmtStore.currentViewingUser.username)){ + if(await acctMgmtStore.deleteAccount(acctMgmtStore.currentViewingUser.username)){ toast.success(i18next.t("AcctMgmt.MsgAccountDeleteSuccess")); modalStore.closeModal(); acctMgmtStore.setShouldUpdateList(true); - router.push("/account-admin"); + await router.push("/account-admin"); } }