vue2-client 1.11.3 → 1.11.4
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/package.json
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<a-card :bordered="false">
|
|
3
|
-
<!-- <a-button @click="()=>{queryParamsName = 'MeterBookUnallocatedUserCRUD'}">测试1</a-button>-->
|
|
4
|
-
<!-- <a-button @click="()=>{queryParamsName = 'MeterBookUnallocatedAreaCRUD'}">测试2</a-button>-->
|
|
5
|
-
<x-form-table
|
|
6
|
-
title="示例表单"
|
|
7
|
-
:queryParamsName="queryParamsName"
|
|
8
|
-
:fixedAddForm="fixedAddForm"
|
|
9
|
-
service-name="af-
|
|
10
|
-
@action="action"
|
|
11
|
-
@columnClick="columnClick"
|
|
12
|
-
ref="xFormTable">
|
|
13
|
-
</x-form-table>
|
|
14
|
-
</a-card>
|
|
15
|
-
</template>
|
|
16
|
-
|
|
17
|
-
<script>
|
|
18
|
-
import XFormTable from '@vue2-client/base-client/components/common/XFormTable/XFormTable.vue'
|
|
19
|
-
import { microDispatch } from '@vue2-client/utils/microAppUtils'
|
|
20
|
-
export default {
|
|
21
|
-
name: 'Demo',
|
|
22
|
-
components: {
|
|
23
|
-
XFormTable
|
|
24
|
-
},
|
|
25
|
-
data () {
|
|
26
|
-
return {
|
|
27
|
-
// 查询配置文件名
|
|
28
|
-
queryParamsName: '
|
|
29
|
-
// 查询配置左侧tree
|
|
30
|
-
// xTreeConfigName: 'addressType',
|
|
31
|
-
// 新增表单固定值
|
|
32
|
-
fixedAddForm: {},
|
|
33
|
-
// 是否显示详情抽屉
|
|
34
|
-
detailVisible: false,
|
|
35
|
-
// 当前记录
|
|
36
|
-
record: {}
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
methods: {
|
|
40
|
-
columnClick (key, value, record) {
|
|
41
|
-
microDispatch({ type: 'v3route', path: '/bingliguanli/dianzibingliluru', props: { selected: arguments[0].his_f_admission_id } })
|
|
42
|
-
},
|
|
43
|
-
action (record, id, actionType) {
|
|
44
|
-
this.detailVisible = true
|
|
45
|
-
console.log('触发了详情操作', record, id, actionType)
|
|
46
|
-
},
|
|
47
|
-
onClose () {
|
|
48
|
-
this.detailVisible = false
|
|
49
|
-
// 关闭详情之后重新查询表单
|
|
50
|
-
this.$refs.xFormTable.refreshTable(true)
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
computed: {
|
|
54
|
-
},
|
|
55
|
-
}
|
|
56
|
-
</script>
|
|
57
|
-
|
|
58
|
-
<style scoped>
|
|
59
|
-
|
|
60
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<a-card :bordered="false">
|
|
3
|
+
<!-- <a-button @click="()=>{queryParamsName = 'MeterBookUnallocatedUserCRUD'}">测试1</a-button>-->
|
|
4
|
+
<!-- <a-button @click="()=>{queryParamsName = 'MeterBookUnallocatedAreaCRUD'}">测试2</a-button>-->
|
|
5
|
+
<x-form-table
|
|
6
|
+
title="示例表单"
|
|
7
|
+
:queryParamsName="queryParamsName"
|
|
8
|
+
:fixedAddForm="fixedAddForm"
|
|
9
|
+
service-name="af-system"
|
|
10
|
+
@action="action"
|
|
11
|
+
@columnClick="columnClick"
|
|
12
|
+
ref="xFormTable">
|
|
13
|
+
</x-form-table>
|
|
14
|
+
</a-card>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
import XFormTable from '@vue2-client/base-client/components/common/XFormTable/XFormTable.vue'
|
|
19
|
+
import { microDispatch } from '@vue2-client/utils/microAppUtils'
|
|
20
|
+
export default {
|
|
21
|
+
name: 'Demo',
|
|
22
|
+
components: {
|
|
23
|
+
XFormTable
|
|
24
|
+
},
|
|
25
|
+
data () {
|
|
26
|
+
return {
|
|
27
|
+
// 查询配置文件名
|
|
28
|
+
queryParamsName: 'ceshiCRUD',
|
|
29
|
+
// 查询配置左侧tree
|
|
30
|
+
// xTreeConfigName: 'addressType',
|
|
31
|
+
// 新增表单固定值
|
|
32
|
+
fixedAddForm: {},
|
|
33
|
+
// 是否显示详情抽屉
|
|
34
|
+
detailVisible: false,
|
|
35
|
+
// 当前记录
|
|
36
|
+
record: {}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
methods: {
|
|
40
|
+
columnClick (key, value, record) {
|
|
41
|
+
microDispatch({ type: 'v3route', path: '/bingliguanli/dianzibingliluru', props: { selected: arguments[0].his_f_admission_id } })
|
|
42
|
+
},
|
|
43
|
+
action (record, id, actionType) {
|
|
44
|
+
this.detailVisible = true
|
|
45
|
+
console.log('触发了详情操作', record, id, actionType)
|
|
46
|
+
},
|
|
47
|
+
onClose () {
|
|
48
|
+
this.detailVisible = false
|
|
49
|
+
// 关闭详情之后重新查询表单
|
|
50
|
+
this.$refs.xFormTable.refreshTable(true)
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
computed: {
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<style scoped>
|
|
59
|
+
|
|
60
|
+
</style>
|
|
@@ -1,390 +1,426 @@
|
|
|
1
|
-
import T from 'ant-design-vue/es/table/Table'
|
|
2
|
-
import get from 'lodash.get'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* /users/
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
* @param
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
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
|
-
this.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
this.
|
|
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
|
-
if (this.
|
|
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
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
1
|
+
import T from 'ant-design-vue/es/table/Table'
|
|
2
|
+
import get from 'lodash.get'
|
|
3
|
+
import { mapState } from 'vuex'
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
data () {
|
|
7
|
+
return {
|
|
8
|
+
clickedRowKey: null,
|
|
9
|
+
needTotalList: [],
|
|
10
|
+
|
|
11
|
+
selectedRows: [],
|
|
12
|
+
selectedRowKeys: [],
|
|
13
|
+
|
|
14
|
+
localLoading: false,
|
|
15
|
+
localDataSource: [],
|
|
16
|
+
localPagination: Object.assign({}, this.pagination),
|
|
17
|
+
|
|
18
|
+
sortField: undefined,
|
|
19
|
+
sortOrder: undefined,
|
|
20
|
+
pageNum: 1,
|
|
21
|
+
pageSize: 10
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
props: Object.assign({}, T.props, {
|
|
25
|
+
rowKey: {
|
|
26
|
+
type: [String, Function],
|
|
27
|
+
default: 'key'
|
|
28
|
+
},
|
|
29
|
+
data: {
|
|
30
|
+
type: Function,
|
|
31
|
+
required: true
|
|
32
|
+
},
|
|
33
|
+
setScrollYHeight: {
|
|
34
|
+
type: Function,
|
|
35
|
+
required: true
|
|
36
|
+
},
|
|
37
|
+
showSizeChanger: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
default: true
|
|
40
|
+
},
|
|
41
|
+
showSummary: {
|
|
42
|
+
type: Boolean,
|
|
43
|
+
default: false
|
|
44
|
+
},
|
|
45
|
+
selectRowMode: {
|
|
46
|
+
type: String,
|
|
47
|
+
default: 'default'
|
|
48
|
+
},
|
|
49
|
+
size: {
|
|
50
|
+
type: String,
|
|
51
|
+
default: 'default'
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* alert: {
|
|
55
|
+
* show: true,
|
|
56
|
+
* clear: Function
|
|
57
|
+
* }
|
|
58
|
+
*/
|
|
59
|
+
alert: {
|
|
60
|
+
type: [Object, Boolean],
|
|
61
|
+
default: null
|
|
62
|
+
},
|
|
63
|
+
rowSelection: {
|
|
64
|
+
type: Object,
|
|
65
|
+
default: null
|
|
66
|
+
},
|
|
67
|
+
/** @Deprecated */
|
|
68
|
+
showAlertInfo: {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
default: false
|
|
71
|
+
},
|
|
72
|
+
showPagination: {
|
|
73
|
+
type: String | Boolean,
|
|
74
|
+
default: 'auto'
|
|
75
|
+
},
|
|
76
|
+
// 是否隐藏翻页,如果隐藏,彻底不显示翻译
|
|
77
|
+
hidePagination: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: false
|
|
80
|
+
},
|
|
81
|
+
// 是否显示表头已选择部分
|
|
82
|
+
showSelected: {
|
|
83
|
+
type: Boolean,
|
|
84
|
+
default: true
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* enable page URI mode
|
|
88
|
+
*
|
|
89
|
+
* e.g:
|
|
90
|
+
* /users/1
|
|
91
|
+
* /users/2
|
|
92
|
+
* /users/3?queryParam=test
|
|
93
|
+
* ...
|
|
94
|
+
*/
|
|
95
|
+
pageURI: {
|
|
96
|
+
type: Boolean,
|
|
97
|
+
default: false
|
|
98
|
+
}
|
|
99
|
+
}),
|
|
100
|
+
computed: {
|
|
101
|
+
...mapState('setting', ['theme']), // 添加 theme 到计算属性
|
|
102
|
+
|
|
103
|
+
// 计算点击行的背景色,使用 10% 透明度
|
|
104
|
+
clickedRowColor () {
|
|
105
|
+
if (!this.theme?.color) return '#e6f7ff'
|
|
106
|
+
return this.hexToRgba(this.theme.color, 0.1)
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
watch: {
|
|
110
|
+
'localPagination.current' (val) {
|
|
111
|
+
this.pageURI && this.$router.push({
|
|
112
|
+
...this.$route,
|
|
113
|
+
name: this.$route.name,
|
|
114
|
+
params: Object.assign({}, this.$route.params, {
|
|
115
|
+
pageNo: val
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
// change pagination, reset total data
|
|
119
|
+
this.needTotalList = this.initTotalList(this.columns)
|
|
120
|
+
if (this.selectRowMode === 'default') {
|
|
121
|
+
this.selectedRowKeys = []
|
|
122
|
+
this.selectedRows = []
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
pageNum (val) {
|
|
126
|
+
Object.assign(this.localPagination, {
|
|
127
|
+
current: val
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
pageSize (val) {
|
|
131
|
+
Object.assign(this.localPagination, {
|
|
132
|
+
pageSize: val
|
|
133
|
+
})
|
|
134
|
+
},
|
|
135
|
+
showSizeChanger (val) {
|
|
136
|
+
Object.assign(this.localPagination, {
|
|
137
|
+
showSizeChanger: val
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
created () {
|
|
142
|
+
const { pageNo } = this.$route.params
|
|
143
|
+
const localPageNum = this.pageURI && (pageNo && parseInt(pageNo)) || this.pageNum
|
|
144
|
+
this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, {
|
|
145
|
+
current: localPageNum,
|
|
146
|
+
pageSize: this.pageSize,
|
|
147
|
+
showSizeChanger: this.showSizeChanger
|
|
148
|
+
}) || false
|
|
149
|
+
this.needTotalList = this.initTotalList(this.columns)
|
|
150
|
+
// this.loadData()
|
|
151
|
+
},
|
|
152
|
+
methods: {
|
|
153
|
+
/**
|
|
154
|
+
* 表格重新加载方法
|
|
155
|
+
* 如果参数为 true, 则强制刷新到第一页
|
|
156
|
+
* @param Boolean bool
|
|
157
|
+
*/
|
|
158
|
+
refresh (bool = false) {
|
|
159
|
+
bool && (this.localPagination = Object.assign({}, {
|
|
160
|
+
current: 1, pageSize: this.pageSize
|
|
161
|
+
}))
|
|
162
|
+
this.loadData()
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* 加载数据方法
|
|
166
|
+
* @param {Object} pagination 分页选项器
|
|
167
|
+
* @param {Object} filters 过滤条件
|
|
168
|
+
* @param {Object} sorter 排序条件
|
|
169
|
+
*/
|
|
170
|
+
loadData (pagination, filters, sorter) {
|
|
171
|
+
this.localLoading = true
|
|
172
|
+
// 暂存排序方式,避免 refresh 之后排序失效
|
|
173
|
+
if (sorter && sorter.field) {
|
|
174
|
+
this.sortField = sorter.field
|
|
175
|
+
}
|
|
176
|
+
if (sorter && sorter.order) {
|
|
177
|
+
this.sortOrder = sorter.order
|
|
178
|
+
}
|
|
179
|
+
const parameter = Object.assign({
|
|
180
|
+
querySummary: !pagination && this.showSummary, // 分页查询的情况不重新获取汇总数据
|
|
181
|
+
pageNo: (pagination && pagination.current) ||
|
|
182
|
+
this.showPagination && this.localPagination.current || this.pageNum,
|
|
183
|
+
pageSize: (pagination && pagination.pageSize) ||
|
|
184
|
+
this.showPagination && this.localPagination.pageSize || this.pageSize
|
|
185
|
+
},
|
|
186
|
+
(this.sortField && { sortField: this.sortField }) || {},
|
|
187
|
+
(this.sortOrder && { sortOrder: this.sortOrder }) || {},
|
|
188
|
+
{ ...filters }
|
|
189
|
+
)
|
|
190
|
+
const result = this.data(parameter)
|
|
191
|
+
// 对接自己的通用数据接口需要修改下方代码中的 r.pageNo, r.totalCount, r.data
|
|
192
|
+
// eslint-disable-next-line
|
|
193
|
+
if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {
|
|
194
|
+
result.then(r => {
|
|
195
|
+
this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
|
|
196
|
+
current: r.pageNo, // 返回结果中的当前分页数
|
|
197
|
+
total: r.totalCount, // 返回结果中的总记录数
|
|
198
|
+
showSizeChanger: this.showSizeChanger,
|
|
199
|
+
pageSize: (pagination && pagination.pageSize) || this.localPagination.pageSize
|
|
200
|
+
}) || false
|
|
201
|
+
// 为防止删除数据后导致页面当前页面数据长度为 0 ,自动翻页到上一页
|
|
202
|
+
if (r.data.length === 0 && this.showPagination && this.localPagination.current > 1) {
|
|
203
|
+
this.localPagination.current--
|
|
204
|
+
this.loadData()
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// 这里用于判断接口是否有返回 r.totalCount 且 this.showPagination = 'auto' 且 pageNo 和 pageSize 存在 且 totalCount 小于等于 pageNo * pageSize 的大小
|
|
209
|
+
// 当情况满足时,表示数据不满足分页大小,关闭 table 分页功能
|
|
210
|
+
try {
|
|
211
|
+
if ((['auto'].includes(this.showPagination) && r.totalCount <= (r.pageNo * this.localPagination.pageSize))) {
|
|
212
|
+
this.localPagination.hideOnSinglePage = true
|
|
213
|
+
}
|
|
214
|
+
} catch (e) {
|
|
215
|
+
this.localPagination = false
|
|
216
|
+
}
|
|
217
|
+
this.localDataSource = r.data // 返回结果中的数组数据
|
|
218
|
+
this.localLoading = false
|
|
219
|
+
this.setScrollYHeight({ type: 'default' })
|
|
220
|
+
}, () => {
|
|
221
|
+
this.localLoading = false
|
|
222
|
+
this.setScrollYHeight({ type: 'default' })
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
initTotalList (columns) {
|
|
227
|
+
const totalList = []
|
|
228
|
+
columns && columns instanceof Array && columns.forEach(column => {
|
|
229
|
+
if (column.needTotal) {
|
|
230
|
+
totalList.push({
|
|
231
|
+
...column,
|
|
232
|
+
total: 0
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
return totalList
|
|
237
|
+
},
|
|
238
|
+
/**
|
|
239
|
+
* 用于更新已选中的列表数据 total 统计
|
|
240
|
+
* @param selectedRowKeys
|
|
241
|
+
* @param selectedRows
|
|
242
|
+
*/
|
|
243
|
+
updateSelect (selectedRowKeys, selectedRows) {
|
|
244
|
+
this.selectedRows = selectedRows
|
|
245
|
+
this.selectedRowKeys = selectedRowKeys
|
|
246
|
+
const list = this.needTotalList
|
|
247
|
+
this.needTotalList = list.map(item => {
|
|
248
|
+
return {
|
|
249
|
+
...item,
|
|
250
|
+
total: selectedRows.reduce((sum, val) => {
|
|
251
|
+
const total = sum + parseInt(get(val, item.dataIndex))
|
|
252
|
+
return isNaN(total) ? 0 : total
|
|
253
|
+
}, 0)
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
},
|
|
257
|
+
/**
|
|
258
|
+
* 清空 table 已选中项
|
|
259
|
+
*/
|
|
260
|
+
clearSelected () {
|
|
261
|
+
if (this.rowSelection) {
|
|
262
|
+
this.rowSelection.onChange([], [])
|
|
263
|
+
this.updateSelect([], [])
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
/**
|
|
267
|
+
* 处理交给 table 使用者去处理 clear 事件时,内部选中统计同时调用
|
|
268
|
+
* @param callback
|
|
269
|
+
* @returns {*}
|
|
270
|
+
*/
|
|
271
|
+
renderClear (callback) {
|
|
272
|
+
if (this.selectedRowKeys.length <= 0) return null
|
|
273
|
+
return (
|
|
274
|
+
<a style="margin-left: 24px" onClick={() => {
|
|
275
|
+
callback()
|
|
276
|
+
this.clearSelected()
|
|
277
|
+
}}>清空</a>
|
|
278
|
+
)
|
|
279
|
+
},
|
|
280
|
+
renderAlert () {
|
|
281
|
+
// 绘制统计列数据
|
|
282
|
+
const needTotalItems = this.needTotalList.map((item) => {
|
|
283
|
+
return (<span style="margin-right: 12px">
|
|
284
|
+
{item.title}总计 <a
|
|
285
|
+
style="font-weight: 600">{!item.customRender ? item.total : item.customRender(item.total)}</a>
|
|
286
|
+
</span>)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
// 绘制 清空 按钮
|
|
290
|
+
const clearItem = (typeof this.alert.clear === 'boolean' && this.alert.clear) ? (
|
|
291
|
+
this.renderClear(this.clearSelected)
|
|
292
|
+
) : (typeof this.alert.clear === 'function') ? (
|
|
293
|
+
this.renderClear(this.alert.clear)
|
|
294
|
+
) : null
|
|
295
|
+
|
|
296
|
+
// 绘制 alert 组件
|
|
297
|
+
return (
|
|
298
|
+
<a-alert showIcon={true} style={{ marginBottom: '8px', fontSize: '14px' }}>
|
|
299
|
+
<template slot="message">
|
|
300
|
+
<span style="margin-right: 12px;">已选择: <a style="font-weight: 600">{this.selectedRows.length}</a></span>
|
|
301
|
+
{needTotalItems}
|
|
302
|
+
{clearItem}
|
|
303
|
+
</template>
|
|
304
|
+
</a-alert>
|
|
305
|
+
)
|
|
306
|
+
},
|
|
307
|
+
onExpand (expanded, record) {
|
|
308
|
+
this.$emit('expand', expanded, record)
|
|
309
|
+
},
|
|
310
|
+
handleRowClick (record) {
|
|
311
|
+
this.clickedRowKey = record[this.rowKey]
|
|
312
|
+
this.$emit('rowClick', record)
|
|
313
|
+
},
|
|
314
|
+
hexToRgba (hex, alpha = 1) {
|
|
315
|
+
try {
|
|
316
|
+
const r = parseInt(hex.slice(1, 3), 16)
|
|
317
|
+
const g = parseInt(hex.slice(3, 5), 16)
|
|
318
|
+
const b = parseInt(hex.slice(5, 7), 16)
|
|
319
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`
|
|
320
|
+
} catch (e) {
|
|
321
|
+
return '#e6f7ff'
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
|
|
326
|
+
render () {
|
|
327
|
+
const props = {}
|
|
328
|
+
const localKeys = Object.keys(this.$data)
|
|
329
|
+
const showAlert = (typeof this.alert === 'object' && this.alert !== null && this.alert.show) && typeof this.rowSelection.selectedRowKeys !== 'undefined' || this.alert
|
|
330
|
+
|
|
331
|
+
Object.keys(T.props).forEach(k => {
|
|
332
|
+
const localKey = `local${k.substring(0, 1).toUpperCase()}${k.substring(1)}`
|
|
333
|
+
if (localKeys.includes(localKey)) {
|
|
334
|
+
props[k] = this[localKey]
|
|
335
|
+
return props[k]
|
|
336
|
+
}
|
|
337
|
+
if (k === 'rowSelection') {
|
|
338
|
+
if (showAlert && this.rowSelection) {
|
|
339
|
+
// 如果需要使用alert,则重新绑定 rowSelection 事件
|
|
340
|
+
props[k] = {
|
|
341
|
+
...this.rowSelection,
|
|
342
|
+
selectedRows: this.selectedRows,
|
|
343
|
+
selectedRowKeys: this.selectedRowKeys,
|
|
344
|
+
onChange: (selectedRowKeys, selectedRows) => {
|
|
345
|
+
this.updateSelect(selectedRowKeys, selectedRows)
|
|
346
|
+
typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return props[k]
|
|
350
|
+
} else if (!this.rowSelection) {
|
|
351
|
+
// 如果没打算开启 rowSelection 则清空默认的选择项
|
|
352
|
+
props[k] = null
|
|
353
|
+
return props[k]
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
this[k] && (props[k] = this[k])
|
|
357
|
+
return props[k]
|
|
358
|
+
})
|
|
359
|
+
// 取消原有的分页组件 产品设计分页组件和汇总在一行 重新分页逻辑
|
|
360
|
+
props.pagination = false
|
|
361
|
+
// 在 props 中添加自定义行属性
|
|
362
|
+
props.customRow = (record) => {
|
|
363
|
+
return {
|
|
364
|
+
on: {
|
|
365
|
+
click: () => this.handleRowClick(record)
|
|
366
|
+
},
|
|
367
|
+
style: {
|
|
368
|
+
'background-color': this.clickedRowKey === record[this.rowKey] ? this.clickedRowColor : ''
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// 自定义底部汇总插槽组件
|
|
373
|
+
const pagination = (
|
|
374
|
+
!!this.showPagination && <a-row type={'flex'} justify={'start'} style={{ marginTop: '8px' }}>
|
|
375
|
+
<a-col flex="1" style={{
|
|
376
|
+
alignItems: 'center',
|
|
377
|
+
display: 'flex',
|
|
378
|
+
justifyContent: 'start',
|
|
379
|
+
boxSizing: 'border-box',
|
|
380
|
+
paddingRight: '2rem'
|
|
381
|
+
}}>
|
|
382
|
+
{this.$slots.fixedfooter}
|
|
383
|
+
</a-col>
|
|
384
|
+
<a-col flex="0 0">
|
|
385
|
+
<a-pagination
|
|
386
|
+
total={this.localPagination.total}
|
|
387
|
+
onChange={(page, pageSize) => {
|
|
388
|
+
this.pageSize = pageSize
|
|
389
|
+
this.pageNum = page
|
|
390
|
+
this.loadData({
|
|
391
|
+
current: page,
|
|
392
|
+
pageSize: pageSize
|
|
393
|
+
})
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
onShowSizeChange={(page, pageSize) => {
|
|
397
|
+
this.pageSize = pageSize
|
|
398
|
+
this.pageNum = page
|
|
399
|
+
this.loadData({
|
|
400
|
+
current: page,
|
|
401
|
+
pageSize: pageSize
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
show-total={(total, range) => range[0] === range[1] ? `${range[0]} | 共 ${total} 项` : `${range[0]}-${range[1]} | 共 ${total} 项`}
|
|
406
|
+
default-current={this.localPagination.current}
|
|
407
|
+
showSizeChanger={this.localPagination.showSizeChanger}/>
|
|
408
|
+
</a-col>
|
|
409
|
+
</a-row>
|
|
410
|
+
)
|
|
411
|
+
const table = (
|
|
412
|
+
<a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}
|
|
413
|
+
onExpand={(expanded, record) => this.onExpand(expanded, record)}>
|
|
414
|
+
{Object.keys(this.$slots).map(name => (<template slot={name}>{this.$slots[name]}</template>))}
|
|
415
|
+
</a-table>
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
return (
|
|
419
|
+
<div class="table-wrapper">
|
|
420
|
+
{showAlert && this.showSelected && this.selectRowMode === 'default' ? this.renderAlert() : null}
|
|
421
|
+
{table}
|
|
422
|
+
{!this.hidePagination ? pagination : null}
|
|
423
|
+
</div>
|
|
424
|
+
)
|
|
425
|
+
}
|
|
426
|
+
}
|