后台管理功能进行一些优化

This commit is contained in:
xiaowang
2026-02-28 14:32:28 +08:00
parent 36e2950a99
commit 725cb07fcf
23 changed files with 2297 additions and 92 deletions
+46 -6
View File
@@ -256,13 +256,43 @@ const getUserTypeText = (type: number) => {
const filteredUserList = computed(() => {
if (!currentLoginUser.value) return []
return userList.value.filter(user => user.type < currentLoginUser.value!.type && user.type !== 0)
// 管理员可以看到所有用户(除了普通用户和自己)
if (currentLoginUser.value.type === 4) {
return userList.value.filter(user => user.type !== 0 && user.id !== currentLoginUser.value!.id)
}
// 店长只能看到美甲师(除了自己)
if (currentLoginUser.value.type === 2) {
return userList.value.filter(user => user.type === 3 && user.id !== currentLoginUser.value!.id)
}
// 其他用户类型(如美甲师)不能管理权限
return []
})
const fetchCurrentUser = async () => {
try {
const res = await userApi.getUserInfo()
currentLoginUser.value = res as unknown as UserVO
// 尝试从API获取用户信息
try {
const res = await userApi.getUserInfo()
currentLoginUser.value = res as unknown as UserVO
console.log('从API获取当前用户信息:', currentLoginUser.value)
} catch (apiError) {
// 如果API调用失败,尝试从本地存储获取
const userInfoStr = localStorage.getItem('adminUserInfo')
if (userInfoStr) {
try {
const userInfo = JSON.parse(userInfoStr)
currentLoginUser.value = userInfo as UserVO
console.log('从本地存储获取当前用户信息:', currentLoginUser.value)
} catch (parseError) {
console.error('解析本地存储的用户信息失败:', parseError)
}
} else {
console.error('获取当前用户信息失败,本地存储也没有用户信息')
}
}
} catch (error) {
console.error('获取当前用户信息失败:', error)
}
@@ -284,11 +314,18 @@ const fetchPermissionList = async () => {
const fetchUserList = async () => {
userLoading.value = true
try {
const res = await userApi.listUsers({
const params: any = {
page: 1,
size: 100,
keyword: userSearchText.value
})
}
// 如果当前用户不是管理员,只获取当前店铺的用户
if (currentLoginUser.value && currentLoginUser.value.type !== 4 && currentLoginUser.value.shopId) {
params.shopId = currentLoginUser.value.shopId
}
const res = await userApi.listUsers(params)
userList.value = res.list || []
} catch (error) {
message.error('获取用户列表失败')
@@ -397,7 +434,10 @@ onMounted(async () => {
await fetchCurrentUser()
await loadUserPermissions()
fetchPermissionList()
fetchUserList()
// 确保在获取当前用户信息后再获取用户列表
setTimeout(() => {
fetchUserList()
}, 100)
})
</script>