From c7bfa1c3ba0f43fcd362837b56e589367e127a4b Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 21 Jul 2026 09:39:19 +0800 Subject: [PATCH] fix: standardize file URL generation in common.ts and ParagraphDocumentContent.vue --- .../ParagraphDocumentContent.vue | 2 +- ui/src/utils/common.ts | 73 +++++++++---------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/ui/src/components/ai-chat/component/knowledge-source-component/ParagraphDocumentContent.vue b/ui/src/components/ai-chat/component/knowledge-source-component/ParagraphDocumentContent.vue index dff38dfc205..37beb19e77e 100644 --- a/ui/src/components/ai-chat/component/knowledge-source-component/ParagraphDocumentContent.vue +++ b/ui/src/components/ai-chat/component/knowledge-source-component/ParagraphDocumentContent.vue @@ -66,7 +66,7 @@ const isPdf = computed(() => !!props.detail?.meta?.source_file_id) const pdfSrc = computed(() => { const fileId = props.detail?.meta?.source_file_id - return fileId ? `${window.MaxKB.prefix}/oss/file/${fileId}` : '' + return fileId ? `./oss/file/${fileId}` : '' }) const overlayText = computed(() => { diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts index f3e6d83dd7e..ef92fa7c2ea 100644 --- a/ui/src/utils/common.ts +++ b/ui/src/utils/common.ts @@ -1,5 +1,5 @@ -import {nanoid} from 'nanoid' -import {t} from '@/locales' +import { nanoid } from 'nanoid' +import { t } from '@/locales' /** * 数字处理 @@ -11,7 +11,7 @@ export function toThousands(num: any) { } export function numberFormat(num: number) { - return num < 1000 ? toThousands(num): toThousands((num / 1000).toFixed(1)) + 'k' + return num < 1000 ? toThousands(num) : toThousands((num / 1000).toFixed(1)) + 'k' } export function filesize(size: number) { @@ -87,13 +87,13 @@ export function downloadByURL(url: string, name: string) { } // 替换固定数据国际化 -const i18n_default_name_map:any = { - "系统管理员": 'layout.about.inner_admin', - "工作空间管理员": 'layout.about.inner_wsm', - "普通用户": 'layout.about.inner_user', - "根目录": 'layout.about.root', - "默认工作空间": 'layout.about.default_workspace', - "默认用户组": 'layout.about.default_user_group', +const i18n_default_name_map: any = { + 系统管理员: 'layout.about.inner_admin', + 工作空间管理员: 'layout.about.inner_wsm', + 普通用户: 'layout.about.inner_user', + 根目录: 'layout.about.root', + 默认工作空间: 'layout.about.default_workspace', + 默认用户组: 'layout.about.default_user_group', } export function i18n_name(name: string) { @@ -101,7 +101,6 @@ export function i18n_name(name: string) { return key ? t(key) : name } - // 截取文件名 export function cutFilename(filename: string, num: number) { const lastIndex = filename.lastIndexOf('.') @@ -115,51 +114,51 @@ interface LoadScriptOptions { } export const loadScript = (url: string, options: LoadScriptOptions = {}): Promise => { - const { jsId, forceReload = false } = options; - const scriptId = jsId || `script-${btoa(url).slice(0, 12)}`; + const { jsId, forceReload = false } = options + const scriptId = jsId || `script-${btoa(url).slice(0, 12)}` const cleanupScript = (script: HTMLScriptElement) => { if (script && script.parentElement) { - script.parentElement.removeChild(script); + script.parentElement.removeChild(script) } - }; + } return new Promise((resolve, reject) => { if (typeof document === 'undefined') { - reject(new Error('Cannot load script in non-browser environment')); - return; + reject(new Error('Cannot load script in non-browser environment')) + return } - const existingScript = document.getElementById(scriptId) as HTMLScriptElement | null; + const existingScript = document.getElementById(scriptId) as HTMLScriptElement | null if (existingScript && !forceReload) { if (existingScript.src === url) { - console.log(`[loadScript] Reuse existing script: ${url}`); - resolve(); - return; + console.log(`[loadScript] Reuse existing script: ${url}`) + resolve() + return } - existingScript.remove(); + existingScript.remove() } - const script = document.createElement('script'); - script.id = scriptId; - script.src = url; - script.async = true; + const script = document.createElement('script') + script.id = scriptId + script.src = url + script.async = true script.onload = () => { - console.log(`[loadScript] Script loaded: ${url}`); - resolve(); - }; + console.log(`[loadScript] Script loaded: ${url}`) + resolve() + } script.onerror = () => { - console.error(`[loadScript] Failed to load: ${url}`); - cleanupScript(script); - reject(new Error(`Failed to load script: ${url}`)); - }; + console.error(`[loadScript] Failed to load: ${url}`) + cleanupScript(script) + reject(new Error(`Failed to load script: ${url}`)) + } - document.head.appendChild(script); - }); -}; + document.head.appendChild(script) + }) +} // 清理脚本(可选) const cleanupScript = (script: HTMLScriptElement) => { @@ -177,7 +176,7 @@ export function getNormalizedUrl(url: string) { export function getFileUrl(fileId?: string) { if (fileId) { - return `${window.MaxKB.prefix}/oss/file/${fileId}` + return `./oss/file/${fileId}` } return '' }