重构:重做后台用户停用删除解绑语义
This commit is contained in:
@@ -82,8 +82,17 @@
|
||||
重置密码
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('user:delete') && record.type !== 4"
|
||||
title="确定要将这个用户从当前店铺移除吗?"
|
||||
v-if="canShowUnbind(record)"
|
||||
title="确定要解绑该用户与当前店铺的关系吗?"
|
||||
@confirm="handleUnbind(record)"
|
||||
>
|
||||
<a-button type="link" size="small">
|
||||
解绑
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<a-popconfirm
|
||||
v-if="canShowDelete(record)"
|
||||
title="确定要删除这个用户吗?删除后账号将被标记为已删除。"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
@@ -437,6 +446,12 @@ const canOpenAssetPanel = computed(() =>
|
||||
const canCreateUser = computed(() =>
|
||||
hasPermission('user:create') || currentUserInfo?.type === 2 || currentUserInfo?.type === 4
|
||||
)
|
||||
const canDeleteUser = computed(() =>
|
||||
currentUserInfo?.type === 4 && hasPermission('user:delete')
|
||||
)
|
||||
const canUnbindUser = computed(() =>
|
||||
hasPermission('user:unbind')
|
||||
)
|
||||
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
||||
|
||||
const pagination = reactive({
|
||||
@@ -650,6 +665,23 @@ const getUserTypeColor = (type: number) => {
|
||||
return map[type] || 'default'
|
||||
}
|
||||
|
||||
const canShowDelete = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
if (!canDeleteUser.value) {
|
||||
return false
|
||||
}
|
||||
if (record.type === 4) {
|
||||
return false
|
||||
}
|
||||
return String(record.id) !== String(currentUserInfo?.id ?? '')
|
||||
}
|
||||
|
||||
const canShowUnbind = (record: Partial<UserVO> | Record<string, any>) => {
|
||||
if (!canUnbindUser.value) {
|
||||
return false
|
||||
}
|
||||
return record.type !== 4
|
||||
}
|
||||
|
||||
const getSceneText = (scene?: string) => {
|
||||
const map: Record<string, string> = {
|
||||
RECHARGE: '充值',
|
||||
@@ -973,12 +1005,12 @@ const handleStatusChange = async (record: any, checked: boolean) => {
|
||||
try {
|
||||
const success = await adminUserApi.updateUserStatus(record.id, checked ? 1 : 0)
|
||||
if (!success) {
|
||||
message.warning('未找到当前店铺下可更新状态的用户绑定')
|
||||
message.warning('未找到可更新状态的用户')
|
||||
await fetchUserList()
|
||||
return
|
||||
}
|
||||
record.status = checked ? 1 : 0
|
||||
message.success(`已${checked ? '启用' : '停用'}当前店铺下的用户访问`)
|
||||
message.success(`已${checked ? '启用' : '停用'}该用户账号`)
|
||||
} catch (error) {
|
||||
console.error('状态更新失败:', error)
|
||||
message.error('状态更新失败')
|
||||
@@ -1009,13 +1041,13 @@ const handleDelete = async (record: any) => {
|
||||
}
|
||||
const success = await adminUserApi.deleteUser(record.id)
|
||||
if (!success) {
|
||||
message.warning('未找到当前店铺下可删除的用户绑定')
|
||||
message.warning('未找到可删除的用户')
|
||||
await fetchUserList()
|
||||
return
|
||||
}
|
||||
userList.value = userList.value.filter(user => user.id !== record.id)
|
||||
pagination.total = Math.max(0, Number(pagination.total || 0) - 1)
|
||||
message.success('已移除当前店铺下的用户绑定')
|
||||
message.success('已删除用户账号')
|
||||
await fetchUserList()
|
||||
} catch (error) {
|
||||
console.error('删除用户失败:', error)
|
||||
@@ -1023,6 +1055,28 @@ const handleDelete = async (record: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleUnbind = async (record: any) => {
|
||||
try {
|
||||
if (record.type === 4) {
|
||||
message.warning('管理员账号无法解绑')
|
||||
return
|
||||
}
|
||||
const success = await adminUserApi.unbindUser(record.id)
|
||||
if (!success) {
|
||||
message.warning('未找到当前店铺下可解绑的用户绑定')
|
||||
await fetchUserList()
|
||||
return
|
||||
}
|
||||
userList.value = userList.value.filter(user => user.id !== record.id)
|
||||
pagination.total = Math.max(0, Number(pagination.total || 0) - 1)
|
||||
message.success('已解绑当前店铺下的用户')
|
||||
await fetchUserList()
|
||||
} catch (error) {
|
||||
console.error('解绑用户失败:', error)
|
||||
message.error('解绑失败')
|
||||
}
|
||||
}
|
||||
|
||||
const refreshAssetPanel = async () => {
|
||||
if (!assetTargetUser.value) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user