Vue3 重构:REVIEW 短信渠道

This commit is contained in:
YunaiV 2023-03-25 00:41:06 +08:00
parent 74aeffec12
commit fa32194772
3 changed files with 71 additions and 109 deletions

View File

@ -12,21 +12,8 @@ export interface SmsChannelVO {
createTime: Date createTime: Date
} }
export interface SmsChannelListVO {
id: number
code: string
signature: string
}
export interface SmsChannelPageReqVO extends PageParam {
signature?: string
code?: string
status?: number
createTime?: Date[]
}
// 查询短信渠道列表 // 查询短信渠道列表
export const getSmsChannelPageApi = (params: SmsChannelPageReqVO) => { export const getSmsChannelPage = (params: PageParam) => {
return request.get({ url: '/system/sms-channel/page', params }) return request.get({ url: '/system/sms-channel/page', params })
} }
@ -36,21 +23,21 @@ export function getSimpleSmsChannelList() {
} }
// 查询短信渠道详情 // 查询短信渠道详情
export const getSmsChannelApi = (id: number) => { export const getSmsChannel = (id: number) => {
return request.get({ url: '/system/sms-channel/get?id=' + id }) return request.get({ url: '/system/sms-channel/get?id=' + id })
} }
// 新增短信渠道 // 新增短信渠道
export const createSmsChannelApi = (data: SmsChannelVO) => { export const createSmsChannel = (data: SmsChannelVO) => {
return request.post({ url: '/system/sms-channel/create', data }) return request.post({ url: '/system/sms-channel/create', data })
} }
// 修改短信渠道 // 修改短信渠道
export const updateSmsChannelApi = (data: SmsChannelVO) => { export const updateSmsChannel = (data: SmsChannelVO) => {
return request.put({ url: '/system/sms-channel/update', data }) return request.put({ url: '/system/sms-channel/update', data })
} }
// 删除短信渠道 // 删除短信渠道
export const deleteSmsChannelApi = (id: number) => { export const deleteSmsChannel = (id: number) => {
return request.delete({ url: '/system/sms-channel/delete?id=' + id }) return request.delete({ url: '/system/sms-channel/delete?id=' + id })
} }

View File

@ -1,13 +1,19 @@
<template> <template>
<Dialog :title="modelTitle" v-model="modelVisible"> <Dialog :title="modelTitle" v-model="modelVisible">
<el-form ref="formRef" :model="form" :rules="rules" label-width="130px" v-loading="formLoading"> <el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="130px"
v-loading="formLoading"
>
<el-form-item label="短信签名" prop="signature"> <el-form-item label="短信签名" prop="signature">
<el-input v-model="form.signature" placeholder="请输入短信签名" /> <el-input v-model="formData.signature" placeholder="请输入短信签名" />
</el-form-item> </el-form-item>
<el-form-item label="渠道编码" prop="code"> <el-form-item label="渠道编码" prop="code">
<el-select v-model="form.code" placeholder="请选择渠道编码" clearable> <el-select v-model="formData.code" placeholder="请选择渠道编码" clearable>
<el-option <el-option
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE)" v-for="dict in getStrDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE)"
:key="dict.value" :key="dict.value"
:label="dict.label" :label="dict.label"
:value="dict.value" :value="dict.value"
@ -15,40 +21,39 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="启用状态"> <el-form-item label="启用状态">
<el-radio-group v-model="form.status"> <el-radio-group v-model="formData.status">
<el-radio <el-radio
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)" v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value" :key="dict.value"
:label="parseInt(dict.value)" :label="dict.value"
>{{ dict.label }}</el-radio
> >
{{ dict.label }}
</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="备注" prop="remark"> <el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" /> <el-input v-model="formData.remark" placeholder="请输入备注" />
</el-form-item> </el-form-item>
<el-form-item label="短信 API 的账号" prop="apiKey"> <el-form-item label="短信 API 的账号" prop="apiKey">
<el-input v-model="form.apiKey" placeholder="请输入短信 API 的账号" /> <el-input v-model="formData.apiKey" placeholder="请输入短信 API 的账号" />
</el-form-item> </el-form-item>
<el-form-item label="短信 API 的密钥" prop="apiSecret"> <el-form-item label="短信 API 的密钥" prop="apiSecret">
<el-input v-model="form.apiSecret" placeholder="请输入短信 API 的密钥" /> <el-input v-model="formData.apiSecret" placeholder="请输入短信 API 的密钥" />
</el-form-item> </el-form-item>
<el-form-item label="短信发送回调 URL" prop="callbackUrl"> <el-form-item label="短信发送回调 URL" prop="callbackUrl">
<el-input v-model="form.callbackUrl" placeholder="请输入短信发送回调 URL" /> <el-input v-model="formData.callbackUrl" placeholder="请输入短信发送回调 URL" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<div class="dialog-footer">
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button> <el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="modelVisible = false"> </el-button> <el-button @click="modelVisible = false"> </el-button>
</div>
</template> </template>
</Dialog> </Dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict'
import * as SmsChannelApi from '@/api/system/sms/smsChannel' import * as SmsChannelApi from '@/api/system/sms/smsChannel'
import { CommonStatusEnum } from '@/utils/constants'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
@ -56,17 +61,17 @@ const modelVisible = ref(false) // 弹窗的是否展示
const modelTitle = ref('') // const modelTitle = ref('') //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const formType = ref('') // create - update - const formType = ref('') // create - update -
const form = ref({ const formData = ref({
id: undefined, id: undefined,
signature: '', signature: '',
code: '', code: '',
status: '', status: CommonStatusEnum.ENABLE,
remark: '', remark: '',
apiKey: '', apiKey: '',
apiSecret: '', apiSecret: '',
callbackUrl: '' callbackUrl: ''
}) })
const rules = reactive({ const formRules = reactive({
signature: [{ required: true, message: '短信签名不能为空', trigger: 'blur' }], signature: [{ required: true, message: '短信签名不能为空', trigger: 'blur' }],
code: [{ required: true, message: '渠道编码不能为空', trigger: 'blur' }], code: [{ required: true, message: '渠道编码不能为空', trigger: 'blur' }],
status: [{ required: true, message: '启用状态不能为空', trigger: 'blur' }], status: [{ required: true, message: '启用状态不能为空', trigger: 'blur' }],
@ -75,7 +80,7 @@ const rules = reactive({
const formRef = ref() // Ref const formRef = ref() // Ref
/** 打开弹窗 */ /** 打开弹窗 */
const openModal = async (type: string, id?: number) => { const open = async (type: string, id?: number) => {
modelVisible.value = true modelVisible.value = true
modelTitle.value = t('action.' + type) modelTitle.value = t('action.' + type)
formType.value = type formType.value = type
@ -84,15 +89,14 @@ const openModal = async (type: string, id?: number) => {
if (id) { if (id) {
formLoading.value = true formLoading.value = true
try { try {
form.value = await SmsChannelApi.getSmsChannelApi(id) formData.value = await SmsChannelApi.getSmsChannel(id)
console.log(form) console.log(formData)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
} }
} }
defineExpose({ open }) // open
defineExpose({ openModal }) // openModal
/** 提交表单 */ /** 提交表单 */
const emit = defineEmits(['success']) // success const emit = defineEmits(['success']) // success
@ -106,10 +110,10 @@ const submitForm = async () => {
try { try {
const data = unref(formRef)?.formModel as SmsChannelApi.SmsChannelVO const data = unref(formRef)?.formModel as SmsChannelApi.SmsChannelVO
if (formType.value === 'create') { if (formType.value === 'create') {
await SmsChannelApi.createSmsChannelApi(data) await SmsChannelApi.createSmsChannel(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await SmsChannelApi.updateSmsChannelApi(data) await SmsChannelApi.updateSmsChannel(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
modelVisible.value = false modelVisible.value = false
@ -122,11 +126,11 @@ const submitForm = async () => {
/** 重置表单 */ /** 重置表单 */
const resetForm = () => { const resetForm = () => {
form.value = { formData.value = {
id: undefined, id: undefined,
signature: '', signature: '',
code: '', code: '',
status: '', status: CommonStatusEnum.ENABLE,
remark: '', remark: '',
apiKey: '', apiKey: '',
apiSecret: '', apiSecret: '',

View File

@ -1,6 +1,12 @@
<template> <template>
<ContentWrap> <ContentWrap>
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px"> <el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="短信签名" prop="signature"> <el-form-item label="短信签名" prop="signature">
<el-input <el-input
v-model="queryParams.signature" v-model="queryParams.signature"
@ -12,10 +18,10 @@
<el-form-item label="启用状态" prop="status"> <el-form-item label="启用状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable> <el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable>
<el-option <el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)" v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="parseInt(dict.value)" :key="dict.value"
:label="dict.label" :label="dict.label"
:value="parseInt(dict.value)" :value="dict.value"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -34,24 +40,17 @@
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button <el-button
type="primary" type="primary"
@click="openModal('create')" @click="openForm('create')"
v-hasPermi="['system:sms-channel:create']" v-hasPermi="['system:sms-channel:create']"
> >
<Icon icon="ep:plus" class="mr-5px" /> 新增</el-button <Icon icon="ep:plus" class="mr-5px" /> 新增</el-button
> >
<el-button
type="success"
plain
@click="handleExport"
:loading="exportLoading"
v-hasPermi="['system:sms-channel:export']"
>
<Icon icon="ep:download" class="mr-5px" /> 导出</el-button
>
</el-form-item> </el-form-item>
</el-form> </el-form>
</ContentWrap>
<!-- 列表 --> <!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" align="center"> <el-table v-loading="loading" :data="list" align="center">
<el-table-column label="编号" align="center" prop="id" /> <el-table-column label="编号" align="center" prop="id" />
<el-table-column label="短信签名" align="center" prop="signature" /> <el-table-column label="短信签名" align="center" prop="signature" />
@ -71,18 +70,21 @@
align="center" align="center"
prop="apiKey" prop="apiKey"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
width="180"
/> />
<el-table-column <el-table-column
label="短信 API 的密钥" label="短信 API 的密钥"
align="center" align="center"
prop="apiSecret" prop="apiSecret"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
width="180"
/> />
<el-table-column <el-table-column
label="短信发送回调 URL" label="短信发送回调 URL"
align="center" align="center"
prop="callbackUrl" prop="callbackUrl"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
width="180"
/> />
<el-table-column <el-table-column
label="创建时间" label="创建时间"
@ -96,7 +98,7 @@
<el-button <el-button
link link
type="primary" type="primary"
@click="openModal('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['system:sms-channel:update']" v-hasPermi="['system:sms-channel:update']"
> >
编辑 编辑
@ -120,35 +122,22 @@
@pagination="getList" @pagination="getList"
/> />
</ContentWrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<SmsChannelForm ref="modalRef" @success="getList" /> <SmsChannelForm ref="formRef" @success="getList" />
</template> </template>
<script setup lang="ts" name="SmsChannel"> <script setup lang="ts" name="SmsChannel">
// import import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as SmsChannelApi from '@/api/system/sms/smsChannel'
//
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
// import * as SmsChannelApi from '@/api/system/sms/smsChannel'
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import SmsChannelForm from './SmsChannelForm.vue'
///
import SmsChannelForm from './form.vue'
//
// import download from '@/utils/download'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
// const loading = ref(false) //
const loading = ref(true) const total = ref(0) //
// const list = ref([]) //
const queryFormRef = ref() const queryFormRef = ref() //
//
const total = ref(0)
//
const list = ref([])
//
const exportLoading = ref(false)
//
const queryParams = reactive({ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
@ -160,9 +149,8 @@ const queryParams = reactive({
/** 查询参数列表 */ /** 查询参数列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
//
try { try {
const data = await SmsChannelApi.getSmsChannelPageApi(queryParams) const data = await SmsChannelApi.getSmsChannelPage(queryParams)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
@ -183,26 +171,9 @@ const resetQuery = () => {
} }
/** 添加/修改操作 */ /** 添加/修改操作 */
const modalRef = ref() const formRef = ref()
const openModal = (type: string, id?: number) => { const openForm = (type: string, id?: number) => {
modalRef.value.openModal(type, id) formRef.value.open(type, id)
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
await message.info('该功能目前不支持')
//
// const data = await SmsChannelApi.exportSmsChanelApi(queryParams)
// download.excel(data, '.xls')
} catch {
} finally {
exportLoading.value = false
}
} }
/** 删除按钮操作 */ /** 删除按钮操作 */
@ -211,7 +182,7 @@ const handleDelete = async (id: number) => {
// //
await message.delConfirm() await message.delConfirm()
// //
await SmsChannelApi.deleteSmsChannelApi(id) await SmsChannelApi.deleteSmsChannel(id)
message.success(t('common.delSuccess')) message.success(t('common.delSuccess'))
// //
await getList() await getList()