let fileList = this.restfileList
fileList.forEach((item, index) => {
setTimeout(() => {
let notifyKey = 'q' + nanoid()
window.sessionStorage.setItem("cancelAxiosId", notifyKey)
this.notifyInit[notifyKey] = this.$notify({
iconClass: "el-icon-loading",
title: '提示',
duration: 0,
offset: 65,
dangerouslyUseHTMLString: true,
message: item.name + '文件上传中...',
onClose: () => {
let cancelArr = window.axiosCancel;
cancelArr = cancelArr || [];
cancelArr.forEach((ele, index) => {
if (ele.id == notifyKey) {
this.$message({
message: '取消上传!',
type: 'warning'
});
ele.cancel("取消请求")
delete window.axiosCancel[index]
}
})
}
});
let formData = new FormData()
formData.append("id", id);
formData.append('file', item.raw)
this.$api.systemApi.uploadFile(formData).then((res) => {
if (res.success) {
let cancelArr = window.axiosCancel;
cancelArr = cancelArr || [];
cancelArr.forEach((ele, index) => {
if (ele.id == notifyKey) {
delete window.axiosCancel[index]
}
})
this.$notify({
title: '成功',
message: '文件上传成功!',
type: 'success'
});
this.notifyInit[notifyKey].close()
} else {
let cancelArr = window.axiosCancel;
cancelArr = cancelArr || [];
cancelArr.forEach((ele, index) => {
if (ele.id == notifyKey) {
delete window.axiosCancel[index]
}
})
this.$notify.error({
title: '错误',
message: item.name + "文件上传失败!"
});
setTimeout(() => {
this.notifyInit[notifyKey].close()
}, 100)
}
});
}, 500)
})
window.axiosCancel = []
axios.interceptors.request.use(config => {
let isLogin = config.url.substring(config.url.length - 5, config.url.length);
if (isLogin != 'login'&& config.url.indexOf("https://geo.datav.aliyun.com/") == -1) {
let token = store.state.user.token;
if(token) {
config.headers['x-auth-token'] = `${token}`;
}
}
if(config.url.indexOf("/minio/upload")!=-1||config.url.indexOf("/api/minio/move")!=-1){
let cancelAxiosId = window.sessionStorage.getItem("cancelAxiosId")
config.cancelToken = new axios.CancelToken(cancel => {
window.axiosCancel.push({
id:cancelAxiosId,
cancel:cancel
})
})
}
NProgress.start();
return config;
}, error => {
return Promise.reject(error);
})