responsive name
This commit is contained in:
@@ -59,9 +59,7 @@ export default {
|
|||||||
await loginStore.getUserData();
|
await loginStore.getUserData();
|
||||||
loginUserData.value = loginStore.userData;
|
loginUserData.value = loginStore.userData;
|
||||||
await acctMgmtStore.getUserDetail(loginUserData.value.username);
|
await acctMgmtStore.getUserDetail(loginUserData.value.username);
|
||||||
if(currentViewingUserDetail.value.roles.find(role => role.code === 'admin')) {
|
isAdmin.value = acctMgmtStore.currentViewingUser.is_admin;
|
||||||
isAdmin.value = true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onBtnMyAccountClick = async() => {
|
const onBtnMyAccountClick = async() => {
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ export default defineStore('acctMgmtStore', {
|
|||||||
username: userToEdit,
|
username: userToEdit,
|
||||||
name: newName,
|
name: newName,
|
||||||
is_active: this.currentViewingUser.is_active,
|
is_active: this.currentViewingUser.is_active,
|
||||||
|
is_admin: this.currentViewingUser.is_admin,
|
||||||
});
|
});
|
||||||
return response.status === 200;
|
return response.status === 200;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -206,6 +207,7 @@ export default defineStore('acctMgmtStore', {
|
|||||||
name: this.currentViewingUser.name,
|
name: this.currentViewingUser.name,
|
||||||
password: newPwd,
|
password: newPwd,
|
||||||
is_active: this.currentViewingUser.is_active,
|
is_active: this.currentViewingUser.is_active,
|
||||||
|
is_admin: this.currentViewingUser.is_admin,
|
||||||
});
|
});
|
||||||
return response.status === 200;
|
return response.status === 200;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -249,13 +251,10 @@ export default defineStore('acctMgmtStore', {
|
|||||||
*/
|
*/
|
||||||
async getUserDetail(uniqueUsername: string): Promise<boolean> {
|
async getUserDetail(uniqueUsername: string): Promise<boolean> {
|
||||||
const apiUserDetail = `/api/users/${uniqueUsername}`;
|
const apiUserDetail = `/api/users/${uniqueUsername}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.$axios.get(apiUserDetail);
|
const response = await this.$axios.get(apiUserDetail);
|
||||||
this.currentViewingUser = {
|
this.currentViewingUser = response.data;
|
||||||
...this.currentViewingUser,
|
this.currentViewingUser.is_admin = response.data.roles.some(role => role.code === 'admin');
|
||||||
detail: response.data,
|
|
||||||
};
|
|
||||||
return response.status === 200;
|
return response.status === 200;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//不需要跳出錯誤,因為如果是錯誤反而是好事,表示帳號是獨一的
|
//不需要跳出錯誤,因為如果是錯誤反而是好事,表示帳號是獨一的
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export default {
|
|||||||
|
|
||||||
const visitTime = ref(0);
|
const visitTime = ref(0);
|
||||||
const currentViewingUser = computed(() => acctMgmtStore.currentViewingUser);
|
const currentViewingUser = computed(() => acctMgmtStore.currentViewingUser);
|
||||||
const name = computed(() => acctMgmtStore.currentViewingUser.name);
|
const name = computed(() => currentViewingUser.value.name);
|
||||||
const {
|
const {
|
||||||
username,
|
username,
|
||||||
is_admin,
|
is_admin,
|
||||||
@@ -180,18 +180,9 @@ export default {
|
|||||||
isPwdLengthValid.value = inputPwd.value.length >= PWD_VALID_LENGTH;
|
isPwdLengthValid.value = inputPwd.value.length >= PWD_VALID_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(() => acctMgmtStore.currentViewingUser, (newVal, oldVal) => {
|
onMounted(async() => {
|
||||||
console.log('currentViewingUser updated:', newVal);
|
|
||||||
console.log('newVal.name', newVal.name);
|
|
||||||
});
|
|
||||||
|
|
||||||
onBeforeMount(async() => {
|
|
||||||
// 在此設定 current viewing user 的來源是登入者的身分
|
|
||||||
await acctMgmtStore.getUserDetail(loginStore.userData.username);
|
|
||||||
});
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadingStore.setIsLoading(false);
|
loadingStore.setIsLoading(false);
|
||||||
|
await acctMgmtStore.getUserDetail(loginStore.userData.username);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user