file.js 843 B

123456789101112131415161718192021222324252627282930313233
  1. // 获取图片反显url
  2. export function getImageUrl(path) {
  3. return `${sessionStorage.filePath}${path}`;
  4. // if (process.env.NODE_ENV === 'development') {
  5. // return `http://192.168.3.51:18086/main/file/getFile?${TOKEN_HEADER_NAME}=${getToken()}&objectName=${path}`;
  6. // } else {
  7. // return `${
  8. // sessionStorage.filePath
  9. // }${path}`;
  10. // }
  11. }
  12. // 从反显url上获取接口需要path
  13. export function getImagePath(url) {
  14. if (!url) {
  15. return '';
  16. }
  17. const match = url.match(/&objectName=([\S\s]*)/);
  18. return (match && match[1].split('&')[0]) || '';
  19. }
  20. // 下载方法
  21. export function download(data, name) {
  22. const a = document.createElement('a');
  23. const url = window.URL.createObjectURL(data);
  24. const filename = name;
  25. a.href = url;
  26. a.download = filename;
  27. a.click();
  28. window.URL.revokeObjectURL(url);
  29. }