From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/views/pay/app/components/channel/WeixinChannelForm.vue | 377 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 377 insertions(+), 0 deletions(-)
diff --git a/src/views/pay/app/components/channel/WeixinChannelForm.vue b/src/views/pay/app/components/channel/WeixinChannelForm.vue
new file mode 100644
index 0000000..fd91554
--- /dev/null
+++ b/src/views/pay/app/components/channel/WeixinChannelForm.vue
@@ -0,0 +1,377 @@
+<template>
+ <div>
+ <Dialog v-model="dialogVisible" :title="dialogTitle" width="800px">
+ <el-form
+ ref="formRef"
+ v-loading="formLoading"
+ :model="formData"
+ :rules="formRules"
+ label-width="120px"
+ >
+ <el-form-item label="娓犻亾璐圭巼" label-width="180px" prop="feeRate">
+ <el-input
+ v-model="formData.feeRate"
+ :style="{ width: '100%' }"
+ clearable
+ placeholder="璇疯緭鍏ユ笭閬撹垂鐜�"
+ >
+ <template #append>%</template>
+ </el-input>
+ </el-form-item>
+ <el-form-item label="寰俊 APPID" label-width="180px" prop="config.appId">
+ <el-input
+ v-model="formData.config.appId"
+ :style="{ width: '100%' }"
+ clearable
+ placeholder="璇疯緭鍏ュ井淇� APPID"
+ />
+ </el-form-item>
+ <el-form-item label-width="180px">
+ <a
+ href="https://pay.weixin.qq.com/index.php/extend/merchant_appid/mapay_platform/account_manage"
+ target="_blank"
+ >
+ 鍓嶅線寰俊鍟嗘埛骞冲彴鏌ョ湅 APPID
+ </a>
+ </el-form-item>
+ <el-form-item label="鍟嗘埛鍙�" label-width="180px" prop="config.mchId">
+ <el-input v-model="formData.config.mchId" :style="{ width: '100%' }" />
+ </el-form-item>
+
+ <el-form-item label-width="180px">
+ <a href="https://pay.weixin.qq.com/index.php/extend/pay_setting" target="_blank">
+ 鍓嶅線寰俊鍟嗘埛骞冲彴鏌ョ湅鍟嗘埛鍙�
+ </a>
+ </el-form-item>
+ <el-form-item label="娓犻亾鐘舵��" label-width="180px" prop="status">
+ <el-radio-group v-model="formData.status">
+ <el-radio
+ v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
+ :key="parseInt(dict.value)"
+ :value="parseInt(dict.value)"
+ >
+ {{ dict.label }}
+ </el-radio>
+ </el-radio-group>
+ </el-form-item>
+ <el-form-item label="API 鐗堟湰" label-width="180px" prop="config.apiVersion">
+ <el-radio-group v-model="formData.config.apiVersion">
+ <el-radio value="v2">v2</el-radio>
+ <el-radio value="v3">v3</el-radio>
+ </el-radio-group>
+ </el-form-item>
+ <div v-if="formData.config.apiVersion === 'v2'">
+ <el-form-item label="鍟嗘埛瀵嗛挜" label-width="180px" prop="config.mchKey">
+ <el-input v-model="formData.config.mchKey" clearable placeholder="璇疯緭鍏ュ晢鎴峰瘑閽�" />
+ </el-form-item>
+ <el-form-item
+ label="apiclient_cert.p12 璇佷功"
+ label-width="180px"
+ prop="config.keyContent"
+ >
+ <el-input
+ v-model="formData.config.keyContent"
+ :autosize="{ minRows: 2, maxRows: 4 }"
+ :style="{ width: '100%' }"
+ placeholder="璇蜂笂浼� apiclient_cert.p12 璇佷功"
+ readonly
+ type="textarea"
+ :rows="2"
+ />
+ </el-form-item>
+ <el-form-item label="" label-width="180px">
+ <el-upload
+ :before-upload="p12FileBeforeUpload"
+ :http-request="keyContentUpload"
+ :limit="1"
+ accept=".p12"
+ action=""
+ >
+ <el-button type="primary">
+ <Icon class="mr-5px" icon="ep:upload" />
+ 鐐瑰嚮涓婁紶
+ </el-button>
+ </el-upload>
+ </el-form-item>
+ </div>
+ <div v-if="formData.config.apiVersion === 'v3'">
+ <el-form-item label="API V3 瀵嗛挜" label-width="180px" prop="config.apiV3Key">
+ <el-input
+ v-model="formData.config.apiV3Key"
+ clearable
+ placeholder="璇疯緭鍏� API V3 瀵嗛挜"
+ />
+ </el-form-item>
+ <el-form-item
+ label="apiclient_key.pem 璇佷功"
+ label-width="180px"
+ prop="config.privateKeyContent"
+ >
+ <el-input
+ v-model="formData.config.privateKeyContent"
+ :autosize="{ minRows: 2, maxRows: 4 }"
+ :style="{ width: '100%' }"
+ placeholder="璇蜂笂浼� apiclient_key.pem 璇佷功"
+ readonly
+ type="textarea"
+ :rows="2"
+ />
+ </el-form-item>
+ <el-form-item label="" label-width="180px" prop="privateKeyContentFile">
+ <el-upload
+ ref="privateKeyContentFile"
+ :before-upload="pemFileBeforeUpload"
+ :http-request="privateKeyContentUpload"
+ :limit="1"
+ accept=".pem"
+ action=""
+ >
+ <el-button type="primary">
+ <Icon class="mr-5px" icon="ep:upload" />
+ 鐐瑰嚮涓婁紶
+ </el-button>
+ </el-upload>
+ </el-form-item>
+ <el-form-item label="璇佷功搴忓垪鍙�" label-width="180px" prop="config.certSerialNo">
+ <el-input
+ v-model="formData.config.certSerialNo"
+ clearable
+ placeholder="璇疯緭鍏ヨ瘉涔﹀簭鍒楀彿"
+ />
+ </el-form-item>
+ <el-form-item label-width="180px">
+ <a
+ href="https://pay.weixin.qq.com/index.php/core/cert/api_cert#/api-cert-manage"
+ target="_blank"
+ >
+ 鍓嶅線寰俊鍟嗘埛骞冲彴鏌ョ湅璇佷功搴忓垪鍙�
+ </a>
+ </el-form-item>
+ <el-form-item
+ label="public_key.pem 璇佷功"
+ label-width="180px"
+ prop="config.publicKeyContent"
+ >
+ <el-input
+ v-model="formData.config.publicKeyContent"
+ :autosize="{ minRows: 2, maxRows: 4 }"
+ :style="{ width: '100%' }"
+ placeholder="璇蜂笂浼� public_key.pem 璇佷功"
+ readonly
+ type="textarea"
+ :rows="2"
+ />
+ </el-form-item>
+ <el-form-item label="" label-width="180px" prop="publicKeyContentFile">
+ <el-upload
+ ref="publicKeyContentFile"
+ :before-upload="pemFileBeforeUpload"
+ :http-request="publicKeyContentUpload"
+ :limit="1"
+ accept=".pem"
+ action=""
+ >
+ <el-button type="primary">
+ <Icon class="mr-5px" icon="ep:upload" />
+ 鐐瑰嚮涓婁紶
+ </el-button>
+ </el-upload>
+ </el-form-item>
+ <el-form-item label="鍏挜 ID" label-width="180px" prop="config.publicKeyId">
+ <el-input v-model="formData.config.publicKeyId" clearable placeholder="璇疯緭鍏ュ叕閽� ID" />
+ </el-form-item>
+ <el-form-item label-width="180px">
+ <a href="https://pay.weixin.qq.com/doc/v3/merchant/4012153196" target="_blank">
+ 寰俊鏀粯鍏挜浜у搧绠�浠嬪強浣跨敤璇存槑
+ </a>
+ </el-form-item>
+ </div>
+ <el-form-item label="澶囨敞" label-width="180px" prop="remark">
+ <el-input v-model="formData.remark" :style="{ width: '100%' }" />
+ </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>
+ </div>
+</template>
+<script lang="ts" setup>
+import { CommonStatusEnum } from '@/utils/constants'
+import { DICT_TYPE, getDictOptions } from '@/utils/dict'
+import * as ChannelApi from '@/api/pay/channel'
+
+defineOptions({ name: 'WeixinChannelForm' })
+
+const { t } = useI18n() // 鍥介檯鍖�
+const message = useMessage() // 娑堟伅寮圭獥
+
+const dialogVisible = ref(false) // 寮圭獥鐨勬槸鍚﹀睍绀�
+const dialogTitle = ref('') // 寮圭獥鐨勬爣棰�
+const formLoading = ref(false) // 琛ㄥ崟鐨勫姞杞戒腑锛�1锛変慨鏀规椂鐨勬暟鎹姞杞斤紱2锛夋彁浜ょ殑鎸夐挳绂佺敤
+const formData = ref<any>({
+ appId: '',
+ code: '',
+ status: undefined,
+ feeRate: undefined,
+ remark: '',
+ config: {
+ appId: '',
+ mchId: '',
+ apiVersion: '',
+ mchKey: '',
+ keyContent: '',
+ privateKeyContent: '',
+ certSerialNo: '',
+ apiV3Key: '',
+ publicKeyContent: '',
+ publicKeyId: ''
+ }
+})
+const formRules = {
+ 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.pem 璇佷功', trigger: 'blur' }
+ ],
+ 'config.certSerialNo': [{ required: true, message: '璇疯緭鍏ヨ瘉涔﹀簭鍒楀彿', trigger: 'blur' }],
+ 'config.publicKeyId': [{ required: true, message: '璇疯緭鍏ュ叕閽� ID', trigger: 'blur' }],
+ 'config.apiV3Key': [{ required: true, message: '璇蜂笂浼� api V3 瀵嗛挜鍊�', trigger: 'blur' }]
+}
+const formRef = ref() // 琛ㄥ崟 Ref
+
+/** 鎵撳紑寮圭獥 */
+const open = async (appId, code) => {
+ dialogVisible.value = true
+ formLoading.value = true
+ resetForm(appId, code)
+ // 鍔犺浇鏁版嵁
+ try {
+ const data = await ChannelApi.getChannel(appId, code)
+ if (data && data.id) {
+ formData.value = data
+ formData.value.config = JSON.parse(data.config)
+ }
+ dialogTitle.value = !formData.value.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 ChannelApi.ChannelVO
+ data.config = JSON.stringify(formData.value.config)
+ if (!data.id) {
+ await ChannelApi.createChannel(data)
+ message.success(t('common.createSuccess'))
+ } else {
+ await ChannelApi.updateChannel(data)
+ message.success(t('common.updateSuccess'))
+ }
+ dialogVisible.value = false
+ // 鍙戦�佹搷浣滄垚鍔熺殑浜嬩欢
+ emit('success')
+ } finally {
+ formLoading.value = false
+ }
+}
+
+/** 閲嶇疆琛ㄥ崟 */
+const resetForm = (appId, code) => {
+ formData.value = {
+ appId: appId,
+ code: code,
+ status: CommonStatusEnum.ENABLE,
+ feeRate: undefined,
+ remark: '',
+ config: {
+ appId: '',
+ mchId: '',
+ apiVersion: '',
+ mchKey: '',
+ keyContent: '',
+ privateKeyContent: '',
+ certSerialNo: '',
+ apiV3Key: '',
+ publicKeyContent: '',
+ publicKeyId: ''
+ }
+ }
+ formRef.value?.resetFields()
+}
+
+/**
+ * apiclient_cert.p12銆乤piclient_key.pem 涓婁紶鍓嶇殑鏍¢獙
+ */
+const fileBeforeUpload = (file, fileAccept) => {
+ 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 p12FileBeforeUpload = (file) => {
+ fileBeforeUpload(file, '.p12')
+}
+
+const pemFileBeforeUpload = (file) => {
+ fileBeforeUpload(file, '.pem')
+}
+
+/**
+ * 璇诲彇 apiclient_key.pem 鍒� privateKeyContent 瀛楁
+ */
+const privateKeyContentUpload = async (event) => {
+ const readFile = new FileReader()
+ readFile.onload = (e: any) => {
+ formData.value.config.privateKeyContent = e.target.result
+ }
+ readFile.readAsText(event.file)
+}
+
+/**
+ * 璇诲彇 apiclient_cert.p12 鍒� keyContent 瀛楁
+ */
+const keyContentUpload = async (event) => {
+ const readFile = new FileReader()
+ readFile.onload = (e: any) => {
+ formData.value.config.keyContent = e.target.result.split(',')[1]
+ }
+ readFile.readAsDataURL(event.file) // 璇绘垚 base64
+}
+
+/**
+ * 璇诲彇 public_key.pem 鍒� publicKeyContent 瀛楁
+ */
+const publicKeyContentUpload = async (event) => {
+ const readFile = new FileReader()
+ readFile.onload = (e: any) => {
+ formData.value.config.publicKeyContent = e.target.result
+ }
+ readFile.readAsText(event.file)
+}
+</script>
--
Gitblit v1.8.0