From da7d4794ffc610d0aa12cd0f3889ce239f1536b6 Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Wed, 19 Jul 2023 22:31:53 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=8A=BD=E7=A6=BB=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BA=91=E4=BB=A3=E7=90=86=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.ts | 15 +++++++++++++++ src/views/system/file/file.data.ts | 13 +++---------- 2 files changed, 18 insertions(+), 10 deletions(-) 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',