file.js 1.2 KB

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