add: 改造vue2中的短信模板到vue3中

This commit is contained in:
puhui999 2023-03-21 16:29:11 +08:00
parent c1b1ffa467
commit 6e90bbe2e1
6 changed files with 607 additions and 331 deletions

View File

@ -12,6 +12,12 @@ export interface SmsChannelVO {
createTime: Date
}
export interface SmsChannelListVO {
id: number
code: string
signature: string
}
export interface SmsChannelPageReqVO extends PageParam {
signature?: string
code?: string

View File

@ -1,18 +1,18 @@
import request from '@/config/axios'
export interface SmsTemplateVO {
id: number
type: number
status: number
id: number | null
type: number | null
status: number | null
code: string
name: string
content: string
remark: string
apiTemplateId: string
channelId: number
channelCode: string
params: string[]
createTime: Date
channelId: number | null
channelCode?: string
params?: string[]
createTime?: Date
}
export interface SendSmsReqVO {
@ -21,13 +21,13 @@ export interface SendSmsReqVO {
templateParams: Map<String, Object>
}
export interface SmsTemplatePageReqVO {
type?: number
status?: number
export interface SmsTemplatePageReqVO extends PageParam {
type?: number | null
status?: number | null
code?: string
content?: string
apiTemplateId?: string
channelId?: number
channelId?: number | null
createTime?: Date[]
}

View File

@ -302,7 +302,14 @@ export default {
dialog: {
dialog: '弹窗',
open: '打开',
close: '关闭'
close: '关闭',
sms: {
template: {
addTitle: '添加短信模板',
updtaeTitle: '修改短信模板',
sendSms: '发送短信'
}
}
},
sys: {
api: {

View File

@ -0,0 +1,262 @@
<template>
<Dialog :title="modelTitle" v-model="modelVisible">
<el-form
v-if="['template.addTitle', 'template.updtaeTitle'].includes(formType)"
ref="formRef"
:model="formData"
:rules="formRules"
label-width="140px"
>
<el-form-item label="短信渠道编号" prop="channelId">
<el-select v-model="formData.channelId" placeholder="请选择短信渠道编号">
<el-option
v-for="channel in channelOptions"
:key="channel.id"
:value="channel.id"
:label="
channel.signature + optionLabel(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE, channel.code)
"
/>
</el-select>
</el-form-item>
<el-form-item label="短信类型" prop="type">
<el-select v-model="formData.type" placeholder="请选择短信类型">
<el-option
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE)"
:key="dict.value"
:label="dict.label"
:value="parseInt(dict.value)"
/>
</el-select>
</el-form-item>
<el-form-item label="模板编号" prop="code">
<el-input v-model="formData.code" placeholder="请输入模板编号" />
</el-form-item>
<el-form-item label="模板名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入模板名称" />
</el-form-item>
<el-form-item label="模板内容" prop="content">
<el-input type="textarea" v-model="formData.content" placeholder="请输入模板内容" />
</el-form-item>
<el-form-item label="开启状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:label="parseInt(dict.value)"
>{{ dict.label }}</el-radio
>
</el-radio-group>
</el-form-item>
<el-form-item label="短信 API 模板编号" prop="apiTemplateId">
<el-input v-model="formData.apiTemplateId" placeholder="请输入短信 API 的模板编号" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="formData.remark" placeholder="请输入备注" />
</el-form-item>
</el-form>
<el-form
v-if="formType === 'template.sendSms'"
ref="sendSmsFormRef"
:model="sendSmsForm"
:rules="sendSmsRules"
>
<el-form-item label="模板内容" prop="content">
<el-input
v-model="sendSmsForm.content"
type="textarea"
placeholder="请输入模板内容"
readonly
/>
</el-form-item>
<el-form-item label="手机号" prop="mobile">
<el-input v-model="sendSmsForm.mobile" placeholder="请输入手机号" />
</el-form-item>
<el-form-item
v-for="param in sendSmsForm.params"
:key="param"
:label="'参数 {' + param + '}'"
:prop="'templateParams.' + param"
>
<el-input
v-model="sendSmsForm.templateParams[param]"
:placeholder="'请输入 ' + param + ' 参数'"
/>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="modelVisible = false"> </el-button>
</div>
</template>
</Dialog>
</template>
<script setup lang="ts" name="SmsTemplateFrom">
import { DICT_TYPE, getDictOptions, getDictLabel } from '@/utils/dict'
import * as templateApi from '@/api/system/sms/smsTemplate'
import * as SmsChannelApi from '@/api/system/sms/smsChannel'
const { t } = useI18n() //
const message = useMessage() //
defineProps({
channelOptions: {
type: Array as PropType<SmsChannelApi.SmsChannelListVO[]>,
define: () => {}
}
})
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') //
const formData = ref<templateApi.SmsTemplateVO>({
id: null,
type: null,
status: null,
code: '',
name: '',
content: '',
remark: '',
apiTemplateId: '',
channelId: null
})
const formRules = reactive({
type: [{ required: true, message: '短信类型不能为空', trigger: 'change' }],
status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }],
code: [{ required: true, message: '模板编码不能为空', trigger: 'blur' }],
name: [{ required: true, message: '模板名称不能为空', trigger: 'blur' }],
content: [{ required: true, message: '模板内容不能为空', trigger: 'blur' }],
apiTemplateId: [{ required: true, message: '短信 API 的模板编号不能为空', trigger: 'blur' }],
channelId: [{ required: true, message: '短信渠道编号不能为空', trigger: 'change' }]
})
const formRef = ref() // Ref
const optionLabel = computed(
() => (type: string, code: string) => `${getDictLabel(type, code)}`
)
//
const sendSmsForm = ref({
content: '',
params: {},
mobile: '',
templateCode: '',
templateParams: {}
})
const sendSmsRules = reactive({
mobile: [{ required: true, message: '手机不能为空', trigger: 'blur' }],
templateCode: [{ required: true, message: '模版编码不能为空', trigger: 'blur' }],
templateParams: {}
})
const sendSmsFormRef = ref()
/** 打开弹窗 */
interface openModalOption {
type: string
id?: ''
row?: any
}
const openModal = async (option: openModalOption) => {
modelVisible.value = true
modelTitle.value = t('dialog.sms.' + option.type)
formType.value = option.type
resetForm()
resetSendSms()
//
if (option.row) {
sendSmsForm.value.content = option.row.content
sendSmsForm.value.params = option.row.params
sendSmsForm.value.templateCode = option.row.code
sendSmsForm.value.templateParams = option.row.params.reduce(function (obj, item) {
obj[item] = undefined
return obj
}, {})
sendSmsRules.templateParams = option.row.params.reduce(function (obj, item) {
obj[item] = { required: true, message: '参数 ' + item + ' 不能为空', trigger: 'change' }
return obj
}, {})
}
//
if (option.id) {
formLoading.value = true
try {
formData.value = await templateApi.getSmsTemplateApi(option.id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ openModal }) // openModal
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
if (['template.addTitle', 'template.updtaeTitle'].includes(formType.value)) {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as templateApi.SmsTemplateVO
if (formType.value === 'template.addTitle') {
await templateApi.createSmsTemplateApi(data)
message.success(t('common.createSuccess'))
} else {
await templateApi.updateSmsTemplateApi(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
if (formType.value === 'template.sendSms') {
sendSmsTest()
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: null,
type: null,
status: null,
code: '',
name: '',
content: '',
remark: '',
apiTemplateId: '',
channelId: null
}
formRef.value?.resetFields()
}
/** 重置发送短信的表单 */
const resetSendSms = () => {
// row
sendSmsForm.value = {
content: '',
params: {},
mobile: '',
templateCode: '',
templateParams: {}
}
sendSmsFormRef.value?.resetFields()
}
/** 发送短信 */
const sendSmsTest = async () => {
const data: templateApi.SendSmsReqVO = {
mobile: sendSmsForm.value.mobile,
templateCode: sendSmsForm.value.templateCode,
templateParams: sendSmsForm.value.templateParams as unknown as Map<string, Object>
}
const res = await templateApi.sendSmsApi(data)
if (res) {
message.success('提交发送成功!发送结果,见发送日志编号:' + res)
}
formLoading.value = false
}
</script>

View File

@ -1,232 +1,340 @@
<template>
<ContentWrap>
<!-- 列表 -->
<XTable @register="registerTable">
<!-- 操作新增 -->
<template #toolbar_buttons>
<XButton
type="primary"
preIcon="ep:zoom-in"
:title="t('action.add')"
v-hasPermi="['system:sms-channel:create']"
@click="handleCreate()"
/>
</template>
<template #actionbtns_default="{ row }">
<XTextButton
preIcon="ep:cpu"
:title="t('action.test')"
v-hasPermi="['system:sms-template:send-sms']"
@click="handleSendSms(row)"
/>
<!-- 操作修改 -->
<XTextButton
preIcon="ep:edit"
:title="t('action.edit')"
v-hasPermi="['system:sms-template:update']"
@click="handleUpdate(row.id)"
/>
<!-- 操作详情 -->
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
v-hasPermi="['system:sms-template:query']"
@click="handleDetail(row.id)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.del')"
v-hasPermi="['system:sms-template:delete']"
@click="deleteData(row.id)"
/>
</template>
</XTable>
</ContentWrap>
<XModal id="smsTemplate" v-model="dialogVisible" :title="dialogTitle">
<!-- 对话框(添加 / 修改) -->
<Form
v-if="['create', 'update'].includes(actionType)"
:schema="allSchemas.formSchema"
:rules="rules"
ref="formRef"
/>
<!-- 对话框(详情) -->
<Descriptions
v-if="actionType === 'detail'"
:schema="allSchemas.detailSchema"
:data="detailData"
/>
<!-- 操作按钮 -->
<template #footer>
<!-- 按钮保存 -->
<XButton
v-if="['create', 'update'].includes(actionType)"
type="primary"
:title="t('action.save')"
:loading="actionLoading"
@click="submitForm()"
/>
<!-- 按钮关闭 -->
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
<XModal id="sendTest" v-model="sendVisible" title="测试">
<el-form :model="sendSmsForm" :rules="sendSmsRules" label-width="200px" label-position="top">
<el-form-item label="模板内容" prop="content">
<el-input
v-model="sendSmsForm.content"
type="textarea"
placeholder="请输入模板内容"
readonly
/>
</el-form-item>
<el-form-item label="手机号" prop="mobile">
<el-input v-model="sendSmsForm.mobile" placeholder="请输入手机号" />
</el-form-item>
<el-form-item
v-for="param in sendSmsForm.params"
:key="param"
:label="'参数 {' + param + '}'"
:prop="'templateParams.' + param"
<content-wrap>
<!-- 搜索工作栏 -->
<el-form
:model="queryParams"
ref="queryForm"
:inline="true"
v-show="showSearch"
label-width="150px"
>
<el-input
v-model="sendSmsForm.templateParams[param]"
:placeholder="'请输入 ' + param + ' 参数'"
<el-form-item label="短信类型" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择短信类型" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="开启状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择开启状态" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="模板编码" prop="code">
<el-input
v-model="queryParams.code"
placeholder="请输入模板编码"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="短信 API 的模板编号" prop="apiTemplateId">
<el-input
v-model="queryParams.apiTemplateId"
placeholder="请输入短信 API 的模板编号"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="短信渠道" prop="channelId">
<el-select v-model="queryParams.channelId" placeholder="请选择短信渠道" clearable>
<el-option
v-for="channel in channelOptions"
:key="channel.id"
:value="channel.id"
:label="
channel.signature +
'【' +
getDictObj(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE, channel.code) +
'】'
"
/>
</el-select>
</el-form-item>
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
style="width: 240px"
value-format="yyyy-MM-dd HH:mm:ss"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="['00:00:00', '23:59:59']"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
</el-form>
<!-- 操作按钮 -->
<template #footer>
<XButton
<!-- 操作工具栏 -->
<el-row>
<el-col :span="12">
<el-row :gutter="10">
<el-col :span="1.5">
<el-button
type="primary"
:title="t('action.test')"
:loading="actionLoading"
@click="sendSmsTest()"
plain
@click="handleAdd('template.addTitle')"
v-hasPermi="['system:sms-template:create']"
><Icon icon="ep:plus" class="mr-5px" />新增</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['system:sms-template:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出
</el-button>
</el-col>
</el-row>
</el-col>
<el-col :span="12">
<right-toolbar v-model:showSearch="showSearch" @query-table="getList" />
</el-col>
</el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="templateList" align="center">
<el-table-column
label="模板编码"
align="center"
prop="code"
width="120"
:show-overflow-tooltip="true"
/>
<XButton :title="t('dialog.close')" @click="sendVisible = false" />
<el-table-column
label="模板名称"
align="center"
prop="name"
width="120"
:show-overflow-tooltip="true"
/>
<el-table-column
label="模板内容"
align="center"
prop="content"
width="200"
:show-overflow-tooltip="true"
/>
<el-table-column label="短信类型" align="center" prop="type">
<template #default="scope">
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE" :value="scope.row.type" />
</template>
</XModal>
</el-table-column>
<el-table-column label="状态" align="center" prop="status" width="80">
<template #default="scope">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column
label="短信 API 的模板编号"
align="center"
prop="apiTemplateId"
width="200"
:show-overflow-tooltip="true"
/>
<el-table-column label="短信渠道" align="center" width="120">
<template #default="scope">
<div>{{ formatChannelSignature(scope.row.channelId) }}</div>
<dict-tag :type="DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE" :value="scope.row.channelCode" />
</template>
</el-table-column>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
width="180"
:formatter="dateFormatter"
/>
<el-table-column
label="操作"
align="center"
class-name="small-padding fixed-width"
width="210"
fixed="right"
>
<template #default="scope">
<el-button
link
type="primary"
@click="handleSendSms('template.sendSms', scope.row)"
v-hasPermi="['system:sms-template:send-sms']"
><Icon icon="ep:share" class="mr-3px" />测试</el-button
>
<el-button
link
type="primary"
@click="handleUpdate('template.updtaeTitle', scope.row)"
v-hasPermi="['system:sms-template:update']"
><Icon icon="ep:edit" class="mr-3px" />修改</el-button
>
<el-button
link
type="primary"
@click="handleDelete(scope.row)"
v-hasPermi="['system:sms-template:delete']"
><Icon icon="ep:delete" class="mr-3px" />删除</el-button
>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</content-wrap>
<!-- 表单弹窗添加/修改 -->
<SmsTemplateFrom ref="modalRef" :channelOptions="channelOptions" @success="getList" />
</template>
<script setup lang="ts" name="SmsTemplate">
import type { FormExpose } from '@/components/Form'
// import
import * as SmsTemplateApi from '@/api/system/sms/smsTemplate'
import { rules, allSchemas } from './sms.template.data'
const { t } = useI18n() //
import { DICT_TYPE, getDictOptions, getDictObj } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import * as templateApi from '@/api/system/sms/smsTemplate'
import * as SmsChannelApi from '@/api/system/sms/smsChannel'
import download from '@/utils/download'
import SmsTemplateFrom from './form.vue'
const message = useMessage() //
// const { t } = useI18n() //
//
const [registerTable, { reload, deleteData }] = useXTable({
allSchemas: allSchemas,
getListApi: SmsTemplateApi.getSmsTemplatePageApi,
deleteApi: SmsTemplateApi.deleteSmsTemplateApi
// ref
const modalRef = ref()
//
const loading = ref(true)
//
// const exportLoading = ref(false)
//
const showSearch = ref(true)
// ref
const queryForm = ref()
//
const queryParams = ref<templateApi.SmsTemplatePageReqVO>({
pageNo: 1,
pageSize: 10,
type: null,
status: null,
code: '',
content: '',
apiTemplateId: '',
channelId: null,
createTime: []
})
//
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const actionType = ref('') //
const actionLoading = ref(false) // Loading
const formRef = ref<FormExpose>() // Ref
const detailData = ref() // Ref
//
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
actionType.value = type
dialogVisible.value = true
}
//
const handleCreate = () => {
setDialogTile('create')
}
//
const handleUpdate = async (rowId: number) => {
setDialogTile('update')
//
const res = await SmsTemplateApi.getSmsTemplateApi(rowId)
unref(formRef)?.setValues(res)
}
//
const handleDetail = async (rowId: number) => {
setDialogTile('detail')
//
const res = await SmsTemplateApi.getSmsTemplateApi(rowId)
detailData.value = res
}
//
const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true
//
try {
const data = unref(formRef)?.formModel as SmsTemplateApi.SmsTemplateVO
if (actionType.value === 'create') {
await SmsTemplateApi.createSmsTemplateApi(data)
message.success(t('common.createSuccess'))
} else {
await SmsTemplateApi.updateSmsTemplateApi(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
} finally {
actionLoading.value = false
//
await reload()
}
}
//
const total = ref(0)
//
const templateList = ref([])
/** 查询列表 */
const getList = () => {
loading.value = true
//
templateApi.getSmsTemplatePageApi(queryParams.value).then((response) => {
templateList.value = response.list
total.value = response.total
loading.value = false
})
}
// ========== ==========
const sendSmsForm = ref({
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
resetForm()
handleQuery()
}
/** 重置搜索表单 */
const resetForm = () => {
queryParams.value = {
pageNo: 1,
pageSize: 10,
type: null,
status: null,
code: '',
content: '',
params: {},
mobile: '',
templateCode: '',
templateParams: {}
apiTemplateId: '',
channelId: null,
createTime: []
}
queryForm.value?.resetFields()
}
//
const channelOptions = ref<SmsChannelApi.SmsChannelListVO[]>([])
onMounted(() => {
SmsChannelApi.getSimpleSmsChannels().then((res) => {
channelOptions.value = res
})
})
const sendSmsRules = ref({
mobile: [{ required: true, message: '手机不能为空', trigger: 'blur' }],
templateCode: [{ required: true, message: '模版编号不能为空', trigger: 'blur' }],
templateParams: {}
})
const sendVisible = ref(false)
const handleSendSms = (row: any) => {
sendSmsForm.value.content = row.content
sendSmsForm.value.params = row.params
sendSmsForm.value.templateCode = row.code
sendSmsForm.value.templateParams = row.params.reduce(function (obj, item) {
obj[item] = undefined
return obj
}, {})
sendSmsRules.value.templateParams = row.params.reduce(function (obj, item) {
obj[item] = { required: true, message: '参数 ' + item + ' 不能为空', trigger: 'change' }
return obj
}, {})
sendVisible.value = true
/** 格式化短信渠道 */
const formatChannelSignature = (channelId: number) => {
channelOptions.value.forEach((item) => {
if (item.id === channelId) {
return item.signature
}
})
return '找不到签名:' + channelId
}
/** 新增按钮操作 */
const handleAdd = (type: string) => {
modalRef.value.openModal({ type })
}
/** 修改按钮操作 */
// const handleUpdate = (row) => {}
const exportLoading = ref(false)
/** 导出按钮操作 */
const handleExport = () => {
//
let params = { ...queryParams.value } as templateApi.SmsTemplateExportReqVO
//
message
.confirm('是否确认导出所有短信模板数据项?', '警告')
.then(() => {
exportLoading.value = true
return templateApi.exportPostApi(params)
})
.then((response) => {
download.excel(response, '短信模板.xls')
exportLoading.value = false
})
.catch(() => {})
}
/** 发送短信按钮 */
const handleSendSms = (type, row: any) => {
modalRef.value.openModal({ type, row })
}
const handleUpdate = (type: string, { id }: { id: number }) => {
modalRef.value.openModal({ type, id })
}
/** 删除按钮操作 */
const handleDelete = ({ id }: { id: number }) => {
message
.confirm('是否确认删除短信模板编号为"' + id + '"的数据项?')
.then(function () {
return templateApi.deleteSmsTemplateApi(id)
})
.then(() => {
getList()
message.success('删除成功')
})
.catch(() => {})
}
const sendSmsTest = async () => {
const data: SmsTemplateApi.SendSmsReqVO = {
mobile: sendSmsForm.value.mobile,
templateCode: sendSmsForm.value.templateCode,
templateParams: sendSmsForm.value.templateParams as unknown as Map<string, Object>
}
const res = await SmsTemplateApi.sendSmsApi(data)
if (res) {
message.success('提交发送成功!发送结果,见发送日志编号:' + res)
}
sendVisible.value = false
}
getList()
</script>

View File

@ -1,107 +0,0 @@
import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas'
import * as smsApi from '@/api/system/sms/smsChannel'
const { t } = useI18n() // 国际化
const tenantPackageOption = []
const getTenantPackageOptions = async () => {
const res = await smsApi.getSimpleSmsChannels()
console.log(res, 'resresres')
res.forEach((tenantPackage: TenantPackageVO) => {
tenantPackageOption.push({
key: tenantPackage.id,
value: tenantPackage.id,
label: tenantPackage.signature
})
})
}
getTenantPackageOptions()
// 表单校验
export const rules = reactive({
type: [required],
status: [required],
code: [required],
name: [required],
content: [required],
apiTemplateId: [required],
channelId: [required]
})
// CrudSchema
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'id',
primaryTitle: '模板编号',
action: true,
actionWidth: '280',
columns: [
{
title: '短信渠道编码',
field: 'channelId',
isSearch: false,
isForm: true,
isTable: false,
form: {
component: 'Select',
componentProps: {
options: tenantPackageOption
}
}
},
{
title: '模板编码',
field: 'code',
isSearch: true
},
{
title: '模板名称',
field: 'name',
isSearch: true
},
{
title: '模板内容',
field: 'content'
},
{
title: '短信 API 的模板编号',
field: 'apiTemplateId',
isSearch: true
},
{
title: '短信类型',
field: 'type',
dictType: DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE,
dictClass: 'number',
isSearch: true,
table: {
width: 80
}
},
{
title: t('common.status'),
field: 'status',
dictType: DICT_TYPE.COMMON_STATUS,
dictClass: 'number',
isSearch: true,
table: {
width: 80
}
},
{
title: t('form.remark'),
field: 'remark',
isTable: false
},
{
title: t('common.createTime'),
field: 'createTime',
formatter: 'formatDate',
isForm: false,
search: {
show: true,
itemRender: {
name: 'XDataTimePicker'
}
}
}
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)