file.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. }
  32. export function download1(url, name) {
  33. const a = document.createElement('a');
  34. const filename = name;
  35. a.href = url;
  36. a.download = filename;
  37. a.click();
  38. }