|
|
@@ -1,6 +1,6 @@
|
|
|
import { http } from '@/utils/http';
|
|
|
-import store from '@/store';
|
|
|
import { app } from '@/store/mutation-types';
|
|
|
+import { getRuntimeServices } from '@/utils/runtime-services';
|
|
|
|
|
|
/**
|
|
|
* @description 得到系统标志
|
|
|
@@ -39,6 +39,7 @@ export async function fileUpload(
|
|
|
file,
|
|
|
{ handleUploadProgress, isGlobalprogress = false } = { isGlobalprogress: false },
|
|
|
) {
|
|
|
+ const { store } = getRuntimeServices();
|
|
|
let formData = null;
|
|
|
if (file instanceof FormData) {
|
|
|
formData = file;
|
|
|
@@ -48,7 +49,7 @@ export async function fileUpload(
|
|
|
}
|
|
|
|
|
|
let onUploadProgress = handleUploadProgress || null;
|
|
|
- if (isGlobalprogress) {
|
|
|
+ if (isGlobalprogress && store) {
|
|
|
store.commit(`app/${app.SHOW_PROGRESS}`, true);
|
|
|
onUploadProgress = ({ loaded, progress, total }) => {
|
|
|
// 因为上传进度为 1 后,上传事件还会继续一段时间,所以这里将进度设置为 0.99
|
|
|
@@ -58,7 +59,7 @@ export async function fileUpload(
|
|
|
}
|
|
|
|
|
|
const controller = new AbortController();
|
|
|
- store.commit(`app/${app.SET_UPLOAD_CONTROLLER}`, controller);
|
|
|
+ store?.commit(`app/${app.SET_UPLOAD_CONTROLLER}`, controller);
|
|
|
|
|
|
try {
|
|
|
const res = await http.postForm('/FileServer/WebFileUpload', formData, {
|
|
|
@@ -70,10 +71,10 @@ export async function fileUpload(
|
|
|
onUploadProgress,
|
|
|
timeout: 0,
|
|
|
});
|
|
|
- store.commit(`app/${app.SET_UPLOAD_INFO}`, { progress: 1 });
|
|
|
+ store?.commit(`app/${app.SET_UPLOAD_INFO}`, { progress: 1 });
|
|
|
return res;
|
|
|
} finally {
|
|
|
- store.commit(`app/${app.SET_UPLOAD_CONTROLLER}`, null);
|
|
|
+ store?.commit(`app/${app.SET_UPLOAD_CONTROLLER}`, null);
|
|
|
}
|
|
|
}
|
|
|
|