@idooel/components 0.0.2-beta.3 → 0.0.2-beta.31
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/README.md +98 -98
- package/dist/@idooel/components.esm.js +3599 -1574
- package/dist/@idooel/components.umd.js +3653 -1629
- package/jsconfig.json +7 -7
- package/package.json +64 -50
- package/packages/alert/index.js +4 -4
- package/packages/alert/src/index.vue +45 -45
- package/packages/batch-export/index.js +4 -4
- package/packages/batch-export/src/index.vue +104 -104
- package/packages/business-components/modal-fsm/index.js +4 -4
- package/packages/business-components/modal-fsm/src/index.vue +163 -163
- package/packages/business-components/modal-import/index.js +4 -4
- package/packages/business-components/modal-import/src/index.vue +222 -139
- package/packages/business-components/modal-timeline/index.js +4 -4
- package/packages/business-components/modal-timeline/src/index.vue +77 -77
- package/packages/business-components/tabs-sub-center/index.js +4 -4
- package/packages/business-components/tabs-sub-center/src/index.vue +116 -116
- package/packages/button/index.js +4 -4
- package/packages/button/src/index.vue +65 -65
- package/packages/checkbox/index.js +4 -4
- package/packages/checkbox/src/index.vue +52 -52
- package/packages/composite-components/button-group/index.js +4 -4
- package/packages/composite-components/button-group/src/index.vue +151 -151
- package/packages/composite-components/form-attachment/src/index.vue +14 -14
- package/packages/composite-components/form-img-crop/index.js +4 -4
- package/packages/composite-components/form-img-crop/src/index.vue +131 -131
- package/packages/composite-components/modal-confirm/index.js +4 -4
- package/packages/composite-components/modal-confirm/src/index.vue +103 -103
- package/packages/composite-components/modal-form/index.js +4 -4
- package/packages/composite-components/modal-form/src/index.vue +230 -230
- package/packages/composite-components/modal-img-crop/index.js +4 -4
- package/packages/composite-components/modal-img-crop/src/index.vue +298 -298
- package/packages/composite-components/modal-table/index.js +4 -4
- package/packages/composite-components/modal-table/src/index.vue +155 -155
- package/packages/composite-components/modal-tree/index.js +4 -4
- package/packages/composite-components/modal-tree/src/index.vue +75 -75
- package/packages/composite-components/search-area/index.js +4 -4
- package/packages/composite-components/search-area/src/index.vue +239 -237
- package/packages/composite-components/search-area/src/label.vue +35 -35
- package/packages/composite-components/select-entity-modal-table/index.js +4 -4
- package/packages/composite-components/select-entity-modal-table/src/index.vue +171 -171
- package/packages/date/index.js +4 -4
- package/packages/date/src/index.vue +112 -112
- package/packages/date-range/index.js +4 -4
- package/packages/date-range/src/index.vue +47 -47
- package/packages/form/index.js +4 -4
- package/packages/form/src/index.vue +393 -319
- package/packages/icon/index.js +4 -4
- package/packages/icon/src/index.vue +31 -31
- package/packages/index.js +159 -153
- package/packages/input/index.js +4 -4
- package/packages/input/src/index.vue +35 -35
- package/packages/input-number/index.js +4 -4
- package/packages/input-number/src/index.vue +23 -23
- package/packages/loading/index.js +4 -4
- package/packages/loading/src/index.vue +36 -36
- package/packages/meta/provider.js +4 -0
- package/packages/modal/index.js +4 -4
- package/packages/modal/src/index.vue +184 -184
- package/packages/models/form-group-model/index.js +4 -4
- package/packages/models/form-group-model/src/index.vue +271 -273
- package/packages/models/form-model/index.js +4 -4
- package/packages/models/form-model/src/index.vue +236 -232
- package/packages/models/step-model/index.js +4 -4
- package/packages/models/step-model/src/index.vue +224 -224
- package/packages/models/tree-table-model/README.md +0 -0
- package/packages/models/tree-table-model/index.js +4 -4
- package/packages/models/tree-table-model/src/index.vue +963 -689
- package/packages/pagination/index.js +5 -0
- package/packages/pagination/src/index.vue +372 -0
- package/packages/radio/index.js +4 -4
- package/packages/radio/src/index.vue +56 -56
- package/packages/select/index.js +4 -4
- package/packages/select/src/index.vue +113 -105
- package/packages/select-entity/index.js +4 -4
- package/packages/select-entity/src/index.vue +119 -119
- package/packages/table/index.js +4 -4
- package/packages/table/src/action.vue +176 -172
- package/packages/table/src/index.vue +605 -319
- package/packages/tabs/index.js +4 -4
- package/packages/tabs/src/index.vue +55 -55
- package/packages/text/index.js +4 -4
- package/packages/text/src/index.vue +47 -47
- package/packages/text-editor/index.js +4 -4
- package/packages/text-editor/src/index.vue +72 -72
- package/packages/textarea/index.js +4 -4
- package/packages/textarea/src/index.vue +57 -57
- package/packages/theme/form.scss +21 -21
- package/packages/theme/index.scss +43 -43
- package/packages/theme/overrid.scss +7 -7
- package/packages/theme/styleClass.scss +2 -2
- package/packages/theme/variables.scss +55 -55
- package/packages/timeline/index.js +4 -4
- package/packages/timeline/src/index.vue +257 -257
- package/packages/tpl/index.js +4 -4
- package/packages/tpl/src/index.vue +55 -55
- package/packages/tree/index.js +4 -4
- package/packages/tree/src/TreeNode.vue +29 -29
- package/packages/tree/src/index.vue +101 -101
- package/packages/tree-select/index.js +4 -4
- package/packages/tree-select/src/index.vue +142 -142
- package/packages/upload/index.js +4 -4
- package/packages/upload/src/index.vue +998 -494
- package/packages/utils/README.md +172 -0
- package/packages/utils/index.js +66 -62
- package/packages/utils/runtime-context/dataPoolAPI.js +501 -0
- package/packages/utils/runtime-context/globalDataPool.js +279 -0
- package/packages/utils/runtime-context/index.js +76 -0
- package/packages/utils/runtime-context/modelSchema.js +174 -0
- package/scripts/rollup.config.js +42 -42
- package/scripts/rollup.esm.config.js +11 -11
- package/scripts/rollup.umd.config.js +17 -14
- package/vitest.config.js +17 -0
|
@@ -1,320 +1,606 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="g-table__wrapper"
|
|
3
|
-
<a-table
|
|
4
|
-
:
|
|
5
|
-
:
|
|
6
|
-
:
|
|
7
|
-
:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
:
|
|
11
|
-
:row-
|
|
12
|
-
:
|
|
13
|
-
:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
show-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
type:
|
|
85
|
-
default:
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
type:
|
|
89
|
-
default:
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
type: Boolean,
|
|
93
|
-
default:
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
1
|
+
<template>
|
|
2
|
+
<div class="g-table__wrapper" ref="tableWrapper" :style="wrapperStyle">
|
|
3
|
+
<a-table
|
|
4
|
+
:key="tableRenderKey"
|
|
5
|
+
:bordered="bordered"
|
|
6
|
+
:class="[isNoData && 'g-table__no-data']"
|
|
7
|
+
:pagination="false"
|
|
8
|
+
:loading="loading"
|
|
9
|
+
size="middle"
|
|
10
|
+
:columns="smartColumns"
|
|
11
|
+
:row-selection="smartRowSelection"
|
|
12
|
+
:row-class-name="setRowClassName"
|
|
13
|
+
:data-source="dataSource"
|
|
14
|
+
:scroll="smartScroll">
|
|
15
|
+
<template slot="action" slot-scope="record">
|
|
16
|
+
<Actions v-on="$listeners" :data-source="actions" :record="record"></Actions>
|
|
17
|
+
</template>
|
|
18
|
+
</a-table>
|
|
19
|
+
<div class="g-table__pagination">
|
|
20
|
+
<a-pagination
|
|
21
|
+
:show-total="all => `共 ${all} 条数据`"
|
|
22
|
+
v-if="mode === 'default'"
|
|
23
|
+
show-size-changer
|
|
24
|
+
show-quick-jumper
|
|
25
|
+
:pageSize="innerPageSize"
|
|
26
|
+
:current="innerCurrentPage"
|
|
27
|
+
:pageSizeOptions="pageSizeOptions"
|
|
28
|
+
@change="onChangePagination"
|
|
29
|
+
@showSizeChange="onShowSizeChange"
|
|
30
|
+
:total="total">
|
|
31
|
+
</a-pagination>
|
|
32
|
+
<ele-pagination
|
|
33
|
+
v-else
|
|
34
|
+
:pageSize="innerPageSize"
|
|
35
|
+
:current="innerCurrentPage"
|
|
36
|
+
:pageSizeOptions="pageSizeOptions"
|
|
37
|
+
:data="dataSource.length"
|
|
38
|
+
@change="onChangePagination"
|
|
39
|
+
@showSizeChange="onShowSizeChange"
|
|
40
|
+
:total="total"
|
|
41
|
+
></ele-pagination>
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<script>
|
|
47
|
+
import Actions from './action.vue'
|
|
48
|
+
export default {
|
|
49
|
+
name: 'ele-table',
|
|
50
|
+
components: {
|
|
51
|
+
Actions
|
|
52
|
+
},
|
|
53
|
+
props: {
|
|
54
|
+
mode: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: 'default',
|
|
57
|
+
validator: (value) => {
|
|
58
|
+
return ['default', 'next-cursor'].includes(value)
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
// ant table wrapper
|
|
62
|
+
height: {
|
|
63
|
+
type: Number
|
|
64
|
+
},
|
|
65
|
+
width: {
|
|
66
|
+
type: Number
|
|
67
|
+
},
|
|
68
|
+
x: {
|
|
69
|
+
// ant-design-vue: scroll.x 支持 number | string(如 'max-content')
|
|
70
|
+
type: [Number, String],
|
|
71
|
+
default: 1200
|
|
72
|
+
},
|
|
73
|
+
y: {
|
|
74
|
+
type: Number,
|
|
75
|
+
default: 200
|
|
76
|
+
},
|
|
77
|
+
scroll: {
|
|
78
|
+
type: Object
|
|
79
|
+
},
|
|
80
|
+
rowSelection: {
|
|
81
|
+
type: Object
|
|
82
|
+
},
|
|
83
|
+
actions: {
|
|
84
|
+
type: Array,
|
|
85
|
+
default: () => []
|
|
86
|
+
},
|
|
87
|
+
total: {
|
|
88
|
+
type: Number,
|
|
89
|
+
default: 0
|
|
90
|
+
},
|
|
91
|
+
loading: {
|
|
92
|
+
type: Boolean,
|
|
93
|
+
default: false
|
|
94
|
+
},
|
|
95
|
+
columns: {
|
|
96
|
+
type: Array,
|
|
97
|
+
default: () => []
|
|
98
|
+
},
|
|
99
|
+
dataSource: {
|
|
100
|
+
type: Array,
|
|
101
|
+
default: () => []
|
|
102
|
+
},
|
|
103
|
+
pageSize: {
|
|
104
|
+
type: [Number, String],
|
|
105
|
+
default: 10
|
|
106
|
+
},
|
|
107
|
+
pageSizeOptions: {
|
|
108
|
+
type: Array,
|
|
109
|
+
default: () => ['10', '20', '30', '40']
|
|
110
|
+
},
|
|
111
|
+
bordered: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
default: true
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
data() {
|
|
117
|
+
return {
|
|
118
|
+
tableHeaderHeight: 0,
|
|
119
|
+
paginationHeight: 0,
|
|
120
|
+
innerPageSize: 10,
|
|
121
|
+
innerCurrentPage: 1,
|
|
122
|
+
tableContentHeight: 0,
|
|
123
|
+
obs: [],
|
|
124
|
+
// 容器宽度,用于智能判断是否需要 fixed 列
|
|
125
|
+
containerWidth: 0,
|
|
126
|
+
// 用于强制重新渲染表格(当 fixed 列状态切换时)
|
|
127
|
+
tableRenderKey: 0
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
computed: {
|
|
131
|
+
wrapperStyle () {
|
|
132
|
+
// 外层容器样式
|
|
133
|
+
if (!this.height) return {}
|
|
134
|
+
return { height: `${this.height}px` }
|
|
135
|
+
},
|
|
136
|
+
needScrollY () {
|
|
137
|
+
// 判断是否需要 y 轴滚动:基于数据行数与可用高度预估
|
|
138
|
+
if (!this.height) return false
|
|
139
|
+
|
|
140
|
+
const availableHeight = this.getScrollHeightByHeight
|
|
141
|
+
if (availableHeight <= 0) return false
|
|
142
|
+
|
|
143
|
+
// 预估每行高度(包含边框),antd 默认约 54px
|
|
144
|
+
const estimatedRowHeight = 54
|
|
145
|
+
const estimatedTableHeight = this.dataSource.length * estimatedRowHeight
|
|
146
|
+
|
|
147
|
+
return estimatedTableHeight > availableHeight
|
|
148
|
+
},
|
|
149
|
+
innerColumns () {
|
|
150
|
+
return this.columns.filter(col => !Object.keys(col).includes('multiple'))
|
|
151
|
+
},
|
|
152
|
+
isNoData () {
|
|
153
|
+
return !this.dataSource.length
|
|
154
|
+
},
|
|
155
|
+
getScrollHeightByHeight () {
|
|
156
|
+
// 始终返回可用的剩余高度,让表格内容不足时也能占满容器
|
|
157
|
+
return this.height - this.tableHeaderHeight - this.paginationHeight
|
|
158
|
+
},
|
|
159
|
+
isFlexColumn () {
|
|
160
|
+
return this.columns.every(col => !col.width)
|
|
161
|
+
},
|
|
162
|
+
/**
|
|
163
|
+
* 计算所有列的总宽度(包括 rowSelection 的 checkbox 列和操作列)
|
|
164
|
+
*/
|
|
165
|
+
totalColumnsWidth () {
|
|
166
|
+
const cols = this.innerColumns || []
|
|
167
|
+
let total = cols.reduce((sum, col) => {
|
|
168
|
+
const w = col && col.width
|
|
169
|
+
return sum + (typeof w === 'number' ? w : 0)
|
|
170
|
+
}, 0)
|
|
171
|
+
// rowSelection 的 checkbox/radio 列,antd 默认约 60px
|
|
172
|
+
if (this.rowSelection) total += 60
|
|
173
|
+
// 操作列(operations)的宽度
|
|
174
|
+
if (this.operations && this.operations.width && typeof this.operations.width === 'number') {
|
|
175
|
+
total += this.operations.width
|
|
176
|
+
}
|
|
177
|
+
return total
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* 是否需要横向滚动:容器宽度 < 列总宽度
|
|
181
|
+
*/
|
|
182
|
+
needHorizontalScroll () {
|
|
183
|
+
// 未获取容器宽度前,先假定需要滚动(保守策略)
|
|
184
|
+
if (!this.containerWidth) return true
|
|
185
|
+
// 加一点容差
|
|
186
|
+
return this.containerWidth < this.totalColumnsWidth - 5
|
|
187
|
+
},
|
|
188
|
+
/**
|
|
189
|
+
* 智能列配置:
|
|
190
|
+
* - 当需要横向滚动时,保留原始 fixed 属性
|
|
191
|
+
* - 当容器足够宽时,移除 fixed 属性,让表格自动铺满
|
|
192
|
+
*/
|
|
193
|
+
smartColumns () {
|
|
194
|
+
if (this.needHorizontalScroll) {
|
|
195
|
+
// 需要滚动,保留原始配置
|
|
196
|
+
return this.innerColumns
|
|
197
|
+
}
|
|
198
|
+
// 不需要滚动,移除所有 fixed 属性
|
|
199
|
+
return this.innerColumns.map(col => {
|
|
200
|
+
if (col.fixed) {
|
|
201
|
+
const { fixed, ...rest } = col
|
|
202
|
+
return rest
|
|
203
|
+
}
|
|
204
|
+
return col
|
|
205
|
+
})
|
|
206
|
+
},
|
|
207
|
+
/**
|
|
208
|
+
* 智能 scroll 配置:
|
|
209
|
+
* - 当需要横向滚动时,设置 scroll.x
|
|
210
|
+
* - 当容器足够宽时,不设置 scroll.x,避免产生空白区域
|
|
211
|
+
*/
|
|
212
|
+
smartScroll () {
|
|
213
|
+
if (!this.needHorizontalScroll) {
|
|
214
|
+
// 不需要横向滚动,只保留 y 方向(如果需要)
|
|
215
|
+
if (this.height && this.needScrollY) {
|
|
216
|
+
const availableHeight = this.tableHeaderHeight && this.paginationHeight
|
|
217
|
+
? this.getScrollHeightByHeight
|
|
218
|
+
: this.height - 100
|
|
219
|
+
if (availableHeight > 50) {
|
|
220
|
+
return { y: availableHeight }
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return {}
|
|
224
|
+
}
|
|
225
|
+
// 需要横向滚动,使用原有逻辑
|
|
226
|
+
return this.getScroll
|
|
227
|
+
},
|
|
228
|
+
/**
|
|
229
|
+
* 智能 rowSelection 配置:
|
|
230
|
+
* - 当需要横向滚动时,保留原始 fixed 属性
|
|
231
|
+
* - 当容器足够宽时,移除 fixed 属性
|
|
232
|
+
*/
|
|
233
|
+
smartRowSelection () {
|
|
234
|
+
if (!this.rowSelection) return null
|
|
235
|
+
if (this.needHorizontalScroll) {
|
|
236
|
+
return this.rowSelection
|
|
237
|
+
}
|
|
238
|
+
// 不需要滚动,移除 fixed 属性
|
|
239
|
+
if (this.rowSelection.fixed) {
|
|
240
|
+
const { fixed, ...rest } = this.rowSelection
|
|
241
|
+
return rest
|
|
242
|
+
}
|
|
243
|
+
return this.rowSelection
|
|
244
|
+
},
|
|
245
|
+
getScroll () {
|
|
246
|
+
if (this.scroll) {
|
|
247
|
+
return this.scroll
|
|
248
|
+
} else {
|
|
249
|
+
// 固定列需要 scroll.x 才能正确同步行高,始终设置一个有效值
|
|
250
|
+
let baseX = (this.x === '' || this.x === null || this.x === undefined) ? 1200 : this.x
|
|
251
|
+
|
|
252
|
+
// 解决“x 给太大导致操作列前出现大块空白”的问题:
|
|
253
|
+
// 当所有列都给了明确 width 时,scroll.x 取列宽总和最合理;大于总和会产生多余区域。
|
|
254
|
+
if (typeof baseX === 'number') {
|
|
255
|
+
const cols = this.innerColumns || []
|
|
256
|
+
const total = cols.reduce((sum, col) => {
|
|
257
|
+
const w = col && col.width
|
|
258
|
+
return sum + (typeof w === 'number' ? w : 0)
|
|
259
|
+
}, 0)
|
|
260
|
+
|
|
261
|
+
// rowSelection 的 checkbox/radio 列是 antd 自动加的,给一个经验宽度避免误差
|
|
262
|
+
const selectionWidth = this.rowSelection ? 60 : 0
|
|
263
|
+
|
|
264
|
+
// 只有当所有列都明确给了宽度(total > 0)时才 clamp
|
|
265
|
+
if (total > 0) {
|
|
266
|
+
const minX = total + selectionWidth
|
|
267
|
+
if (baseX > minX) baseX = minX
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (this.height && this.needScrollY) {
|
|
272
|
+
const availableHeight = this.tableHeaderHeight && this.paginationHeight
|
|
273
|
+
? this.getScrollHeightByHeight
|
|
274
|
+
: this.height - 100
|
|
275
|
+
|
|
276
|
+
if (availableHeight > 50) {
|
|
277
|
+
return { x: baseX, y: availableHeight }
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return { x: baseX }
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
watch: {
|
|
285
|
+
pageSize: {
|
|
286
|
+
handler (pageSize) {
|
|
287
|
+
this.innerPageSize = pageSize
|
|
288
|
+
},
|
|
289
|
+
immediate: true
|
|
290
|
+
},
|
|
291
|
+
/**
|
|
292
|
+
* 监听 needHorizontalScroll 变化,强制重新渲染表格
|
|
293
|
+
* 当从"需要固定列"切换到"不需要固定列"或反之时,antd 的 a-table 需要完全重新渲染
|
|
294
|
+
*/
|
|
295
|
+
needHorizontalScroll (newVal, oldVal) {
|
|
296
|
+
if (newVal !== oldVal) {
|
|
297
|
+
// 更新 key 强制 Vue 销毁并重建 a-table 组件
|
|
298
|
+
this.tableRenderKey++
|
|
299
|
+
// 使用重试机制确保固定列完全渲染
|
|
300
|
+
this.$nextTick(() => {
|
|
301
|
+
this.retrySyncFixedColumns(newVal)
|
|
302
|
+
})
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
methods: {
|
|
307
|
+
onShowSizeChange (current, pageSize) {
|
|
308
|
+
this.innerCurrentPage = current
|
|
309
|
+
this.innerPageSize = pageSize
|
|
310
|
+
this.$emit('change-page', current, pageSize)
|
|
311
|
+
},
|
|
312
|
+
setPaginationHeight () {
|
|
313
|
+
this.$nextTick(() => {
|
|
314
|
+
const el = this.$el.querySelector('.g-table__pagination')
|
|
315
|
+
if (el) {
|
|
316
|
+
const { height } = el.getBoundingClientRect()
|
|
317
|
+
this.paginationHeight = height
|
|
318
|
+
}
|
|
319
|
+
})
|
|
320
|
+
},
|
|
321
|
+
setTableHeaderHeight () {
|
|
322
|
+
this.$nextTick(() => {
|
|
323
|
+
const el = this.$el.querySelector('.ant-table-header')
|
|
324
|
+
if (!el) return
|
|
325
|
+
const { height } = el.getBoundingClientRect()
|
|
326
|
+
this.tableHeaderHeight = height
|
|
327
|
+
})
|
|
328
|
+
},
|
|
329
|
+
setTableTbodyHeight () {
|
|
330
|
+
this.$nextTick(() => {
|
|
331
|
+
this.setTableHeaderHeight()
|
|
332
|
+
})
|
|
333
|
+
},
|
|
334
|
+
setRowClassName (record, idx) {
|
|
335
|
+
return idx % 2 === 0 ? 'g-table__row--even' : 'g-table__row--odd'
|
|
336
|
+
},
|
|
337
|
+
onChangePagination (page, pageSize) {
|
|
338
|
+
this.innerCurrentPage = page
|
|
339
|
+
this.innerPageSize = pageSize
|
|
340
|
+
this.$emit('change-page', page, pageSize)
|
|
341
|
+
},
|
|
342
|
+
syncFixedColumns () {
|
|
343
|
+
// 强制 ant-design-vue 重新计算固定列的宽度
|
|
344
|
+
this.$nextTick(() => {
|
|
345
|
+
const tableEl = this.$el.querySelector('.ant-table')
|
|
346
|
+
if (tableEl) {
|
|
347
|
+
// 触发窗口 resize 事件,让 ant-design-vue 重新计算
|
|
348
|
+
window.dispatchEvent(new Event('resize'))
|
|
349
|
+
}
|
|
350
|
+
})
|
|
351
|
+
},
|
|
352
|
+
/**
|
|
353
|
+
* 带重试的固定列同步机制
|
|
354
|
+
* antd 的 a-table 在 key 变化后重新渲染固定列需要一定时间,
|
|
355
|
+
* 这里通过重试确保固定列渲染完成后再同步。
|
|
356
|
+
* @param {boolean} needFixed - 是否需要固定列
|
|
357
|
+
* @param {number} retries - 当前重试次数
|
|
358
|
+
*/
|
|
359
|
+
retrySyncFixedColumns (needFixed, retries = 0) {
|
|
360
|
+
const MAX_RETRIES = 5
|
|
361
|
+
const DELAY = 100 // 每次延迟 100ms
|
|
362
|
+
|
|
363
|
+
setTimeout(() => {
|
|
364
|
+
this.syncFixedColumns()
|
|
365
|
+
this.syncHeaderTableWidth()
|
|
366
|
+
this.bindScrollSync()
|
|
367
|
+
|
|
368
|
+
// 如果需要固定列,检查是否已渲染
|
|
369
|
+
if (needFixed && retries < MAX_RETRIES) {
|
|
370
|
+
const hasFixedLeft = this.$el.querySelector('.ant-table-fixed-left .ant-table-body tbody tr')
|
|
371
|
+
const hasFixedRight = this.$el.querySelector('.ant-table-fixed-right .ant-table-body tbody tr')
|
|
372
|
+
|
|
373
|
+
// 如果有固定列配置但还没渲染出来,继续重试
|
|
374
|
+
const hasFixedConfig = this.innerColumns.some(c => c.fixed) || (this.rowSelection && this.rowSelection.fixed)
|
|
375
|
+
if (hasFixedConfig && !hasFixedLeft && !hasFixedRight) {
|
|
376
|
+
this.retrySyncFixedColumns(needFixed, retries + 1)
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}, DELAY)
|
|
380
|
+
},
|
|
381
|
+
/**
|
|
382
|
+
* 修复 x: 'max-content' 场景下表头不跟着横向滚动的问题。
|
|
383
|
+
* 原因:ant-design-vue 的 header table 和 body table 各自算 max-content,
|
|
384
|
+
* header 按表头文字算、body 按实际数据算,二者宽度不同时 header 就"滚不动"。
|
|
385
|
+
* 方案:数据渲染后把 header table 的 width 强制设成和 body table 一样。
|
|
386
|
+
*/
|
|
387
|
+
syncHeaderTableWidth () {
|
|
388
|
+
this.$nextTick(() => {
|
|
389
|
+
const headerTable = this.$el.querySelector('.ant-table-scroll .ant-table-header table')
|
|
390
|
+
const bodyTable = this.$el.querySelector('.ant-table-scroll .ant-table-body table')
|
|
391
|
+
if (!headerTable || !bodyTable) return
|
|
392
|
+
|
|
393
|
+
const bodyW = bodyTable.getBoundingClientRect().width
|
|
394
|
+
const headerW = headerTable.getBoundingClientRect().width
|
|
395
|
+
|
|
396
|
+
// 始终同步表头宽度到表体宽度,确保窗口变大/变小时都能正确响应
|
|
397
|
+
// 只有当宽度差异超过 2px 时才更新,避免频繁设置样式
|
|
398
|
+
if (Math.abs(bodyW - headerW) > 2) {
|
|
399
|
+
headerTable.style.width = `${bodyW}px`
|
|
400
|
+
headerTable.style.minWidth = `${bodyW}px`
|
|
401
|
+
}
|
|
402
|
+
})
|
|
403
|
+
},
|
|
404
|
+
/**
|
|
405
|
+
* 监听表体横向滚动,同步到表头(防止 antd 自带同步失效)
|
|
406
|
+
*/
|
|
407
|
+
bindScrollSync () {
|
|
408
|
+
const body = this.$el.querySelector('.ant-table-scroll .ant-table-body')
|
|
409
|
+
const header = this.$el.querySelector('.ant-table-scroll .ant-table-header')
|
|
410
|
+
if (!body || !header) return
|
|
411
|
+
|
|
412
|
+
if (this._scrollHandler) return // 已绑定
|
|
413
|
+
this._scrollHandler = () => {
|
|
414
|
+
header.scrollLeft = body.scrollLeft
|
|
415
|
+
}
|
|
416
|
+
body.addEventListener('scroll', this._scrollHandler, { passive: true })
|
|
417
|
+
},
|
|
418
|
+
unbindScrollSync () {
|
|
419
|
+
const body = this.$el.querySelector('.ant-table-scroll .ant-table-body')
|
|
420
|
+
if (body && this._scrollHandler) {
|
|
421
|
+
body.removeEventListener('scroll', this._scrollHandler)
|
|
422
|
+
this._scrollHandler = null
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
/**
|
|
426
|
+
* 测量容器宽度
|
|
427
|
+
*/
|
|
428
|
+
measureContainerWidth () {
|
|
429
|
+
const wrapper = this.$refs.tableWrapper
|
|
430
|
+
if (wrapper) {
|
|
431
|
+
this.containerWidth = wrapper.clientWidth
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
/**
|
|
435
|
+
* 使用 ResizeObserver 监听容器宽度变化
|
|
436
|
+
*/
|
|
437
|
+
observeContainerWidth () {
|
|
438
|
+
const wrapper = this.$refs.tableWrapper
|
|
439
|
+
if (!wrapper || typeof ResizeObserver === 'undefined') return
|
|
440
|
+
|
|
441
|
+
if (this._containerResizeObserver) return // 已绑定
|
|
442
|
+
|
|
443
|
+
this._containerResizeObserver = new ResizeObserver((entries) => {
|
|
444
|
+
for (const entry of entries) {
|
|
445
|
+
const newWidth = entry.contentRect.width
|
|
446
|
+
// 只有宽度变化超过阈值才触发更新,避免微小变化导致频繁重渲染
|
|
447
|
+
if (Math.abs(newWidth - this.containerWidth) > 10) {
|
|
448
|
+
const oldNeedScroll = this.needHorizontalScroll
|
|
449
|
+
this.containerWidth = newWidth
|
|
450
|
+
// 容器宽度变化会触发 needHorizontalScroll 的重新计算
|
|
451
|
+
// needHorizontalScroll 的 watcher 会处理表格重新渲染和列宽同步
|
|
452
|
+
// 这里不需要直接调用 syncFixedColumns,避免与 watcher 的执行时机冲突
|
|
453
|
+
// 无论 needHorizontalScroll 是否变化,都立即同步表头宽度
|
|
454
|
+
// 确保窗口变大/变小时表头都能及时响应
|
|
455
|
+
this.$nextTick(() => {
|
|
456
|
+
// 使用 requestAnimationFrame 确保在浏览器重绘后同步表头宽度
|
|
457
|
+
// 这样能确保表体宽度已经更新完成
|
|
458
|
+
requestAnimationFrame(() => {
|
|
459
|
+
this.syncHeaderTableWidth()
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
// 如果 needHorizontalScroll 状态没有变化,说明只是列宽需要调整,直接同步
|
|
463
|
+
// 如果状态变化了,watcher 会处理重新渲染
|
|
464
|
+
if (this.needHorizontalScroll === oldNeedScroll) {
|
|
465
|
+
// 防抖:延迟同步固定列,避免频繁调用
|
|
466
|
+
if (this._resizeDebounceTimer) {
|
|
467
|
+
clearTimeout(this._resizeDebounceTimer)
|
|
468
|
+
}
|
|
469
|
+
this._resizeDebounceTimer = setTimeout(() => {
|
|
470
|
+
this.syncFixedColumns()
|
|
471
|
+
this.syncHeaderTableWidth()
|
|
472
|
+
this.bindScrollSync()
|
|
473
|
+
}, 150)
|
|
474
|
+
}
|
|
475
|
+
})
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
})
|
|
479
|
+
this._containerResizeObserver.observe(wrapper)
|
|
480
|
+
},
|
|
481
|
+
/**
|
|
482
|
+
* 断开容器宽度监听
|
|
483
|
+
*/
|
|
484
|
+
unobserveContainerWidth () {
|
|
485
|
+
if (this._containerResizeObserver) {
|
|
486
|
+
this._containerResizeObserver.disconnect()
|
|
487
|
+
this._containerResizeObserver = null
|
|
488
|
+
}
|
|
489
|
+
// 清理防抖定时器
|
|
490
|
+
if (this._resizeDebounceTimer) {
|
|
491
|
+
clearTimeout(this._resizeDebounceTimer)
|
|
492
|
+
this._resizeDebounceTimer = null
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
mounted() {
|
|
497
|
+
this.$nextTick(() => {
|
|
498
|
+
// 先测量容器宽度,用于智能判断是否需要 fixed 列
|
|
499
|
+
this.measureContainerWidth()
|
|
500
|
+
this.observeContainerWidth()
|
|
501
|
+
|
|
502
|
+
this.setPaginationHeight()
|
|
503
|
+
setTimeout(() => {
|
|
504
|
+
this.setTableTbodyHeight()
|
|
505
|
+
this.setPaginationHeight()
|
|
506
|
+
// 强制同步固定列和主表的列宽
|
|
507
|
+
this.syncFixedColumns()
|
|
508
|
+
// 同步表头 table 宽度(修复 max-content 场景)
|
|
509
|
+
this.syncHeaderTableWidth()
|
|
510
|
+
// 绑定横向滚动同步
|
|
511
|
+
this.bindScrollSync()
|
|
512
|
+
}, 200)
|
|
513
|
+
})
|
|
514
|
+
|
|
515
|
+
// 监听数据变化,重新同步列宽
|
|
516
|
+
this.$watch('dataSource', () => {
|
|
517
|
+
this.$nextTick(() => {
|
|
518
|
+
setTimeout(() => {
|
|
519
|
+
this.syncFixedColumns()
|
|
520
|
+
this.syncHeaderTableWidth()
|
|
521
|
+
this.bindScrollSync()
|
|
522
|
+
}, 100)
|
|
523
|
+
})
|
|
524
|
+
}, { deep: true })
|
|
525
|
+
},
|
|
526
|
+
destroyed () {
|
|
527
|
+
this.obs.forEach(ob => ob.disconnect())
|
|
528
|
+
this.unbindScrollSync()
|
|
529
|
+
this.unobserveContainerWidth()
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
</script>
|
|
533
|
+
|
|
534
|
+
<style lang="scss" scoped>
|
|
535
|
+
.g-table__wrapper {
|
|
536
|
+
/**
|
|
537
|
+
* 修复"宽屏下表格两侧出现空白"问题:
|
|
538
|
+
* 当视口宽度大于表格内容宽度时,主表(ant-table-scroll)不会自动拉伸,
|
|
539
|
+
* 而固定列(fixed-left/fixed-right)是 position:absolute 定位在容器边缘,中间就出现空白。
|
|
540
|
+
* 解决方案:让主表的 table 元素 min-width:100%,使其始终填满滚动容器。
|
|
541
|
+
*/
|
|
542
|
+
::v-deep .ant-table-scroll .ant-table-header table,
|
|
543
|
+
::v-deep .ant-table-scroll .ant-table-body table {
|
|
544
|
+
min-width: 100%;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* 修复"固定列 + scroll.x"场景下,主表(ant-table-scroll)里会渲染一份 fixed 列的占位 header/cell。
|
|
549
|
+
* 这份占位本来只用于计算宽度,但在某些布局下会被看见,表现为"操作列前多了一大块空白/空列"。
|
|
550
|
+
* 这里用 visibility:hidden 隐藏占位(不影响占位宽度与 fixed 计算),避免视觉空白。
|
|
551
|
+
*/
|
|
552
|
+
::v-deep .ant-table-scroll .ant-table-header thead > tr > th.ant-table-fixed-columns-in-body.ant-table-row-cell-last,
|
|
553
|
+
::v-deep .ant-table-scroll .ant-table-body tbody > tr > td.ant-table-fixed-columns-in-body.ant-table-row-cell-last {
|
|
554
|
+
visibility: hidden;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/* 强制统一行高,确保主表和固定列对齐 */
|
|
558
|
+
::v-deep .ant-table-tbody > tr > td {
|
|
559
|
+
height: 54px;
|
|
560
|
+
padding: 8px 16px;
|
|
561
|
+
vertical-align: middle;
|
|
562
|
+
box-sizing: border-box;
|
|
563
|
+
line-height: 38px;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/* 表头也统一高度和样式 */
|
|
567
|
+
::v-deep .ant-table-thead > tr > th {
|
|
568
|
+
height: 54px;
|
|
569
|
+
padding: 8px 16px;
|
|
570
|
+
vertical-align: middle;
|
|
571
|
+
box-sizing: border-box;
|
|
572
|
+
line-height: 38px;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/* 分页区域固定在底部 */
|
|
576
|
+
.g-table__pagination {
|
|
577
|
+
display: flex;
|
|
578
|
+
flex-direction: row;
|
|
579
|
+
justify-content: end;
|
|
580
|
+
border-top: unset;
|
|
581
|
+
padding-top: 8px;
|
|
582
|
+
padding-bottom: 8px;
|
|
583
|
+
background: #fff;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/* 空数据状态顶部显示 */
|
|
587
|
+
.g-table__no-data {
|
|
588
|
+
position: relative;
|
|
589
|
+
::v-deep .ant-table-placeholder {
|
|
590
|
+
position: absolute;
|
|
591
|
+
top: 50%;
|
|
592
|
+
left: 50%;
|
|
593
|
+
transform: translate(-50%, -40%);
|
|
594
|
+
width: 100%;
|
|
595
|
+
height: 100%;
|
|
596
|
+
text-align: center;
|
|
597
|
+
color: #999;
|
|
598
|
+
font-size: 14px;
|
|
599
|
+
font-weight: normal;
|
|
600
|
+
line-height: 20px;
|
|
601
|
+
overflow: hidden;
|
|
602
|
+
border: unset;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
320
606
|
</style>
|