file.js 941 B

1234567891011121314151617181920212223242526272829303132333435
  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) {
  17. return '';
  18. }
  19. const match = url.match(/&objectName=([\S\s]*)/);
  20. return (match && match[1].split('&')[0]) || '';
  21. }
  22. // 下载方法
  23. export function download (data, name) {
  24. const a = document.createElement('a');
  25. const url = window.URL.createObjectURL(data);
  26. const filename = name;
  27. a.href = url;
  28. a.download = filename;
  29. a.click();
  30. window.URL.revokeObjectURL(url);
  31. }