vue2-client 1.11.4 → 1.11.6

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.
Files changed (26) hide show
  1. package/package.json +1 -1
  2. package/src/base-client/components/common/CitySelect/CitySelect.vue +366 -342
  3. package/src/base-client/components/common/Upload/Upload.vue +322 -322
  4. package/src/base-client/components/common/XDescriptions/XDescriptionsGroup.vue +61 -51
  5. package/src/base-client/components/common/XDescriptions/demo.vue +10 -9
  6. package/src/base-client/components/common/XFormGroup/demo.vue +3 -10
  7. package/src/base-client/components/common/XFormTable/demo.vue +60 -60
  8. package/src/components/STable/index.js +426 -426
  9. package/src/expression/ExpressionRunner.ts +28 -0
  10. package/src/expression/TestExpression.ts +509 -0
  11. package/src/expression/core/Delegate.ts +114 -0
  12. package/src/expression/core/Expression.ts +1295 -0
  13. package/src/expression/core/Program.ts +950 -0
  14. package/src/expression/core/Token.ts +29 -0
  15. package/src/expression/enums/ExpressionType.ts +81 -0
  16. package/src/expression/enums/TokenType.ts +13 -0
  17. package/src/expression/exception/BreakWayException.ts +2 -0
  18. package/src/expression/exception/ContinueWayException.ts +2 -0
  19. package/src/expression/exception/ExpressionException.ts +28 -0
  20. package/src/expression/exception/ReturnWayException.ts +14 -0
  21. package/src/expression/exception/ServiceException.ts +22 -0
  22. package/src/expression/instances/JSONArray.ts +48 -0
  23. package/src/expression/instances/JSONObject.ts +109 -0
  24. package/src/expression/instances/LogicConsole.ts +32 -0
  25. package/src/router/async/router.map.js +3 -2
  26. package/src/utils/indexedDB.js +234 -234
@@ -1,426 +1,426 @@
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
- }
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
+ }