feat(sms): align provider and verification flow
This commit is contained in:
1 parent
d0a3972ca7
commit
5091da6a60
20 files changed
+489
-994
No files matched your search
@@ -6,7 +6,7 @@
|
||||
:icon="pageMeta.icon"
|
||||
:schema="pageMeta.groups"
|
||||
:form-data="formData"
|
||||
:dirty="dirty"
|
||||
:dirty="isSmsPage ? isSmsSettingsDirty : dirty"
|
||||
:loading="loading"
|
||||
:saving="saving"
|
||||
:load-error="loadError"
|
||||
@@ -131,6 +131,7 @@ const showTestModal = ref(false)
|
||||
const testLoading = ref(false)
|
||||
const testResult = ref(null)
|
||||
const serverSchema = ref(null)
|
||||
const smsSavedSettings = ref('')
|
||||
const captchaSecretsToClear = ref(new Set())
|
||||
const captchaProviders = [
|
||||
{ key: 'tencent', label: '腾讯云 Captcha', component: TencentConfig },
|
||||
@@ -144,8 +145,17 @@ const captchaProviderTab = ref('tencent')
|
||||
const resolvedDomain = computed(() => normalizeSchemaDomain(props.domain || route.meta?.canonicalDomain || route.meta?.schemaDomain || resolveDomainFromPath(route.path)))
|
||||
const resolvedSection = computed(() => props.section || route.meta?.section || route.meta?.schemaSection || resolveSectionFromPath(route.path))
|
||||
const isEmailPage = computed(() => resolvedDomain.value === 'global' && resolvedSection.value === 'email')
|
||||
const isSmsPage = computed(() => resolvedDomain.value === 'users' && resolvedSection.value === 'sms')
|
||||
const isPermissionsLogin = computed(() => resolvedDomain.value === 'permissions' && resolvedSection.value === 'login')
|
||||
const isPermissionsModeration = computed(() => resolvedDomain.value === 'permissions' && resolvedSection.value === 'moderation')
|
||||
const isSmsSettingsDirty = computed(() => smsSavedSettings.value !== '' && smsSavedSettings.value !== smsSettingsSnapshot(formData.value))
|
||||
|
||||
function smsSettingsSnapshot(data) {
|
||||
const settings = { ...(data || {}) }
|
||||
delete settings.sms_test_phone
|
||||
delete settings.sms_test_send
|
||||
return JSON.stringify(settings)
|
||||
}
|
||||
|
||||
function resolveDomainFromPath(path) {
|
||||
const parts = path.split('/').filter(Boolean)
|
||||
@@ -216,6 +226,10 @@ const {
|
||||
delete payload[key]
|
||||
}
|
||||
})
|
||||
if (isSmsPage.value) {
|
||||
delete payload.sms_test_phone
|
||||
delete payload.sms_test_send
|
||||
}
|
||||
if (clearSecrets.length) payload.__clear_secrets = clearSecrets
|
||||
if (isPermissionsLogin.value && captchaSecretsToClear.value.size) {
|
||||
payload.__clear_secrets = [...(payload.__clear_secrets || []), ...captchaSecretsToClear.value]
|
||||
@@ -226,12 +240,34 @@ const {
|
||||
return response
|
||||
},
|
||||
defaults: defaults.value,
|
||||
onLoaded: (data) => {
|
||||
if (isSmsPage.value) smsSavedSettings.value = smsSettingsSnapshot(data)
|
||||
},
|
||||
onSaved: () => {
|
||||
if (isSmsPage.value) smsSavedSettings.value = smsSettingsSnapshot(formData.value)
|
||||
message.success('设置已保存')
|
||||
},
|
||||
})
|
||||
|
||||
async function handleFieldAction(key) {
|
||||
if (key === 'sms_test_send' && isSmsPage.value) {
|
||||
const phone = String(formData.value?.sms_test_phone || '').trim()
|
||||
if (!phone) {
|
||||
message.warning('请先填写测试手机号')
|
||||
return
|
||||
}
|
||||
if (isSmsSettingsDirty.value) {
|
||||
message.warning('请先保存当前配置,再发送测试短信')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const response = await api.testSms(phone)
|
||||
message.success(response?.message || '测试短信已发送')
|
||||
} catch (error) {
|
||||
message.error(error?.message || '测试短信发送失败')
|
||||
}
|
||||
return
|
||||
}
|
||||
if (key !== 'email_test_send' || !isEmailPage.value) return
|
||||
const to = String(formData.value?.email_test_to || '').trim()
|
||||
if (!to) {
|
||||
|
||||
Reference in new issue
Block a user