fixed: #313 use index [ ] instead of splice function to prevent removal

This commit is contained in:
Cindy Chang
2024-07-09 15:08:55 +08:00
parent a2703bef6e
commit 74bc22b736
3 changed files with 15 additions and 7 deletions

View File

@@ -60,6 +60,7 @@ 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 ? userFind : { username: '', detail: {} }; this.currentViewingUser = userFind ? userFind : { username: '', detail: {} };
}, },
/** /**

View File

@@ -79,7 +79,7 @@
<template #body="slotProps"> <template #body="slotProps">
<div class="row-container flex-w-full-hoverable w-full flex justify-center" @mouseenter="handleRowMouseOver(slotProps.data.username)"> <div class="row-container flex-w-full-hoverable w-full flex justify-center" @mouseenter="handleRowMouseOver(slotProps.data.username)">
<img :src="slotProps.data.isEditHovered ? iconEditOn : iconEditOff" alt="Edit" class="btn-edit cursor-pointer" <img :src="slotProps.data.isEditHovered ? iconEditOn : iconEditOff" alt="Edit" class="btn-edit cursor-pointer"
@click="onEditBtnClick(slotProps.data.username)" @click="onEditButtonClick(slotProps.data.username)"
@mouseover="handleEditMouseOver(slotProps.data.username)" @mouseover="handleEditMouseOver(slotProps.data.username)"
@mouseout="handleEditMouseOut(slotProps.data.username)" @mouseout="handleEditMouseOut(slotProps.data.username)"
/> />
@@ -179,8 +179,8 @@ export default {
const index = allAccountResponsive.value.findIndex(user => user.username === currentLoginUsername); const index = allAccountResponsive.value.findIndex(user => user.username === currentLoginUsername);
if (index !== -1) { if (index !== -1) {
// 移除匹配的對象(現正登入的使用者)並將其插入到陣列的第一位 // 移除匹配的對象(現正登入的使用者)並將其插入到 infiniteAcctData 陣列的第一位
const [loginUser] = allAccountResponsive.value.splice(index, 1); const [loginUser] = allAccountResponsive.value[index];
infiniteAcctData.value.unshift(loginUser); infiniteAcctData.value.unshift(loginUser);
} }
} }
@@ -248,6 +248,11 @@ export default {
acctMgmtStore.changeIsDetailHoveredByUser(username, false); acctMgmtStore.changeIsDetailHoveredByUser(username, false);
}; };
const onEditButtonClick = userNameToEdit => {
acctMgmtStore.setCurrentViewingUser(userNameToEdit);
modalStore.openModal(MODAL_ACCT_EDIT);
}
const onDeleteBtnClick = (usernameToDelete) => { const onDeleteBtnClick = (usernameToDelete) => {
acctMgmtStore.setCurrentViewingUser(usernameToDelete); acctMgmtStore.setCurrentViewingUser(usernameToDelete);
modalStore.openModal(MODAL_DELETE); modalStore.openModal(MODAL_DELETE);
@@ -355,6 +360,7 @@ export default {
infiniteAcctData, infiniteAcctData,
isOneAccountJustCreate, isOneAccountJustCreate,
justCreateUsername, justCreateUsername,
onEditButtonClick,
onCreateNewClick, onCreateNewClick,
onAcctDoubleClick, onAcctDoubleClick,
onSearchAccountButtonClick, onSearchAccountButtonClick,
@@ -431,10 +437,9 @@ export default {
this.openModal(MODAL_ACCT_INFO); this.openModal(MODAL_ACCT_INFO);
this.setCurrentViewingUser(dataKey); this.setCurrentViewingUser(dataKey);
}, },
onEditBtnClick(clickedUserName){ onEditBtnClickVue2(clickedUserName){
this.openModal(MODAL_ACCT_EDIT);
console.log('TODO:', clickedUserName);
this.setCurrentViewingUser(clickedUserName); this.setCurrentViewingUser(clickedUserName);
this.openModal(MODAL_ACCT_EDIT);
}, },
moveCurrentLoginUserToFirstRow(){ moveCurrentLoginUserToFirstRow(){

View File

@@ -169,6 +169,7 @@ export default defineComponent({
const whichCurrentModal = computed(() => modalStore.whichModal); const whichCurrentModal = computed(() => modalStore.whichModal);
const isSSO = computed(() => acctMgmtStore.currentViewingUser.is_sso); const isSSO = computed(() => acctMgmtStore.currentViewingUser.is_sso);
const isAdmin = computed(() => acctMgmtStore.currentViewingUser.is_admin);
const username = computed(() => acctMgmtStore.currentViewingUser.username); const username = computed(() => acctMgmtStore.currentViewingUser.username);
const name = computed(() => acctMgmtStore.currentViewingUser.name); const name = computed(() => acctMgmtStore.currentViewingUser.name);
@@ -309,6 +310,7 @@ export default defineComponent({
} }
onMounted(() => { onMounted(() => {
console.log('TODO:', username.value, name.value, isAdmin.value);
console.log('username', username, name, ); console.log('username', username, name, );
console.log('userData TODO:', loginStore.userData); console.log('userData TODO:', loginStore.userData);
}); });