diff --git a/src/api/file.js b/src/api/file.js index 46c4d59..bfa0b01 100644 --- a/src/api/file.js +++ b/src/api/file.js @@ -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); diff --git a/src/views/pay/application/form.vue b/src/views/pay/application/form.vue index e40fa6a..659fff8 100644 --- a/src/views/pay/application/form.vue +++ b/src/views/pay/application/form.vue @@ -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 -->