完善权限的管理和校验
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<a-tabs v-model:activeKey="activeTab">
|
||||
<a-tab-pane key="permissions" tab="权限列表">
|
||||
<template #extra>
|
||||
<a-button v-if="hasPermission('permission:create')" type="primary" @click="showAddPermissionModal">
|
||||
<a-button v-if="currentLoginUser?.type === 4 || hasPermission('permission:create')" type="primary" @click="showAddPermissionModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
@@ -28,11 +28,11 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('permission:edit')" type="link" size="small" @click="showEditPermissionModal(record)">
|
||||
<a-button v-if="currentLoginUser?.type === 4 || hasPermission('permission:edit')" type="link" size="small" @click="showEditPermissionModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('permission:delete')"
|
||||
v-if="currentLoginUser?.type === 4 || hasPermission('permission:delete')"
|
||||
title="确定要删除这个权限吗?"
|
||||
@confirm="handleDeletePermission(record)"
|
||||
>
|
||||
@@ -86,7 +86,7 @@
|
||||
:bordered="false"
|
||||
>
|
||||
<template #extra>
|
||||
<a-button v-if="selectedUser && hasPermission('permission:assign')" type="primary" @click="handleSaveUserPermissions">
|
||||
<a-button v-if="selectedUser && (currentLoginUser?.type === 4 || hasPermission('permission:assign'))" type="primary" @click="handleSaveUserPermissions">
|
||||
保存权限
|
||||
</a-button>
|
||||
</template>
|
||||
@@ -181,7 +181,7 @@ import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { permissionApi, type PermissionVO, userApi, type UserVO } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission } = usePermission()
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const activeTab = ref('permissions')
|
||||
const loading = ref(false)
|
||||
@@ -326,6 +326,8 @@ const handleSaveUserPermissions = async () => {
|
||||
try {
|
||||
await permissionApi.assignUserPermissions(selectedUser.value.id, selectedPermissions.value)
|
||||
message.success('权限保存成功')
|
||||
// 重新加载当前用户的权限
|
||||
await loadUserPermissions()
|
||||
} catch (error) {
|
||||
message.error('权限保存失败')
|
||||
}
|
||||
@@ -393,6 +395,7 @@ const handleDeletePermission = async (record: PermissionVO) => {
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchCurrentUser()
|
||||
await loadUserPermissions()
|
||||
fetchPermissionList()
|
||||
fetchUserList()
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
style="width: 250px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="hasPermission('product:create')" type="primary" @click="showAddModal">
|
||||
<a-button v-if="isAdmin || hasPermission('product:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
@@ -58,11 +58,11 @@
|
||||
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('product:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
<a-button v-if="isAdmin || hasPermission('product:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('product:delete')"
|
||||
v-if="isAdmin || hasPermission('product:delete')"
|
||||
title="确定要删除这个商品吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
@@ -249,6 +249,7 @@ import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
|
||||
import { adminProductApi, type Product, adminShopApi, type Shop, adminFileApi, type ObjectStorageFileVO, adminTagApi, adminArtistApi, adminCouponApi } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const productList = ref<Product[]>([])
|
||||
@@ -272,7 +273,6 @@ const imageUrls = ref<Record<number, string[]>>({})
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const isAdmin = ref(false)
|
||||
const formRef = ref<any>(null)
|
||||
const { hasPermission } = usePermission()
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -672,7 +672,8 @@ const handleDelete = async (record: Product) => {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
fetchShops()
|
||||
fetchTags()
|
||||
fetchCoupons()
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
style="width: 250px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="hasPermission('shop:create')" type="primary" @click="showAddModal">
|
||||
<a-button v-if="isAdmin || hasPermission('shop:create')" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
@@ -52,11 +52,11 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button v-if="hasPermission('shop:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
<a-button v-if="isAdmin || hasPermission('shop:edit')" type="link" size="small" @click="showEditModal(record)">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm
|
||||
v-if="hasPermission('shop:delete')"
|
||||
v-if="isAdmin || hasPermission('shop:delete')"
|
||||
title="确定要删除这个店铺吗?"
|
||||
@confirm="handleDelete(record)"
|
||||
>
|
||||
@@ -134,7 +134,7 @@ import { DEFAULT_SHOP_IMAGE } from '@/constants'
|
||||
import { adminShopApi, adminFileApi, type Shop } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const { hasPermission } = usePermission()
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
@@ -144,6 +144,7 @@ const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentShop = ref<Shop | null>(null)
|
||||
const isAdmin = ref(false)
|
||||
|
||||
// 图片相关
|
||||
const imageFileList = ref<any[]>([])
|
||||
@@ -191,7 +192,10 @@ 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)
|
||||
@@ -422,7 +426,8 @@ const handleDelete = async (record: Shop) => {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
await loadUserPermissions()
|
||||
fetchShopList()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -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