修复上传文件问题

feature/pay-0704-ch
ch 2 years ago
parent 43bec0f46e
commit 6089283696

@ -2,9 +2,10 @@
* @Author: ch
* @Date: 2022-07-07 17:27:04
* @LastEditors: ch
* @LastEditTime: 2022-07-09 11:14:35
* @LastEditTime: 2022-07-11 17:24:09
* @Description: file content
*/
import { ElMessage } from '@/plugins/element-plus';
import request from '@/utils/request';
// OSS签名
export function sign(serviceName, configId) {
@ -25,18 +26,23 @@ export function payCenterSign() {
}
// 上传文件
export async function upload(serviceName, configId, file, cancelToken) {
export async function upload(serviceName, configId, file, cancelToken, suffix) {
const _suffix = file.name.substring(file.name.lastIndexOf('.'));
const suffixObj = typeof suffix === 'string' ? suffix.split(',') : suffix;
if (!suffixObj.includes(_suffix)) {
ElMessage.error('上传文件类型错误');
return '';
}
let oss = {};
if (serviceName) {
oss = await sign(serviceName, configId);
} else {
oss = await payCenterSign();
}
// return false;
let data = new FormData();
let name = file.uid + file.name.substring(file.name.lastIndexOf('.'));
const data = new FormData();
const name = file.uid + _suffix;
data.append('name', name);
data.append('key', `${oss.dir}${'${filename}'}`);
data.append('key', `${oss.dir}${name}`);
data.append('policy', oss.policy);
data.append('OSSAccessKeyId', oss.accessId);
data.append('Signature', oss.signature);

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-07-04 16:42:21
* @LastEditors: ch
* @LastEditTime: 2022-07-09 10:38:04
* @LastEditTime: 2022-07-11 17:06:12
* @Description: file content
-->
<template>
@ -170,7 +170,7 @@
* 上传阿里应用证书
*/
const handleUpload = async ({ file }) => {
const res = await upload(null, null, file);
const res = await upload(null, null, file, null, '.crt');
form.appCertUrl = res;
};
const handleSave = async () => {

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-07-04 17:57:55
* @LastEditors: ch
* @LastEditTime: 2022-07-09 10:39:00
* @LastEditTime: 2022-07-11 17:07:42
* @Description: file content
-->
<template>
@ -100,14 +100,14 @@
* 上传公钥证书
*/
const handleUploadCert = async ({ file }) => {
const res = await upload(null, null, file);
const res = await upload(null, null, file, null, '.crt');
form.aliPayCertUrl = res;
};
/**
* 上传根证书
*/
const handleUploadRootCert = async ({ file }) => {
const res = await upload(null, null, file);
const res = await upload(null, null, file, null, '.crt');
form.aliPayRootCertUrl = res;
};
/**

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-07-04 17:57:45
* @LastEditors: ch
* @LastEditTime: 2022-07-09 11:14:59
* @LastEditTime: 2022-07-11 17:06:45
* @Description: file content
-->
<template>
@ -27,7 +27,7 @@
<el-button type="primary" v-else></el-button>
</el-upload>
</el-form-item>
<el-form-item label="商户证书(key.pem)" prop="certOssUrl">
<el-form-item label="商户证书(cert.pem)" prop="certOssUrl">
<el-upload action="none" accept=".pem" :show-file-list="false" :http-request="handleUploadCert">
<el-button type="success" v-if="modelValue.hasCert || form.certOssUrl"></el-button>
<el-button type="primary" v-else></el-button>
@ -149,22 +149,21 @@
* 上传公钥证书
*/
const handleUploadCert = async ({ file }) => {
const res = await upload(null, null, file);
const res = await upload(null, null, file, null, '.pem');
form.certOssUrl = res;
};
/**
* 上传私钥证书
*/
const handleUploadKeyCert = async ({ file }) => {
const res = await upload(null, null, file);
const res = await upload(null, null, file, null, '.pem');
form.keyOssUrl = res;
};
/**
* 上传p12证书
*/
const handleUploadCert120 = async ({ file }) => {
// const res = await upload('payCenter', 'merchant/', file);
const res = await upload(null, null, file);
const res = await upload(null, null, file, null, '.p12');
form.certP12OssUrl = res;
};
/**

Loading…
Cancel
Save