file.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { getToken } from './token-util';
  2. import { TOKEN_HEADER_NAME } from '@/config/setting';
  3. // 获取图片反显url
  4. export function getImageUrl(path) {
  5. if (!path) {
  6. return;
  7. }
  8. let fileNames = path.split('/');
  9. let url =
  10. 'https://37xu1hy03623.vicp.fun/api/main/file/getFile?objectName=' +
  11. path +
  12. '&fullfilename=' +
  13. fileNames[fileNames.length - 1];
  14. return url;
  15. // return `${sessionStorage.filePath}${path}`;
  16. // if (process.env.NODE_ENV === 'development') {
  17. // return `http://192.168.3.51:18086/main/file/getFile?${TOKEN_HEADER_NAME}=${getToken()}&objectName=${path}`;
  18. // } else {
  19. // return `${
  20. // sessionStorage.filePath
  21. // }${path}`;
  22. // }
  23. }
  24. // 从反显url上获取接口需要path
  25. export function getImagePath(url) {
  26. if (!url) {
  27. return '';
  28. }
  29. const match = url.match(/&objectName=([\S\s]*)/);
  30. return (match && match[1].split('&')[0]) || '';
  31. }
  32. // 下载方法
  33. export function download(data, name) {
  34. const a = document.createElement('a');
  35. const url = window.URL.createObjectURL(data);
  36. const filename = name;
  37. a.href = url;
  38. a.download = filename;
  39. a.click();
  40. window.URL.revokeObjectURL(url);
  41. }
  42. export function download1(url, name) {
  43. const a = document.createElement('a');
  44. const filename = name;
  45. a.href = url;
  46. a.download = filename;
  47. a.click();
  48. }