app.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { http } from '@/utils/http';
  2. import store from '@/store';
  3. import { app } from '@/store/mutation-types';
  4. /**
  5. * @description 得到验证码图像
  6. */
  7. export function GetVerificationCodeImage() {
  8. return http.get(`${process.env.VUE_APP_FileServer}?MethodName=login_control-GetVerificationCodeImage`);
  9. }
  10. /**
  11. * @description 得到系统标志
  12. * @param {object} data 请求数据
  13. */
  14. export function GetLogo(data) {
  15. return http.post(`${process.env.VUE_APP_FileServer}?MethodName=sys_config_manager-GetLogo`, data);
  16. }
  17. /**
  18. * 得到文件 ID 与 URL 的映射
  19. */
  20. export function GetFileURLMap(data) {
  21. return http.post(`${process.env.VUE_APP_FileServer}?MethodName=file_store_manager-GetFileURLMap`, data);
  22. }
  23. /**
  24. * 得到文件存储信息
  25. */
  26. export function GetFileStoreInfo(data) {
  27. return http.post(`${process.env.VUE_APP_FileServer}?MethodName=file_store_manager-GetFileStoreInfo`, data);
  28. }
  29. /**
  30. * 得到用户能进入的子系统列表(电脑端)
  31. */
  32. export function GetChildSysList_CanEnter_PC(data) {
  33. return http.post(`${process.env.VUE_APP_FileServer}?MethodName=login_control-GetChildSysList_CanEnter_PC`, data);
  34. }
  35. /**
  36. * 解开访问令牌
  37. * @param {object} data 请求数据
  38. * @param {string} data.access_token 访问令牌
  39. */
  40. export function ParseAccessToken(data) {
  41. return http.post(`${process.env.VUE_APP_FileServer}?MethodName=login_control-ParseAccessToken`, data);
  42. }
  43. /**
  44. * 保存文件字节流的 Base64 编码文本信息
  45. */
  46. export function SaveFileByteBase64Text(data) {
  47. return http.post(`${process.env.VUE_APP_FileServer}?MethodName=file_store_manager-SaveFileByteBase64Text`, data);
  48. }
  49. /**
  50. * 上传文件
  51. * @param {String} SecurityLevel 保密级别
  52. * @param {object} file 文件对象
  53. * @param {object} option 上传选项
  54. * @param {function} option.handleUploadProgress 上传进度回调
  55. * @param {boolean} option.isGlobalprogress 是否使用全局进度条
  56. */
  57. export async function fileUpload(
  58. SecurityLevel,
  59. file,
  60. { handleUploadProgress, isGlobalprogress = false } = { isGlobalprogress: false },
  61. ) {
  62. let formData = null;
  63. if (file instanceof FormData) {
  64. formData = file;
  65. } else {
  66. formData = new FormData();
  67. formData.append(file.filename, file.file, file.file.name);
  68. }
  69. let onUploadProgress = handleUploadProgress || null;
  70. if (isGlobalprogress) {
  71. store.commit(`app/${app.SHOW_PROGRESS}`, true);
  72. onUploadProgress = ({ loaded, progress, total }) => {
  73. // 因为上传进度为 1 后,上传事件还会继续一段时间,所以这里将进度设置为 0.99
  74. let precent = progress >= 1 ? 0.99 : progress;
  75. store.commit(`app/${app.SET_UPLOAD_INFO}`, { loaded, progress: precent, total });
  76. };
  77. }
  78. const controller = new AbortController();
  79. store.commit(`app/${app.SET_UPLOAD_CONTROLLER}`, controller);
  80. try {
  81. const res = await http.postForm('/GCLSFileServer/WebFileUpload', formData, {
  82. params: {
  83. SecurityLevel,
  84. },
  85. signal: controller.signal,
  86. transformRequest: [(data) => data],
  87. onUploadProgress,
  88. timeout: 0,
  89. });
  90. store.commit(`app/${app.SET_UPLOAD_INFO}`, { progress: 1 });
  91. return res;
  92. } finally {
  93. store.commit(`app/${app.SET_UPLOAD_CONTROLLER}`, null);
  94. }
  95. }
  96. export function GetStaticResources(MethodName, data) {
  97. return http.post(`/GCLSFileServer/ServiceInterface?MethodName=${MethodName}`, data);
  98. }