Browse Source

chore: 抽离获取云代理路径

master
wangxiang 2 years ago
parent
commit
da7d4794ff
  1. 15
      src/utils/index.ts
  2. 13
      src/views/system/file/file.data.ts

15
src/utils/index.ts

@ -11,7 +11,10 @@ import type { App, Component } from 'vue';
import { unref } from 'vue'; import { unref } from 'vue';
import { isObject } from '/@/utils/is'; import { isObject } from '/@/utils/is';
import { isEmpty, cloneDeep } from 'lodash-es'; import { isEmpty, cloneDeep } from 'lodash-es';
import { isDevMode } from '/@/utils/env';
import { useGlobSetting } from '/@/hooks/setting';
const { apiUrl } = useGlobSetting();
export const noop = () => {}; export const noop = () => {};
/** /**
@ -130,3 +133,15 @@ export const findListNameById = (id: string, list: any[], options: Partial<{ idF
} }
return ''; return '';
}; };
/** 获取后端微服务代理地址 */
export function getCloudProxyUrl(): string {
let baseUrl = `${window.location.origin}${apiUrl}`;
if (isDevMode()) {
const proxy: [string[]] = JSON.parse(import.meta.env.VITE_PROXY);
const api = proxy.find(item => item[0] == apiUrl) || [];
baseUrl = api[1];
}
return baseUrl;
}

13
src/views/system/file/file.data.ts

@ -11,10 +11,10 @@ import { getFileSize } from '/@/utils/file/download';
import { h } from 'vue'; import { h } from 'vue';
import { useGlobSetting } from '/@/hooks/setting'; import { useGlobSetting } from '/@/hooks/setting';
import { Tag, Button } from 'ant-design-vue'; import { Tag, Button } from 'ant-design-vue';
const { filePreviewUrl = '', apiUrl } = useGlobSetting(); const { filePreviewUrl = '' } = useGlobSetting();
import { Api } from '/@/api/platform/system/controller/file'; import { Api } from '/@/api/platform/system/controller/file';
import { encodeURL } from 'js-base64'; import { encodeURL } from 'js-base64';
import { isDevMode } from '/@/utils/env'; import { getCloudProxyUrl } from '/@/utils';
/** 表格列配置 */ /** 表格列配置 */
export const columns: BasicColumn[] = [ export const columns: BasicColumn[] = [
@ -33,14 +33,7 @@ export const columns: BasicColumn[] = [
ellipsis: true, ellipsis: true,
width: 380, width: 380,
customRender: ({ record }) => { customRender: ({ record }) => {
// 获取当前文件流基础地址 const url = encodeURL(`${getCloudProxyUrl()}${Api.get}/${record.bucketName}/${record.fileName}`);
let baseUrl;
if (isDevMode()) {
const proxy: [string[]] = JSON.parse(import.meta.env.VITE_PROXY);
const api = proxy.find(item => item[0] == apiUrl) || [];
baseUrl = api[1];
} else baseUrl = `${window.location.origin}${apiUrl}`;
const url = encodeURL(`${baseUrl}${Api.get}/${record.bucketName}/${record.fileName}`);
return record.fileName ? h(Button, { return record.fileName ? h(Button, {
type: 'link', type: 'link',
target: '_blank', target: '_blank',

Loading…
Cancel
Save