重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,480 @@
<template>
<div class="admin-page">
<div class="page-head">
<div>
<h2>参数管理</h2>
<p>统一维护地图 Key、短信 MessageHub 对接参数等平台级配置,仅平台管理员可修改。</p>
</div>
<a-button type="primary" @click="openCreate">新增配置</a-button>
</div>
<a-card title="地图服务配置" :bordered="false">
<a-form layout="vertical">
<a-form-item label="当前地图渠道">
<a-radio-group v-model:value="mapProvider">
<a-radio-button value="TENCENT">腾讯地图</a-radio-button>
<a-radio-button value="AMAP">高德地图</a-radio-button>
</a-radio-group>
</a-form-item>
<a-form-item label="腾讯 Web Key">
<a-input-password v-model:value="mapForms.tencentWeb.configValue" placeholder="用于后台腾讯地图选点和 Web 展示" />
</a-form-item>
<a-form-item label="高德 Web Key">
<a-input-password v-model:value="mapForms.amapWeb.configValue" placeholder="用于后台高德地图选点和 Web 展示" />
</a-form-item>
<a-form-item label="高德小程序 Key">
<a-input-password v-model:value="mapForms.amapMini.configValue" placeholder="用于后续小程序端高德 SDK / API 调用" />
</a-form-item>
<a-form-item label="备注">
<a-textarea v-model:value="mapRemark" :rows="2" placeholder="例如:默认使用腾讯地图,高德小程序 Key 单独申请填写" />
</a-form-item>
<a-form-item>
<a-space>
<a-switch v-model:checked="mapEnabled" checked-children="启用" un-checked-children="停用" />
<a-button type="primary" :loading="savingMap" @click="saveMapConfig">保存地图配置</a-button>
</a-space>
</a-form-item>
</a-form>
</a-card>
<a-card title="用户默认密码" :bordered="false">
<a-form layout="vertical">
<a-alert
type="info"
show-icon
message="后台新增用户时,密码留空会自动使用这里配置的默认密码。"
class="inline-alert"
/>
<a-form-item label="后台新增用户默认密码">
<a-input-password
v-model:value="defaultPasswordForm.configValue"
placeholder="请输入 8-32 位强密码"
autocomplete="new-password"
/>
</a-form-item>
<a-form-item label="备注">
<a-textarea v-model:value="defaultPasswordForm.remark" :rows="2" />
</a-form-item>
<a-form-item>
<a-space>
<a-switch v-model:checked="defaultPasswordEnabled" checked-children="启用" un-checked-children="停用" />
<a-button type="primary" :loading="savingDefaultPassword" @click="saveDefaultPasswordConfig">
保存默认密码
</a-button>
</a-space>
</a-form-item>
</a-form>
</a-card>
<a-alert
type="info"
show-icon
message="这里不配置 Spug、阿里云等供应商密钥;真实短信通道仍在 MessageHub 中独立管理。"
/>
<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="yuminail" />
</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,
adminSystemParameterConfigApi,
type MessageHubPushConfigVO,
type SystemParameterConfigVO
} 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: savingMap supports MessageHubPushConfigsView.vue by holding or executing the saving map 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 savingMap = ref(false)
const savingDefaultPassword = ref(false)
/**
* Purpose: mapEnabled supports MessageHubPushConfigsView.vue by holding or executing the map enabled 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 mapEnabled = ref(true)
const defaultPasswordEnabled = ref(true)
/**
* Purpose: mapProvider supports MessageHubPushConfigsView.vue by holding or executing the map provider 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 mapProvider = ref<'TENCENT' | 'AMAP'>('TENCENT')
/**
* Purpose: mapRemark supports MessageHubPushConfigsView.vue by holding or executing the map remark 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 mapRemark = ref('地图渠道由平台管理员选择;高德 Web Key 与高德小程序 Key 分开填写。')
/**
* Purpose: createMapForm supports MessageHubPushConfigsView.vue by holding or executing the create map 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 createMapForm = (configKey: string, configName: string, remark: string) => ({
configGroup: 'MAP',
configKey,
configName,
configValue: '',
enabled: 1,
remark
})
/**
* Purpose: mapForms supports MessageHubPushConfigsView.vue by holding or executing the map forms 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 mapForms = reactive({
provider: createMapForm('MAP_PROVIDER', '当前地图渠道', 'TENCENT 或 AMAP;决定后台店铺选点默认使用哪个地图渠道'),
tencentWeb: createMapForm('TENCENT_MAP_KEY', '腾讯 Web Key', '用于后台腾讯地图选点和 Web 展示'),
amapWeb: createMapForm('AMAP_WEB_KEY', '高德 Web Key', '用于后台高德地图选点和 Web 展示'),
amapMini: createMapForm('AMAP_MINI_KEY', '高德小程序 Key', '用于后续小程序端高德 SDK / API 调用')
})
const defaultPasswordForm = reactive<SystemParameterConfigVO>({
configGroup: 'USER',
configKey: 'DEFAULT_PASSWORD',
configName: '后台新增用户默认密码',
configValue: 'Fingertip@123',
enabled: 1,
remark: '后台新增用户不填写密码时使用;需满足 8-32 位且至少包含数字、小写字母、大写字母、特殊符号中的 3 类'
})
/**
* 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: 'yuminail',
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 {
const [messageConfigs, mapConfigs, userConfigs] = await Promise.all([
adminMessageHubPushConfigApi.listConfigs(),
adminSystemParameterConfigApi.listConfigs('MAP'),
adminSystemParameterConfigApi.listConfigs('USER')
])
configs.value = messageConfigs
const providerConfig = mapConfigs.find(item => item.configKey === 'MAP_PROVIDER')
const tencentMapConfig = mapConfigs.find(item => item.configKey === 'TENCENT_MAP_KEY')
const amapWebConfig = mapConfigs.find(item => item.configKey === 'AMAP_WEB_KEY')
const amapMiniConfig = mapConfigs.find(item => item.configKey === 'AMAP_MINI_KEY')
if (providerConfig?.configValue) {
mapProvider.value = providerConfig.configValue === 'AMAP' ? 'AMAP' : 'TENCENT'
mapEnabled.value = providerConfig.enabled === 1
Object.assign(mapForms.provider, providerConfig)
}
if (tencentMapConfig) Object.assign(mapForms.tencentWeb, tencentMapConfig)
if (amapWebConfig) Object.assign(mapForms.amapWeb, amapWebConfig)
if (amapMiniConfig) Object.assign(mapForms.amapMini, amapMiniConfig)
const defaultPasswordConfig = userConfigs.find(item => item.configKey === 'DEFAULT_PASSWORD')
if (defaultPasswordConfig) {
Object.assign(defaultPasswordForm, defaultPasswordConfig)
defaultPasswordEnabled.value = defaultPasswordConfig.enabled === 1
}
} finally {
loading.value = false
}
}
/**
* Purpose: saveMapConfig supports MessageHubPushConfigsView.vue by holding or executing the save map config 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 saveMapConfig = async () => {
savingMap.value = true
try {
await adminSystemParameterConfigApi.saveConfig({
...mapForms.provider,
configValue: mapProvider.value,
enabled: mapEnabled.value ? 1 : 0
})
await adminSystemParameterConfigApi.saveConfig({
...mapForms.tencentWeb,
enabled: mapEnabled.value ? 1 : 0
})
await adminSystemParameterConfigApi.saveConfig({
...mapForms.amapWeb,
enabled: mapEnabled.value ? 1 : 0
})
await adminSystemParameterConfigApi.saveConfig({
...mapForms.amapMini,
enabled: mapEnabled.value ? 1 : 0
})
message.success('地图配置已保存')
await load()
} finally {
savingMap.value = false
}
}
const validateDefaultPasswordInput = () => {
const password = defaultPasswordForm.configValue.trim()
if (password.length < 8 || password.length > 32) {
message.warning('默认密码长度需为 8-32 位')
return false
}
const categoryCount = [
/\d/.test(password),
/[a-z]/.test(password),
/[A-Z]/.test(password),
/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password)
].filter(Boolean).length
if (categoryCount < 3) {
message.warning('默认密码需至少包含数字、小写字母、大写字母、特殊符号中的 3 类')
return false
}
return true
}
const saveDefaultPasswordConfig = async () => {
if (!validateDefaultPasswordInput()) {
return
}
savingDefaultPassword.value = true
try {
await adminSystemParameterConfigApi.saveConfig({
...defaultPasswordForm,
configValue: defaultPasswordForm.configValue.trim(),
enabled: defaultPasswordEnabled.value ? 1 : 0
})
message.success('默认密码已保存')
await load()
} finally {
savingDefaultPassword.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: 'yuminail',
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>