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

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