完善权限的管理和校验
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
style="width: 250px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="hasPermission('user:create')" type="primary" @click="showAddModal">
|
||||
<a-button v-if="isAdmin || hasPermission('user:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
@@ -48,14 +48,14 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('user:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
<a-button v-if="isAdmin || hasPermission('user:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-button v-if="hasPermission('user:reset_password')" type="link" size="small" @click="handleResetPassword(record)">
|
||||
<a-button v-if="isAdmin || hasPermission('user:reset_password')" type="link" size="small" @click="handleResetPassword(record)">
|
||||
重置密码
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('user:delete')"
|
||||
v-if="isAdmin || hasPermission('user:delete')"
|
||||
title="确定要删除这个用户吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
@@ -148,13 +148,16 @@ import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { userApi, type UserVO, adminShopApi, type Shop } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission } = usePermission()
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
return JSON.parse(userInfoStr)
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
// 判断用户是否为管理员(类型为4)
|
||||
isAdmin.value = userInfo.type === 4
|
||||
return userInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
@@ -170,6 +173,7 @@ const shopList = ref<Shop[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const isAdmin = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentUser = ref<UserVO | null>(null)
|
||||
const currentUserInfo = getCurrentUserInfo()
|
||||
@@ -372,7 +376,8 @@ const handleDelete = async (record: UserVO) => {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
fetchShopList()
|
||||
fetchUserList()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user