| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { getToken } from './token-util';
- import { TOKEN_HEADER_NAME } from '@/config/setting';
- // 获取图片反显url
- export function getImageUrl(path) {
- if (!path) {
- return;
- }
- let fileNames = path.split('/');
- let url =
- window.location.origin +
- '/api/main/file/getFile?objectName=' +
- path +
- '&fullfilename=' +
- fileNames[fileNames.length - 1];
- return url;
- // return `${sessionStorage.filePath}${path}`;
- // if (process.env.NODE_ENV === 'development') {
- // return `http://192.168.3.51:18086/main/file/getFile?${TOKEN_HEADER_NAME}=${getToken()}&objectName=${path}`;
- // } else {
- // return `${
- // sessionStorage.filePath
- // }${path}`;
- // }
- }
- // 从反显url上获取接口需要path
- export function getImagePath(url) {
- if (!url) {
- return '';
- }
- const match = url.match(/&objectName=([\S\s]*)/);
- return (match && match[1].split('&')[0]) || '';
- }
- // 下载方法
- export function download(data, name) {
- const a = document.createElement('a');
- const url = window.URL.createObjectURL(data);
- const filename = name;
- a.href = url;
- a.download = filename;
- a.click();
- window.URL.revokeObjectURL(url);
- }
|