后台管理页面用户管理删除用户实现
This commit is contained in:
@@ -32,6 +32,9 @@
|
||||
<template v-if="column.key === 'avatar'">
|
||||
<a-avatar :size="40" :src="record.avatar || DEFAULT_AVATAR" />
|
||||
</template>
|
||||
<template v-else-if="column.key === 'shopName'">
|
||||
{{ record.shopName || '-' }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'type'">
|
||||
<a-tag :color="getUserTypeColor(record.type)">
|
||||
{{ getUserTypeText(record.type) }}
|
||||
@@ -91,14 +94,6 @@
|
||||
<a-form-item v-if="!isEdit" label="密码" name="password">
|
||||
<a-input-password v-model:value="formState.password" placeholder="请输入密码" />
|
||||
</a-form-item>
|
||||
<a-form-item label="用户类型" name="type">
|
||||
<a-select v-model:value="formState.type" placeholder="请选择用户类型">
|
||||
<a-select-option :value="0">用户</a-select-option>
|
||||
<a-select-option :value="2">店长</a-select-option>
|
||||
<a-select-option :value="3">美甲师</a-select-option>
|
||||
<a-select-option :value="4">管理员</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item v-if="currentUserInfo?.type !== 4" label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
@@ -118,9 +113,8 @@
|
||||
<a-form-item v-else label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择店铺(可选)"
|
||||
placeholder="请选择店铺"
|
||||
:loading="shopLoading"
|
||||
allowClear
|
||||
>
|
||||
<a-select-option
|
||||
v-for="shop in shopList"
|
||||
@@ -131,6 +125,14 @@
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item label="用户类型" name="type">
|
||||
<a-select v-model:value="formState.type" placeholder="请选择用户类型">
|
||||
<a-select-option :value="0">用户</a-select-option>
|
||||
<a-select-option :value="2">店长</a-select-option>
|
||||
<a-select-option :value="3">美甲师</a-select-option>
|
||||
<a-select-option :value="4">管理员</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
@@ -145,6 +147,18 @@ import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { adminShopApi, type Shop } from '@/api/admin'
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
return JSON.parse(userInfoStr)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
const shopLoading = ref(false)
|
||||
const searchText = ref('')
|
||||
@@ -175,17 +189,13 @@ const formState = reactive({
|
||||
shopId: undefined as number | undefined
|
||||
})
|
||||
|
||||
const isShopRequired = computed(() => {
|
||||
return currentUserInfo?.type !== 4
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
||||
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }],
|
||||
shopId: [{ required: isShopRequired.value, message: '请选择店铺', trigger: 'change' }]
|
||||
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
@@ -220,32 +230,14 @@ const getUserTypeColor = (type: number) => {
|
||||
return map[type] || 'default'
|
||||
}
|
||||
|
||||
const getCurrentUserInfo = () => {
|
||||
try {
|
||||
const userInfoStr = localStorage.getItem('adminUserInfo')
|
||||
if (userInfoStr) {
|
||||
return JSON.parse(userInfoStr)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const fetchShopList = async () => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
const params: any = {
|
||||
page: 1,
|
||||
size: 100
|
||||
}
|
||||
|
||||
const res = await adminShopApi.listShops()
|
||||
shopList.value = res || []
|
||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||
params.shopId = currentUserInfo.shopId
|
||||
formState.shopId = currentUserInfo.shopId
|
||||
}
|
||||
|
||||
const res = await adminShopApi.listShops(params)
|
||||
shopList.value = res.list || []
|
||||
} catch (error) {
|
||||
message.error('获取店铺列表失败')
|
||||
} finally {
|
||||
@@ -256,15 +248,14 @@ const fetchShopList = async () => {
|
||||
const fetchUserList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const currentUser = getCurrentUserInfo()
|
||||
const params: any = {
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize,
|
||||
keyword: searchText.value
|
||||
}
|
||||
|
||||
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
|
||||
params.shopId = currentUser.shopId
|
||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||
params.shopId = currentUserInfo.shopId
|
||||
}
|
||||
|
||||
const res = await userApi.listUsers(params)
|
||||
@@ -290,14 +281,13 @@ const handleTableChange = (pag: any) => {
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
const defaultShopId = currentUserInfo?.type !== 4 ? currentUserInfo?.shopId : undefined
|
||||
Object.assign(formState, {
|
||||
account: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
type: 0,
|
||||
shopId: defaultShopId
|
||||
shopId: currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId ? currentUserInfo.shopId : undefined
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user