wui-components-v2 1.2.80 → 1.2.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utils/index.ts +49 -3
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -112,6 +112,52 @@ function isOssPath(url: string) {
|
|
|
112
112
|
return !!path && !/^v3\//i.test(path)
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* 判断是否为带日期段的 OSS 对象路径(如 .../hwane28794/2026/9/1/xxx.wav)。
|
|
117
|
+
* OSS 上的文件路径含 /YYYY/M/D/ 日期段(getOssConfig 也按此切换配置);
|
|
118
|
+
* 不带日期段的路径(如 hwane29293/<md5>/<雪花id>.txt)不在 OSS 上,
|
|
119
|
+
* 需走后端 /v3/files/ 接口(对齐 PC 端下载行为)。
|
|
120
|
+
*/
|
|
121
|
+
function isDatedOssPath(url: string) {
|
|
122
|
+
const path = String(url || '').replace(/^\/+/, '')
|
|
123
|
+
return /\/(\d{4})\/(\d{1,2})\/(\d{1,2})\//.test(`/${path}`)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 拼后端文件接口地址:{baseUrl}/v3/files/{path}?@token=...&@programToken=...
|
|
128
|
+
* 对齐 PC 端:曲线 txt 等文件只有后端能取到,直链 OSS 会 404。
|
|
129
|
+
* baseUrl / token / programToken 与宿主工程 request 封装一样从本地存储读取。
|
|
130
|
+
*/
|
|
131
|
+
export function buildServerFileSrc(path: string) {
|
|
132
|
+
const clean = String(path || '').replace(/^\/+/, '')
|
|
133
|
+
if (!clean) return ''
|
|
134
|
+
const baseUrl = uni.getStorageSync('baseUrl') || ''
|
|
135
|
+
if (!baseUrl) return ''
|
|
136
|
+
const token = uni.getStorageSync('token') || ''
|
|
137
|
+
const programToken = uni.getStorageSync('hydrocarbonProgramToken') || ''
|
|
138
|
+
const query = [
|
|
139
|
+
token ? `@token=${token}` : '',
|
|
140
|
+
programToken ? `@programToken=${programToken}` : '',
|
|
141
|
+
].filter(Boolean).join('&')
|
|
142
|
+
// 已带 v3/ 前缀的服务端路径直接用;其余是纯对象路径,补 v3/files/ 前缀(对齐 PC 端)
|
|
143
|
+
const target = /^v3\//i.test(clean) ? clean : `v3/files/${clean}`
|
|
144
|
+
const base = `${baseUrl}/${target}`
|
|
145
|
+
return query ? `${base}${clean.includes('?') ? '&' : '?'}${query}` : base
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 文件地址路由:绝对地址原样返回;
|
|
150
|
+
* 带日期段的 OSS 对象路径 → OSS 直链;
|
|
151
|
+
* 其余相对路径(v3/... 或 hwane.../xxx.txt 等)→ 后端 /v3/files/ 接口。
|
|
152
|
+
*/
|
|
153
|
+
function resolveFileSrc(raw: string) {
|
|
154
|
+
if (!raw || isAbsoluteUrl(raw)) return raw
|
|
155
|
+
const path = raw.replace(/^\/+/, '')
|
|
156
|
+
if (!path) return raw
|
|
157
|
+
if (isDatedOssPath(path)) return buildOssSrc(path)
|
|
158
|
+
return buildServerFileSrc(path) || raw
|
|
159
|
+
}
|
|
160
|
+
|
|
115
161
|
/**
|
|
116
162
|
* 按文件地址构造展示项(用于 direct-file 等直接存文件地址的场景)。
|
|
117
163
|
* 值可能是完整 URL,也可能是 OSS 对象路径(如 4301.../hwane28794/2026/9/1/xxx.wav),
|
|
@@ -125,7 +171,7 @@ function buildFileItemByUrl(url: string) {
|
|
|
125
171
|
const cleanUrl = raw.split('?')[0]
|
|
126
172
|
const name = getAfterLastMatch(cleanUrl, '/') || cleanUrl
|
|
127
173
|
return {
|
|
128
|
-
url:
|
|
174
|
+
url: resolveFileSrc(cleanUrl) || raw,
|
|
129
175
|
name,
|
|
130
176
|
type: (getAfterLastMatch(name, '.') || '').toLowerCase(),
|
|
131
177
|
}
|
|
@@ -143,8 +189,8 @@ export function buildFileSrc(base: any): string {
|
|
|
143
189
|
if (!base) return ''
|
|
144
190
|
const ossUrl = String(base.path || '')
|
|
145
191
|
if (!ossUrl) return ''
|
|
146
|
-
//
|
|
147
|
-
return
|
|
192
|
+
// 已是完整地址则直接用;OSS 对象路径拼直链;其余走后端 /v3/files/ 接口
|
|
193
|
+
return resolveFileSrc(ossUrl)
|
|
148
194
|
}
|
|
149
195
|
|
|
150
196
|
/**
|