Skip to content

Commit b3b1d97

Browse files
committed
支付应用:微信支付的添加代码优化
1 parent 86e0a37 commit b3b1d97

File tree

3 files changed

+61
-68
lines changed

3 files changed

+61
-68
lines changed

src/views/pay/app/components/channel/AlipayChannelForm.vue

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
<template>
22
<div>
3-
<Dialog
4-
v-model="dialogVisible"
5-
:title="dialogTitle"
6-
@closed="close"
7-
append-to-body
8-
destroy-on-close
9-
width="830px"
10-
>
3+
<Dialog v-model="dialogVisible" :title="dialogTitle" @closed="close" width="830px">
114
<el-form
125
ref="formRef"
136
:model="formData"
@@ -164,11 +157,13 @@
164157
</Dialog>
165158
</div>
166159
</template>
167-
<script lang="ts" setup name="AlipayChannelForm">
160+
<script lang="ts" setup>
168161
import { CommonStatusEnum } from '@/utils/constants'
169162
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
170163
import * as ChannelApi from '@/api/pay/channel'
171164
165+
defineOptions({ name: 'AlipayChannelForm' })
166+
172167
const { t } = useI18n() // 国际化
173168
const message = useMessage() // 消息弹窗
174169

src/views/pay/app/components/weixinChannelForm.vue renamed to src/views/pay/app/components/channel/WeixinChannelForm.vue

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
<template>
22
<div>
3-
<el-dialog
4-
v-model="dialogVisible"
5-
:title="title"
6-
@close="close"
7-
append-to-body
8-
destroy-on-close
9-
width="800px"
10-
>
3+
<Dialog v-model="dialogVisible" :title="dialogTitle" @close="close" width="800px">
114
<el-form
125
ref="formRef"
136
:model="formData"
14-
:rules="rules"
7+
:rules="formRules"
158
label-width="120px"
169
v-loading="formLoading"
1710
>
@@ -86,7 +79,9 @@
8679
:before-upload="p12FileBeforeUpload"
8780
:http-request="keyContentUpload"
8881
>
89-
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
82+
<el-button type="primary">
83+
<Icon icon="ep:upload" class="mr-5px" /> 点击上传
84+
</el-button>
9085
</el-upload>
9186
</el-form-item>
9287
</div>
@@ -124,7 +119,9 @@
124119
:before-upload="pemFileBeforeUpload"
125120
:http-request="privateKeyContentUpload"
126121
>
127-
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
122+
<el-button type="primary">
123+
<Icon icon="ep:upload" class="mr-5px" /> 点击上传
124+
</el-button>
128125
</el-upload>
129126
</el-form-item>
130127
<el-form-item
@@ -150,7 +147,9 @@
150147
:before-upload="pemFileBeforeUpload"
151148
:http-request="privateCertContentUpload"
152149
>
153-
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
150+
<el-button type="primary">
151+
<Icon icon="ep:upload" class="mr-5px" /> 点击上传
152+
</el-button>
154153
</el-upload>
155154
</el-form-item>
156155
</div>
@@ -162,19 +161,22 @@
162161
<el-button @click="close">取消</el-button>
163162
<el-button type="primary" @click="submitForm">确定</el-button>
164163
</template>
165-
</el-dialog>
164+
</Dialog>
166165
</div>
167166
</template>
168-
<script lang="ts" setup name="WeixinChannelForm">
169-
import { createChannel, getChannel, updateChannel } from '@/api/pay/channel'
167+
<script lang="ts" setup>
170168
import { CommonStatusEnum } from '@/utils/constants'
171169
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
170+
import * as ChannelApi from '@/api/pay/channel'
172171
172+
defineOptions({ name: 'WeixinChannelForm' })
173+
174+
const { t } = useI18n() // 国际化
173175
const message = useMessage() // 消息弹窗
174176
175-
const dialogVisible = ref(false)
176-
const formLoading = ref(false)
177-
const title = ref('')
177+
const dialogVisible = ref(false) // 弹窗的是否展示
178+
const dialogTitle = ref('') // 弹窗的标题
179+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
178180
const formData = ref<any>({
179181
appId: '',
180182
code: '',
@@ -192,11 +194,7 @@ const formData = ref<any>({
192194
apiV3Key: ''
193195
}
194196
})
195-
const formRef = ref()
196-
197-
const emit = defineEmits(['success'])
198-
199-
const rules = {
197+
const formRules = {
200198
feeRate: [{ required: true, message: '请输入渠道费率', trigger: 'blur' }],
201199
status: [{ required: true, message: '渠道状态不能为空', trigger: 'blur' }],
202200
'config.mchId': [{ required: true, message: '请传入商户号', trigger: 'blur' }],
@@ -214,53 +212,56 @@ const rules = {
214212
],
215213
'config.apiV3Key': [{ required: true, message: '请上传 api V3 密钥值', trigger: 'blur' }]
216214
}
215+
const formRef = ref() // 表单 Ref
217216
217+
/** 打开弹窗 */
218218
const open = async (appId, code) => {
219219
dialogVisible.value = true
220220
formLoading.value = true
221-
reset(appId, code)
222-
221+
resetForm(appId, code)
222+
// 加载数据
223223
try {
224-
const data = await getChannel(appId, code)
224+
const data = await ChannelApi.getChannel(appId, code)
225225
if (data && data.id) {
226226
formData.value = data
227227
formData.value.config = JSON.parse(data.config)
228228
}
229-
title.value = !formData.value.id ? '创建支付渠道' : '编辑支付渠道'
229+
dialogTitle.value = !formData.value.id ? '创建支付渠道' : '编辑支付渠道'
230230
} finally {
231231
formLoading.value = false
232232
}
233233
}
234+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
234235
235-
const close = () => {
236-
dialogVisible.value = false
237-
reset(undefined, undefined)
238-
}
239-
236+
/** 提交表单 */
237+
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
240238
const submitForm = async () => {
239+
// 校验表单
240+
if (!formRef) return
241241
const valid = await formRef.value.validate()
242-
if (!valid) {
243-
return
244-
}
245-
const data: any = { ...formData.value }
246-
data.config = JSON.stringify(formData.value.config)
247-
if (!data.id) {
248-
createChannel(data).then(() => {
249-
message.alertSuccess('新增成功')
250-
emit('success')
251-
close()
252-
})
253-
} else {
254-
updateChannel(data).then(() => {
255-
message.alertSuccess('修改成功')
256-
emit('success')
257-
close()
258-
})
242+
if (!valid) return
243+
// 提交请求
244+
formLoading.value = true
245+
try {
246+
const data = { ...formData.value } as unknown as ChannelApi.ChannelVO
247+
data.config = JSON.stringify(formData.value.config)
248+
if (!data.id) {
249+
await ChannelApi.createChannel(data)
250+
message.success(t('common.createSuccess'))
251+
} else {
252+
await ChannelApi.updateChannel(data)
253+
message.success(t('common.updateSuccess'))
254+
}
255+
dialogVisible.value = false
256+
// 发送操作成功的事件
257+
emit('success')
258+
} finally {
259+
formLoading.value = false
259260
}
260261
}
261262
262263
/** 重置表单 */
263-
const reset = (appId, code) => {
264+
const resetForm = (appId, code) => {
264265
formData.value = {
265266
appId: appId,
266267
code: code,
@@ -338,6 +339,4 @@ const keyContentUpload = (event) => {
338339
}
339340
readFile.readAsDataURL(event.file) // 读成 base64
340341
}
341-
342-
defineExpose({ open })
343342
</script>

src/views/pay/app/index.vue

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@
305305
<script lang="ts" setup>
306306
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
307307
import download from '@/utils/download'
308-
import * as PayappApi from '@/api/pay/app'
308+
import * as AppApi from '@/api/pay/app'
309309
import AppForm from './components/AppForm.vue'
310310
import { PayChannelEnum, PayType } from '@/utils/constants'
311311
import AlipayChannelForm from './components/channel/AlipayChannelForm.vue'
312-
import WeixinChannelForm from './components/weixinChannelForm.vue'
312+
import WeixinChannelForm from './components/channel/WeixinChannelForm.vue'
313313
import MockChannelForm from './components/mockChannelForm.vue'
314314
import { CommonStatusEnum } from '@/utils/constants'
315315
@@ -333,7 +333,6 @@ const queryParams = reactive({
333333
remark: undefined,
334334
payNotifyUrl: undefined,
335335
refundNotifyUrl: undefined,
336-
merchantName: undefined,
337336
createTime: []
338337
})
339338
const queryFormRef = ref() // 搜索的表单
@@ -343,7 +342,7 @@ const exportLoading = ref(false) // 导出的加载中
343342
const getList = async () => {
344343
loading.value = true
345344
try {
346-
const data = await PayappApi.getAppPage(queryParams)
345+
const data = await AppApi.getAppPage(queryParams)
347346
list.value = data.list
348347
total.value = data.total
349348
} finally {
@@ -368,7 +367,7 @@ const handleStatusChange = async (row: any) => {
368367
let text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
369368
try {
370369
await message.confirm('确认要"' + text + '""' + row.name + '"应用吗?')
371-
await PayappApi.changeAppStatus({ id: row.id, status: row.status })
370+
await AppApi.changeAppStatus({ id: row.id, status: row.status })
372371
message.success(text + '成功')
373372
} catch {
374373
row.status =
@@ -393,7 +392,7 @@ const handleDelete = async (id: number) => {
393392
// 删除的二次确认
394393
await message.delConfirm()
395394
// 发起删除
396-
await PayappApi.deleteApp(id)
395+
await AppApi.deleteApp(id)
397396
message.success(t('common.delSuccess'))
398397
// 刷新列表
399398
await getList()
@@ -407,7 +406,7 @@ const handleExport = async () => {
407406
await message.exportConfirm()
408407
// 发起导出
409408
exportLoading.value = true
410-
const data = await PayappApi.exportApp(queryParams)
409+
const data = await AppApi.exportApp(queryParams)
411410
download.excel(data, '支付应用信息.xls')
412411
} finally {
413412
exportLoading.value = false

0 commit comments

Comments
 (0)