web-component-gallery 2.3.27 → 2.3.29
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.
|
@@ -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
|
|
41
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
172
|
-
|
|
173
|
-
let itemCount = 0
|
|
146
|
+
const rows = container.querySelectorAll('.ant-descriptions-row')
|
|
147
|
+
let itemCount = 0
|
|
174
148
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
|
208
|
-
|
|
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(
|
|
212
|
-
|
|
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
|
|
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
|