1- import { nanoid } from 'nanoid'
1+ import { nanoid } from 'nanoid'
2+
23/**
34 * 数字处理
45 */
@@ -7,6 +8,7 @@ export function toThousands(num: any) {
78 return n . replace ( / ( \d ) (? = (?: \d { 3 } ) + $ ) / g, '$1,' )
89 } )
910}
11+
1012export function numberFormat ( num : number ) {
1113 return num < 1000 ? toThousands ( num ) : toThousands ( ( num / 1000 ) . toFixed ( 1 ) ) + 'k'
1214}
@@ -25,6 +27,7 @@ export function filesize(size: number) {
2527
2628// 头像
2729export const defaultIcon = '/${window.MaxKB.prefix}/favicon.ico'
30+
2831export function isAppIcon ( url : string | undefined ) {
2932 return url === defaultIcon ? '' : url
3033}
@@ -65,6 +68,7 @@ export function getImgUrl(name: string) {
6568 : 'unknown'
6669 return new URL ( `../assets/fileType/${ type } -icon.svg` , import . meta. url ) . href
6770}
71+
6872// 是否是白名单后缀
6973export function isRightType ( name : string , type : string ) {
7074 return typeList [ type ] . includes ( fileType ( name ) . toLowerCase ( ) )
@@ -94,7 +98,7 @@ interface LoadScriptOptions {
9498}
9599
96100export const loadScript = ( url : string , options : LoadScriptOptions = { } ) : Promise < void > => {
97- const { jsId, forceReload = false } = options
101+ const { jsId, forceReload = false } = options
98102 const scriptId = jsId || `script-${ btoa ( url ) . slice ( 0 , 12 ) } ` // 生成唯一 ID
99103
100104 return new Promise ( ( resolve , reject ) => {
@@ -144,12 +148,14 @@ export function getNormalizedUrl(url: string) {
144148 }
145149 return url
146150}
151+
147152export function getFileUrl ( fileId ?: string ) {
148153 if ( fileId ) {
149154 return `${ window . MaxKB . prefix } /oss/file/${ fileId } `
150155 }
151156 return ''
152157}
158+
153159export const resetUrl = ( url : string , defaultUrl ?: string ) => {
154160 if ( url && url . startsWith ( './' ) ) {
155161 return `${ window . MaxKB . prefix } /${ url . substring ( 2 ) } `
0 commit comments