diff --git a/src/utils/index.ts b/src/utils/index.ts index 98a0740..503cd75 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -11,7 +11,10 @@ import type { App, Component } from 'vue'; import { unref } from 'vue'; import { isObject } from '/@/utils/is'; import { isEmpty, cloneDeep } from 'lodash-es'; +import { isDevMode } from '/@/utils/env'; +import { useGlobSetting } from '/@/hooks/setting'; +const { apiUrl } = useGlobSetting(); export const noop = () => {}; /** @@ -130,3 +133,15 @@ export const findListNameById = (id: string, list: any[], options: Partial<{ idF } 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; +} diff --git a/src/views/system/file/file.data.ts b/src/views/system/file/file.data.ts index 7299b8b..4e2518d 100644 --- a/src/views/system/file/file.data.ts +++ b/src/views/system/file/file.data.ts @@ -11,10 +11,10 @@ import { getFileSize } from '/@/utils/file/download'; import { h } from 'vue'; import { useGlobSetting } from '/@/hooks/setting'; import { Tag, Button } from 'ant-design-vue'; -const { filePreviewUrl = '', apiUrl } = useGlobSetting(); +const { filePreviewUrl = '' } = useGlobSetting(); import { Api } from '/@/api/platform/system/controller/file'; import { encodeURL } from 'js-base64'; -import { isDevMode } from '/@/utils/env'; +import { getCloudProxyUrl } from '/@/utils'; /** 表格列配置 */ export const columns: BasicColumn[] = [ @@ -33,14 +33,7 @@ export const columns: BasicColumn[] = [ ellipsis: true, width: 380, customRender: ({ record }) => { - // 获取当前文件流基础地址 - 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}`); + const url = encodeURL(`${getCloudProxyUrl()}${Api.get}/${record.bucketName}/${record.fileName}`); return record.fileName ? h(Button, { type: 'link', target: '_blank',