Skip to content

Commit fa32194

Browse files
committed
Vue3 重构:REVIEW 短信渠道
1 parent 74aeffe commit fa32194

File tree

3 files changed

+71
-109
lines changed

3 files changed

+71
-109
lines changed

src/api/system/sms/smsChannel/index.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,8 @@ export interface SmsChannelVO {
1212
createTime: Date
1313
}
1414

15-
export interface SmsChannelListVO {
16-
id: number
17-
code: string
18-
signature: string
19-
}
20-
21-
export interface SmsChannelPageReqVO extends PageParam {
22-
signature?: string
23-
code?: string
24-
status?: number
25-
createTime?: Date[]
26-
}
27-
2815
// 查询短信渠道列表
29-
export const getSmsChannelPageApi = (params: SmsChannelPageReqVO) => {
16+
export const getSmsChannelPage = (params: PageParam) => {
3017
return request.get({ url: '/system/sms-channel/page', params })
3118
}
3219

@@ -36,21 +23,21 @@ export function getSimpleSmsChannelList() {
3623
}
3724

3825
// 查询短信渠道详情
39-
export const getSmsChannelApi = (id: number) => {
26+
export const getSmsChannel = (id: number) => {
4027
return request.get({ url: '/system/sms-channel/get?id=' + id })
4128
}
4229

4330
// 新增短信渠道
44-
export const createSmsChannelApi = (data: SmsChannelVO) => {
31+
export const createSmsChannel = (data: SmsChannelVO) => {
4532
return request.post({ url: '/system/sms-channel/create', data })
4633
}
4734

4835
// 修改短信渠道
49-
export const updateSmsChannelApi = (data: SmsChannelVO) => {
36+
export const updateSmsChannel = (data: SmsChannelVO) => {
5037
return request.put({ url: '/system/sms-channel/update', data })
5138
}
5239

5340
// 删除短信渠道
54-
export const deleteSmsChannelApi = (id: number) => {
41+
export const deleteSmsChannel = (id: number) => {
5542
return request.delete({ url: '/system/sms-channel/delete?id=' + id })
5643
}

src/views/system/sms/channel/form.vue renamed to src/views/system/sms/channel/SmsChannelForm.vue

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,77 @@
11
<template>
22
<Dialog :title="modelTitle" v-model="modelVisible">
3-
<el-form ref="formRef" :model="form" :rules="rules" label-width="130px" v-loading="formLoading">
3+
<el-form
4+
ref="formRef"
5+
:model="formData"
6+
:rules="formRules"
7+
label-width="130px"
8+
v-loading="formLoading"
9+
>
410
<el-form-item label="短信签名" prop="signature">
5-
<el-input v-model="form.signature" placeholder="请输入短信签名" />
11+
<el-input v-model="formData.signature" placeholder="请输入短信签名" />
612
</el-form-item>
713
<el-form-item label="渠道编码" prop="code">
8-
<el-select v-model="form.code" placeholder="请选择渠道编码" clearable>
14+
<el-select v-model="formData.code" placeholder="请选择渠道编码" clearable>
915
<el-option
10-
v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE)"
16+
v-for="dict in getStrDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE)"
1117
:key="dict.value"
1218
:label="dict.label"
1319
:value="dict.value"
1420
/>
1521
</el-select>
1622
</el-form-item>
1723
<el-form-item label="启用状态">
18-
<el-radio-group v-model="form.status">
24+
<el-radio-group v-model="formData.status">
1925
<el-radio
20-
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
26+
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
2127
:key="dict.value"
22-
:label="parseInt(dict.value)"
23-
>{{ dict.label }}</el-radio
28+
:label="dict.value"
2429
>
30+
{{ dict.label }}
31+
</el-radio>
2532
</el-radio-group>
2633
</el-form-item>
2734
<el-form-item label="备注" prop="remark">
28-
<el-input v-model="form.remark" placeholder="请输入备注" />
35+
<el-input v-model="formData.remark" placeholder="请输入备注" />
2936
</el-form-item>
3037
<el-form-item label="短信 API 的账号" prop="apiKey">
31-
<el-input v-model="form.apiKey" placeholder="请输入短信 API 的账号" />
38+
<el-input v-model="formData.apiKey" placeholder="请输入短信 API 的账号" />
3239
</el-form-item>
3340
<el-form-item label="短信 API 的密钥" prop="apiSecret">
34-
<el-input v-model="form.apiSecret" placeholder="请输入短信 API 的密钥" />
41+
<el-input v-model="formData.apiSecret" placeholder="请输入短信 API 的密钥" />
3542
</el-form-item>
3643
<el-form-item label="短信发送回调 URL" prop="callbackUrl">
37-
<el-input v-model="form.callbackUrl" placeholder="请输入短信发送回调 URL" />
44+
<el-input v-model="formData.callbackUrl" placeholder="请输入短信发送回调 URL" />
3845
</el-form-item>
3946
</el-form>
4047
<template #footer>
41-
<div class="dialog-footer">
42-
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
43-
<el-button @click="modelVisible = false">取 消</el-button>
44-
</div>
48+
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
49+
<el-button @click="modelVisible = false">取 消</el-button>
4550
</template>
4651
</Dialog>
4752
</template>
4853
<script setup lang="ts">
49-
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
54+
import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict'
5055
import * as SmsChannelApi from '@/api/system/sms/smsChannel'
51-
56+
import { CommonStatusEnum } from '@/utils/constants'
5257
const { t } = useI18n() // 国际化
5358
const message = useMessage() // 消息弹窗
5459
5560
const modelVisible = ref(false) // 弹窗的是否展示
5661
const modelTitle = ref('') // 弹窗的标题
5762
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
5863
const formType = ref('') // 表单的类型:create - 新增;update - 修改
59-
const form = ref({
64+
const formData = ref({
6065
id: undefined,
6166
signature: '',
6267
code: '',
63-
status: '',
68+
status: CommonStatusEnum.ENABLE,
6469
remark: '',
6570
apiKey: '',
6671
apiSecret: '',
6772
callbackUrl: ''
6873
})
69-
const rules = reactive({
74+
const formRules = reactive({
7075
signature: [{ required: true, message: '短信签名不能为空', trigger: 'blur' }],
7176
code: [{ required: true, message: '渠道编码不能为空', trigger: 'blur' }],
7277
status: [{ required: true, message: '启用状态不能为空', trigger: 'blur' }],
@@ -75,7 +80,7 @@ const rules = reactive({
7580
const formRef = ref() // 表单 Ref
7681
7782
/** 打开弹窗 */
78-
const openModal = async (type: string, id?: number) => {
83+
const open = async (type: string, id?: number) => {
7984
modelVisible.value = true
8085
modelTitle.value = t('action.' + type)
8186
formType.value = type
@@ -84,15 +89,14 @@ const openModal = async (type: string, id?: number) => {
8489
if (id) {
8590
formLoading.value = true
8691
try {
87-
form.value = await SmsChannelApi.getSmsChannelApi(id)
88-
console.log(form)
92+
formData.value = await SmsChannelApi.getSmsChannel(id)
93+
console.log(formData)
8994
} finally {
9095
formLoading.value = false
9196
}
9297
}
9398
}
94-
95-
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
99+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
96100
97101
/** 提交表单 */
98102
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
@@ -106,10 +110,10 @@ const submitForm = async () => {
106110
try {
107111
const data = unref(formRef)?.formModel as SmsChannelApi.SmsChannelVO
108112
if (formType.value === 'create') {
109-
await SmsChannelApi.createSmsChannelApi(data)
113+
await SmsChannelApi.createSmsChannel(data)
110114
message.success(t('common.createSuccess'))
111115
} else {
112-
await SmsChannelApi.updateSmsChannelApi(data)
116+
await SmsChannelApi.updateSmsChannel(data)
113117
message.success(t('common.updateSuccess'))
114118
}
115119
modelVisible.value = false
@@ -122,11 +126,11 @@ const submitForm = async () => {
122126
123127
/** 重置表单 */
124128
const resetForm = () => {
125-
form.value = {
129+
formData.value = {
126130
id: undefined,
127131
signature: '',
128132
code: '',
129-
status: '',
133+
status: CommonStatusEnum.ENABLE,
130134
remark: '',
131135
apiKey: '',
132136
apiSecret: '',

src/views/system/sms/channel/index.vue

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<template>
22
<ContentWrap>
3-
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
3+
<el-form
4+
class="-mb-15px"
5+
:model="queryParams"
6+
ref="queryFormRef"
7+
:inline="true"
8+
label-width="68px"
9+
>
410
<el-form-item label="短信签名" prop="signature">
511
<el-input
612
v-model="queryParams.signature"
@@ -12,10 +18,10 @@
1218
<el-form-item label="启用状态" prop="status">
1319
<el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable>
1420
<el-option
15-
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
16-
:key="parseInt(dict.value)"
21+
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
22+
:key="dict.value"
1723
:label="dict.label"
18-
:value="parseInt(dict.value)"
24+
:value="dict.value"
1925
/>
2026
</el-select>
2127
</el-form-item>
@@ -34,24 +40,17 @@
3440
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
3541
<el-button
3642
type="primary"
37-
@click="openModal('create')"
43+
@click="openForm('create')"
3844
v-hasPermi="['system:sms-channel:create']"
3945
>
4046
<Icon icon="ep:plus" class="mr-5px" /> 新增</el-button
4147
>
42-
<el-button
43-
type="success"
44-
plain
45-
@click="handleExport"
46-
:loading="exportLoading"
47-
v-hasPermi="['system:sms-channel:export']"
48-
>
49-
<Icon icon="ep:download" class="mr-5px" /> 导出</el-button
50-
>
5148
</el-form-item>
5249
</el-form>
50+
</ContentWrap>
5351

54-
<!-- 列表 -->
52+
<!-- 列表 -->
53+
<ContentWrap>
5554
<el-table v-loading="loading" :data="list" align="center">
5655
<el-table-column label="编号" align="center" prop="id" />
5756
<el-table-column label="短信签名" align="center" prop="signature" />
@@ -71,18 +70,21 @@
7170
align="center"
7271
prop="apiKey"
7372
:show-overflow-tooltip="true"
73+
width="180"
7474
/>
7575
<el-table-column
7676
label="短信 API 的密钥"
7777
align="center"
7878
prop="apiSecret"
7979
:show-overflow-tooltip="true"
80+
width="180"
8081
/>
8182
<el-table-column
8283
label="短信发送回调 URL"
8384
align="center"
8485
prop="callbackUrl"
8586
:show-overflow-tooltip="true"
87+
width="180"
8688
/>
8789
<el-table-column
8890
label="创建时间"
@@ -96,7 +98,7 @@
9698
<el-button
9799
link
98100
type="primary"
99-
@click="openModal('update', scope.row.id)"
101+
@click="openForm('update', scope.row.id)"
100102
v-hasPermi="['system:sms-channel:update']"
101103
>
102104
编辑
@@ -120,35 +122,22 @@
120122
@pagination="getList"
121123
/>
122124
</ContentWrap>
125+
123126
<!-- 表单弹窗:添加/修改 -->
124-
<SmsChannelForm ref="modalRef" @success="getList" />
127+
<SmsChannelForm ref="formRef" @success="getList" />
125128
</template>
126129
<script setup lang="ts" name="SmsChannel">
127-
// 业务相关的 import
128-
import * as SmsChannelApi from '@/api/system/sms/smsChannel'
129-
//格式化时间
130+
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
130131
import { dateFormatter } from '@/utils/formatTime'
131-
//字典
132-
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
133-
//表单弹窗:添加/修改
134-
import SmsChannelForm from './form.vue'
135-
//下载
136-
// import download from '@/utils/download'
137-
132+
import * as SmsChannelApi from '@/api/system/sms/smsChannel'
133+
import SmsChannelForm from './SmsChannelForm.vue'
138134
const { t } = useI18n() // 国际化
139135
const message = useMessage() // 消息弹窗
140136
141-
// 列表的加载中
142-
const loading = ref(true)
143-
//搜索的表单
144-
const queryFormRef = ref()
145-
// 列表的总页数
146-
const total = ref(0)
147-
// 列表的数据
148-
const list = ref([])
149-
//导出的加载中
150-
const exportLoading = ref(false)
151-
//查询参数
137+
const loading = ref(false) // 列表的加载中
138+
const total = ref(0) // 列表的总页数
139+
const list = ref([]) // 列表的数据
140+
const queryFormRef = ref() // 搜索的表单
152141
const queryParams = reactive({
153142
pageNo: 1,
154143
pageSize: 10,
@@ -160,9 +149,8 @@ const queryParams = reactive({
160149
/** 查询参数列表 */
161150
const getList = async () => {
162151
loading.value = true
163-
// 执行查询
164152
try {
165-
const data = await SmsChannelApi.getSmsChannelPageApi(queryParams)
153+
const data = await SmsChannelApi.getSmsChannelPage(queryParams)
166154
list.value = data.list
167155
total.value = data.total
168156
} finally {
@@ -183,26 +171,9 @@ const resetQuery = () => {
183171
}
184172
185173
/** 添加/修改操作 */
186-
const modalRef = ref()
187-
const openModal = (type: string, id?: number) => {
188-
modalRef.value.openModal(type, id)
189-
}
190-
191-
/** 导出按钮操作 */
192-
const handleExport = async () => {
193-
try {
194-
// 导出的二次确认
195-
await message.exportConfirm()
196-
// 发起导出
197-
exportLoading.value = true
198-
await message.info('该功能目前不支持')
199-
//导出功能先不考虑
200-
// const data = await SmsChannelApi.exportSmsChanelApi(queryParams)
201-
// download.excel(data, '短信渠道.xls')
202-
} catch {
203-
} finally {
204-
exportLoading.value = false
205-
}
174+
const formRef = ref()
175+
const openForm = (type: string, id?: number) => {
176+
formRef.value.open(type, id)
206177
}
207178
208179
/** 删除按钮操作 */
@@ -211,7 +182,7 @@ const handleDelete = async (id: number) => {
211182
// 删除的二次确认
212183
await message.delConfirm()
213184
// 发起删除
214-
await SmsChannelApi.deleteSmsChannelApi(id)
185+
await SmsChannelApi.deleteSmsChannel(id)
215186
message.success(t('common.delSuccess'))
216187
// 刷新列表
217188
await getList()

0 commit comments

Comments
 (0)