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