Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
73 changes: 36 additions & 37 deletions ui/src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {nanoid} from 'nanoid'
import {t} from '@/locales'
import { nanoid } from 'nanoid'
import { t } from '@/locales'

/**
* 数字处理
Expand All @@ -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) {
Expand Down Expand Up @@ -87,21 +87,20 @@ 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) {
const key = i18n_default_name_map[name]
return key ? t(key) : name
}


// 截取文件名
export function cutFilename(filename: string, num: number) {
const lastIndex = filename.lastIndexOf('.')
Expand All @@ -115,51 +114,51 @@ interface LoadScriptOptions {
}

export const loadScript = (url: string, options: LoadScriptOptions = {}): Promise<void> => {
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) => {
Expand All @@ -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 ''
}
Expand Down
Loading