修复:修复用户管理手机号和所属店铺问题
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'shopName'">
|
||||
{{ record.shopName || '-' }}
|
||||
{{ record.shopName || getShopNameById(record.shopId) || '-' }}
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'type'">
|
||||
@@ -117,7 +117,13 @@
|
||||
<a-input v-model:value="formState.nickname" placeholder="请输入昵称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="手机号" name="phone">
|
||||
<a-input v-model:value="formState.phone" placeholder="请输入手机号" />
|
||||
<a-input
|
||||
v-model:value="formState.phone"
|
||||
placeholder="请输入手机号"
|
||||
:maxlength="11"
|
||||
inputmode="numeric"
|
||||
autocomplete="off"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item v-if="!isEdit" label="密码" name="password">
|
||||
<a-input-password v-model:value="formState.password" placeholder="请输入密码" />
|
||||
@@ -132,7 +138,7 @@
|
||||
<a-select-option
|
||||
v-for="shop in shopList"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
:value="getShopOptionValue(shop)"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
@@ -400,6 +406,7 @@ const balanceHistory = ref<UserBalanceHistoryItem[]>([])
|
||||
const canOpenAssetPanel = computed(() =>
|
||||
hasAnyPermission(['user:balance:view', 'user:balance:manage', 'user:vip:manage'])
|
||||
)
|
||||
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -416,7 +423,7 @@ const formState = reactive({
|
||||
phone: '',
|
||||
password: '',
|
||||
type: 0,
|
||||
shopId: undefined as number | undefined
|
||||
shopId: undefined as string | undefined
|
||||
})
|
||||
|
||||
const balanceForm = reactive<AdminUserBalanceChangeRequest>({
|
||||
@@ -435,7 +442,22 @@ const vipForm = reactive<AdminUserVipOverrideRequest>({
|
||||
const formRules = {
|
||||
account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
||||
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{
|
||||
validator: async (_rule: unknown, value: string) => {
|
||||
const normalized = value?.trim()
|
||||
if (!normalized) {
|
||||
return Promise.reject('请输入手机号')
|
||||
}
|
||||
if (!PHONE_REGEX.test(normalized)) {
|
||||
return Promise.reject('请输入正确的 11 位手机号')
|
||||
}
|
||||
return Promise.resolve()
|
||||
},
|
||||
trigger: ['blur', 'change']
|
||||
}
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
|
||||
@@ -521,13 +543,39 @@ const filterVisibleUsers = (list: UserVO[]) => {
|
||||
return list
|
||||
}
|
||||
|
||||
const normalizeShopId = (value: unknown) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return undefined
|
||||
}
|
||||
return String(value)
|
||||
}
|
||||
|
||||
const getShopOptionValue = (shop: Shop) => normalizeShopId((shop as any).id) || ''
|
||||
|
||||
const getShopNameById = (shopId?: string | number | null) => {
|
||||
const targetShopId = normalizeShopId(shopId)
|
||||
if (!targetShopId) {
|
||||
return ''
|
||||
}
|
||||
const matchedShop = shopList.value.find(shop => getShopOptionValue(shop) === targetShopId)
|
||||
return matchedShop?.shopName || ''
|
||||
}
|
||||
|
||||
const resolveEditableShopId = (shopId?: string | number | null) => {
|
||||
const targetShopId = normalizeShopId(shopId)
|
||||
if (targetShopId && shopList.value.some(shop => getShopOptionValue(shop) === targetShopId)) {
|
||||
return targetShopId
|
||||
}
|
||||
return shopList.value.length === 1 ? getShopOptionValue(shopList.value[0]!) : undefined
|
||||
}
|
||||
|
||||
const fetchShopList = async () => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
const shops = await adminShopApi.listAllShops() as unknown as Shop[]
|
||||
shopList.value = shops || []
|
||||
if (currentUserInfo?.type !== 4 && currentUserInfo?.shopId) {
|
||||
formState.shopId = currentUserInfo.shopId
|
||||
formState.shopId = normalizeShopId(currentUserInfo.shopId)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
@@ -568,7 +616,9 @@ const resetFormState = () => {
|
||||
phone: '',
|
||||
password: '',
|
||||
type: 0,
|
||||
shopId: currentUserInfo?.type !== 4 && currentUserInfo?.shopId ? currentUserInfo.shopId : undefined
|
||||
shopId: currentUserInfo?.type !== 4 && currentUserInfo?.shopId
|
||||
? normalizeShopId(currentUserInfo.shopId)
|
||||
: undefined
|
||||
})
|
||||
}
|
||||
|
||||
@@ -599,7 +649,7 @@ const showEditModal = (record: any) => {
|
||||
phone: record.phone || '',
|
||||
password: '',
|
||||
type: record.type,
|
||||
shopId: record.shopId
|
||||
shopId: resolveEditableShopId(record.shopId)
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
@@ -663,12 +713,20 @@ const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
const requestData = {
|
||||
account: formState.account.trim(),
|
||||
nickname: formState.nickname.trim(),
|
||||
phone: formState.phone.trim(),
|
||||
type: formState.type,
|
||||
shopId: formState.shopId || undefined,
|
||||
...(formState.password.trim() ? { password: formState.password.trim() } : {})
|
||||
}
|
||||
|
||||
if (isEdit.value && currentUser.value) {
|
||||
await adminUserApi.updateUser(currentUser.value.id, formState)
|
||||
await adminUserApi.updateUser(currentUser.value.id, requestData)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminUserApi.createUser(formState)
|
||||
await adminUserApi.createUser(requestData)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user