erp-el-element/utils/alioss.js

44 lines
1.4 KiB
JavaScript

import axios from "axios"; //引入axios
import { get_oss_sign_aliyun } from '@/api/user';
const instance = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: 300000,
});
// let baseURL = process.env.BASE_URL.toString();
//这里根据自己项目接口的位置自行设定
let baseURL = process.env.VUE_APP_BASE_API;
// if (process.env.NODE_ENV == "production") {
// baseURL = "http://1xx.1xx.1xx.1xx/hyr";
// }
// instance.defaults.baseURL = baseURL; //baseURL用于自动切换本地环境接口和生产环境接口
instance.defaults.headers.post["Content-Type"] ="multipart/form-data";
// instance.defaults.headers.post["Access-Control-Allow-Origin"] = "*";
// instance.defaults.withCredentials = false; // 携带cookie
//上传附件axios接口封装
const upload = {
async uploadFile( payload,v, cd) {
let res = await get_oss_sign_aliyun({type:v})
payload.append("policy", res.datas.policy);
payload.append("OSSAccessKeyId", res.datas.accessid);
payload.append("signature", res.datas.signature);
payload.append("success_action_status", '200');
return instance({
url: `https://${res.datas.host}`,
method: "post",
data: payload,
onUploadProgress: function(progressEvent) {
if (progressEvent.lengthComputable) {
cd(progressEvent);
}
},
// cancelToken: cancelToken,
});
},
}
export {
upload,
axios,
}