index.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export const downloadFile = (blob: any, fileName: string) => {
  2. const downUrl = window.URL.createObjectURL(new Blob([blob]));
  3. const elementA = document.createElement('a');
  4. elementA.href = downUrl;
  5. elementA.download = fileName;
  6. elementA.style.display = 'none';
  7. document.body.appendChild(elementA);
  8. elementA.click();
  9. document.body.removeChild(elementA);
  10. };
  11. // 其他工具函数...
  12. // 切片数据 分为 正常 和 废弃两种
  13. export const processSliceData = (data: any) => {
  14. const result = data.reduce((acc: any, item: any) => {
  15. // 1. 筛选出 slice_type 为 'deprecated' 的 chunks
  16. const deprecatedChunks = item.chunk_info_list.filter((chunk: any) => chunk.slice_type === 'deprecated');
  17. // 2. 筛选出 slice_type 不为 'deprecated' 的 chunks (例如 'normal')
  18. const normalChunks = item.chunk_info_list.filter((chunk: any) => chunk.slice_type !== 'deprecated');
  19. // 3. 如果筛选结果不为空,则创建一个新的文档对象并添加到对应的数组中
  20. if (deprecatedChunks.length > 0) {
  21. acc.withDeprecated.push({
  22. ...item, // 复制原文档的所有属性
  23. chunk_info_list: deprecatedChunks // 用筛选后的 chunks 替换原有的 chunk_info_list
  24. });
  25. }
  26. if (normalChunks.length > 0) {
  27. acc.withoutDeprecated.push({
  28. ...item, // 复制原文档的所有属性
  29. chunk_info_list: normalChunks // 用筛选后的 chunks 替换原有的 chunk_info_list
  30. });
  31. }
  32. // 返回累加器以供下一次迭代使用
  33. return acc;
  34. }, { withDeprecated: [], withoutDeprecated: [] });
  35. return result;
  36. }
  37. // 重定向地址
  38. export const replaceUrl = 'http://10.1.14.17:3200/login';
  39. // export const replaceUrl = 'http://192.168.110.12:3100/login';