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
}
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 })
}
@ -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 })
}
// 新增短信渠道
export const createSmsChannelApi = (data: SmsChannelVO) => {
export const createSmsChannel = (data: SmsChannelVO) => {
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 })
}
// 删除短信渠道
export const deleteSmsChannelApi = (id: number) => {
export const deleteSmsChannel = (id: number) => {
return request.delete({ url: '/system/sms-channel/delete?id=' + id })
}

View File

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

View File

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