web-component-gallery 2.3.26 → 2.3.28

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.
@@ -40,7 +40,9 @@ export const AmapDrawProps = {
40
40
  // 是否为纯展示模式(不显示控制按钮)
41
41
  isExhibition: PropTypes.bool.def(false),
42
42
  // 自定义绘制操作按钮
43
- drawButtonOperate: PropTypes.array
43
+ drawButtonOperate: PropTypes.array,
44
+ // 绘制时是否清除地图上的覆盖物
45
+ clearOnDraw: PropTypes.bool.def(true)
44
46
  }
45
47
 
46
48
  export default {
@@ -90,8 +92,8 @@ export default {
90
92
  // 监听绘制信息变化,当变化时重新渲染对应类型的绘制图层
91
93
  drawInfo: {
92
94
  handler(newVal) {
93
- newVal && this.echoDrawLayers(this.drawType)
94
- },
95
+ newVal && this.echoDrawLayers(this.drawType)
96
+ },
95
97
  deep: true
96
98
  },
97
99
  // 监听所有绘制信息变化,重新渲染全部绘制图层
@@ -217,8 +219,11 @@ export default {
217
219
 
218
220
  // 清除当前绘制的所有图层
219
221
  handleDrawClear() {
220
- // 清理地图上的所有覆盖物
221
- this.cleanOverlays()
222
+ // 根据配置决定是否清除之前的绘制内容
223
+ if (this.clearOnDraw) {
224
+ this.cleanOverlays()
225
+ }
226
+
222
227
  // 重置绘制图层数组
223
228
  this.drawLayers = null
224
229
  // 重置绘制图层信息
@@ -233,12 +238,16 @@ export default {
233
238
  }
234
239
  // 分配绘制图层信息
235
240
  this.assignDrawLayers(this.drawType)
241
+ // 触发保存事件
242
+ this.$emit('drawSave')
236
243
  },
237
244
 
238
245
  // 取消绘制操作
239
246
  handleDrawReset() {
240
247
  // 直接调用清除方法
241
248
  this.handleDrawClear()
249
+ // 触发取消事件
250
+ this.$emit('drawCancel')
242
251
  },
243
252
 
244
253
  // 处理搜索结果选择
@@ -15,6 +15,18 @@ const DESC_DEFAULT_ATTRS = {
15
15
  bordered: true
16
16
  }
17
17
 
18
+ // 响应式列数配置:根据容器宽度动态计算列数
19
+ const COLUMN_CONFIG = [
20
+ { minWidth: 1600, getColumn: (column) => column || 4 },
21
+ { minWidth: 1200, getColumn: (column) => Math.min(4, column) },
22
+ { minWidth: 992, getColumn: (column) => Math.min(3, column) },
23
+ { minWidth: 576, getColumn: (column) => Math.min(2, column) },
24
+ { minWidth: 0, getColumn: () => 1 }
25
+ ]
26
+
27
+ // 防抖延迟时间(毫秒)
28
+ const RESIZE_DEBOUNCE_DELAY = 150
29
+
18
30
  // 组件的 Props 定义
19
31
  const DescriptionsProps = {
20
32
  title: PropTypes.string, // 标题
@@ -37,10 +49,9 @@ const renderContent = (h, item, details) => {
37
49
  const CustomTag = item.type === 'file' ? Browse : 'span'
38
50
 
39
51
  // 获取内容值:优先使用自定义渲染函数,否则直接取数据
40
- const getContentValue = () =>
41
- item.customRender ? item.customRender(details[item.props], details) : details[item.props]
42
-
43
- const contentValue = getContentValue()
52
+ const contentValue = item.customRender
53
+ ? item.customRender(details[item.props], details)
54
+ : details[item.props]
44
55
 
45
56
  // 处理数据:如果是文件类型且未自定义渲染,则进行数据转换
46
57
  const processData = () => {
@@ -54,24 +65,13 @@ const renderContent = (h, item, details) => {
54
65
  return contentValue
55
66
  }
56
67
 
57
- const data = processData()
58
-
59
68
  return (
60
- <CustomTag {...{ props: { data, isThumb: true, astrictH: 78 } }}>
69
+ <CustomTag {...{ props: { data: processData(), isThumb: true, astrictH: 78 } }}>
61
70
  {contentValue ?? '暂无'}
62
71
  </CustomTag>
63
72
  )
64
73
  }
65
74
 
66
- // 响应式列数配置:根据容器宽度动态计算列数
67
- const COLUMN_CONFIG = [
68
- { minWidth: 1600, getColumn: (column) => column || 4 },
69
- { minWidth: 1200, getColumn: (column) => Math.min(4, column) },
70
- { minWidth: 992, getColumn: (column) => Math.min(3, column) },
71
- { minWidth: 576, getColumn: (column) => Math.min(2, column) },
72
- { minWidth: 0, getColumn: () => 1 }
73
- ]
74
-
75
75
  const DescriptionsList = {
76
76
  name: 'DescriptionsList',
77
77
  props: DescriptionsProps,
@@ -81,44 +81,33 @@ const DescriptionsList = {
81
81
  resizeTimer: null // 防抖定时器
82
82
  }
83
83
  },
84
-
84
+
85
85
  mounted() {
86
86
  this.initComponent()
87
87
  },
88
88
 
89
+ updated() {
90
+ // DOM 更新后重新计算宽度
91
+ this.$nextTick(this.setDescContentWidth)
92
+ },
93
+
89
94
  beforeDestroy() {
90
95
  this.cleanupResize()
91
96
  },
92
97
 
93
98
  methods: {
94
- // 初始化组件逻辑
95
- initComponent() {
96
- if (this.isResponsive) {
97
- this.setDescContentWidth()
98
- this.bindResize()
99
- return
100
- }
101
- this.responsiveColumn = this.getColumnValue()
102
- },
99
+ // 初始化组件
103
100
  initComponent() {
104
- if (this.isResponsive) {
105
- this.setDescContentWidth()
106
- this.bindResize()
107
- return
108
- }
109
- this.responsiveColumn = this.getColumnValue()
110
- this.$nextTick(() => {
111
- const container = this.$refs.Descriptions
112
- if (container) this.updateItemStyles(container, container.offsetWidth)
113
- })
101
+ // 响应式模式:绑定事件监听;非响应式模式:使用固定列数
102
+ this.isResponsive ? this.bindResize() : (this.responsiveColumn = this.getColumnValue())
103
+ // 确保 DOM 渲染后设置宽度
104
+ this.$nextTick(this.setDescContentWidth)
114
105
  },
115
106
 
116
107
  // 清理窗口大小监听和定时器
117
108
  cleanupResize() {
118
- if (this.resizeTimer) {
119
- clearTimeout(this.resizeTimer)
120
- this.resizeTimer = null
121
- }
109
+ clearTimeout(this.resizeTimer)
110
+ this.resizeTimer = null
122
111
  },
123
112
 
124
113
  // 绑定窗口大小变化事件
@@ -128,90 +117,68 @@ const DescriptionsList = {
128
117
 
129
118
  // 处理窗口大小变化(带防抖)
130
119
  handleResize() {
131
- if (this.resizeTimer) clearTimeout(this.resizeTimer)
132
- this.resizeTimer = setTimeout(() => {
133
- this.setDescContentWidth()
134
- }, 150)
120
+ this.cleanupResize()
121
+ this.resizeTimer = setTimeout(this.setDescContentWidth, RESIZE_DEBOUNCE_DELAY)
135
122
  },
136
123
 
137
124
  // 获取非响应式模式下的列数值
138
125
  getColumnValue() {
139
- return typeof this.column === 'object' ? this.column.xs : this.column || 4
126
+ return typeof this.column === 'object' ? this.column.xs : (this.column || 4)
140
127
  },
141
128
 
142
129
  // 根据当前宽度获取应显示的列数
143
130
  getCurrentColumn(width) {
144
- const config = COLUMN_CONFIG.find(item => width >= item.minWidth)
145
- return config?.getColumn(this.column) ?? 1
131
+ return COLUMN_CONFIG.find(item => width >= item.minWidth)?.getColumn(this.column) ?? 1
146
132
  },
147
133
 
148
134
  // 计算并设置描述内容的宽度和列数
149
135
  setDescContentWidth() {
150
- if (!this.isResponsive) return
151
-
152
136
  const container = this.$refs.Descriptions
153
- if (!container) return
154
-
155
- const viewElement = container.querySelector('.ant-descriptions-view')
156
- if (!viewElement) return
157
-
158
- const width = viewElement.offsetWidth
159
- // 如果宽度为 0(可能尚未渲染),延迟重试
160
- if (width === 0) {
161
- setTimeout(() => this.setDescContentWidth(), 100)
162
- return
163
- }
137
+ const width = container.querySelector('.ant-descriptions-view').offsetWidth
164
138
 
165
- this.responsiveColumn = this.getCurrentColumn(width)
139
+ // 响应式模式下更新列数
140
+ this.isResponsive && (this.responsiveColumn = this.getCurrentColumn(width))
166
141
  this.updateItemStyles(container, width)
167
142
  },
168
143
 
169
- // 更新每一项的标签和内容宽度样式
144
+ // 更新每一项的标签宽度样式
170
145
  updateItemStyles(container, totalWidth) {
171
- this.$nextTick(() => {
172
- const rows = container.querySelectorAll('.ant-descriptions-row')
173
- let itemCount = 0
146
+ const rows = container.querySelectorAll('.ant-descriptions-row')
147
+ let itemCount = 0
174
148
 
175
- rows.forEach(row => {
176
- const labels = row.querySelectorAll('.ant-descriptions-item-label')
177
- const contents = row.querySelectorAll('.ant-descriptions-item-content')
149
+ rows.forEach(row => {
150
+ row.querySelectorAll('.ant-descriptions-item-label').forEach(label => {
151
+ // 获取当前项的 span 配置,默认为 1
152
+ const span = this.descSettings?.[itemCount]?.span || 1
178
153
 
179
- labels.forEach((label, index) => {
180
- const itemConfig = this.descSettings[itemCount]
181
- const span = itemConfig?.span || 1
182
-
183
- // 计算每项总宽度和内容区域宽度
184
- const eachWidth = (totalWidth / this.responsiveColumn) * span
185
- const contentWidth = eachWidth - this.labelWidth
186
-
187
- // 设置固定标签宽度
188
- this.setStyle(label, { width: `${this.labelWidth}px`, minWidth: `${this.labelWidth}px`, maxWidth: `${this.labelWidth}px` })
189
- // 设置自适应内容宽度 (table-layout: auto; 自适应情况下不需要设置内容宽度)
190
- // this.setStyle(contents[index], { width: `${contentWidth}px`, minWidth: `${contentWidth}px`, maxWidth: `${contentWidth}px` })
191
-
192
- itemCount++
154
+ // 计算每项总宽度和内容区域宽度
155
+ const eachWidth = (totalWidth / this.responsiveColumn) * span
156
+ const contentWidth = eachWidth - this.labelWidth
157
+
158
+ // 设置标签的宽度样式
159
+ Object.assign(label.style, {
160
+ width: `${this.labelWidth}px`,
161
+ minWidth: `${this.labelWidth}px`,
162
+ maxWidth: `${this.labelWidth}px`
193
163
  })
164
+
165
+ itemCount++
194
166
  })
195
167
  })
196
- },
197
-
198
- // 辅助方法:设置元素样式
199
- setStyle(element, styles) {
200
- if (element) Object.assign(element.style, styles)
201
168
  }
202
169
  },
203
170
 
204
171
  watch: {
205
172
  // 监听响应式开关变化
206
173
  isResponsive(val) {
207
- val ? this.bindResize() : this.cleanupResize()
208
- this.responsiveColumn = val ? this.getCurrentColumn(window.innerWidth) : this.getColumnValue()
174
+ val
175
+ ? (this.bindResize(), this.responsiveColumn = this.getCurrentColumn(window.innerWidth))
176
+ : (this.cleanupResize(), this.responsiveColumn = this.getColumnValue())
209
177
  },
178
+
210
179
  // 监听列数配置变化
211
- column(val) {
212
- if (!this.isResponsive) {
213
- this.responsiveColumn = this.getColumnValue()
214
- }
180
+ column() {
181
+ !this.isResponsive && (this.responsiveColumn = this.getColumnValue())
215
182
  }
216
183
  },
217
184
 
@@ -225,7 +192,7 @@ const DescriptionsList = {
225
192
  column={this.responsiveColumn}
226
193
  {...{ attrs: { ...DESC_DEFAULT_ATTRS, ...descAttrs } }}
227
194
  >
228
- {descSettings.map((descItem, key) => (
195
+ {descSettings?.map((descItem, key) => (
229
196
  <DescriptionsItem key={key} span={descItem.span ?? 1}>
230
197
  <span slot="label">
231
198
  {$slots[`${descItem.props}Label`] ?? descItem.label}
@@ -247,4 +214,4 @@ DescriptionsList.install = function(Vue) {
247
214
  Vue.component('DescriptionsList', DescriptionsList)
248
215
  }
249
216
 
250
- export default DescriptionsList
217
+ export default DescriptionsList
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-gallery",
3
- "version": "2.3.26",
3
+ "version": "2.3.28",
4
4
  "description": "基础vue、antdvue、less实现的私有组件库",
5
5
  "main": "dist/index.umd.js",
6
6
  "files": [