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

@@ -79,7 +79,7 @@
<template #body="slotProps">
<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"
@click="onEditBtnClick(slotProps.data.username)"
@click="onEditButtonClick(slotProps.data.username)"
@mouseover="handleEditMouseOver(slotProps.data.username)"
@mouseout="handleEditMouseOut(slotProps.data.username)"
/>
@@ -179,8 +179,8 @@ export default {
const index = allAccountResponsive.value.findIndex(user => user.username === currentLoginUsername);
if (index !== -1) {
// 移除匹配的對象(現正登入的使用者)並將其插入到陣列的第一位
const [loginUser] = allAccountResponsive.value.splice(index, 1);
// 移除匹配的對象(現正登入的使用者)並將其插入到 infiniteAcctData 陣列的第一位
const [loginUser] = allAccountResponsive.value[index];
infiniteAcctData.value.unshift(loginUser);
}
}
@@ -248,6 +248,11 @@ export default {
acctMgmtStore.changeIsDetailHoveredByUser(username, false);
};
const onEditButtonClick = userNameToEdit => {
acctMgmtStore.setCurrentViewingUser(userNameToEdit);
modalStore.openModal(MODAL_ACCT_EDIT);
}
const onDeleteBtnClick = (usernameToDelete) => {
acctMgmtStore.setCurrentViewingUser(usernameToDelete);
modalStore.openModal(MODAL_DELETE);
@@ -355,6 +360,7 @@ export default {
infiniteAcctData,
isOneAccountJustCreate,
justCreateUsername,
onEditButtonClick,
onCreateNewClick,
onAcctDoubleClick,
onSearchAccountButtonClick,
@@ -431,10 +437,9 @@ export default {
this.openModal(MODAL_ACCT_INFO);
this.setCurrentViewingUser(dataKey);
},
onEditBtnClick(clickedUserName){
this.openModal(MODAL_ACCT_EDIT);
console.log('TODO:', clickedUserName);
onEditBtnClickVue2(clickedUserName){
this.setCurrentViewingUser(clickedUserName);
this.openModal(MODAL_ACCT_EDIT);
},
moveCurrentLoginUserToFirstRow(){

View File

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