wui-components-v2 1.2.72 → 1.2.73

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/index.ts +17 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.72",
3
+ "version": "1.2.73",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",
package/utils/index.ts CHANGED
@@ -1,17 +1,29 @@
1
1
  import dayjs from 'dayjs'
2
2
  import type { Comparator } from '../type'
3
- import { ossConfig } from '../../config'
4
3
 
5
4
  // const filefxd = ['image', 'video', 'audio', 'file', 'wav']
6
5
 
7
- /** 将主配置与 otherConfig 合并为配置数组,按日期选择对应的 oss 配置 */
8
- const ossConfigs: any[] = [ossConfig, ...(ossConfig.otherConfig || [])]
6
+ /** OSS 配置的 storage key,由宿主工程在 App.vue 中写入(与 BASE_URL 等方式保持一致) */
7
+ const OSS_CONFIG_KEY = 'OSS_CONFIG'
8
+
9
+ /**
10
+ * 获取 OSS 配置数组(主配置 + otherConfig)。
11
+ * 运行时读取,避免组件库作为独立包(wui-components-v2)引用宿主工程 config 导致路径无法解析。
12
+ */
13
+ function getOssConfigs(): any[] {
14
+ const ossConfig = uni.getStorageSync(OSS_CONFIG_KEY)
15
+ if (!ossConfig) return []
16
+ return [ossConfig, ...(ossConfig.otherConfig || [])]
17
+ }
9
18
 
10
19
  /**
11
20
  * 根据文件地址中的日期(/YYYY/M/D/)选择对应的 OSS 配置。
12
21
  * 无日期或只有一份配置时返回主配置。
13
22
  */
14
23
  export function getOssConfig(url: string) {
24
+ const ossConfigs = getOssConfigs()
25
+ // 宿主工程未配置 OSS 时返回空对象,由调用方兜底
26
+ if (!ossConfigs.length) return {}
15
27
  const match = (url || '').match(/\/(\d{4})\/(\d{1,2})\/(\d{1,2})\//)
16
28
  if (!match || ossConfigs.length === 1) {
17
29
  return ossConfigs[0]
@@ -66,6 +78,8 @@ export function buildOssSrc(ossUrl: string) {
66
78
  const path = String(ossUrl || '').replace(/^\/+/, '')
67
79
  if (!path) return ''
68
80
  const cfg = getOssConfig(path)
81
+ // 宿主工程未配置 OSS(缺 endpoint / bucket)时返回空串,由调用方兜底
82
+ if (!cfg.endpoint || !cfg.bucket) return ''
69
83
  return `${cfg.protocol || 'http'}://${cfg.bucket}.${cfg.endpoint}/${path}`
70
84
  }
71
85