1
1
<template >
2
2
<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" >
11
4
<el-form
12
5
ref =" formRef"
13
6
:model =" formData"
14
- :rules =" rules "
7
+ :rules =" formRules "
15
8
label-width =" 120px"
16
9
v-loading =" formLoading"
17
10
>
86
79
:before-upload =" p12FileBeforeUpload"
87
80
:http-request =" keyContentUpload"
88
81
>
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 >
90
85
</el-upload >
91
86
</el-form-item >
92
87
</div >
124
119
:before-upload =" pemFileBeforeUpload"
125
120
:http-request =" privateKeyContentUpload"
126
121
>
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 >
128
125
</el-upload >
129
126
</el-form-item >
130
127
<el-form-item
150
147
:before-upload =" pemFileBeforeUpload"
151
148
:http-request =" privateCertContentUpload"
152
149
>
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 >
154
153
</el-upload >
155
154
</el-form-item >
156
155
</div >
162
161
<el-button @click =" close" >取消</el-button >
163
162
<el-button type =" primary" @click =" submitForm" >确定</el-button >
164
163
</template >
165
- </el-dialog >
164
+ </Dialog >
166
165
</div >
167
166
</template >
168
- <script lang="ts" setup name="WeixinChannelForm">
169
- import { createChannel , getChannel , updateChannel } from ' @/api/pay/channel'
167
+ <script lang="ts" setup>
170
168
import { CommonStatusEnum } from ' @/utils/constants'
171
169
import { DICT_TYPE , getDictOptions } from ' @/utils/dict'
170
+ import * as ChannelApi from ' @/api/pay/channel'
172
171
172
+ defineOptions ({ name: ' WeixinChannelForm' })
173
+
174
+ const { t } = useI18n () // 国际化
173
175
const message = useMessage () // 消息弹窗
174
176
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)提交的按钮禁用
178
180
const formData = ref <any >({
179
181
appId: ' ' ,
180
182
code: ' ' ,
@@ -192,11 +194,7 @@ const formData = ref<any>({
192
194
apiV3Key: ' '
193
195
}
194
196
})
195
- const formRef = ref ()
196
-
197
- const emit = defineEmits ([' success' ])
198
-
199
- const rules = {
197
+ const formRules = {
200
198
feeRate: [{ required: true , message: ' 请输入渠道费率' , trigger: ' blur' }],
201
199
status: [{ required: true , message: ' 渠道状态不能为空' , trigger: ' blur' }],
202
200
' config.mchId' : [{ required: true , message: ' 请传入商户号' , trigger: ' blur' }],
@@ -214,53 +212,56 @@ const rules = {
214
212
],
215
213
' config.apiV3Key' : [{ required: true , message: ' 请上传 api V3 密钥值' , trigger: ' blur' }]
216
214
}
215
+ const formRef = ref () // 表单 Ref
217
216
217
+ /** 打开弹窗 */
218
218
const open = async (appId , code ) => {
219
219
dialogVisible .value = true
220
220
formLoading .value = true
221
- reset (appId , code )
222
-
221
+ resetForm (appId , code )
222
+ // 加载数据
223
223
try {
224
- const data = await getChannel (appId , code )
224
+ const data = await ChannelApi . getChannel (appId , code )
225
225
if (data && data .id ) {
226
226
formData .value = data
227
227
formData .value .config = JSON .parse (data .config )
228
228
}
229
- title .value = ! formData .value .id ? ' 创建支付渠道' : ' 编辑支付渠道'
229
+ dialogTitle .value = ! formData .value .id ? ' 创建支付渠道' : ' 编辑支付渠道'
230
230
} finally {
231
231
formLoading .value = false
232
232
}
233
233
}
234
+ defineExpose ({ open }) // 提供 open 方法,用于打开弹窗
234
235
235
- const close = () => {
236
- dialogVisible .value = false
237
- reset (undefined , undefined )
238
- }
239
-
236
+ /** 提交表单 */
237
+ const emit = defineEmits ([' success' ]) // 定义 success 事件,用于操作成功后的回调
240
238
const submitForm = async () => {
239
+ // 校验表单
240
+ if (! formRef ) return
241
241
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
259
260
}
260
261
}
261
262
262
263
/** 重置表单 */
263
- const reset = (appId , code ) => {
264
+ const resetForm = (appId , code ) => {
264
265
formData .value = {
265
266
appId: appId ,
266
267
code: code ,
@@ -338,6 +339,4 @@ const keyContentUpload = (event) => {
338
339
}
339
340
readFile .readAsDataURL (event .file ) // 读成 base64
340
341
}
341
-
342
- defineExpose ({ open })
343
342
</script >
0 commit comments