web-component-gallery 2.3.6 → 2.3.8

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/utils/Tree.js CHANGED
@@ -96,7 +96,7 @@ export function joinTreeMessage(
96
96
  node[replaceField] = fields
97
97
  .filter(field => node[field])
98
98
  .map(field => node[field])
99
- .join(' ');
99
+ .join(' ')
100
100
 
101
101
  if (Array.isArray(node[childNode])) {
102
102
  node[childNode].forEach(processNode)
@@ -151,9 +151,7 @@ export function getAllParents(tree, nodeId, { children = 'children', key = 'id'
151
151
  metaInfo.set(node, { parentId })
152
152
  nodeMap.set(node[key], { node, metaInfo })
153
153
 
154
- if (node[children] && Array.isArray(node[children])) {
155
- buildMap(node[children], node[key])
156
- }
154
+ if (node[children]?.length) buildMap(node[children], node[key])
157
155
  })
158
156
  }
159
157
  buildMap(tree)
@@ -162,14 +160,17 @@ export function getAllParents(tree, nodeId, { children = 'children', key = 'id'
162
160
  const path = []
163
161
  let current = nodeMap.get(nodeId)
164
162
  while (current) {
165
- returnObjects
166
- ? path.unshift(current.node) // 直接返回原对象
167
- : path.unshift(current.node[key])
168
-
169
- const parentId = current.metaInfo.get(current.node)?.parentId
170
- current = parentId ? nodeMap.get(parentId) : null
163
+ if (returnObjects) {
164
+ // 直接返回原对象
165
+ path.unshift(current.node)
166
+ } else {
167
+ path.unshift(current.node[key])
168
+ }
169
+ current = current.metaInfo.get(current.node).parentId
170
+ ? nodeMap.get(current.metaInfo.get(current.node).parentId)
171
+ : null
171
172
  }
172
173
 
173
174
  // 对象集合则返回父级
174
- return returnObjects ? path.slice(0, -1) : path.slice(0, -1)
175
- }
175
+ return returnObjects ? path[0] : path
176
+ }
package/utils/Utils.js CHANGED
@@ -17,35 +17,65 @@ export function chunkArray(arr, size) {
17
17
  return result
18
18
  }
19
19
 
20
+
20
21
  /**
21
22
  * 下载文件
22
- * @param {Blob} response - 文档流
23
+ * @param {Blob|Object} response - 文档流或包含data和headers的对象
23
24
  * @param {string} name - 文件名称
24
25
  * @param {string} type - 文件类型
25
26
  * @returns {void}
26
27
  */
27
- export function downLoadFn( response, name, type = "application/vnd.ms-excel" ) {
28
-
28
+ export function downLoadFn(response, name, type = "application/vnd.ms-excel") {
29
+ // 兼容新写法:从response对象中解析data和headers
30
+ let fileData = response
31
+ let fileName = name
32
+ let fileType = type
33
+
34
+ // 如果response是对象且包含data属性,则使用新写法
35
+ if (response && typeof response === 'object' && response.data) {
36
+ fileData = response.data
37
+
38
+ // 从headers中解析文件名和类型
39
+ if (response.headers) {
40
+ const headers = response.headers
41
+
42
+ // 解析文件类型
43
+ if (headers['content-type']) {
44
+ fileType = headers['content-type']
45
+ }
46
+
47
+ // 解析文件名
48
+ if (headers['content-disposition']) {
49
+ const contentDisposition = headers['content-disposition']
50
+ const match = contentDisposition.match(/filename=([^;]+)/)
51
+ if (match && match[1]) {
52
+ fileName = decodeURIComponent(match[1].replace(/['"]/g, ''))
53
+ }
54
+ }
55
+ }
56
+ }
57
+
29
58
  let reader = new FileReader()
30
59
 
31
- reader.readAsText( response, "utf-8" )
60
+ reader.readAsText(fileData, "utf-8")
32
61
 
33
62
  reader.onload = function () {
34
63
  try {
35
- message.error( JSON.parse( reader.result ).msg )
64
+ message.error(JSON.parse(reader.result).msg)
36
65
  } catch (err) {
37
- message.success( "下载中..." )
38
- let blob = new Blob( [ response ], { type } )
39
- let url = window.URL.createObjectURL( blob )
40
- const link = document.createElement( "a" )
66
+ message.success("下载中...")
67
+ let blob = new Blob([fileData], { type: fileType })
68
+ let url = window.URL.createObjectURL(blob)
69
+ const link = document.createElement("a")
41
70
  link.href = url
42
- link.download = name
71
+ link.download = fileName
43
72
  link.click()
44
- window.URL.revokeObjectURL( url )
73
+ window.URL.revokeObjectURL(url)
45
74
  }
46
75
  }
47
76
  }
48
77
 
78
+
49
79
  /**
50
80
  * 获取图片宽高 (如超出限制高度,则根据高度比计算出对应的宽度比)
51
81
  * @param {string} url - 图片地址