mirror of
				https://gitee.com/hhyykk/ipms-sjy-ui.git
				synced 2025-10-31 02:08:45 +08:00 
			
		
		
		
	Vue3 重构:REVIEW 短信渠道
This commit is contained in:
		| @@ -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 }) | ||||
| } | ||||
|   | ||||
| @@ -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) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | ||||
| 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: '', | ||||
| @@ -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() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV