fix: #327 add needed await keyword

This commit is contained in:
Cindy Chang
2024-08-09 16:07:08 +08:00
parent 17e51ca98a
commit d8c1e84622
4 changed files with 15 additions and 31 deletions

View File

@@ -62,7 +62,6 @@ export default defineStore('acctMgmtStore', {
*/ */
setCurrentViewingUser(username: string) { setCurrentViewingUser(username: string) {
const userFind: User | undefined = this.allUserAccoutList.find(user => user.username === username); const userFind: User | undefined = this.allUserAccoutList.find(user => user.username === username);
console.log('userFind', userFind);
this.currentViewingUser = userFind || { username: '', detail: {} }; this.currentViewingUser = userFind || { username: '', detail: {} };
}, },
/** /**

View File

@@ -3,5 +3,10 @@ import { defineStore } from "pinia";
export default defineStore('loadingStore', { export default defineStore('loadingStore', {
state: () => ({ state: () => ({
isLoading: true, isLoading: true,
}) }),
actions: {
setIsLoading(isLoadingBoolean) {
this.isLoading = isLoadingBoolean;
}
},
}); });

View File

@@ -135,30 +135,12 @@ import {
import iconDetailOn from '@/assets/icon-detail-on.svg'; import iconDetailOn from '@/assets/icon-detail-on.svg';
import iconDetailOff from '@/assets/icon-detail-card.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 { export default {
setup() { setup() {
const toast = useToast(); const toast = useToast();
const acctMgmtStore = useAcctMgmtStore(); const acctMgmtStore = useAcctMgmtStore();
const loadingStore = LoadingStore(); const loadingStore = LoadingStore();
const modalStore = useModalStore(); const modalStore = useModalStore();
const { isLoading } = storeToRefs(loadingStore);
const loginStore = piniaLoginStore(); const loginStore = piniaLoginStore();
const infiniteStart = ref(0); const infiniteStart = ref(0);
@@ -256,13 +238,14 @@ export default {
watch(shouldUpdateList, async(newShouldUpdateList) => { watch(shouldUpdateList, async(newShouldUpdateList) => {
if (newShouldUpdateList) { if (newShouldUpdateList) {
await acctMgmtStore.getAllUserAccounts(); await acctMgmtStore.getAllUserAccounts();
acctMgmtStore.setShouldUpdateList(false);
// 當夾帶有infiniteStart.value就表示依然考慮到無限捲動的需求 // 當夾帶有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(); moveJustCreateUserToFirstRow();
accountSearchResults.value = infiniteAcctData.value;
} }
acctMgmtStore.setShouldUpdateList(false);
}); });
const onSearchAccountButtonClick = (inputQueryString) => { const onSearchAccountButtonClick = (inputQueryString) => {
@@ -302,7 +285,8 @@ export default {
toast.success(i18next.t("AcctMgmt.MsgAccountEdited")); toast.success(i18next.t("AcctMgmt.MsgAccountEdited"));
} }
onMounted(async () => { onMounted(async () => {
loadingStore.setIsLoading(false);
await fetchLoginUserData(); await fetchLoginUserData();
await acctMgmtStore.getAllUserAccounts(); await acctMgmtStore.getAllUserAccounts();
}); });
@@ -344,7 +328,6 @@ export default {
return { return {
accountSearchResults, accountSearchResults,
isLoading,
modalStore, modalStore,
loginUserData, loginUserData,
infiniteAcctData, infiniteAcctData,
@@ -413,14 +396,11 @@ export default {
* 無限滾動: 滾到底後,要載入數據 * 無限滾動: 滾到底後,要載入數據
*/ */
async fetchMoreDataVue2() { async fetchMoreDataVue2() {
this.isLoading = true;
this.infiniteFinish = false; this.infiniteFinish = false;
this.infiniteStart += ONCE_RENDER_NUM_OF_DATA; this.infiniteStart += ONCE_RENDER_NUM_OF_DATA;
this.infiniteAcctDataVue2 = await [...this.infiniteAcctDataVue2, ...this.allUserAccoutList.slice( this.infiniteAcctDataVue2 = await [...this.infiniteAcctDataVue2, ...this.allUserAccoutList.slice(
this.infiniteStart, this.infiniteStart + ONCE_RENDER_NUM_OF_DATA)]; this.infiniteStart, this.infiniteStart + ONCE_RENDER_NUM_OF_DATA)];
this.isInfiniteFinish = true; this.isInfiniteFinish = true;
this.isLoading = false;
}, },
onDetailBtnClick(dataKey){ onDetailBtnClick(dataKey){
this.openModal(MODAL_ACCT_INFO); this.openModal(MODAL_ACCT_INFO);

View File

@@ -43,11 +43,11 @@ export default defineComponent({
const router = useRouter(); const router = useRouter();
const onDeleteConfirmBtnClick = async() => { const onDeleteConfirmBtnClick = async() => {
if(acctMgmtStore.deleteAccount(acctMgmtStore.currentViewingUser.username)){ if(await acctMgmtStore.deleteAccount(acctMgmtStore.currentViewingUser.username)){
toast.success(i18next.t("AcctMgmt.MsgAccountDeleteSuccess")); toast.success(i18next.t("AcctMgmt.MsgAccountDeleteSuccess"));
modalStore.closeModal(); modalStore.closeModal();
acctMgmtStore.setShouldUpdateList(true); acctMgmtStore.setShouldUpdateList(true);
router.push("/account-admin"); await router.push("/account-admin");
} }
} }