修复:修复后台用户校验与店长新增美甲师
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
style="width: 260px"
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<a-button v-if="hasPermission('user:create')" type="primary" @click="showAddModal">
|
||||
<a-button v-if="canCreateUser" type="primary" @click="showAddModal">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
@@ -132,6 +132,7 @@
|
||||
:maxlength="11"
|
||||
inputmode="numeric"
|
||||
autocomplete="off"
|
||||
@input="handlePhoneInput"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item v-if="!isEdit" label="密码" name="password">
|
||||
@@ -382,6 +383,7 @@ import DraftActions from '@/components/DraftActions.vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||||
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
|
||||
import { userApi, type AvailabilityCheckResponse } from '@/api/user'
|
||||
import {
|
||||
adminShopApi,
|
||||
adminUserApi,
|
||||
@@ -432,6 +434,9 @@ const vipDraftSavedAt = ref<number | null>(null)
|
||||
const canOpenAssetPanel = computed(() =>
|
||||
hasAnyPermission(['user:balance:view', 'user:balance:manage', 'user:vip:manage'])
|
||||
)
|
||||
const canCreateUser = computed(() =>
|
||||
hasPermission('user:create') || currentUserInfo?.type === 2 || currentUserInfo?.type === 4
|
||||
)
|
||||
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
||||
|
||||
const pagination = reactive({
|
||||
@@ -459,6 +464,37 @@ const handleAccountInput = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handlePhoneInput = () => {
|
||||
const normalized = formState.phone.replace(/\D/g, '').slice(0, 11)
|
||||
if (normalized !== formState.phone) {
|
||||
formState.phone = normalized
|
||||
}
|
||||
}
|
||||
|
||||
const validatePhoneUniqueness = async (value: string) => {
|
||||
const normalized = value?.trim()
|
||||
if (!normalized) {
|
||||
throw new Error('请输入手机号')
|
||||
}
|
||||
if (!PHONE_REGEX.test(normalized)) {
|
||||
throw new Error('请输入正确的 11 位手机号')
|
||||
}
|
||||
if (isEdit.value && currentUser.value?.phone?.trim() === normalized) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const response = await userApi.checkPhoneAvailability(normalized) as unknown as AvailabilityCheckResponse
|
||||
if (!response.available) {
|
||||
throw new Error(response.message || '该手机号已绑定其他用户')
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error instanceof Error && error.message) {
|
||||
throw error
|
||||
}
|
||||
throw new Error('手机号校验失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
const balanceForm = reactive<AdminUserBalanceChangeRequest>({
|
||||
changeScene: 'RECHARGE',
|
||||
amount: undefined as unknown as number,
|
||||
@@ -553,16 +589,10 @@ const formRules = {
|
||||
{ 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 位手机号')
|
||||
}
|
||||
await validatePhoneUniqueness(value)
|
||||
return Promise.resolve()
|
||||
},
|
||||
trigger: ['blur', 'change']
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
|
||||
Reference in New Issue
Block a user