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) {
const userFind: User | undefined = this.allUserAccoutList.find(user => user.username === username);
console.log('userFind', userFind);
this.currentViewingUser = userFind || { username: '', detail: {} };
},
/**

View File

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

View File

@@ -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);
@@ -257,12 +239,13 @@ export default {
watch(shouldUpdateList, async(newShouldUpdateList) => {
if (newShouldUpdateList) {
await acctMgmtStore.getAllUserAccounts();
acctMgmtStore.setShouldUpdateList(false);
// 當夾帶有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) => {
@@ -303,6 +286,7 @@ export default {
}
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);

View File

@@ -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");
}
}