提交
This commit is contained in:
1 parent
7e9155fef1
commit
2fd826dbe1
80 files changed
+32546
-36145
No files matched your search
@@ -2,11 +2,40 @@ import { downloadAttachmentFile } from '@/utils/download-attachment'
|
||||
|
||||
const minioBaseUrl = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
|
||||
|
||||
/**
|
||||
* 附件存储路径 → 浏览器可访问 URL。
|
||||
* 兼容:
|
||||
* - 完整 http(s) URL
|
||||
* - 同域网关路径 `/minio/{bucket}/objectKey`(上传回写常见形态)
|
||||
* - 相对 object key,如 `oa-approval/202608/10/xxx.png`
|
||||
*
|
||||
* 注意:对已带 `/minio/...` 的路径不得再拼一次 `VITE_MINIO_BASE_URL`,否则会变成
|
||||
* `http://host/zkxw/minio/zkxw/...` 导致缩略图破图。
|
||||
*/
|
||||
export function attachmentFullUrl(url: string) {
|
||||
const u = String(url || '').trim()
|
||||
if (!u) return ''
|
||||
if (/^https?:\/\//i.test(u)) return u
|
||||
return minioBaseUrl ? `${minioBaseUrl}/${u.replace(/^\//, '')}` : u
|
||||
|
||||
const base = minioBaseUrl
|
||||
|
||||
// `/minio/zkxw/oa-approval/...` → 按环境改写或原样返回
|
||||
if (u.startsWith('/minio/')) {
|
||||
const parts = u.split('/').filter(Boolean) // minio, bucket, ...key
|
||||
const objectKey = parts.length >= 3 ? parts.slice(2).join('/') : ''
|
||||
if (objectKey && /^https?:\/\//i.test(base)) {
|
||||
// 本地开发:VITE_MINIO_BASE_URL=http://host:port/bucket
|
||||
return `${base}/${objectKey}`
|
||||
}
|
||||
// 生产/同域反代:路径本身即可访问
|
||||
if (!base || u === base || u.startsWith(`${base}/`)) return u
|
||||
if (objectKey) return `${base}/${objectKey}`
|
||||
return u
|
||||
}
|
||||
|
||||
if (base && (u === base || u.startsWith(`${base}/`))) return u
|
||||
if (!base) return u
|
||||
return `${base}/${u.replace(/^\//, '')}`
|
||||
}
|
||||
|
||||
export function useAttachmentActions() {
|
||||
|
||||
Reference in new issue
Block a user