1
1
<template >
2
2
<div >
3
- <el-dialog
3
+ <Dialog
4
4
v-model =" dialogVisible"
5
- :title =" title "
5
+ :title =" dialogTitle "
6
6
@closed =" close"
7
7
append-to-body
8
8
destroy-on-close
11
11
<el-form
12
12
ref =" formRef"
13
13
:model =" formData"
14
- :rules = " rules "
14
+ :formRules = " formRules "
15
15
label-width =" 100px"
16
16
v-loading =" formLoading"
17
17
>
37
37
<el-form-item label-width =" 180px" label =" 网关地址" prop =" config.serverUrl" >
38
38
<el-radio-group v-model =" formData.config.serverUrl" >
39
39
<el-radio label =" https://openapi.alipay.com/gateway.do" >线上环境</el-radio >
40
- <el-radio label =" https://openapi-sandbox.dl.alipaydev.com/gateway.do"
41
- > 沙箱环境</ el-radio
42
- >
40
+ <el-radio label =" https://openapi-sandbox.dl.alipaydev.com/gateway.do" >
41
+ 沙箱环境
42
+ </ el-radio >
43
43
</el-radio-group >
44
44
</el-form-item >
45
45
<el-form-item label-width =" 180px" label =" 算法类型" prop =" config.signType" >
95
95
:http-request =" appCertUpload"
96
96
:before-upload =" fileBeforeUpload"
97
97
>
98
- <el-button size =" small" type =" primary" icon =" el-icon-upload" >点击上传</el-button >
98
+ <el-button type =" primary" >
99
+ <Icon icon =" ep:upload" class =" mr-5px" /> 点击上传
100
+ </el-button >
99
101
</el-upload >
100
102
</el-form-item >
101
103
<el-form-item
121
123
:before-upload =" fileBeforeUpload"
122
124
:http-request =" alipayPublicCertUpload"
123
125
>
124
- <el-button size =" small" type =" primary" icon =" el-icon-upload" >点击上传</el-button >
126
+ <el-button type =" primary" >
127
+ <Icon icon =" ep:upload" class =" mr-5px" /> 点击上传
128
+ </el-button >
125
129
</el-upload >
126
130
</el-form-item >
127
131
<el-form-item label-width =" 180px" label =" 根证书" prop =" config.rootCertContent" >
143
147
:before-upload =" fileBeforeUpload"
144
148
:http-request =" rootCertUpload"
145
149
>
146
- <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 >
147
153
</el-upload >
148
154
</el-form-item >
149
155
</div >
155
161
<el-button @click =" close" >取消</el-button >
156
162
<el-button type =" primary" @click =" submitForm" >确定</el-button >
157
163
</template >
158
- </el-dialog >
164
+ </Dialog >
159
165
</div >
160
166
</template >
161
167
<script lang="ts" setup name="AlipayChannelForm">
162
- import { createChannel , getChannel , updateChannel } from ' @/api/pay/channel'
163
168
import { CommonStatusEnum } from ' @/utils/constants'
164
169
import { DICT_TYPE , getDictOptions } from ' @/utils/dict'
170
+ import * as ChannelApi from ' @/api/pay/channel'
165
171
172
+ const { t } = useI18n () // 国际化
166
173
const message = useMessage () // 消息弹窗
167
174
168
- const emit = defineEmits ([' success' ])
169
-
170
- const dialogVisible = ref (false )
171
- const formLoading = ref (false )
172
- const title = ref (' ' )
175
+ const dialogVisible = ref (false ) // 弹窗的是否展示
176
+ const dialogTitle = ref (' ' ) // 弹窗的标题
177
+ const formLoading = ref (false ) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
173
178
const formData = ref <any >({
174
179
appId: ' ' ,
175
180
code: ' ' ,
@@ -188,8 +193,7 @@ const formData = ref<any>({
188
193
rootCertContent: ' '
189
194
}
190
195
})
191
-
192
- const rules = {
196
+ const formRules = {
193
197
feeRate: [{ required: true , message: ' 请输入渠道费率' , trigger: ' blur' }],
194
198
status: [{ required: true , message: ' 渠道状态不能为空' , trigger: ' blur' }],
195
199
' config.appId' : [{ required: true , message: ' 请输入开放平台上创建的应用的 ID' , trigger: ' blur' }],
@@ -206,55 +210,57 @@ const rules = {
206
210
],
207
211
' config.rootCertContent' : [{ required: true , message: ' 请上传指定根证书' , trigger: ' blur' }]
208
212
}
209
-
210
213
const fileAccept = ' .crt'
214
+ const formRef = ref () // 表单 Ref
211
215
212
- const formRef = ref ()
213
-
216
+ /** 打开弹窗 */
214
217
const open = async (appId , code ) => {
215
218
dialogVisible .value = true
216
219
formLoading .value = true
217
- reset (appId , code )
218
-
220
+ resetForm (appId , code )
221
+ // 加载数据
219
222
try {
220
- const data = await getChannel (appId , code )
223
+ const data = await ChannelApi . getChannel (appId , code )
221
224
if (data && data .id ) {
222
225
formData .value = data
223
226
formData .value .config = JSON .parse (data .config )
224
227
}
225
- title .value = ! formData .value .id ? ' 创建支付渠道' : ' 编辑支付渠道'
228
+ dialogTitle .value = ! formData .value .id ? ' 创建支付渠道' : ' 编辑支付渠道'
226
229
} finally {
227
230
formLoading .value = false
228
231
}
229
232
}
233
+ defineExpose ({ open }) // 提供 open 方法,用于打开弹窗
230
234
231
- defineExpose ({ open })
232
-
233
- const close = () => {
234
- dialogVisible .value = false
235
- reset (undefined , undefined )
236
- }
237
-
235
+ /** 提交表单 */
236
+ const emit = defineEmits ([' success' ]) // 定义 success 事件,用于操作成功后的回调
238
237
const submitForm = async () => {
238
+ // 校验表单
239
+ if (! formRef ) return
239
240
const valid = await formRef .value .validate ()
240
241
if (! valid ) return
241
-
242
- const data: any = { ... formData .value }
243
- data .config = JSON .stringify (formData .value .config )
244
- if (! data .id ) {
245
- await createChannel (data )
246
- message .success (' 新增成功' )
247
- } else {
248
- await updateChannel (data )
249
- message .success (' 修改成功' )
242
+ // 提交请求
243
+ formLoading .value = true
244
+ try {
245
+ const data = { ... formData .value } as unknown as ChannelApi .ChannelVO
246
+ data .config = JSON .stringify (formData .value .config )
247
+ if (! data .id ) {
248
+ await ChannelApi .createChannel (data )
249
+ message .success (t (' common.createSuccess' ))
250
+ } else {
251
+ await ChannelApi .updateChannel (data )
252
+ message .success (t (' common.updateSuccess' ))
253
+ }
254
+ dialogVisible .value = false
255
+ // 发送操作成功的事件
256
+ emit (' success' )
257
+ } finally {
258
+ formLoading .value = false
250
259
}
251
-
252
- emit (' success' )
253
- close ()
254
260
}
255
261
256
262
/** 重置表单 */
257
- const reset = (appId , code ) => {
263
+ const resetForm = (appId , code ) => {
258
264
formData .value = {
259
265
appId: appId ,
260
266
code: code ,
@@ -273,7 +279,7 @@ const reset = (appId, code) => {
273
279
rootCertContent: ' '
274
280
}
275
281
}
276
- // formRef.value?.resetFields()
282
+ formRef .value ?.resetFields ()
277
283
}
278
284
279
285
const fileBeforeUpload = (file ) => {
0 commit comments