mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-07-26 08:45:08 +08:00
feat: 支付管理/应用信息(alpha)
This commit is contained in:
130
src/views/pay/app/components/AppForm.vue
Normal file
130
src/views/pay/app/components/AppForm.vue
Normal file
@ -0,0 +1,130 @@
|
||||
<template>
|
||||
<Dialog v-model="dialogVisible" :title="dialogTitle">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
v-loading="formLoading"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="160px"
|
||||
>
|
||||
<el-form-item label="应用名" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入应用名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="开启状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="dict.value"
|
||||
:label="dict.value"
|
||||
>
|
||||
{{ dict.label }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="支付结果的回调地址" prop="payNotifyUrl">
|
||||
<el-input v-model="formData.payNotifyUrl" placeholder="请输入支付结果的回调地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="退款结果的回调地址" prop="refundNotifyUrl">
|
||||
<el-input v-model="formData.refundNotifyUrl" placeholder="请输入退款结果的回调地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" placeholder="请输入备注" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import * as AppApi from '@/api/pay/app'
|
||||
import { CommonStatusEnum } from '@/utils/constants'
|
||||
|
||||
defineOptions({ name: 'PayAppForm' })
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
packageId: undefined,
|
||||
contactName: undefined,
|
||||
contactMobile: undefined,
|
||||
accountCount: undefined,
|
||||
expireTime: undefined,
|
||||
domain: undefined,
|
||||
status: CommonStatusEnum.ENABLE
|
||||
})
|
||||
const formRules = reactive({
|
||||
name: [{ required: true, message: '应用名不能为空', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '开启状态不能为空', trigger: 'blur' }],
|
||||
payNotifyUrl: [{ required: true, message: '支付结果的回调地址不能为空', trigger: 'blur' }],
|
||||
refundNotifyUrl: [{ required: true, message: '退款结果的回调地址不能为空', trigger: 'blur' }]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await AppApi.getApp(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
if (!formRef) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as AppApi.AppVO
|
||||
if (formType.value === 'create') {
|
||||
await AppApi.createApp(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await AppApi.updateApp(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
status: CommonStatusEnum.ENABLE,
|
||||
remark: undefined,
|
||||
payNotifyUrl: undefined,
|
||||
refundNotifyUrl: undefined
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
315
src/views/pay/app/components/alipayChannelForm.vue
Normal file
315
src/views/pay/app/components/alipayChannelForm.vue
Normal file
@ -0,0 +1,315 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="title"
|
||||
@closed="close"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
width="830px"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
label-width="100px"
|
||||
v-loading="formLoading"
|
||||
>
|
||||
<el-form-item label-width="180px" label="渠道费率" prop="feeRate">
|
||||
<el-input v-model="formData.feeRate" placeholder="请输入渠道费率" clearable>
|
||||
<template #append>%</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="开放平台 APPID" prop="config.appId">
|
||||
<el-input v-model="formData.config.appId" placeholder="请输入开放平台 APPID" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="渠道状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio
|
||||
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="parseInt(dict.value)"
|
||||
:label="parseInt(dict.value)"
|
||||
>
|
||||
{{ dict.label }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="网关地址" prop="config.serverUrl">
|
||||
<el-radio-group v-model="formData.config.serverUrl">
|
||||
<el-radio label="https://openapi.alipay.com/gateway.do">线上环境</el-radio>
|
||||
<el-radio label="https://openapi-sandbox.dl.alipaydev.com/gateway.do"
|
||||
>沙箱环境</el-radio
|
||||
>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="算法类型" prop="config.signType">
|
||||
<el-radio-group v-model="formData.config.signType">
|
||||
<el-radio key="RSA2" label="RSA2">RSA2</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="公钥类型" prop="config.mode">
|
||||
<el-radio-group v-model="formData.config.mode">
|
||||
<el-radio key="公钥模式" :label="1">公钥模式</el-radio>
|
||||
<el-radio key="证书模式" :label="2">证书模式</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<div v-if="formData.config.mode === 1">
|
||||
<el-form-item label-width="180px" label="应用私钥" prop="config.privateKey">
|
||||
<el-input
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
v-model="formData.config.privateKey"
|
||||
placeholder="请输入应用私钥"
|
||||
clearable
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="支付宝公钥" prop="config.alipayPublicKey">
|
||||
<el-input
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
v-model="formData.config.alipayPublicKey"
|
||||
placeholder="请输入支付宝公钥"
|
||||
clearable
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="formData.config.mode === 2">
|
||||
<el-form-item label-width="180px" label="商户公钥应用证书" prop="config.appCertContent">
|
||||
<el-input
|
||||
v-model="formData.config.appCertContent"
|
||||
type="textarea"
|
||||
placeholder="请上传商户公钥应用证书"
|
||||
readonly
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="">
|
||||
<el-upload
|
||||
action=""
|
||||
ref="privateKeyContentFile"
|
||||
:limit="1"
|
||||
:accept="fileAccept"
|
||||
:http-request="appCertUpload"
|
||||
:before-upload="fileBeforeUpload"
|
||||
>
|
||||
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label-width="180px"
|
||||
label="支付宝公钥证书"
|
||||
prop="config.alipayPublicCertContent"
|
||||
>
|
||||
<el-input
|
||||
v-model="formData.config.alipayPublicCertContent"
|
||||
type="textarea"
|
||||
placeholder="请上传支付宝公钥证书"
|
||||
readonly
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="">
|
||||
<el-upload
|
||||
ref="privateCertContentFile"
|
||||
action=""
|
||||
:limit="1"
|
||||
:accept="fileAccept"
|
||||
:before-upload="fileBeforeUpload"
|
||||
:http-request="alipayPublicCertUpload"
|
||||
>
|
||||
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="根证书" prop="config.rootCertContent">
|
||||
<el-input
|
||||
v-model="formData.config.rootCertContent"
|
||||
type="textarea"
|
||||
placeholder="请上传根证书"
|
||||
readonly
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="">
|
||||
<el-upload
|
||||
ref="privateCertContentFile"
|
||||
:limit="1"
|
||||
:accept="fileAccept"
|
||||
action=""
|
||||
:before-upload="fileBeforeUpload"
|
||||
:http-request="rootCertUpload"
|
||||
>
|
||||
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<el-form-item label-width="180px" label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" :style="{ width: '100%' }" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="close">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="AlipayChannelForm">
|
||||
import { createChannel, getChannel, updateChannel } from '@/api/pay/channel'
|
||||
import { CommonStatusEnum } from '@/utils/constants'
|
||||
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const emit = defineEmits(['success'])
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const formLoading = ref(false)
|
||||
const title = ref('')
|
||||
const formData = ref<any>({
|
||||
appId: '',
|
||||
code: '',
|
||||
status: undefined,
|
||||
feeRate: undefined,
|
||||
remark: '',
|
||||
config: {
|
||||
appId: '',
|
||||
serverUrl: null,
|
||||
signType: '',
|
||||
mode: null,
|
||||
privateKey: '',
|
||||
alipayPublicKey: '',
|
||||
appCertContent: '',
|
||||
alipayPublicCertContent: '',
|
||||
rootCertContent: ''
|
||||
}
|
||||
})
|
||||
|
||||
const rules = {
|
||||
feeRate: [{ required: true, message: '请输入渠道费率', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '渠道状态不能为空', trigger: 'blur' }],
|
||||
'config.appId': [{ required: true, message: '请输入开放平台上创建的应用的 ID', trigger: 'blur' }],
|
||||
'config.serverUrl': [{ required: true, message: '请传入网关地址', trigger: 'blur' }],
|
||||
'config.signType': [{ required: true, message: '请传入签名算法类型', trigger: 'blur' }],
|
||||
'config.mode': [{ required: true, message: '公钥类型不能为空', trigger: 'blur' }],
|
||||
'config.privateKey': [{ required: true, message: '请输入商户私钥', trigger: 'blur' }],
|
||||
'config.alipayPublicKey': [
|
||||
{ required: true, message: '请输入支付宝公钥字符串', trigger: 'blur' }
|
||||
],
|
||||
'config.appCertContent': [{ required: true, message: '请上传商户公钥应用证书', trigger: 'blur' }],
|
||||
'config.alipayPublicCertContent': [
|
||||
{ required: true, message: '请上传支付宝公钥证书', trigger: 'blur' }
|
||||
],
|
||||
'config.rootCertContent': [{ required: true, message: '请上传指定根证书', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const fileAccept = '.crt'
|
||||
|
||||
const formRef = ref()
|
||||
|
||||
const open = async (appId, code) => {
|
||||
dialogVisible.value = true
|
||||
formLoading.value = true
|
||||
reset(appId, code)
|
||||
|
||||
try {
|
||||
const data = await getChannel(appId, code)
|
||||
if (data && data.id) {
|
||||
formData.value = data
|
||||
formData.value.config = JSON.parse(data.config)
|
||||
}
|
||||
title.value = !formData.value.id ? '创建支付渠道' : '编辑支付渠道'
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
|
||||
const close = () => {
|
||||
dialogVisible.value = false
|
||||
reset(undefined, undefined)
|
||||
}
|
||||
|
||||
const submitForm = async () => {
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
|
||||
const data: any = { ...formData.value }
|
||||
data.config = JSON.stringify(formData.value.config)
|
||||
if (!data.id) {
|
||||
await createChannel(data)
|
||||
message.success('新增成功')
|
||||
} else {
|
||||
await updateChannel(data)
|
||||
message.success('修改成功')
|
||||
}
|
||||
|
||||
emit('success')
|
||||
close()
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const reset = (appId, code) => {
|
||||
formData.value = {
|
||||
appId: appId,
|
||||
code: code,
|
||||
status: CommonStatusEnum.ENABLE,
|
||||
remark: '',
|
||||
feeRate: null,
|
||||
config: {
|
||||
appId: '',
|
||||
serverUrl: null,
|
||||
signType: 'RSA2',
|
||||
mode: null,
|
||||
privateKey: '',
|
||||
alipayPublicKey: '',
|
||||
appCertContent: '',
|
||||
alipayPublicCertContent: '',
|
||||
rootCertContent: ''
|
||||
}
|
||||
}
|
||||
// formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const fileBeforeUpload = (file) => {
|
||||
let format = '.' + file.name.split('.')[1]
|
||||
if (format !== fileAccept) {
|
||||
message.error(`请上传指定格式"${fileAccept}"文件`)
|
||||
return false
|
||||
}
|
||||
let isRightSize = file.size / 1024 / 1024 < 2
|
||||
if (!isRightSize) {
|
||||
message.error('文件大小超过 2MB')
|
||||
}
|
||||
return isRightSize
|
||||
}
|
||||
|
||||
const appCertUpload = (event) => {
|
||||
const readFile = new FileReader()
|
||||
readFile.onload = (e: any) => {
|
||||
formData.value.config.appCertContent = e.target.result
|
||||
}
|
||||
readFile.readAsText(event.file)
|
||||
}
|
||||
|
||||
const alipayPublicCertUpload = (event) => {
|
||||
const readFile = new FileReader()
|
||||
readFile.onload = (e: any) => {
|
||||
formData.value.config.alipayPublicCertContent = e.target.result
|
||||
}
|
||||
readFile.readAsText(event.file)
|
||||
}
|
||||
|
||||
const rootCertUpload = (event) => {
|
||||
const readFile = new FileReader()
|
||||
readFile.onload = (e: any) => {
|
||||
formData.value.config.rootCertContent = e.target.result
|
||||
}
|
||||
readFile.readAsText(event.file)
|
||||
}
|
||||
</script>
|
130
src/views/pay/app/components/mockChannelForm.vue
Normal file
130
src/views/pay/app/components/mockChannelForm.vue
Normal file
@ -0,0 +1,130 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog
|
||||
v-model:visible="dialogVisible"
|
||||
:title="title"
|
||||
@closed="close"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
width="800px"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
label-width="100px"
|
||||
v-loading="formLoading"
|
||||
>
|
||||
<el-form-item label-width="180px" label="渠道状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio
|
||||
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="parseInt(dict.value)"
|
||||
:label="parseInt(dict.value)"
|
||||
>
|
||||
{{ dict.label }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" :style="{ width: '100%' }" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="close">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="MockChannelForm">
|
||||
import { createChannel, getChannel, updateChannel } from '@/api/pay/channel'
|
||||
import { CommonStatusEnum } from '@/utils/constants'
|
||||
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const formLoading = ref(false)
|
||||
const title = ref('')
|
||||
const formData = ref<any>({
|
||||
appId: '',
|
||||
code: '',
|
||||
status: undefined,
|
||||
feeRate: 0,
|
||||
remark: '',
|
||||
config: {
|
||||
name: 'mock-conf'
|
||||
}
|
||||
})
|
||||
|
||||
const rules = {
|
||||
status: [{ required: true, message: '渠道状态不能为空', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const formRef = ref()
|
||||
|
||||
const emit = defineEmits(['success'])
|
||||
|
||||
const open = async (appId, code) => {
|
||||
dialogVisible.value = true
|
||||
formLoading.value = true
|
||||
reset(appId, code)
|
||||
|
||||
try {
|
||||
const data = await getChannel(appId, code)
|
||||
|
||||
if (data && data.id) {
|
||||
formData.value = data
|
||||
formData.value.config = JSON.parse(data.config)
|
||||
}
|
||||
title.value = !formData.value.id ? '创建支付渠道' : '编辑支付渠道'
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
dialogVisible.value = false
|
||||
reset(undefined, undefined)
|
||||
}
|
||||
|
||||
const submitForm = async () => {
|
||||
const valid = await formRef.value?.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
const data = { ...formData.value }
|
||||
data.config = JSON.stringify(formData.value.config)
|
||||
if (!data.id) {
|
||||
createChannel(data).then(() => {
|
||||
message.success('新增成功')
|
||||
emit('success')
|
||||
close()
|
||||
})
|
||||
} else {
|
||||
updateChannel(data).then(() => {
|
||||
message.success('修改成功')
|
||||
emit('success')
|
||||
close()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const reset = (appId, code) => {
|
||||
formData.value = {
|
||||
appId: appId,
|
||||
code: code,
|
||||
status: CommonStatusEnum.ENABLE,
|
||||
remark: '',
|
||||
feeRate: 0,
|
||||
config: {
|
||||
name: 'mock-conf'
|
||||
}
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
343
src/views/pay/app/components/weixinChannelForm.vue
Normal file
343
src/views/pay/app/components/weixinChannelForm.vue
Normal file
@ -0,0 +1,343 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="title"
|
||||
@close="close"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
width="800px"
|
||||
>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
label-width="120px"
|
||||
v-loading="formLoading"
|
||||
>
|
||||
<el-form-item label-width="180px" label="渠道费率" prop="feeRate">
|
||||
<el-input
|
||||
v-model="formData.feeRate"
|
||||
placeholder="请输入渠道费率"
|
||||
clearable
|
||||
:style="{ width: '100%' }"
|
||||
>
|
||||
<template #append>%</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="公众号 APPID" prop="config.appId">
|
||||
<el-input
|
||||
v-model="formData.config.appId"
|
||||
placeholder="请输入公众号 APPID"
|
||||
clearable
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="商户号" prop="config.mchId">
|
||||
<el-input v-model="formData.config.mchId" :style="{ width: '100%' }" />
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="渠道状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio
|
||||
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="parseInt(dict.value)"
|
||||
:label="parseInt(dict.value)"
|
||||
>
|
||||
{{ dict.label }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="API 版本" prop="config.apiVersion">
|
||||
<el-radio-group v-model="formData.config.apiVersion">
|
||||
<el-radio label="v2">v2</el-radio>
|
||||
<el-radio label="v3">v3</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<div v-if="formData.config.apiVersion === 'v2'">
|
||||
<el-form-item label-width="180px" label="商户密钥" prop="config.mchKey">
|
||||
<el-input
|
||||
v-model="formData.config.mchKey"
|
||||
placeholder="请输入商户密钥"
|
||||
clearable
|
||||
:style="{ width: '100%' }"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label-width="180px"
|
||||
label="apiclient_cert.p12 证书"
|
||||
prop="config.keyContent"
|
||||
>
|
||||
<el-input
|
||||
v-model="formData.config.keyContent"
|
||||
type="textarea"
|
||||
placeholder="请上传 apiclient_cert.p12 证书"
|
||||
readonly
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="">
|
||||
<el-upload
|
||||
:limit="1"
|
||||
accept=".p12"
|
||||
action=""
|
||||
:before-upload="p12FileBeforeUpload"
|
||||
:http-request="keyContentUpload"
|
||||
>
|
||||
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="formData.config.apiVersion === 'v3'">
|
||||
<el-form-item label-width="180px" label="API V3 密钥" prop="config.apiV3Key">
|
||||
<el-input
|
||||
v-model="formData.config.apiV3Key"
|
||||
placeholder="请输入 API V3 密钥"
|
||||
clearable
|
||||
:style="{ width: '100%' }"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label-width="180px"
|
||||
label="apiclient_key.perm 证书"
|
||||
prop="config.privateKeyContent"
|
||||
>
|
||||
<el-input
|
||||
v-model="formData.config.privateKeyContent"
|
||||
type="textarea"
|
||||
placeholder="请上传 apiclient_key.perm 证书"
|
||||
readonly
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="" prop="privateKeyContentFile">
|
||||
<el-upload
|
||||
ref="privateKeyContentFile"
|
||||
:limit="1"
|
||||
accept=".pem"
|
||||
action=""
|
||||
:before-upload="pemFileBeforeUpload"
|
||||
:http-request="privateKeyContentUpload"
|
||||
>
|
||||
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
label-width="180px"
|
||||
label="apiclient_cert.perm证书"
|
||||
prop="config.privateCertContent"
|
||||
>
|
||||
<el-input
|
||||
v-model="formData.config.privateCertContent"
|
||||
type="textarea"
|
||||
placeholder="请上传apiclient_cert.perm证书"
|
||||
readonly
|
||||
:autosize="{ minRows: 8, maxRows: 8 }"
|
||||
:style="{ width: '100%' }"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label-width="180px" label="" prop="privateCertContentFile">
|
||||
<el-upload
|
||||
ref="privateCertContentFile"
|
||||
:limit="1"
|
||||
accept=".pem"
|
||||
action=""
|
||||
:before-upload="pemFileBeforeUpload"
|
||||
:http-request="privateCertContentUpload"
|
||||
>
|
||||
<el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<el-form-item label-width="180px" label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" :style="{ width: '100%' }" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="close">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="WeixinChannelForm">
|
||||
import { createChannel, getChannel, updateChannel } from '@/api/pay/channel'
|
||||
import { CommonStatusEnum } from '@/utils/constants'
|
||||
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const formLoading = ref(false)
|
||||
const title = ref('')
|
||||
const formData = ref<any>({
|
||||
appId: '',
|
||||
code: '',
|
||||
status: undefined,
|
||||
feeRate: undefined,
|
||||
remark: '',
|
||||
config: {
|
||||
appId: '',
|
||||
mchId: '',
|
||||
apiVersion: '',
|
||||
mchKey: '',
|
||||
keyContent: '',
|
||||
privateKeyContent: '',
|
||||
privateCertContent: '',
|
||||
apiV3Key: ''
|
||||
}
|
||||
})
|
||||
const formRef = ref()
|
||||
|
||||
const emit = defineEmits(['success'])
|
||||
|
||||
const rules = {
|
||||
feeRate: [{ required: true, message: '请输入渠道费率', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '渠道状态不能为空', trigger: 'blur' }],
|
||||
'config.mchId': [{ required: true, message: '请传入商户号', trigger: 'blur' }],
|
||||
'config.appId': [{ required: true, message: '请输入公众号APPID', trigger: 'blur' }],
|
||||
'config.apiVersion': [{ required: true, message: 'API版本不能为空', trigger: 'blur' }],
|
||||
'config.mchKey': [{ required: true, message: '请输入商户密钥', trigger: 'blur' }],
|
||||
'config.keyContent': [
|
||||
{ required: true, message: '请上传 apiclient_cert.p12 证书', trigger: 'blur' }
|
||||
],
|
||||
'config.privateKeyContent': [
|
||||
{ required: true, message: '请上传 apiclient_key.perm 证书', trigger: 'blur' }
|
||||
],
|
||||
'config.privateCertContent': [
|
||||
{ required: true, message: '请上传 apiclient_cert.perm证 书', trigger: 'blur' }
|
||||
],
|
||||
'config.apiV3Key': [{ required: true, message: '请上传 api V3 密钥值', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const open = async (appId, code) => {
|
||||
dialogVisible.value = true
|
||||
formLoading.value = true
|
||||
reset(appId, code)
|
||||
|
||||
try {
|
||||
const data = await getChannel(appId, code)
|
||||
if (data && data.id) {
|
||||
formData.value = data
|
||||
formData.value.config = JSON.parse(data.config)
|
||||
}
|
||||
title.value = !formData.value.id ? '创建支付渠道' : '编辑支付渠道'
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
dialogVisible.value = false
|
||||
reset(undefined, undefined)
|
||||
}
|
||||
|
||||
const submitForm = async () => {
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
const data: any = { ...formData.value }
|
||||
data.config = JSON.stringify(formData.value.config)
|
||||
if (!data.id) {
|
||||
createChannel(data).then(() => {
|
||||
message.alertSuccess('新增成功')
|
||||
emit('success')
|
||||
close()
|
||||
})
|
||||
} else {
|
||||
updateChannel(data).then(() => {
|
||||
message.alertSuccess('修改成功')
|
||||
emit('success')
|
||||
close()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const reset = (appId, code) => {
|
||||
formData.value = {
|
||||
appId: appId,
|
||||
code: code,
|
||||
status: CommonStatusEnum.ENABLE,
|
||||
feeRate: undefined,
|
||||
remark: '',
|
||||
config: {
|
||||
appId: '',
|
||||
mchId: '',
|
||||
apiVersion: '',
|
||||
mchKey: '',
|
||||
keyContent: '',
|
||||
privateKeyContent: '',
|
||||
privateCertContent: '',
|
||||
apiV3Key: ''
|
||||
}
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* apiclient_cert.p12、apiclient_cert.pem、apiclient_key.pem 上传前的校验
|
||||
*/
|
||||
const fileBeforeUpload = (file, fileAccept) => {
|
||||
let format = '.' + file.name.split('.')[1]
|
||||
if (format !== fileAccept) {
|
||||
debugger
|
||||
message.error('请上传指定格式"' + fileAccept + '"文件')
|
||||
return false
|
||||
}
|
||||
let isRightSize = file.size / 1024 / 1024 < 2
|
||||
if (!isRightSize) {
|
||||
message.error('文件大小超过 2MB')
|
||||
}
|
||||
return isRightSize
|
||||
}
|
||||
|
||||
const p12FileBeforeUpload = (file) => {
|
||||
fileBeforeUpload(file, '.p12')
|
||||
}
|
||||
|
||||
const pemFileBeforeUpload = (file) => {
|
||||
fileBeforeUpload(file, '.pem')
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取 apiclient_key.pem 到 privateKeyContent 字段
|
||||
*/
|
||||
const privateKeyContentUpload = (event) => {
|
||||
const readFile = new FileReader()
|
||||
readFile.onload = (e: any) => {
|
||||
formData.value.config.privateKeyContent = e.target.result
|
||||
}
|
||||
readFile.readAsText(event.file)
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取 apiclient_cert.pem 到 privateCertContent 字段
|
||||
*/
|
||||
const privateCertContentUpload = (event) => {
|
||||
const readFile = new FileReader()
|
||||
readFile.onload = (e: any) => {
|
||||
formData.value.config.privateCertContent = e.target.result
|
||||
}
|
||||
readFile.readAsText(event.file)
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取 apiclient_cert.p12 到 keyContent 字段
|
||||
*/
|
||||
const keyContentUpload = (event) => {
|
||||
const readFile = new FileReader()
|
||||
readFile.onload = (e: any) => {
|
||||
formData.value.config.keyContent = e.target.result.split(',')[1]
|
||||
}
|
||||
readFile.readAsDataURL(event.file) // 读成 base64
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
Reference in New Issue
Block a user