feat: 添加手动设置短信验证码功能及相关前端支持
Some checks failed
build quyun / Build (push) Failing after 1m26s

This commit is contained in:
2025-12-23 23:59:01 +08:00
parent d9737d4ee3
commit 6c9063a2c3
6 changed files with 154 additions and 18 deletions

View File

@@ -9,6 +9,11 @@ export const smsCodeSendService = {
phone: phone.trim()
}
});
},
manualSet({ phone = '', code = '' } = {}) {
return httpClient.post('/sms-code-sends/manual-set', {
phone: phone.trim(),
code: code.trim()
});
}
};

View File

@@ -1,8 +1,10 @@
<script setup>
import { smsCodeSendService } from '@/api/smsCodeSendService';
import { formatDate } from '@/utils/date';
import Button from 'primevue/button';
import Column from 'primevue/column';
import DataTable from 'primevue/datatable';
import Dialog from 'primevue/dialog';
import InputText from 'primevue/inputtext';
import ProgressSpinner from 'primevue/progressspinner';
import Toast from 'primevue/toast';
@@ -15,6 +17,11 @@ const phone = ref('');
const loading = ref(false);
const searchTimeout = ref(null);
const manualDialogVisible = ref(false);
const manualPhone = ref('');
const manualCode = ref('');
const manualSaving = ref(false);
const records = ref({
items: [],
total: 0,
@@ -62,14 +69,72 @@ const onSearch = () => {
onMounted(() => {
fetchRecords();
});
const gen4Digits = () => {
return String(Math.floor(Math.random() * 10000)).padStart(4, '0');
};
const openManualDialog = () => {
manualPhone.value = '';
manualCode.value = gen4Digits();
manualDialogVisible.value = true;
};
const regenerateCode = () => {
manualCode.value = gen4Digits();
};
const submitManualSet = async () => {
manualSaving.value = true;
try {
const resp = await smsCodeSendService.manualSet({
phone: manualPhone.value,
code: manualCode.value
});
toast.add({ severity: 'success', summary: '成功', detail: `已设置验证码:${resp.data.code}`, life: 3000 });
manualDialogVisible.value = false;
fetchRecords();
} catch (error) {
console.error('Failed to manual set sms code:', error);
toast.add({ severity: 'error', summary: '错误', detail: '设置验证码失败', life: 3000 });
} finally {
manualSaving.value = false;
}
};
</script>
<template>
<Toast />
<Dialog v-model:visible="manualDialogVisible" modal header="手动设置认证码" :style="{ width: '420px' }">
<div class="space-y-3">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">手机号</label>
<InputText v-model="manualPhone" class="w-full" placeholder="请输入 11 位手机号" inputmode="numeric"
maxlength="11" />
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">验证码</label>
<div class="flex gap-2">
<InputText v-model="manualCode" class="flex-1" readonly />
<Button label="生成" icon="pi pi-refresh" severity="secondary" @click="regenerateCode" />
</div>
<div class="text-xs text-gray-500 mt-1">有效期 5 分钟</div>
</div>
</div>
<template #footer>
<div class="flex justify-end gap-2">
<Button label="取消" text @click="manualDialogVisible = false" />
<Button label="设置" severity="success" :loading="manualSaving" @click="submitManualSet" />
</div>
</template>
</Dialog>
<div class="w-full">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-semibold text-gray-800">短信认证</h1>
<Button label="手动设置认证码" icon="pi pi-key" severity="success" @click="openManualDialog" />
</div>
<div class="card">
@@ -112,4 +177,3 @@ onMounted(() => {
</div>
</div>
</template>