功能:完善多店铺登录与首次部署SQL

This commit is contained in:
xiaowang
2026-03-26 10:28:28 +08:00
parent 5601428087
commit 764bfadb51
79 changed files with 6524 additions and 2603 deletions
+68 -31
View File
@@ -34,7 +34,7 @@
</template>
<template v-else-if="column.key === 'shopName'">
{{ record.shopName || getShopNameById(record.shopId) || '-' }}
{{ getShopDisplay(record) || '-' }}
</template>
<template v-else-if="column.key === 'type'">
@@ -83,7 +83,7 @@
</a-button>
<a-popconfirm
v-if="hasPermission('user:delete') && record.type !== 4"
title="确定要删除这个用户吗?"
title="确定要将这个用户从当前店铺移除吗?"
@confirm="handleDelete(record)"
>
<a-button type="link" size="small" danger>
@@ -128,10 +128,11 @@
<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="shopId">
<a-form-item label="所属店铺" name="shopIds">
<a-select
v-model:value="formState.shopId"
placeholder="请选择店铺"
v-model:value="formState.shopIds"
mode="multiple"
:placeholder="currentUserInfo?.type === 4 ? '请选择一个或多个店铺' : '请选择店铺'"
:loading="shopLoading"
:disabled="currentUserInfo?.type !== 4 && !!currentUserInfo?.shopId"
>
@@ -169,7 +170,7 @@
<a-descriptions-item label="账号">{{ viewRecord?.account || '-' }}</a-descriptions-item>
<a-descriptions-item label="昵称">{{ viewRecord?.nickname || '-' }}</a-descriptions-item>
<a-descriptions-item label="手机号">{{ viewRecord?.phone || '-' }}</a-descriptions-item>
<a-descriptions-item label="所属店铺">{{ viewRecord?.shopName || '-' }}</a-descriptions-item>
<a-descriptions-item label="所属店铺">{{ getShopDisplay(viewRecord) || '-' }}</a-descriptions-item>
<a-descriptions-item label="用户类型">{{ getUserTypeText(viewRecord?.type || 0) }}</a-descriptions-item>
<a-descriptions-item label="VIP 等级">{{ viewRecord?.level || '普通' }}</a-descriptions-item>
<a-descriptions-item label="状态">{{ viewRecord?.status === 1 ? '正常' : '禁用' }}</a-descriptions-item>
@@ -188,7 +189,7 @@
<div v-if="assetTargetUser" class="asset-modal">
<a-alert
:message="`${assetTargetUser.nickname}(${assetTargetUser.account})`"
:description="assetTargetUser.shopName ? `所属店铺:${assetTargetUser.shopName}` : '未绑定店铺'"
:description="getShopDisplay(assetTargetUser) ? `所属店铺:${getShopDisplay(assetTargetUser)}` : '未绑定店铺'"
type="info"
show-icon
style="margin-bottom: 16px"
@@ -423,7 +424,7 @@ const formState = reactive({
phone: '',
password: '',
type: 0,
shopId: undefined as string | undefined
shopIds: [] as string[]
})
const balanceForm = reactive<AdminUserBalanceChangeRequest>({
@@ -459,7 +460,15 @@ const formRules = {
}
],
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
shopIds: [{
validator: async (_rule: unknown, value: string[]) => {
if (Array.isArray(value) && value.length > 0) {
return Promise.resolve()
}
return Promise.reject('请选择至少一个店铺')
},
trigger: 'change'
}],
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
} as any
@@ -561,12 +570,41 @@ const getShopNameById = (shopId?: string | number | null) => {
return matchedShop?.shopName || ''
}
const resolveEditableShopId = (shopId?: string | number | null) => {
const targetShopId = normalizeShopId(shopId)
if (targetShopId && shopList.value.some(shop => getShopOptionValue(shop) === targetShopId)) {
return targetShopId
const getShopDisplay = (user?: Partial<UserVO> | Record<string, any> | null) => {
if (!user) {
return ''
}
return shopList.value.length === 1 ? getShopOptionValue(shopList.value[0]!) : undefined
const names = (user.shopNames || []).filter(Boolean)
if (names.length) {
return names.join('、')
}
if (user.shopName) {
return user.shopName
}
if (user.shopIds?.length) {
return (user.shopIds as Array<string | number>)
.map((id: string | number) => getShopNameById(id) || `店铺 ${id}`)
.join('、')
}
return getShopNameById(user.shopId) || ''
}
const resolveEditableShopIds = (user?: UserVO | null) => {
const sourceIds = user?.shopIds?.length
? user.shopIds
: (user?.shopId ? [user.shopId] : [])
const normalizedIds = sourceIds
.map(id => normalizeShopId(id))
.filter((id): id is string => Boolean(id))
.filter(id => shopList.value.some(shop => getShopOptionValue(shop) === id))
if (normalizedIds.length) {
return normalizedIds
}
return currentUserInfo?.type !== 4 && currentUserInfo?.shopId
? [normalizeShopId(currentUserInfo.shopId)!]
: []
}
const fetchShopList = async () => {
@@ -575,7 +613,7 @@ const fetchShopList = async () => {
const shops = await adminShopApi.listAllShops() as unknown as Shop[]
shopList.value = shops || []
if (currentUserInfo?.type !== 4 && currentUserInfo?.shopId) {
formState.shopId = normalizeShopId(currentUserInfo.shopId)
formState.shopIds = [normalizeShopId(currentUserInfo.shopId)!]
}
} catch (error) {
console.error('获取店铺列表失败:', error)
@@ -593,7 +631,7 @@ const fetchUserList = async () => {
keyword: searchText.value || undefined
}
if (currentUserInfo?.type !== 4 && currentUserInfo?.shopId) {
if (currentUserInfo?.shopId) {
params.shopId = currentUserInfo.shopId
}
@@ -616,9 +654,9 @@ const resetFormState = () => {
phone: '',
password: '',
type: 0,
shopId: currentUserInfo?.type !== 4 && currentUserInfo?.shopId
? normalizeShopId(currentUserInfo.shopId)
: undefined
shopIds: currentUserInfo?.type !== 4 && currentUserInfo?.shopId
? [normalizeShopId(currentUserInfo.shopId)!]
: []
})
}
@@ -649,7 +687,7 @@ const showEditModal = (record: any) => {
phone: record.phone || '',
password: '',
type: record.type,
shopId: resolveEditableShopId(record.shopId)
shopIds: resolveEditableShopIds(record)
})
modalVisible.value = true
}
@@ -713,15 +751,21 @@ const handleModalOk = async () => {
try {
await formRef.value?.validate()
modalLoading.value = true
const requestData = {
const requestData: Record<string, unknown> = {
account: formState.account.trim(),
nickname: formState.nickname.trim(),
phone: formState.phone.trim(),
type: formState.type,
shopId: formState.shopId || undefined,
shopIds: formState.shopIds,
shopId: formState.shopIds.length ? formState.shopIds[0] : undefined,
...(formState.password.trim() ? { password: formState.password.trim() } : {})
}
if (isEdit.value && currentUserInfo?.type !== 4) {
delete requestData.shopIds
delete requestData.shopId
}
if (isEdit.value && currentUser.value) {
await adminUserApi.updateUser(currentUser.value.id, requestData)
message.success('更新成功')
@@ -751,7 +795,7 @@ const handleStatusChange = async (record: any, checked: boolean) => {
try {
await adminUserApi.updateUserStatus(record.id, checked ? 1 : 0)
record.status = checked ? 1 : 0
message.success('状态更新成功')
message.success(`已${checked ? '启用' : '停用'}当前店铺下的用户访问`)
} catch (error) {
console.error('状态更新失败:', error)
message.error('状态更新失败')
@@ -780,15 +824,8 @@ const handleDelete = async (record: any) => {
message.warning('管理员账号无法被删除')
return
}
const timestamp = Date.now()
await adminUserApi.updateUser(record.id, {
account: `${record.account}_deleted_${timestamp}`,
phone: record.phone ? `${record.phone}_deleted_${timestamp}` : undefined
})
await adminUserApi.deleteUser(record.id)
message.success('删除成功')
message.success('已移除当前店铺下的用户绑定')
await fetchUserList()
} catch (error) {
console.error('删除用户失败:', error)