|
|
|
@ -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);
|
|
|
|
|