From 3a44b74bbcb8b31072b8235d6559c21485356916 Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Thu, 29 Aug 2024 14:41:41 +0800 Subject: [PATCH] responsive name --- src/components/AccountMenu/AcctMenu.vue | 4 +--- src/stores/acctMgmt.ts | 9 ++++----- src/views/AccountManagement/MyAccount.vue | 15 +++------------ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/components/AccountMenu/AcctMenu.vue b/src/components/AccountMenu/AcctMenu.vue index 1dc36ec..7623808 100644 --- a/src/components/AccountMenu/AcctMenu.vue +++ b/src/components/AccountMenu/AcctMenu.vue @@ -59,9 +59,7 @@ export default { await loginStore.getUserData(); loginUserData.value = loginStore.userData; await acctMgmtStore.getUserDetail(loginUserData.value.username); - if(currentViewingUserDetail.value.roles.find(role => role.code === 'admin')) { - isAdmin.value = true; - } + isAdmin.value = acctMgmtStore.currentViewingUser.is_admin; }; const onBtnMyAccountClick = async() => { diff --git a/src/stores/acctMgmt.ts b/src/stores/acctMgmt.ts index 72af30f..343c524 100644 --- a/src/stores/acctMgmt.ts +++ b/src/stores/acctMgmt.ts @@ -190,6 +190,7 @@ export default defineStore('acctMgmtStore', { username: userToEdit, name: newName, is_active: this.currentViewingUser.is_active, + is_admin: this.currentViewingUser.is_admin, }); return response.status === 200; } catch (error) { @@ -206,6 +207,7 @@ export default defineStore('acctMgmtStore', { name: this.currentViewingUser.name, password: newPwd, is_active: this.currentViewingUser.is_active, + is_admin: this.currentViewingUser.is_admin, }); return response.status === 200; } catch (error) { @@ -249,13 +251,10 @@ export default defineStore('acctMgmtStore', { */ async getUserDetail(uniqueUsername: string): Promise { const apiUserDetail = `/api/users/${uniqueUsername}`; - try { const response = await this.$axios.get(apiUserDetail); - this.currentViewingUser = { - ...this.currentViewingUser, - detail: response.data, - }; + this.currentViewingUser = response.data; + this.currentViewingUser.is_admin = response.data.roles.some(role => role.code === 'admin'); return response.status === 200; } catch (error) { //不需要跳出錯誤,因為如果是錯誤反而是好事,表示帳號是獨一的 diff --git a/src/views/AccountManagement/MyAccount.vue b/src/views/AccountManagement/MyAccount.vue index eda99c1..c911f05 100644 --- a/src/views/AccountManagement/MyAccount.vue +++ b/src/views/AccountManagement/MyAccount.vue @@ -128,7 +128,7 @@ export default { const visitTime = ref(0); const currentViewingUser = computed(() => acctMgmtStore.currentViewingUser); - const name = computed(() => acctMgmtStore.currentViewingUser.name); + const name = computed(() => currentViewingUser.value.name); const { username, is_admin, @@ -180,18 +180,9 @@ export default { isPwdLengthValid.value = inputPwd.value.length >= PWD_VALID_LENGTH; } - watch(() => acctMgmtStore.currentViewingUser, (newVal, oldVal) => { - console.log('currentViewingUser updated:', newVal); - console.log('newVal.name', newVal.name); - }); - - onBeforeMount(async() => { - // 在此設定 current viewing user 的來源是登入者的身分 - await acctMgmtStore.getUserDetail(loginStore.userData.username); - }); - - onMounted(() => { + onMounted(async() => { loadingStore.setIsLoading(false); + await acctMgmtStore.getUserDetail(loginStore.userData.username); }); return {