app.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { http } from '@/utils/http';
  2. import store from '@/store';
  3. import { app } from '@/store/mutation-types';
  4. /**
  5. * @description 得到系统标志
  6. * @param {object} data 请求数据
  7. */
  8. export function GetLogo(data) {
  9. return http.post(`${process.env.VUE_APP_EepServer}?MethodName=sys_config_manager-GetLogo`, data);
  10. }
  11. /**
  12. * 得到文件 ID 与 URL 的映射
  13. */
  14. export function GetFileURLMap(data) {
  15. return http.post(`${process.env.VUE_APP_EepServer}?MethodName=file_store_manager-GetFileURLMap`, data);
  16. }
  17. /**
  18. * 得到文件存储信息
  19. * @param {object} data 请求数据
  20. * @param {string} data.file_id 文件 ID
  21. */
  22. export function GetFileStoreInfo(data) {
  23. return http.post(`${process.env.VUE_APP_EepServer}?MethodName=file_store_manager-GetFileStoreInfo`, data);
  24. }
  25. /**
  26. * 上传文件
  27. * @param {string} SecurityLevel 保密级别
  28. * @param {object} file 文件对象
  29. * @param {object} option 上传选项
  30. * @param {function} option.handleUploadProgress 上传进度回调
  31. * @param {boolean} option.isGlobalprogress 是否使用全局进度条
  32. */
  33. export async function fileUpload(
  34. SecurityLevel,
  35. file,
  36. { handleUploadProgress, isGlobalprogress = false } = { isGlobalprogress: false },
  37. ) {
  38. let formData = null;
  39. if (file instanceof FormData) {
  40. formData = file;
  41. } else {
  42. formData = new FormData();
  43. formData.append(file.filename, file.file, file.file.name);
  44. }
  45. let onUploadProgress = handleUploadProgress || null;
  46. if (isGlobalprogress) {
  47. store.commit(`app/${app.SHOW_PROGRESS}`, true);
  48. onUploadProgress = ({ loaded, progress, total }) => {
  49. // 因为上传进度为 1 后,上传事件还会继续一段时间,所以这里将进度设置为 0.99
  50. let precent = progress >= 1 ? 0.99 : progress;
  51. store.commit(`app/${app.SET_UPLOAD_INFO}`, { loaded, progress: precent, total });
  52. };
  53. }
  54. const controller = new AbortController();
  55. store.commit(`app/${app.SET_UPLOAD_CONTROLLER}`, controller);
  56. try {
  57. const res = await http.postForm('/FileServer/WebFileUpload', formData, {
  58. params: {
  59. SecurityLevel,
  60. },
  61. signal: controller.signal,
  62. transformRequest: [(data) => data],
  63. onUploadProgress,
  64. timeout: 0,
  65. });
  66. store.commit(`app/${app.SET_UPLOAD_INFO}`, { progress: 1 });
  67. return res;
  68. } finally {
  69. store.commit(`app/${app.SET_UPLOAD_CONTROLLER}`, null);
  70. }
  71. }
  72. export function GetStaticResources(MethodName, data) {
  73. return http.post(`/OtherSysTool/GCLSBaseServer/SI?MethodName=${MethodName}`, data);
  74. }
  75. export function GetBookWebSIContent(MethodName, data) {
  76. return http.post(`/GCLSBookWebSI/ServiceInterface?MethodName=${MethodName}`, data);
  77. }
  78. /**
  79. * 解压 H5 游戏包并创建启动文件
  80. */
  81. export function H5StartupFile(data) {
  82. return http.post(`/FileServer/SI?MethodName=file_store_manager-UnzipH5GamePackCreateStartupFile`, data);
  83. }
  84. export function LearnWebSI(MethodName, data) {
  85. return http.post(`/GCLSLearnWebSI/ServiceInterface?MethodName=${MethodName}`, data);
  86. }