店长编辑手机号改为仅修改时提交
自动发布开发环境 Nacos 配置 / publish (push) Successful in 25s

编辑弹窗保留脱敏手机号展示,聚焦时清空并提示留空不修改;未修改或仍为脱敏值时不再提交 phone/contactPhone,避免脱敏串写库。
This commit is contained in:
2026-11-04 20:08:45 +08:00
parent 47fced8175
commit e6ecca7d47
+36 -10
View File
@@ -214,10 +214,11 @@
<a-form-item label="手机号" name="phone">
<a-input
v-model:value="formState.phone"
:placeholder="isEdit && isMaskedSensitiveValue(currentUser?.phone) ? '已设置手机号,留空保持不变' : '请输入手机号'"
:placeholder="phonePlaceholder"
:maxlength="11"
inputmode="numeric"
autocomplete="off"
@focus="handlePhoneFocus"
@input="handlePhoneInput"
/>
</a-form-item>
@@ -625,6 +626,22 @@ const formState = reactive({
/** wechatQrUploading tracks QR upload state in the user modal. */
const wechatQrUploading = ref(false)
/** originalPhone keeps the phone value loaded from the backend so edits can be detected. */
const originalPhone = ref('')
/** phonePlaceholder explains that an existing masked phone is kept unless a new number is typed. */
const phonePlaceholder = computed(() =>
isEdit.value && originalPhone.value ? '已设置手机号,留空表示不修改' : '请输入手机号'
)
/** phoneChanged is true only when the user typed a real, different phone number during editing. */
const phoneChanged = computed(() => {
if (!isEdit.value) return true
const current = formState.phone.trim()
if (!current || isMaskedSensitiveValue(current)) return false
return current !== originalPhone.value.trim()
})
/** handleAccountInput is a local helper used by this page script. */
const handleAccountInput = () => {
const normalized = sanitizeAccountInput(formState.account)
@@ -642,6 +659,14 @@ const handlePhoneInput = () => {
formState.contactPhone = formState.phone
}
/** handlePhoneFocus clears the masked placeholder value so stars can never be submitted as a phone number. */
const handlePhoneFocus = () => {
if (isMaskedSensitiveValue(formState.phone)) {
formState.phone = ''
formState.contactPhone = ''
}
}
/** beforeUploadWechatQr validates QR image files before upload. */
const beforeUploadWechatQr = (file: File) => {
const isImage = file.type.startsWith('image/')
@@ -754,7 +779,7 @@ const formRules = {
phone: [
{
validator: async (_rule: unknown, value: string) => {
if (isEdit.value && !value?.trim()) return Promise.resolve()
if (isEdit.value && (!value?.trim() || isMaskedSensitiveValue(value))) return Promise.resolve()
await validatePhoneUniqueness(value)
return Promise.resolve()
},
@@ -1001,6 +1026,7 @@ const resetFilters = () => {
/** resetFormState is a local helper used by this page script. */
const resetFormState = () => {
originalPhone.value = ''
Object.assign(formState, {
account: '',
nickname: '',
@@ -1093,11 +1119,13 @@ const showAddModal = () => {
const showEditModal = (record: any) => {
isEdit.value = true
currentUser.value = record
const loadedPhone = String(record.phone || record.contactPhone || '').trim()
originalPhone.value = loadedPhone
Object.assign(formState, {
account: isMaskedSensitiveValue(record.account) ? '' : record.account,
nickname: record.nickname,
phone: isMaskedSensitiveValue(record.phone || record.contactPhone) ? '' : (record.phone || record.contactPhone || ''),
contactPhone: isMaskedSensitiveValue(record.phone || record.contactPhone) ? '' : (record.phone || record.contactPhone || ''),
phone: loadedPhone,
contactPhone: loadedPhone,
birthday: record.birthday || '',
wechatId: record.wechatId || '',
wechatQrCode: record.wechatQrCode || '',
@@ -1107,10 +1135,6 @@ const showEditModal = (record: any) => {
})
restoreDraft()
if (isMaskedSensitiveValue(formState.account)) formState.account = ''
if (isMaskedSensitiveValue(formState.phone)) {
formState.phone = ''
formState.contactPhone = ''
}
modalVisible.value = true
}
@@ -1147,8 +1171,10 @@ const handleModalOk = async () => {
...(formState.password.trim() ? { password: formState.password.trim() } : {})
}
if (isEdit.value && !formState.account.trim()) delete requestData.account
if (isEdit.value && !primaryPhone) {
if (isEdit.value && (!formState.account.trim() || isMaskedSensitiveValue(formState.account))) {
delete requestData.account
}
if (isEdit.value && (!phoneChanged.value || !primaryPhone || isMaskedSensitiveValue(primaryPhone))) {
delete requestData.phone
delete requestData.contactPhone
}