feat(login): add userID

- 修改按钮判断的逻辑,将 `userName` 替换成 `userID` 判断;解决不管是主程序还是插件修改用户名,都会存在的条件判断导致的渲染异常显示。(拆分自user的pr)
This commit is contained in:
Aqr-K
2024-10-19 11:58:01 +08:00
parent 76a487854b
commit 0036a895e9
3 changed files with 29 additions and 20 deletions

View File

@@ -21,8 +21,8 @@ const props = defineProps({
},
})
// 当前用户名称
const currentLoginUser = store.state.auth.userName
// 当前用户的ID
const currentLoginUserId = computed(() => store.state.auth.userID)
// 定义触发的自定义事件
const emit = defineEmits(['remove', 'save'])
@@ -57,7 +57,7 @@ async function fetchSubscriptions() {
// 删除用户
async function removeUser() {
if (props.user.name == currentLoginUser) {
if (props.user.id === currentLoginUserId.value) {
$toast.error('不能删除当前登录用户!')
return
}
@@ -84,19 +84,6 @@ function editUser() {
userEditDialog.value = true
}
// 计算是否有用户编辑权限
const canEditUser = computed(() => {
if (store.state.auth.superUser && props.user.name !== currentLoginUser) return true
return false
})
// 计算是否有用户管理权限
const canManageUser = computed(() => {
if (props.user.name == currentLoginUser) return false
if (store.state.auth.superUser) return true
return false
})
// 用户重新完成时
function onUserUpdate() {
userEditDialog.value = false
@@ -170,8 +157,21 @@ onMounted(() => {
</VList>
</VCardText>
<VCardText class="flex flex-row justify-center">
<VBtn v-if="canEditUser" color="primary" class="me-4" @click="editUser">编辑</VBtn>
<VBtn v-if="canManageUser" color="error" variant="outlined" @click="removeUser"> 删除 </VBtn>
<VBtn
color="primary"
class="me-4"
@click="editUser"
>
编辑
</VBtn>
<VBtn
v-if="!(props.user.id === currentLoginUserId)"
color="error"
variant="outlined"
@click="removeUser"
>
删除
</VBtn>
</VCardText>
</VCard>
<!-- 用户编辑弹窗 -->