u
This commit is contained in:
1 parent
f9eaacf02a
commit
69eda8b8ad
27 files changed
+2797
-616
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { toast } from 'sard-uniapp'
|
||||
import { getOrgBaseUrl } from '@/request'
|
||||
import { useUserStore } from '@/store'
|
||||
import { getOssKey } from './oss'
|
||||
import { isApp, isH5, isMpWeixin } from './platform'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const aliyunBucket = import.meta.env.VITE_ALIYUN_BUCKET
|
||||
|
||||
/**
|
||||
@@ -115,8 +118,6 @@ export function formatFileSize(size: number): string {
|
||||
else return `${(size / (1024 * 1024 * 1024)).toFixed(2)} GB`
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件到阿里云 OSS(优化版)
|
||||
*/
|
||||
@@ -359,3 +360,39 @@ function downloadAppMedia(fileUrl: string, type: 'image' | 'video') {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function buildPubicUrl(orgUrl, path: string) {
|
||||
if (!path)
|
||||
return ''
|
||||
|
||||
return joinUrl(orgUrl, '/static/file', path)
|
||||
}
|
||||
|
||||
export function joinUrl(...parts: (string | undefined | null)[]): string {
|
||||
if (!parts || parts.length === 0)
|
||||
return ''
|
||||
|
||||
const sb: string[] = []
|
||||
|
||||
for (let part of parts) {
|
||||
if (!part || !part.trim())
|
||||
continue
|
||||
|
||||
part = part.trim()
|
||||
|
||||
// 替换 Windows 路径分隔符
|
||||
part = part.replace(/\\/g, '/')
|
||||
|
||||
if (sb.length === 0) {
|
||||
// 第一段:保留协议,去掉末尾 /
|
||||
sb.push(part.replace(/\/+$/, ''))
|
||||
}
|
||||
else {
|
||||
// 后续段:去掉前后 /
|
||||
sb.push(part.replace(/^\/+|\/+$/g, ''))
|
||||
}
|
||||
}
|
||||
|
||||
// 中间用 / 拼接
|
||||
return sb.join('/')
|
||||
}
|
||||
Reference in new issue
Block a user