272 lines
11 KiB
Vue
272 lines
11 KiB
Vue
<template>
|
||
<div class="admin-page">
|
||
<div class="page-head">
|
||
<div>
|
||
<h2>参数管理</h2>
|
||
<p>维护短信验证码场景的 MessageHub 模板、队列和通道配置,仅平台管理员可修改。</p>
|
||
</div>
|
||
<a-button type="primary" @click="openCreate">新增配置</a-button>
|
||
</div>
|
||
|
||
<a-table :columns="columns" :data-source="configs" :loading="loading" row-key="id" :scroll="{ x: 'max-content' }">
|
||
<template #bodyCell="{ column, record }">
|
||
<template v-if="column.key === 'scene'">
|
||
<strong>{{ record.sceneName }}</strong>
|
||
<div class="muted">{{ record.sceneCode }}</div>
|
||
</template>
|
||
<template v-else-if="column.key === 'messagehub'">
|
||
<div>队列:{{ record.queueName }}</div>
|
||
<div class="muted">来源:{{ record.sourceSystem }}</div>
|
||
</template>
|
||
<template v-else-if="column.key === 'template'">
|
||
<div>{{ record.templateCode }}</div>
|
||
<div class="muted">通道ID:{{ record.channelId || '由 MessageHub 自动选择' }}</div>
|
||
</template>
|
||
<template v-else-if="column.key === 'enabled'">
|
||
<a-switch :checked="record.enabled === 1" @change="(checked: any) => toggleStatus(record as MessageHubPushConfigVO, Boolean(checked))" />
|
||
</template>
|
||
<template v-else-if="column.key === 'action'">
|
||
<a-space>
|
||
<a-button size="small" @click="openEdit(record as MessageHubPushConfigVO)">编辑</a-button>
|
||
<a-button size="small" @click="openTest(record as MessageHubPushConfigVO)">测试</a-button>
|
||
</a-space>
|
||
</template>
|
||
</template>
|
||
</a-table>
|
||
|
||
<a-modal v-model:open="formOpen" :title="editingId ? '编辑配置' : '新增配置'" :mask-closable="false" @ok="submit" :confirm-loading="saving">
|
||
<a-form layout="vertical">
|
||
<a-form-item label="业务场景">
|
||
<a-select v-model:value="form.sceneCode" :options="sceneOptions" show-search @change="handleSceneChange" />
|
||
</a-form-item>
|
||
<a-form-item label="场景名称">
|
||
<a-input v-model:value="form.sceneName" />
|
||
</a-form-item>
|
||
<a-form-item label="MessageHub 队列">
|
||
<a-input v-model:value="form.queueName" placeholder="smsQueue" />
|
||
</a-form-item>
|
||
<a-form-item label="来源系统">
|
||
<a-input v-model:value="form.sourceSystem" placeholder="jayucloud-salon" />
|
||
</a-form-item>
|
||
<a-form-item label="模板编码">
|
||
<a-input v-model:value="form.templateCode" placeholder="MessageHub 中维护的模板编码" />
|
||
</a-form-item>
|
||
<a-form-item label="指定通道 ID">
|
||
<a-input-number v-model:value="form.channelId" :min="1" style="width: 100%" placeholder="不填则由 MessageHub 选择" />
|
||
</a-form-item>
|
||
<a-form-item label="发送方式">
|
||
<a-select v-model:value="form.sendMethod" allow-clear :options="sendMethodOptions" />
|
||
</a-form-item>
|
||
<a-form-item label="备注">
|
||
<a-textarea v-model:value="form.remark" :rows="3" />
|
||
</a-form-item>
|
||
</a-form>
|
||
</a-modal>
|
||
|
||
<a-modal v-model:open="testOpen" title="测试投递" :mask-closable="false" @ok="submitTest" :confirm-loading="testing">
|
||
<a-form layout="vertical">
|
||
<a-form-item label="测试手机号">
|
||
<a-input v-model:value="testPhone" :maxlength="11" />
|
||
</a-form-item>
|
||
</a-form>
|
||
</a-modal>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
/**
|
||
* MessageHubPushConfigsView page script.
|
||
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
||
*/
|
||
import { onMounted, reactive, ref } from 'vue'
|
||
import { message } from 'ant-design-vue'
|
||
/**
|
||
* Purpose: MessageHubPushConfigVO supports MessageHubPushConfigsView.vue by holding or executing the message hub push config vo page or API role.
|
||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||
*/
|
||
import {
|
||
adminMessageHubPushConfigApi,
|
||
type MessageHubPushConfigVO
|
||
} from '@/api/admin'
|
||
|
||
/** loading is a reactive state variable used by the template and event handlers. */
|
||
const loading = ref(false)
|
||
/** saving is a reactive state variable used by the template and event handlers. */
|
||
const saving = ref(false)
|
||
/** testing is a reactive state variable used by the template and event handlers. */
|
||
const testing = ref(false)
|
||
/** formOpen is a reactive state variable used by the template and event handlers. */
|
||
const formOpen = ref(false)
|
||
/** testOpen is a reactive state variable used by the template and event handlers. */
|
||
const testOpen = ref(false)
|
||
/**
|
||
* Purpose: editingId supports MessageHubPushConfigsView.vue by holding or executing the editing id page or API role.
|
||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||
*/
|
||
const editingId = ref<any>()
|
||
/**
|
||
* Purpose: testingId supports MessageHubPushConfigsView.vue by holding or executing the testing id page or API role.
|
||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||
*/
|
||
const testingId = ref<any>()
|
||
/** testPhone is a reactive state variable used by the template and event handlers. */
|
||
const testPhone = ref('')
|
||
/**
|
||
* Purpose: configs supports MessageHubPushConfigsView.vue by holding or executing the configs page or API role.
|
||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||
*/
|
||
const configs = ref<MessageHubPushConfigVO[]>([])
|
||
/**
|
||
* Purpose: sceneOptions supports MessageHubPushConfigsView.vue by holding or executing the scene options page or API role.
|
||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||
*/
|
||
const sceneOptions = [
|
||
{ label: '用户注册验证码', value: 'USER_REGISTER_SMS_CODE' },
|
||
{ label: '手机号登录验证码', value: 'USER_LOGIN_SMS_CODE' },
|
||
{ label: '找回密码验证码', value: 'USER_RESET_PASSWORD_SMS_CODE' },
|
||
{ label: '绑定手机号验证码', value: 'USER_BIND_PHONE_SMS_CODE' },
|
||
{ label: '修改手机号验证码', value: 'USER_CHANGE_PHONE_SMS_CODE' },
|
||
{ label: '修改密码验证码', value: 'USER_CHANGE_PASSWORD_SMS_CODE' }
|
||
]
|
||
|
||
/**
|
||
* Purpose: sendMethodOptions supports MessageHubPushConfigsView.vue by holding or executing the send method options page or API role.
|
||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||
*/
|
||
const sendMethodOptions = [
|
||
{ label: 'SPUG', value: 'SPUG' },
|
||
{ label: 'OTHER', value: 'OTHER' }
|
||
]
|
||
|
||
/**
|
||
* Purpose: form supports MessageHubPushConfigsView.vue by holding or executing the form page or API role.
|
||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||
*/
|
||
const form = reactive<any>({
|
||
sceneCode: 'USER_LOGIN_SMS_CODE',
|
||
sceneName: '手机号登录验证码',
|
||
platform: 'SMS',
|
||
msgType: 'VERIFICATION',
|
||
queueName: 'smsQueue',
|
||
sourceSystem: 'jayucloud-salon',
|
||
templateCode: 'SPUG0001',
|
||
channelId: undefined,
|
||
sendMethod: 'SPUG',
|
||
enabled: 1,
|
||
remark: ''
|
||
})
|
||
|
||
/**
|
||
* Purpose: columns supports MessageHubPushConfigsView.vue by holding or executing the columns page or API role.
|
||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||
*/
|
||
const columns = [
|
||
{ title: '业务场景', key: 'scene' },
|
||
{ title: 'MessageHub', key: 'messagehub' },
|
||
{ title: '模板/通道', key: 'template' },
|
||
{ title: '消息类型', dataIndex: 'msgType', key: 'msgType', width: 110 },
|
||
{ title: '启用', key: 'enabled', width: 90 },
|
||
{ title: '操作', key: 'action', width: 150 }
|
||
]
|
||
|
||
/** load is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||
const load = async () => {
|
||
loading.value = true
|
||
try {
|
||
configs.value = await adminMessageHubPushConfigApi.listConfigs()
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
/** resetForm is a local helper used by this page script. */
|
||
const resetForm = () => Object.assign(form, {
|
||
sceneCode: 'USER_LOGIN_SMS_CODE',
|
||
sceneName: '手机号登录验证码',
|
||
platform: 'SMS',
|
||
msgType: 'VERIFICATION',
|
||
queueName: 'smsQueue',
|
||
sourceSystem: 'jayucloud-salon',
|
||
templateCode: 'SPUG0001',
|
||
channelId: undefined,
|
||
sendMethod: 'SPUG',
|
||
enabled: 1,
|
||
remark: ''
|
||
})
|
||
|
||
/** handleSceneChange is a local helper used by this page script. */
|
||
const handleSceneChange = (value: any) => {
|
||
const option = sceneOptions.find(item => item.value === String(value || ''))
|
||
if (option) form.sceneName = option.label
|
||
}
|
||
|
||
/** openCreate is a local helper used by this page script. */
|
||
const openCreate = () => { editingId.value = undefined; resetForm(); formOpen.value = true }
|
||
/** openEdit is a local helper used by this page script. */
|
||
const openEdit = (record: MessageHubPushConfigVO) => {
|
||
editingId.value = record.id
|
||
Object.assign(form, record)
|
||
formOpen.value = true
|
||
}
|
||
|
||
/** submit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||
const submit = async () => {
|
||
if (!form.sceneCode || !form.sceneName || !form.queueName || !form.sourceSystem || !form.templateCode) {
|
||
message.warning('请填写场景、队列、来源系统和模板编码')
|
||
return
|
||
}
|
||
saving.value = true
|
||
try {
|
||
if (editingId.value) {
|
||
await adminMessageHubPushConfigApi.updateConfig(editingId.value, form)
|
||
} else {
|
||
await adminMessageHubPushConfigApi.createConfig(form)
|
||
}
|
||
message.success('配置已保存')
|
||
formOpen.value = false
|
||
await load()
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
/** toggleStatus is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||
const toggleStatus = async (record: MessageHubPushConfigVO, checked: boolean) => {
|
||
await adminMessageHubPushConfigApi.updateStatus(record.id, checked ? 1 : 0)
|
||
record.enabled = checked ? 1 : 0
|
||
}
|
||
|
||
/** openTest is a local helper used by this page script. */
|
||
const openTest = (record: MessageHubPushConfigVO) => {
|
||
testingId.value = record.id
|
||
testPhone.value = ''
|
||
testOpen.value = true
|
||
}
|
||
|
||
/** submitTest is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||
const submitTest = async () => {
|
||
if (!/^1[3-9]\d{9}$/.test(testPhone.value)) {
|
||
message.warning('请输入正确的测试手机号')
|
||
return
|
||
}
|
||
testing.value = true
|
||
try {
|
||
await adminMessageHubPushConfigApi.testConfig(testingId.value, testPhone.value)
|
||
message.success('测试消息已投递到 MessageHub')
|
||
testOpen.value = false
|
||
} finally {
|
||
testing.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(load)
|
||
</script>
|
||
|
||
<style scoped>
|
||
.admin-page { display: grid; gap: 18px; }
|
||
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
|
||
.page-head h2 { margin: 0 0 4px; }
|
||
.page-head p, .muted { margin: 0; color: var(--text-secondary); }
|
||
.inline-alert { margin-bottom: 16px; }
|
||
</style>
|