fix(frontend): 完善表单校验并添加错误提示
- UserEditModal: 添加 email 必填和 concurrency 最小值校验 - UserAttributesConfigModal: 添加 key/name 必填和 options 非空校验 - GroupsView: 添加 name 必填校验 - ProxiesView: 添加 name/host 必填和 port 范围校验 - UserBalanceModal: 添加 amount 有效性和余额充足性校验 - RedeemView: 添加空兑换码错误提示 - i18n: 添加所有新增校验的中英文翻译
This commit is contained in:
@@ -37,10 +37,21 @@ watch(() => props.show, (v) => { if(v) { form.amount = 0; form.notes = '' } })
|
||||
|
||||
const calculateNewBalance = () => (props.user ? (props.operation === 'add' ? props.user.balance + form.amount : props.user.balance - form.amount) : 0)
|
||||
const handleBalanceSubmit = async () => {
|
||||
if (!props.user) return; submitting.value = true
|
||||
if (!props.user) return
|
||||
if (!form.amount || form.amount <= 0) {
|
||||
appStore.showError(t('admin.users.amountRequired'))
|
||||
return
|
||||
}
|
||||
if (props.operation === 'subtract' && form.amount > props.user.balance) {
|
||||
appStore.showError(t('admin.users.insufficientBalance'))
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
await adminAPI.users.updateBalance(props.user.id, form.amount, props.operation, form.notes)
|
||||
appStore.showSuccess(t('common.success')); emit('success'); emit('close')
|
||||
} catch {} finally { submitting.value = false }
|
||||
} catch (e: any) {
|
||||
appStore.showError(e.response?.data?.detail || t('common.error'))
|
||||
} finally { submitting.value = false }
|
||||
}
|
||||
</script>
|
||||
@@ -86,6 +86,14 @@ const copyPassword = async () => {
|
||||
}
|
||||
const handleUpdateUser = async () => {
|
||||
if (!props.user) return
|
||||
if (!form.email.trim()) {
|
||||
appStore.showError(t('admin.users.emailRequired'))
|
||||
return
|
||||
}
|
||||
if (form.concurrency < 1) {
|
||||
appStore.showError(t('admin.users.concurrencyMin'))
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const data: any = { email: form.email, username: form.username, notes: form.notes, concurrency: form.concurrency }
|
||||
|
||||
@@ -344,6 +344,18 @@ const removeOption = (index: number) => {
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!form.key.trim()) {
|
||||
appStore.showError(t('admin.users.attributes.keyRequired'))
|
||||
return
|
||||
}
|
||||
if (!form.name.trim()) {
|
||||
appStore.showError(t('admin.users.attributes.nameRequired'))
|
||||
return
|
||||
}
|
||||
if ((form.type === 'select' || form.type === 'multi_select') && form.options.length === 0) {
|
||||
appStore.showError(t('admin.users.attributes.optionsRequired'))
|
||||
return
|
||||
}
|
||||
saving.value = true
|
||||
try {
|
||||
const data = {
|
||||
|
||||
Reference in New Issue
Block a user