sone-ui-component-3.2.4 2.1.62 → 2.1.64

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.
@@ -0,0 +1,729 @@
1
+ <!--
2
+ * @Description: 直接copy的table 优化代码 硬是让我删掉了800行。。。
3
+ * @Author:xjl
4
+ * @Date:2021-09-10 11:03
5
+ -->
6
+ <template>
7
+ <div class="sone_table_box" >
8
+ <div class="table-menu-left" v-if="showMenuLeft">
9
+ <slot name="menuLeft"></slot>
10
+ </div>
11
+ <div class="table-menu-right" v-if="showMenuRight">
12
+ <slot name="menuRight"></slot>
13
+ <el-dropdown v-if="showColumnHandleBtn">
14
+ <IconButton
15
+ :iconfont="false"
16
+ :tooltipDisabled="tooltipDisabled"
17
+ class="sort-btn"
18
+ content="列展示"
19
+ icon="el-icon-s-operation" />
20
+ <ColumnTransfer
21
+ ref="column-transfer"
22
+ :columns.sync="internalColumns"
23
+ @save="save"
24
+ @resetColumnTransfer="$emit('resetColumnTransfer')" />
25
+ </el-dropdown>
26
+ <slot name="transferRight"></slot>
27
+ </div>
28
+ <template v-if="useVirtualScroll">
29
+ <VirtualScroll
30
+ v-if="isTable"
31
+ ref="virtualScroll"
32
+ :data="tableData"
33
+ :item-size="itemSize"
34
+ :key-prop="option.rowKey"
35
+ :buffer="buffer"
36
+ :dynamic="dynamic"
37
+ @change="currentList => virtualList = currentList">
38
+ <el-table
39
+ v-loading="loading"
40
+ style="width: 100%"
41
+ :ref="tabelRef"
42
+ :class="'sone-table ' + className"
43
+ :cell-class-name="option.cellClassName"
44
+ :cell-style="option.cellStyle"
45
+ :data="virtualList"
46
+ :header-cell-class-name="option.headerCellClassName"
47
+ :header-cell-style="option.headerCellStyle"
48
+ :header-row-class-name="option.headerRowClassName"
49
+ :header-row-style="option.headerRowStyle"
50
+ :height="option.height"
51
+ :highlight-current-row="option.highlightRow"
52
+ :max-height="option.maxHeight"
53
+ :default-expand-all="option.defaultExpandAll"
54
+ :row-class-name="tableRowClassName"
55
+ :row-key="option.rowKey"
56
+ :row-style="option.rowStyle"
57
+ :show-summary="option.showSummary"
58
+ :render-header="option.renderHeader"
59
+ :span-method="spanMethod"
60
+ :show-header="showHeader"
61
+ :stripe="stripe"
62
+ :border="border"
63
+ :sum-text="option.sumText"
64
+ :summary-method="summaryMethod"
65
+ @filter-change="filterChange"
66
+ @row-click="rowClick"
67
+ @header-dragend="onHeaderDragend"
68
+ @select="selectChange"
69
+ @select-all="selectAll"
70
+ @sort-change="sortChange">
71
+ <el-table-column
72
+ v-if="operation"
73
+ fixed
74
+ type="index"
75
+ :width="operation.width"
76
+ :label="operation.label ? operation.label : '操作'"
77
+ :resizable="operation.hasOwnProperty('resizable') ? operation.resizable : true">
78
+ <template slot-scope="scope">
79
+ <template v-if="!hideButtonMode">
80
+ <div class="sone-table-buttonList" v-if="scope.row.buttonShow&&scope.row.buttonShow.filter(d=>d.isShow).length<=3">
81
+ <template v-for="(item,index) in operation.buttonList">
82
+ <el-tooltip :content="item.label" :key="index" effect="light" placement="top" v-show="scope.row.buttonShow.find(i=>i.id===item.id).isShow">
83
+ <el-button
84
+ :icon="item.icon"
85
+ :style="{color:item.color}"
86
+ :disabled="scope.row.buttonShow.find(i=>i.id===item.id).isDisabled || false"
87
+ @click.native.stop="handButton(item.function, scope, item.id)"
88
+ circle
89
+ type="text"
90
+ ></el-button>
91
+ </el-tooltip>
92
+ </template>
93
+ </div>
94
+
95
+ <div class="sone-table-buttonList" v-if="!scope.row.buttonShow&&operation.buttonList.length<=3">
96
+ <template v-for="(item,index) in operation.buttonList">
97
+ <el-tooltip :content="item.label" :key="index" effect="light" placement="top">
98
+ <el-button
99
+ :icon="item.icon"
100
+ :style="{color:item.color}"
101
+ @click.native.stop="handButton(item.function,scope, item.id)"
102
+ circle
103
+ type="text"
104
+ ></el-button>
105
+ </el-tooltip>
106
+ </template>
107
+ </div>
108
+ </template>
109
+ <template v-else>
110
+ <el-dropdown v-if="scope.row.buttonShow" class="dropdown_box_button sone-table-buttonList">
111
+ <span class="el-dropdown-link color-span menu-more" v-show="scope.row.buttonShow.filter(d=>d.isShow).length > 0">
112
+ <el-button type="text">
113
+ <i :style="{color:operation.moreIconColor}" class="el-icon-more more-handel"></i>
114
+ </el-button>
115
+ </span>
116
+ <el-dropdown-menu slot="dropdown">
117
+ <el-dropdown-item class="sone-table-dropdown" command="copy" v-for="(item, i) in scope.row.buttonShow.filter(d=>d.isShow)" :key="i">
118
+ <el-button
119
+ :icon="operation.buttonList.find(d=>d.id===item.id).icon"
120
+ :disabled="item.hasOwnProperty('isDisabled') ? item.isDisabled : false"
121
+ :style="{color:operation.buttonList.find(d=>d.id===item.id).color}"
122
+ type="text"
123
+ :title="operation.buttonList.find(d=>d.id === item.id).label"
124
+ @click.native.stop="handButton(operation.buttonList.find(d=>d.id===item.id).function, scope, item.id)"
125
+ >{{operation.buttonList.find(d=>d.id===item.id).label}}</el-button>
126
+ </el-dropdown-item>
127
+ </el-dropdown-menu>
128
+ </el-dropdown>
129
+ <el-dropdown v-else @command.stop="(command)=>{handleCommand(command,row)}" class="dropdown_box_button sone-table-buttonList">
130
+ <span class="el-dropdown-link color-span menu-more" v-show="operation.buttonList.length > 0">
131
+ <el-button type="text">
132
+ <i :style="{color:operation.moreIconColor}" class="el-icon-more more-handel"></i>
133
+ </el-button>
134
+ </span>
135
+ <el-dropdown-menu slot="dropdown">
136
+ <el-dropdown-item
137
+ class="sone-table-dropdown"
138
+ command="copy"
139
+ v-for="(item, i) in operation.buttonList"
140
+ :key="i">
141
+ <el-button
142
+ :icon="item.icon"
143
+ :style="{color:item.color}"
144
+ :title="item.label"
145
+ type="text"
146
+ @click.native.stop="handButton(item.function, scope, item.id)"
147
+ >{{item.label}}</el-button>
148
+ </el-dropdown-item>
149
+ </el-dropdown-menu>
150
+ </el-dropdown>
151
+ </template>
152
+ </template>
153
+ </el-table-column>
154
+ <VirtualColumn
155
+ v-if="option.index"
156
+ vfixed
157
+ type="index"
158
+ :width="option.indexWidth||50"
159
+ :label="option.indexLabel ? option.indexLabel : '序号'"
160
+ :index="indexMethod"
161
+ ></VirtualColumn>
162
+ <VirtualColumn v-if="option.selection" vfixed :width="45" type="selection"></VirtualColumn>
163
+ <template v-for="(column, index) in internalColumns">
164
+ <!-- 自定义列 -->
165
+ <slot v-if="column.slot && column.istrue" :name="column.slot"></slot>
166
+ <el-table-column
167
+ v-else-if="column.hasOwnProperty('istrue')?column.istrue:true"
168
+ :filter-method="column.filters ? filterHandler : null"
169
+ :filters="column.filters"
170
+ :fixed="column.fixed"
171
+ :key="`col_${column.prop}_${column.label}`"
172
+ :label="column.label"
173
+ :min-width="column.minWidth"
174
+ :prop="column.prop"
175
+ :width="column.width"
176
+ :align="column.hasOwnProperty('align') ? column.align : 'left'"
177
+ :show-overflow-tooltip="column.hasOwnProperty('showOverflowTooltip') ? column.showOverflowTooltip : false"
178
+ filter-placement="bottom-end"
179
+ :sortable="column.sortable"
180
+ :header-align="column.hasOwnProperty('headerAlign') ? column.headerAlign : 'left'"
181
+ :column-key="column.hasOwnProperty('elementId')? column.elementId:column.prop"
182
+ :resizable="column.hasOwnProperty('resizable') ? column.resizable : true">
183
+ <!-- 表头 -->
184
+ <template slot="header" slot-scope="scope">
185
+ <slot
186
+ v-if="column.slotColumnHeader && isShow"
187
+ :header="{column: scope.column, $index:scope.$index }"
188
+ :name="column.slotColumnHeader"
189
+ ></slot>
190
+ <template v-if="!column.slotColumnHeader && isShow">
191
+ <div class="slot_header_class">
192
+ <span class="table-header-isRequire" v-if="column.isRequire">*</span>
193
+ <span>{{ column.label }}</span>
194
+ <span class="hide">
195
+ <i
196
+ class="iconfont icon-help icon_describe"
197
+ :title="column.headerDescribe"
198
+ v-if="column.headerDescribe"
199
+ ></i>
200
+ <span
201
+ :class="{ 'ascending': sortVal === column.prop + 'ascending', 'descending': sortVal === column.prop + 'descending' }"
202
+ class="caret-wrapper"
203
+ v-if="column.headerFilterSort">
204
+ <i
205
+ @click="handleCommand(column.prop, index, { command: 'ascending' })"
206
+ class="sort-caret ascending"
207
+ title="升序"
208
+ ></i>
209
+ <i
210
+ @click="handleCommand(column.prop, index, { command: 'descending' })"
211
+ class="sort-caret descending"
212
+ title="降序"
213
+ ></i>
214
+ </span>
215
+ </span>
216
+ </div>
217
+ </template>
218
+ </template>
219
+ <!--表体-->
220
+ <template slot-scope="scope">
221
+ <slot :index="scope.$index" :name="column.slotCell" :row="scope.row" v-if="column.slotCell"></slot>
222
+ <template v-else>{{ scope.row[column.prop] }}</template>
223
+ </template>
224
+ </el-table-column>
225
+ </template>
226
+ </el-table>
227
+ </VirtualScroll>
228
+ </template>
229
+ <template v-else>
230
+ <el-table
231
+ v-if="isTable"
232
+ v-loading="loading"
233
+ style="width: 100%"
234
+ :ref="tabelRef"
235
+ :class="'sone-table ' + className"
236
+ :cell-class-name="option.cellClassName"
237
+ :cell-style="option.cellStyle"
238
+ :data="tableData"
239
+ :header-cell-class-name="option.headerCellClassName"
240
+ :header-cell-style="option.headerCellStyle"
241
+ :header-row-class-name="option.headerRowClassName"
242
+ :header-row-style="option.headerRowStyle"
243
+ :height="option.height"
244
+ :highlight-current-row="option.highlightRow"
245
+ :max-height="option.maxHeight"
246
+ :default-expand-all="option.defaultExpandAll"
247
+ :row-class-name="tableRowClassName"
248
+ :row-key="option.rowKey"
249
+ :row-style="option.rowStyle"
250
+ :show-summary="option.showSummary"
251
+ :render-header="option.renderHeader"
252
+ :span-method="spanMethod"
253
+ :show-header="showHeader"
254
+ :stripe="stripe"
255
+ :border="border"
256
+ :sum-text="option.sumText"
257
+ :summary-method="summaryMethod"
258
+ @filter-change="filterChange"
259
+ @row-click="rowClick"
260
+ @header-dragend="onHeaderDragend"
261
+ @select="selectChange"
262
+ @select-all="selectAll"
263
+ @sort-change="sortChange">
264
+ <el-table-column
265
+ v-if="operation"
266
+ fixed
267
+ type="index"
268
+ :width="operation.width"
269
+ :label="operation.label ? operation.label : '操作'"
270
+ :resizable="operation.hasOwnProperty('resizable') ? operation.resizable : true">
271
+ <template slot-scope="scope">
272
+ <template v-if="!hideButtonMode">
273
+ <div class="sone-table-buttonList" v-if="scope.row.buttonShow&&scope.row.buttonShow.filter(d=>d.isShow).length<=3">
274
+ <template v-for="(item,index) in operation.buttonList">
275
+ <el-tooltip :content="item.label" :key="index" effect="light" placement="top" v-show="scope.row.buttonShow.find(i=>i.id===item.id).isShow">
276
+ <el-button
277
+ :icon="item.icon"
278
+ :style="{color:item.color}"
279
+ :disabled="scope.row.buttonShow.find(i=>i.id===item.id).isDisabled || false"
280
+ @click.native.stop="handButton(item.function, scope, item.id)"
281
+ circle
282
+ type="text"
283
+ ></el-button>
284
+ </el-tooltip>
285
+ </template>
286
+ </div>
287
+
288
+ <div class="sone-table-buttonList" v-if="!scope.row.buttonShow&&operation.buttonList.length<=3">
289
+ <template v-for="(item,index) in operation.buttonList">
290
+ <el-tooltip :content="item.label" :key="index" effect="light" placement="top">
291
+ <el-button
292
+ :icon="item.icon"
293
+ :style="{color:item.color}"
294
+ @click.native.stop="handButton(item.function,scope, item.id)"
295
+ circle
296
+ type="text"
297
+ ></el-button>
298
+ </el-tooltip>
299
+ </template>
300
+ </div>
301
+ </template>
302
+ <template v-else>
303
+ <el-dropdown v-if="scope.row.buttonShow" class="dropdown_box_button sone-table-buttonList">
304
+ <span class="el-dropdown-link color-span menu-more" v-show="scope.row.buttonShow.filter(d=>d.isShow).length > 0">
305
+ <el-button type="text">
306
+ <i :style="{color:operation.moreIconColor}" class="el-icon-more more-handel"></i>
307
+ </el-button>
308
+ </span>
309
+ <el-dropdown-menu slot="dropdown">
310
+ <el-dropdown-item class="sone-table-dropdown" command="copy" v-for="(item, i) in scope.row.buttonShow.filter(d=>d.isShow)" :key="i">
311
+ <el-button
312
+ :icon="operation.buttonList.find(d=>d.id===item.id).icon"
313
+ :disabled="item.hasOwnProperty('isDisabled') ? item.isDisabled : false"
314
+ :style="{color:operation.buttonList.find(d=>d.id===item.id).color}"
315
+ type="text"
316
+ :title="operation.buttonList.find(d=>d.id === item.id).label"
317
+ @click.native.stop="handButton(operation.buttonList.find(d=>d.id===item.id).function, scope, item.id)"
318
+ >{{operation.buttonList.find(d=>d.id===item.id).label}}</el-button>
319
+ </el-dropdown-item>
320
+ </el-dropdown-menu>
321
+ </el-dropdown>
322
+ <el-dropdown v-else @command.stop="(command)=>{handleCommand(command,row)}" class="dropdown_box_button sone-table-buttonList">
323
+ <span class="el-dropdown-link color-span menu-more" v-show="operation.buttonList.length > 0">
324
+ <el-button type="text">
325
+ <i :style="{color:operation.moreIconColor}" class="el-icon-more more-handel"></i>
326
+ </el-button>
327
+ </span>
328
+ <el-dropdown-menu slot="dropdown">
329
+ <el-dropdown-item
330
+ class="sone-table-dropdown"
331
+ command="copy"
332
+ v-for="(item, i) in operation.buttonList"
333
+ :key="i">
334
+ <el-button
335
+ :icon="item.icon"
336
+ :style="{color:item.color}"
337
+ :title="item.label"
338
+ type="text"
339
+ @click.native.stop="handButton(item.function, scope, item.id)"
340
+ >{{item.label}}</el-button>
341
+ </el-dropdown-item>
342
+ </el-dropdown-menu>
343
+ </el-dropdown>
344
+ </template>
345
+ </template>
346
+ </el-table-column>
347
+ <el-table-column
348
+ v-if="option.index"
349
+ fixed
350
+ type="index"
351
+ :width="option.indexWidth||50"
352
+ :label="option.indexLabel ? option.indexLabel : '序号'"
353
+ :index="indexMethod"
354
+ ></el-table-column>
355
+ <el-table-column
356
+ v-if="option.selection"
357
+ fixed
358
+ type="selection"
359
+ :show-overflow-tooltip="false"
360
+ :width="option.selectionWidth || 45">
361
+ </el-table-column>
362
+ <template v-for="(column, index) in internalColumns">
363
+ <!-- 自定义列 -->
364
+ <slot v-if="column.slot && column.istrue" :name="column.slot"></slot>
365
+ <el-table-column
366
+ v-else-if="column.hasOwnProperty('istrue')?column.istrue:true"
367
+ :filter-method="column.filters ? filterHandler : null"
368
+ :filters="column.filters"
369
+ :fixed="column.fixed"
370
+ :key="`col_${column.prop}_${column.label}`"
371
+ :label="column.label"
372
+ :min-width="column.minWidth"
373
+ :prop="column.prop"
374
+ :width="column.width"
375
+ :align="column.hasOwnProperty('align') ? column.align : 'left'"
376
+ :show-overflow-tooltip="column.hasOwnProperty('showOverflowTooltip') ? column.showOverflowTooltip : false"
377
+ filter-placement="bottom-end"
378
+ :sortable="column.sortable"
379
+ :header-align="column.hasOwnProperty('headerAlign') ? column.headerAlign : 'left'"
380
+ :column-key="column.hasOwnProperty('elementId')? column.elementId:column.prop"
381
+ :resizable="column.hasOwnProperty('resizable') ? column.resizable : true">
382
+ <!-- 表头 -->
383
+ <template slot="header" slot-scope="scope">
384
+ <slot
385
+ v-if="column.slotColumnHeader && isShow"
386
+ :header="{column: scope.column, $index:scope.$index }"
387
+ :name="column.slotColumnHeader"
388
+ ></slot>
389
+ <template v-if="!column.slotColumnHeader && isShow">
390
+ <div class="slot_header_class">
391
+ <span class="table-header-isRequire" v-if="column.isRequire">*</span>
392
+ <span>{{ column.label }}</span>
393
+ <span class="hide">
394
+ <i
395
+ class="iconfont icon-help icon_describe"
396
+ :title="column.headerDescribe"
397
+ v-if="column.headerDescribe"
398
+ ></i>
399
+ <span
400
+ :class="{ 'ascending': sortVal === column.prop + 'ascending', 'descending': sortVal === column.prop + 'descending' }"
401
+ class="caret-wrapper"
402
+ v-if="column.headerFilterSort">
403
+ <i
404
+ @click="handleCommand(column.prop, index, { command: 'ascending' })"
405
+ class="sort-caret ascending"
406
+ title="升序"
407
+ ></i>
408
+ <i
409
+ @click="handleCommand(column.prop, index, { command: 'descending' })"
410
+ class="sort-caret descending"
411
+ title="降序"
412
+ ></i>
413
+ </span>
414
+ </span>
415
+ </div>
416
+ </template>
417
+ </template>
418
+ <!--表体-->
419
+ <template slot-scope="scope">
420
+ <slot :index="scope.$index" :name="column.slotCell" :row="scope.row" v-if="column.slotCell"></slot>
421
+ <template v-else>{{ scope.row[column.prop] }}</template>
422
+ </template>
423
+ </el-table-column>
424
+ </template>
425
+ </el-table>
426
+ </template>
427
+ <div class="pagination-box" v-if="page && page.total > 0">
428
+ <el-pagination
429
+ :current-page="page.current"
430
+ :layout="page.layout ? page.layout : 'total, sizes, prev, pager, next, jumper'"
431
+ :page-size="page.size"
432
+ :page-sizes="page.pageSizes"
433
+ :total="page.total"
434
+ :page-count="page.pageCount"
435
+ :pager-count="page.pagerCount"
436
+ @current-change="currentChange"
437
+ @size-change="sizeChange"
438
+ background
439
+ ></el-pagination>
440
+ </div>
441
+ </div>
442
+ </template>
443
+
444
+ <script>
445
+ import { deepClone } from 'sone-ui-component/src/utils/util'
446
+ import ColumnTransfer from './columnTransferNew.vue'
447
+ import IconButton from "sone-ui-component/packages/IconButton/index.vue";
448
+ import VirtualScroll from './virtual/el-table-virtual-scroll.vue'
449
+ import VirtualColumn from './virtual/el-table-virtual-column.vue'
450
+ export default {
451
+ name: "SoneNormalTable",
452
+ components: { ColumnTransfer, IconButton, VirtualScroll, VirtualColumn },
453
+ props: {
454
+ useVirtualScroll: {
455
+ type: Boolean,
456
+ default: false
457
+ },
458
+ itemSize: {
459
+ type: Number,
460
+ default: 60
461
+ },
462
+ buffer: {
463
+ type: Number,
464
+ default: 100
465
+ },
466
+ dynamic: {
467
+ type: Boolean,
468
+ default: false
469
+ },
470
+ showMenuLeft: {
471
+ type: Boolean,
472
+ default: false
473
+ },
474
+ showMenuRight: {
475
+ type: Boolean,
476
+ default: true
477
+ },
478
+ showColumnHandleBtn: {
479
+ type: Boolean,
480
+ default: true
481
+ },
482
+ hideButtonMode: {
483
+ type: Boolean,
484
+ default: false
485
+ },
486
+ tabelRef: {
487
+ type: String,
488
+ default: 'tableDataRef'
489
+ },
490
+ loading: {
491
+ type: Boolean,
492
+ default: false,
493
+ },
494
+ showHeader: {
495
+ type: Boolean,
496
+ default: true,
497
+ },
498
+ stripe: {
499
+ type: Boolean,
500
+ default: true,
501
+ },
502
+ border: {
503
+ type: Boolean,
504
+ default: true,
505
+ },
506
+ sortable: {
507
+ type: [Boolean, String],
508
+ default: false,
509
+
510
+ },
511
+ option: {
512
+ type: Object,
513
+ default: () => {
514
+ return {
515
+ index: true,
516
+ indexWidth: 70,
517
+ height: 'auto',
518
+ maxHeight: 'auto',
519
+ showSummary: false,
520
+ }
521
+ }
522
+ },
523
+ operation: {
524
+ type: [Object, Boolean],
525
+ default: () => {
526
+ return {
527
+ width: 82,
528
+ label: '操作',
529
+ buttonList: [
530
+ {
531
+ label: '删除',
532
+ icon: 'el-icon-remove-outline',
533
+ function: 'handDetele',
534
+ tooltipContent: '删除',
535
+ color: 'red'
536
+ }, {
537
+ label: '添加',
538
+ icon: 'el-icon-circle-plus-outline',
539
+ function: 'hand',
540
+ tooltipContent: '删除',
541
+ color: 'red'
542
+ }
543
+ ]
544
+ }
545
+ }
546
+ },
547
+ page: {
548
+ type: Object,
549
+ },
550
+ columns: {
551
+ type: Array,
552
+ default: () => []
553
+ },
554
+ tableData: {
555
+ type: Array,
556
+ default: () => []
557
+ },
558
+ // 表格className
559
+ className:{
560
+ type:String,
561
+ default:''
562
+ },
563
+ // 合计小数位数
564
+ summaryToFixed:{
565
+ type:[Number, String],
566
+ default:''
567
+ },
568
+ spanMethod: Function,
569
+ indexMethod: Function,
570
+ // 默认显示按钮图标加提示,
571
+ tooltipDisabled: {
572
+ type: Boolean,
573
+ default: false,
574
+ },
575
+ },
576
+ data() {
577
+ return {
578
+ internalColumns: deepClone(this.columns).filter(d => d && !d.isHidden),
579
+ sortVal: '', // 排序
580
+ isShow: true,
581
+ isTable: true,
582
+ virtualList: [],
583
+ }
584
+ },
585
+ watch: {
586
+ columns: {
587
+ deep: true,
588
+ handler() {
589
+ this.internalColumns = deepClone(this.columns).filter(d => d && !d.isHidden);
590
+ }
591
+ },
592
+ },
593
+ methods: {
594
+ // 下拉button
595
+ handleCommand(columnName, columnIndex, data) {
596
+ let tableData = deepClone(this.tableData)
597
+ if (data.command === "ascending" || data.command === "descending") {
598
+ if (this.sortVal && this.sortVal.indexOf(data.command) > -1) {
599
+ this.sortVal = ''
600
+ } else {
601
+ this.sortVal = columnName + data.command
602
+ }
603
+ if (this.option.defineSort) {
604
+ this.$emit('handleColumnFilter', columnName, columnIndex, data, !!!this.sortVal)
605
+ } else {
606
+ let isIncludeNaN = tableData.some(item => isNaN(Number(item[columnName])))
607
+ if ( isIncludeNaN ) { // 数据非纯数字使用原生ele方法
608
+ if(this.sortVal){
609
+ this.$refs[this.tabelRef].sort(columnName, data.command);
610
+ } else {
611
+ this.$refs[this.tabelRef].clearSort();
612
+ }
613
+ } else { // 纯数字使用sort排序
614
+ tableData.sort((a, b) => {
615
+ return data.command === 'ascending' ? a[columnName] - b[columnName] : b[columnName] - a[columnName]
616
+ })
617
+ this.$emit('update:tableData', tableData)
618
+ }
619
+ }
620
+ } else {
621
+ this.$emit('handleColumnFilter', columnName, columnIndex, data)
622
+ }
623
+ },
624
+ selectChange(selection, row){
625
+ this.$emit('handleChecked', selection, row);
626
+ },
627
+ selectAll(selection){
628
+ this.$emit('selectAll', selection);
629
+ },
630
+ toggleSelection(rows, selected = true) {
631
+ if (rows) {
632
+ rows.forEach(row => {
633
+ this.$refs[this.tabelRef].toggleRowSelection(row, selected);
634
+ });
635
+ } else {
636
+ this.$refs[this.tabelRef].clearSelection();
637
+ }
638
+ },
639
+ // 翻页
640
+ sizeChange(val) {
641
+ this.$emit('sizeChange', val)
642
+ },
643
+ currentChange(val) {
644
+ this.$emit('currentChange', val)
645
+ },
646
+ // 合计
647
+ summaryMethod({ columns, data }) {
648
+ if (this.option.summaryMethod) {
649
+ return this.option.summaryMethod({ columns, data })
650
+ }
651
+ let _columns = deepClone(this.internalColumns);
652
+ const sums = [];
653
+ // 固定列会导致窜行 待改
654
+ if (!!this.operation ) sums.push(this.option.sumText || '合计')
655
+ if (this.option.selection) {
656
+ !!this.operation ? sums.push('') : sums.push('合计')
657
+ }
658
+ _columns.forEach((column, index) => {
659
+ if ( column.istrue ) {
660
+ let num = 0
661
+ data.forEach(item => num += Number(item[column.prop]))
662
+ if ( isNaN(num) || !column.summary ) {
663
+ sums.push('')
664
+ } else if ( String(num).indexOf('.') != -1 && this.summaryToFixed ) {
665
+ sums.push(num.toFixed(this.summaryToFixed))
666
+ } else {
667
+ sums.push(num)
668
+ }
669
+ }
670
+ });
671
+ return sums;
672
+ },
673
+ // 行点击
674
+ rowClick(row, column, event) {
675
+ this.$emit('rowClick', row, column, event)
676
+ },
677
+ filterChange(filters) {
678
+ let data = deepClone(this.tableData)
679
+ // 判断是哪一列筛选
680
+ if (filters.name) {
681
+ data.name = filters.name[0]
682
+ }
683
+ this.$emit('update:tableData', data)
684
+ },
685
+ //过滤
686
+ filterHandler(value, row, column) {
687
+ const property = column['property'];
688
+ return row[property] === value;
689
+ },
690
+ // class
691
+ tableRowClassName({ row, rowIndex }) {
692
+ if (this.option.rowClassName) {
693
+ return this.option.rowClassName({ row, rowIndex })
694
+ }else return ''
695
+ },
696
+ handButton(functionName, scope, id) {
697
+ this.$emit(functionName, scope, id)
698
+ },
699
+ doLayout() {
700
+ this.$refs[this.tabelRef] && this.$refs[this.tabelRef].doLayout();
701
+ },
702
+ /* 当拖动表头改变了列的宽度的时候会触发该事件 */
703
+ onHeaderDragend(newWidth, oldWidth, column, event){
704
+ let arr = [
705
+ ...this.$refs['column-transfer'].leftColumns,
706
+ ...this.$refs['column-transfer'].noColumns,
707
+ ...this.$refs['column-transfer'].rightColumns
708
+ ]
709
+ this.$emit('headerDragend', newWidth, oldWidth, column, arr, event);
710
+ },
711
+ save(arr){
712
+ this.internalColumns = deepClone(arr);
713
+ this.isTable = false
714
+ this.$nextTick(() => {
715
+ this.isTable = true
716
+ })
717
+ this.$emit('save', arr);
718
+ },
719
+ /* 用于单选表格,设定某一行为选中行,如果调用时不加参数,则会取消目前高亮行的选中状态。 */
720
+ setCurrentRow(row){
721
+ this.$refs[this.tabelRef] && this.$refs[this.tabelRef].setCurrentRow(row);
722
+ this.$emit('setCurrentRow', row);
723
+ },
724
+ sortChange(val){
725
+ if(val.column.sortable === 'custom') this.$emit('sortChange', val);
726
+ },
727
+ },
728
+ }
729
+ </script>