sone-ui-component-3.2.4 2.1.33 → 2.1.34
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/Notice.md +106 -0
- package/lib/sone-ui.common.js +100 -78
- package/lib/sone-ui.common.js.map +1 -1
- package/lib/sone-ui.umd.js +100 -78
- package/lib/sone-ui.umd.js.map +1 -1
- package/lib/sone-ui.umd.min.js +2 -2
- package/lib/sone-ui.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/packages/table/index.js +2 -1
- package/packages/table/src/columnTransferNew.vue +326 -0
- package/packages/table/src/mainNew.vue +1369 -0
- package/src/index.js +1 -1
|
@@ -0,0 +1,1369 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Description:
|
|
3
|
+
* @Author:xjl
|
|
4
|
+
* @Date:2021-09-10 11:03
|
|
5
|
+
-->
|
|
6
|
+
<template>
|
|
7
|
+
<div class="sone_table_box" >
|
|
8
|
+
<div
|
|
9
|
+
class="table-menu-left"
|
|
10
|
+
v-if="showMenuLeft"
|
|
11
|
+
>
|
|
12
|
+
<slot name="menuLeft"></slot>
|
|
13
|
+
</div>
|
|
14
|
+
<div
|
|
15
|
+
class="table-menu-right"
|
|
16
|
+
v-if="showMenuRight"
|
|
17
|
+
>
|
|
18
|
+
<slot name="menuRight"></slot>
|
|
19
|
+
<el-dropdown
|
|
20
|
+
:hide-on-click="false"
|
|
21
|
+
v-if="showColumnHandleBtn"
|
|
22
|
+
@visible-change="onColumnVisibleMenu"
|
|
23
|
+
>
|
|
24
|
+
<icon-button
|
|
25
|
+
:iconfont="false"
|
|
26
|
+
:tooltipDisabled="tooltipDisabled"
|
|
27
|
+
class="sort-btn"
|
|
28
|
+
content="列展示"
|
|
29
|
+
icon="el-icon-s-operation"
|
|
30
|
+
>
|
|
31
|
+
</icon-button>
|
|
32
|
+
<column-transfer
|
|
33
|
+
ref="column-transfer"
|
|
34
|
+
:columns.sync="internalColumns"
|
|
35
|
+
@save="save"
|
|
36
|
+
@dropdownList="dropdownList"
|
|
37
|
+
@handleCheckedColumnChange="handleCheckedColumnChange"
|
|
38
|
+
@selectFixed="selectFixed"
|
|
39
|
+
@resetColumnTransfer="$emit('resetColumnTransfer')"
|
|
40
|
+
></column-transfer>
|
|
41
|
+
</el-dropdown>
|
|
42
|
+
<slot name="transferRight"></slot>
|
|
43
|
+
</div>
|
|
44
|
+
<el-table
|
|
45
|
+
:cell-class-name="option.cellClassName"
|
|
46
|
+
:cell-style="option.cellStyle"
|
|
47
|
+
:data="tableData"
|
|
48
|
+
:header-cell-class-name="option.headerCellClassName"
|
|
49
|
+
:header-cell-style="option.headerCellStyle"
|
|
50
|
+
:header-row-class-name="option.headerRowClassName"
|
|
51
|
+
:header-row-style="option.headerRowStyle"
|
|
52
|
+
:height="option.height"
|
|
53
|
+
:highlight-current-row="option.highlightRow"
|
|
54
|
+
:max-height="option.maxHeight"
|
|
55
|
+
:default-expand-all="option.defaultExpandAll"
|
|
56
|
+
:expand-row-keys="option.expandRowKeys"
|
|
57
|
+
:ref="tabelRef"
|
|
58
|
+
:row-class-name="tableRowClassName"
|
|
59
|
+
:row-key="option.rowKey"
|
|
60
|
+
:row-style="option.rowStyle"
|
|
61
|
+
:show-summary="option.showSummary"
|
|
62
|
+
:render-header="option.renderHeader"
|
|
63
|
+
:span-method="spanMethod"
|
|
64
|
+
:show-header="showHeader"
|
|
65
|
+
:stripe="stripe"
|
|
66
|
+
:border="border"
|
|
67
|
+
:sum-text="option.sumText"
|
|
68
|
+
:summary-method="summaryMethod"
|
|
69
|
+
:lazy="lazy"
|
|
70
|
+
:load="load"
|
|
71
|
+
@cell-mouse-enter="cellMouseEnter"
|
|
72
|
+
@cell-mouse-leave="cellMouseLeave"
|
|
73
|
+
@filter-change="filterChange"
|
|
74
|
+
@header-click="headerClick"
|
|
75
|
+
@header-contextmenu="headerContextmenu"
|
|
76
|
+
@row-click="rowClick"
|
|
77
|
+
@row-contextmenu="rowContextmenu"
|
|
78
|
+
@row-dblclick="rowDblclick"
|
|
79
|
+
style="width: 100%"
|
|
80
|
+
:class="'sone-table ' + className"
|
|
81
|
+
v-if="isTable"
|
|
82
|
+
v-loading="loading"
|
|
83
|
+
@header-dragend="onHeaderDragend"
|
|
84
|
+
@expand-change="expandChange"
|
|
85
|
+
>
|
|
86
|
+
<el-table-column
|
|
87
|
+
:width="operation.width"
|
|
88
|
+
fixed
|
|
89
|
+
:label="operation.label ? operation.label : '操作'"
|
|
90
|
+
type="index"
|
|
91
|
+
v-if="operation"
|
|
92
|
+
:resizable="operation.hasOwnProperty('resizable') ? operation.resizable : true"
|
|
93
|
+
>
|
|
94
|
+
<template slot-scope="scope">
|
|
95
|
+
<template v-if="!hideButtonMode">
|
|
96
|
+
<div
|
|
97
|
+
class="sone-table-buttonList"
|
|
98
|
+
v-if="scope.row.buttonShow&&scope.row.buttonShow.filter(d=>d.isShow).length<=3"
|
|
99
|
+
>
|
|
100
|
+
<template v-for="(item,index) in operation.buttonList">
|
|
101
|
+
<el-tooltip
|
|
102
|
+
:content="item.label"
|
|
103
|
+
:key="index"
|
|
104
|
+
effect="light"
|
|
105
|
+
placement="top"
|
|
106
|
+
v-show="scope.row.buttonShow.find(i=>i.id===item.id).isShow"
|
|
107
|
+
>
|
|
108
|
+
<el-button
|
|
109
|
+
:icon="item.icon"
|
|
110
|
+
:style="{color:item.color}"
|
|
111
|
+
:disabled="scope.row.buttonShow.find(i=>i.id===item.id).isDisabled || false"
|
|
112
|
+
@click.native.stop="handButton(item.function, scope, item.id)"
|
|
113
|
+
circle
|
|
114
|
+
type="text"
|
|
115
|
+
></el-button>
|
|
116
|
+
</el-tooltip>
|
|
117
|
+
</template>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<div
|
|
121
|
+
class="sone-table-buttonList"
|
|
122
|
+
v-if="scope.row.buttonShow&&scope.row.buttonShow.filter(d=>d.isShow).length>3"
|
|
123
|
+
>
|
|
124
|
+
<template v-for="(item,index) in scope.row.buttonShow.filter(d=>d.isShow).slice(0,2)">
|
|
125
|
+
<el-tooltip
|
|
126
|
+
:content="operation.buttonList.find(d=>d.id===item.id).label"
|
|
127
|
+
:key="index"
|
|
128
|
+
effect="light"
|
|
129
|
+
placement="top"
|
|
130
|
+
>
|
|
131
|
+
<el-button
|
|
132
|
+
:icon="operation.buttonList.find(d=>d.id===item.id).icon"
|
|
133
|
+
:style="{color:operation.buttonList.find(d=>d.id===item.id).color}"
|
|
134
|
+
:disabled="item.hasOwnProperty('isDisabled') ? item.isDisabled : false"
|
|
135
|
+
@click.native.stop="handButton(operation.buttonList.find(d=>d.id===item.id).function, scope, item.id)"
|
|
136
|
+
circle
|
|
137
|
+
type="text"
|
|
138
|
+
></el-button>
|
|
139
|
+
</el-tooltip>
|
|
140
|
+
</template>
|
|
141
|
+
|
|
142
|
+
<el-dropdown class="dropdown_box_button">
|
|
143
|
+
<span class="el-dropdown-link color-span menu-more">
|
|
144
|
+
<el-button type="text">
|
|
145
|
+
<i
|
|
146
|
+
:style="{color:operation.moreIconColor}"
|
|
147
|
+
class="el-icon-more more-handel"
|
|
148
|
+
></i>
|
|
149
|
+
</el-button>
|
|
150
|
+
</span>
|
|
151
|
+
<el-dropdown-menu slot="dropdown">
|
|
152
|
+
<el-dropdown-item
|
|
153
|
+
class="sone-table-dropdown"
|
|
154
|
+
command="copy"
|
|
155
|
+
v-for="(item, i) in scope.row.buttonShow.filter(d=>d.isShow).slice(2,scope.row.buttonShow.filter(d=>d.isShow).length)"
|
|
156
|
+
:key="i"
|
|
157
|
+
>
|
|
158
|
+
<el-button
|
|
159
|
+
:icon="operation.buttonList.find(d=>d.id===item.id).icon"
|
|
160
|
+
:disabled="item.hasOwnProperty('isDisabled') ? item.isDisabled : false"
|
|
161
|
+
:style="{color:operation.buttonList.find(d=>d.id===item.id).color}"
|
|
162
|
+
:title="operation.buttonList.find(d=>d.id===item.id).label"
|
|
163
|
+
type="text"
|
|
164
|
+
@click.native.stop="handButton(operation.buttonList.find(d=>d.id===item.id).function, scope, item.id)"
|
|
165
|
+
>
|
|
166
|
+
{{operation.buttonList.find(d=>d.id===item.id).label}}
|
|
167
|
+
</el-button>
|
|
168
|
+
</el-dropdown-item>
|
|
169
|
+
</el-dropdown-menu>
|
|
170
|
+
</el-dropdown>
|
|
171
|
+
</div>
|
|
172
|
+
|
|
173
|
+
<div
|
|
174
|
+
class="sone-table-buttonList"
|
|
175
|
+
v-if="!scope.row.buttonShow&&operation.buttonList.length<=3"
|
|
176
|
+
>
|
|
177
|
+
<template v-for="(item,index) in operation.buttonList">
|
|
178
|
+
<el-tooltip
|
|
179
|
+
:content="item.label"
|
|
180
|
+
:key="index"
|
|
181
|
+
effect="light"
|
|
182
|
+
placement="top"
|
|
183
|
+
>
|
|
184
|
+
<el-button
|
|
185
|
+
:icon="item.icon"
|
|
186
|
+
:style="{color:item.color}"
|
|
187
|
+
@click.native.stop="handButton(item.function,scope, item.id)"
|
|
188
|
+
circle
|
|
189
|
+
type="text"
|
|
190
|
+
></el-button>
|
|
191
|
+
</el-tooltip>
|
|
192
|
+
</template>
|
|
193
|
+
</div>
|
|
194
|
+
|
|
195
|
+
<div
|
|
196
|
+
class="sone-table-buttonList"
|
|
197
|
+
v-if="!scope.row.buttonShow&&operation.buttonList.length>3"
|
|
198
|
+
>
|
|
199
|
+
<template v-for="(item,index) in operation.buttonList.slice(0,2)">
|
|
200
|
+
<el-tooltip
|
|
201
|
+
:content="item.label"
|
|
202
|
+
:key="index"
|
|
203
|
+
effect="light"
|
|
204
|
+
placement="top"
|
|
205
|
+
>
|
|
206
|
+
<el-button
|
|
207
|
+
:icon="item.icon"
|
|
208
|
+
:style="{color:item.color}"
|
|
209
|
+
@click.native.stop="handButton(item.function, scope, item.id)"
|
|
210
|
+
circle
|
|
211
|
+
type="text"
|
|
212
|
+
></el-button>
|
|
213
|
+
</el-tooltip>
|
|
214
|
+
</template>
|
|
215
|
+
<el-dropdown
|
|
216
|
+
@command.stop="(command)=>{handleCommand(command,row)}"
|
|
217
|
+
class="dropdown_box_button"
|
|
218
|
+
>
|
|
219
|
+
<span class="el-dropdown-link color-span menu-more">
|
|
220
|
+
<el-button type="text">
|
|
221
|
+
<i
|
|
222
|
+
:style="{color:operation.moreIconColor}"
|
|
223
|
+
class="el-icon-more more-handel"
|
|
224
|
+
></i>
|
|
225
|
+
</el-button>
|
|
226
|
+
</span>
|
|
227
|
+
<el-dropdown-menu slot="dropdown">
|
|
228
|
+
<el-dropdown-item
|
|
229
|
+
class="sone-table-dropdown"
|
|
230
|
+
command="copy"
|
|
231
|
+
v-for="(item, i) in operation.buttonList.slice(2,operation.buttonList.length)"
|
|
232
|
+
:key="i"
|
|
233
|
+
>
|
|
234
|
+
<el-button
|
|
235
|
+
:icon="item.icon"
|
|
236
|
+
:style="{color:item.color}"
|
|
237
|
+
:title="operation.buttonList.find(d=>d.id===item.id).label"
|
|
238
|
+
type="text"
|
|
239
|
+
@click.native.stop="handButton(operation.buttonList.find(d=>d.id===item.id).function, scope, item.id)"
|
|
240
|
+
>
|
|
241
|
+
{{item.label}}
|
|
242
|
+
</el-button>
|
|
243
|
+
</el-dropdown-item>
|
|
244
|
+
</el-dropdown-menu>
|
|
245
|
+
</el-dropdown>
|
|
246
|
+
</div>
|
|
247
|
+
</template>
|
|
248
|
+
|
|
249
|
+
<template v-else>
|
|
250
|
+
<el-dropdown
|
|
251
|
+
v-if="scope.row.buttonShow"
|
|
252
|
+
class="dropdown_box_button sone-table-buttonList"
|
|
253
|
+
>
|
|
254
|
+
<span
|
|
255
|
+
class="el-dropdown-link color-span menu-more"
|
|
256
|
+
v-show="scope.row.buttonShow.filter(d=>d.isShow).length > 0"
|
|
257
|
+
>
|
|
258
|
+
<el-button type="text">
|
|
259
|
+
<i
|
|
260
|
+
:style="{color:operation.moreIconColor}"
|
|
261
|
+
class="el-icon-more more-handel"
|
|
262
|
+
></i>
|
|
263
|
+
</el-button>
|
|
264
|
+
</span>
|
|
265
|
+
<el-dropdown-menu slot="dropdown">
|
|
266
|
+
<el-dropdown-item
|
|
267
|
+
class="sone-table-dropdown"
|
|
268
|
+
command="copy"
|
|
269
|
+
v-for="(item, i) in scope.row.buttonShow.filter(d=>d.isShow)"
|
|
270
|
+
:key="i"
|
|
271
|
+
>
|
|
272
|
+
<el-button
|
|
273
|
+
:icon="operation.buttonList.find(d=>d.id===item.id).icon"
|
|
274
|
+
:disabled="item.hasOwnProperty('isDisabled') ? item.isDisabled : false"
|
|
275
|
+
:style="{color:operation.buttonList.find(d=>d.id===item.id).color}"
|
|
276
|
+
type="text"
|
|
277
|
+
:title="operation.buttonList.find(d=>d.id === item.id).label"
|
|
278
|
+
@click.native.stop="handButton(operation.buttonList.find(d=>d.id===item.id).function, scope, item.id)"
|
|
279
|
+
>
|
|
280
|
+
{{operation.buttonList.find(d=>d.id===item.id).label}}
|
|
281
|
+
</el-button>
|
|
282
|
+
</el-dropdown-item>
|
|
283
|
+
</el-dropdown-menu>
|
|
284
|
+
</el-dropdown>
|
|
285
|
+
<el-dropdown
|
|
286
|
+
v-else
|
|
287
|
+
@command.stop="(command)=>{handleCommand(command,row)}"
|
|
288
|
+
class="dropdown_box_button sone-table-buttonList"
|
|
289
|
+
>
|
|
290
|
+
<span
|
|
291
|
+
class="el-dropdown-link color-span menu-more"
|
|
292
|
+
v-show="operation.buttonList.length > 0"
|
|
293
|
+
>
|
|
294
|
+
<el-button type="text">
|
|
295
|
+
<i
|
|
296
|
+
:style="{color:operation.moreIconColor}"
|
|
297
|
+
class="el-icon-more more-handel"
|
|
298
|
+
></i>
|
|
299
|
+
</el-button>
|
|
300
|
+
</span>
|
|
301
|
+
<el-dropdown-menu slot="dropdown">
|
|
302
|
+
<el-dropdown-item
|
|
303
|
+
class="sone-table-dropdown"
|
|
304
|
+
command="copy"
|
|
305
|
+
v-for="(item, i) in operation.buttonList"
|
|
306
|
+
:key="i"
|
|
307
|
+
>
|
|
308
|
+
<el-button
|
|
309
|
+
:icon="item.icon"
|
|
310
|
+
:style="{color:item.color}"
|
|
311
|
+
:title="item.label"
|
|
312
|
+
type="text"
|
|
313
|
+
@click.native.stop="handButton(item.function, scope, item.id)"
|
|
314
|
+
>
|
|
315
|
+
{{item.label}}
|
|
316
|
+
</el-button>
|
|
317
|
+
</el-dropdown-item>
|
|
318
|
+
</el-dropdown-menu>
|
|
319
|
+
</el-dropdown>
|
|
320
|
+
</template>
|
|
321
|
+
</template>
|
|
322
|
+
</el-table-column>
|
|
323
|
+
<!--只显示序号-->
|
|
324
|
+
<el-table-column
|
|
325
|
+
:width="option.indexWidth||70"
|
|
326
|
+
fixed
|
|
327
|
+
:label="option.indexLabel ? option.indexLabel : '序号'"
|
|
328
|
+
type="index"
|
|
329
|
+
:index="indexMethod"
|
|
330
|
+
:resizable="option.hasOwnProperty('indexResizable') ? option.indexResizable : true"
|
|
331
|
+
v-if="option.index"
|
|
332
|
+
></el-table-column>
|
|
333
|
+
<!-- 序号+单选 -->
|
|
334
|
+
<el-table-column
|
|
335
|
+
:width="option.indexRadioWidth||70"
|
|
336
|
+
fixed
|
|
337
|
+
:label="option.indexLabel ? option.indexLabel : '序号'"
|
|
338
|
+
type="index"
|
|
339
|
+
v-else-if="option.indexRadio"
|
|
340
|
+
:resizable="option.hasOwnProperty('indexResizable') ? option.indexResizable : true"
|
|
341
|
+
>
|
|
342
|
+
<template slot-scope="scope">
|
|
343
|
+
<div class="index-check-box">
|
|
344
|
+
<el-radio
|
|
345
|
+
:class="{ 'in-block': radioRow && radioRow === scope.row[option.rowKey] }"
|
|
346
|
+
:label="scope.row[option.rowKey]"
|
|
347
|
+
@change="handleRadioChange(scope.row, scope.$index)"
|
|
348
|
+
v-model="scope.row[option.rowKey]"
|
|
349
|
+
class="table-checked"
|
|
350
|
+
></el-radio>
|
|
351
|
+
<!--<!– 有分页时,序号显示 –>-->
|
|
352
|
+
<span
|
|
353
|
+
class="table-index"
|
|
354
|
+
v-if="page"
|
|
355
|
+
v-show="!radioRow || radioRow !== scope.row[option.rowKey]"
|
|
356
|
+
>{{ indexMethod ? indexMethod(scope.$index) : (page.current - 1) * page.size + scope.$index + 1 }}</span>
|
|
357
|
+
<!-- 无分页时,序号显示 -->
|
|
358
|
+
<span
|
|
359
|
+
class="table-index"
|
|
360
|
+
v-else
|
|
361
|
+
v-show="!radioRow || radioRow !== scope.row[option.rowKey]"
|
|
362
|
+
>{{ (indexMethod ? indexMethod(scope.$index) : scope.$index + 1) }}</span>
|
|
363
|
+
</div>
|
|
364
|
+
</template>
|
|
365
|
+
</el-table-column>
|
|
366
|
+
<!-- 序号+复选 -->
|
|
367
|
+
<el-table-column
|
|
368
|
+
:width="option.indexCheckWidth||70"
|
|
369
|
+
fixed
|
|
370
|
+
:label="option.indexLabel ? option.indexLabel : '序号'"
|
|
371
|
+
type="index"
|
|
372
|
+
v-else-if="option.indexCheck"
|
|
373
|
+
:resizable="option.hasOwnProperty('indexResizable') ? option.indexResizable : true"
|
|
374
|
+
>
|
|
375
|
+
<!--全选 -->
|
|
376
|
+
<!--重新slot头部 如果没有选择的时候是出现序号,全选的时候所有全选框出现-->
|
|
377
|
+
<template
|
|
378
|
+
slot="header"
|
|
379
|
+
slot-scope="{}"
|
|
380
|
+
>
|
|
381
|
+
<div
|
|
382
|
+
@click.stop=""
|
|
383
|
+
class="index-check-box"
|
|
384
|
+
>
|
|
385
|
+
<span
|
|
386
|
+
class="table-index"
|
|
387
|
+
v-show="!checkList || checkList.length < 1"
|
|
388
|
+
>{{ option.indexLabel ? option.indexLabel : '序号' }}</span>
|
|
389
|
+
<!--自定义全选表头-->
|
|
390
|
+
<label
|
|
391
|
+
:class="{ 'is-checked': checkAll, 'in-block': checkList && checkList.length > 0 }"
|
|
392
|
+
class="el-checkbox table-checked"
|
|
393
|
+
>
|
|
394
|
+
<!--is-indeterminate半选 is-checked全选-->
|
|
395
|
+
<span
|
|
396
|
+
:class="{ 'is-checked': checkAll, 'is-indeterminate': checkIndeterminate }"
|
|
397
|
+
class="el-checkbox__input"
|
|
398
|
+
>
|
|
399
|
+
<!--全选和半选点击-->
|
|
400
|
+
<span
|
|
401
|
+
@click.stop="handleCheckAllChange(!checkAll)"
|
|
402
|
+
class="el-checkbox__inner"
|
|
403
|
+
></span>
|
|
404
|
+
</span>
|
|
405
|
+
</label>
|
|
406
|
+
</div>
|
|
407
|
+
</template>
|
|
408
|
+
|
|
409
|
+
<template slot-scope="scope">
|
|
410
|
+
<div
|
|
411
|
+
@click.stop=""
|
|
412
|
+
class="index-check-box"
|
|
413
|
+
>
|
|
414
|
+
<label
|
|
415
|
+
:class="{ 'is-checked': scope.row.checked, 'in-block': scope.row.checked }"
|
|
416
|
+
class="el-checkbox table-checked"
|
|
417
|
+
>
|
|
418
|
+
<!--is-indeterminate半选 is-checked全选-->
|
|
419
|
+
<span
|
|
420
|
+
:class="{ 'is-checked': scope.row.checked, 'is-indeterminate': scope.row.indeterminate }"
|
|
421
|
+
class="el-checkbox__input"
|
|
422
|
+
>
|
|
423
|
+
<!--全选和半选点击-->
|
|
424
|
+
<span
|
|
425
|
+
@click.stop="handleCheckedChange(scope.row.checked, scope.row, scope.$index)"
|
|
426
|
+
class="el-checkbox__inner"
|
|
427
|
+
></span>
|
|
428
|
+
</span>
|
|
429
|
+
</label>
|
|
430
|
+
|
|
431
|
+
<!-- <el-checkbox
|
|
432
|
+
:class="{ 'in-block': checkList && checkList.indexOf(scope.row[option.rowKey]) > -1 }"
|
|
433
|
+
:label="scope.row[option.rowKey]"
|
|
434
|
+
@change="handleCheckedChange(scope.row.checked, scope.row, scope.$index)"
|
|
435
|
+
class="table-checked"
|
|
436
|
+
:indeterminate="scope.row.indeterminate"
|
|
437
|
+
></el-checkbox> -->
|
|
438
|
+
<!-- 有分页时,序号显示 -->
|
|
439
|
+
<span
|
|
440
|
+
class="table-index"
|
|
441
|
+
v-if="page"
|
|
442
|
+
v-show="!scope.row.checked"
|
|
443
|
+
>{{ indexMethod ? indexMethod(scope.$index) : (page.current - 1) * page.size + scope.$index + 1 }}</span>
|
|
444
|
+
<!-- 无分页时,序号显示 -->
|
|
445
|
+
<span
|
|
446
|
+
class="table-index"
|
|
447
|
+
v-else
|
|
448
|
+
v-show="!scope.row.checked"
|
|
449
|
+
>{{ (indexMethod ? indexMethod(scope.$index) : scope.$index + 1) }}</span>
|
|
450
|
+
<!-- {{scope.row.indeterminate ? scope.row.indeterminate : false}} -->
|
|
451
|
+
</div>
|
|
452
|
+
</template>
|
|
453
|
+
</el-table-column>
|
|
454
|
+
|
|
455
|
+
<template v-for="(column, index) in internalColumns">
|
|
456
|
+
<!-- 自定义列 -->
|
|
457
|
+
<slot v-if="column.slot && column.istrue" :name="column.slot"></slot>
|
|
458
|
+
<el-table-column
|
|
459
|
+
:filter-method="column.filters ? filterHandler : null"
|
|
460
|
+
:filters="column.filters"
|
|
461
|
+
:fixed="column.fixed"
|
|
462
|
+
:key="`col_${column.prop}_${column.label}`"
|
|
463
|
+
:label="column.label"
|
|
464
|
+
:min-width="column.minWidth"
|
|
465
|
+
:prop="column.prop"
|
|
466
|
+
:width="column.width"
|
|
467
|
+
:align="column.hasOwnProperty('align') ? column.align : 'left'"
|
|
468
|
+
:show-overflow-tooltip="false"
|
|
469
|
+
filter-placement="bottom-end"
|
|
470
|
+
:header-align="column.hasOwnProperty('headerAlign') ? column.headerAlign : 'left'"
|
|
471
|
+
v-else-if="column.hasOwnProperty('istrue')?column.istrue:true"
|
|
472
|
+
:column-key="column.hasOwnProperty('elementId')? column.elementId:column.prop"
|
|
473
|
+
:resizable="column.hasOwnProperty('resizable') ? column.resizable : true"
|
|
474
|
+
>
|
|
475
|
+
<template v-if="isMultipleHeader">
|
|
476
|
+
<template v-for="(childColumn, childIdx) in column.children">
|
|
477
|
+
<el-table-column
|
|
478
|
+
:filter-method="childColumn.filters ? filterHandler : null"
|
|
479
|
+
:filters="childColumn.filters"
|
|
480
|
+
:fixed="childColumn.fixed"
|
|
481
|
+
:key="`col_${index}_${childIdx}`"
|
|
482
|
+
:label="childColumn.label"
|
|
483
|
+
:min-width="childColumn.minWidth"
|
|
484
|
+
:prop="childColumn.prop"
|
|
485
|
+
:width="childColumn.width"
|
|
486
|
+
:show-overflow-tooltip="false"
|
|
487
|
+
:align="childColumn.hasOwnProperty('align') ? childColumn.align : 'left'"
|
|
488
|
+
filter-placement="bottom-end"
|
|
489
|
+
:header-align="childColumn.hasOwnProperty('headerAlign') ? childColumn.headerAlign : 'left'"
|
|
490
|
+
v-if="childColumn.hasOwnProperty('istrue')?childColumn.istrue:true"
|
|
491
|
+
:column-key="childColumn.prop"
|
|
492
|
+
:resizable="childColumn.hasOwnProperty('resizable') ? childColumn.resizable : true"
|
|
493
|
+
>
|
|
494
|
+
<!-- 表头 -->
|
|
495
|
+
<template
|
|
496
|
+
slot="header"
|
|
497
|
+
slot-scope="scope"
|
|
498
|
+
>
|
|
499
|
+
<slot
|
|
500
|
+
:header="scope"
|
|
501
|
+
:name="childColumn.slotColumnHeader"
|
|
502
|
+
v-if="childColumn.slotColumnHeader && isShow"
|
|
503
|
+
></slot>
|
|
504
|
+
<template v-if="!childColumn.slotColumnHeader && isShow">
|
|
505
|
+
<div
|
|
506
|
+
class="slot_header_class"
|
|
507
|
+
>
|
|
508
|
+
<!-- style="display: flex;" -->
|
|
509
|
+
<span
|
|
510
|
+
class="table-header-isRequire"
|
|
511
|
+
v-if="childColumn.isRequire"
|
|
512
|
+
>*</span>
|
|
513
|
+
<span>{{ childColumn.label }}</span>
|
|
514
|
+
<span class="hide">
|
|
515
|
+
<i
|
|
516
|
+
class="iconfont icon-help icon_describe"
|
|
517
|
+
:title="childColumn.headerDescribe"
|
|
518
|
+
v-if="childColumn.headerDescribe"
|
|
519
|
+
></i>
|
|
520
|
+
<span
|
|
521
|
+
:class="{ 'ascending': sortVal === childColumn.prop + 'ascending', 'descending': sortVal === childColumn.prop + 'descending' }"
|
|
522
|
+
class="caret-wrapper"
|
|
523
|
+
v-if="childColumn.headerFilterSort"
|
|
524
|
+
>
|
|
525
|
+
<i
|
|
526
|
+
@click="handleCommand(childColumn.prop, childIdx, { command: 'ascending' })"
|
|
527
|
+
class="sort-caret ascending"
|
|
528
|
+
title="升序"
|
|
529
|
+
></i>
|
|
530
|
+
<i
|
|
531
|
+
@click="handleCommand(childColumn.prop, childIdx, { command: 'descending' })"
|
|
532
|
+
class="sort-caret descending"
|
|
533
|
+
title="降序"
|
|
534
|
+
></i>
|
|
535
|
+
</span>
|
|
536
|
+
</span>
|
|
537
|
+
</div>
|
|
538
|
+
</template>
|
|
539
|
+
</template>
|
|
540
|
+
<!--表体-->
|
|
541
|
+
<template slot-scope="scope">
|
|
542
|
+
<slot
|
|
543
|
+
:index="scope.$index"
|
|
544
|
+
:name="childColumn.slotCell"
|
|
545
|
+
:row="scope.row"
|
|
546
|
+
v-if="childColumn.slotCell"
|
|
547
|
+
></slot>
|
|
548
|
+
<template v-else>
|
|
549
|
+
<el-tooltip :content="scope.row[childColumn.prop]" placement="top" effect="light" popper-class="over_popper">
|
|
550
|
+
<span class="over_title">{{ scope.row[childColumn.prop] }}</span>
|
|
551
|
+
</el-tooltip>
|
|
552
|
+
</template>
|
|
553
|
+
</template>
|
|
554
|
+
</el-table-column>
|
|
555
|
+
</template>
|
|
556
|
+
</template>
|
|
557
|
+
<!-- 表头 -->
|
|
558
|
+
<template
|
|
559
|
+
slot="header"
|
|
560
|
+
slot-scope="scope"
|
|
561
|
+
>
|
|
562
|
+
<slot
|
|
563
|
+
:header="{column: scope.column, $index:scope.$index }"
|
|
564
|
+
:name="column.slotColumnHeader"
|
|
565
|
+
v-if="column.slotColumnHeader && isShow"
|
|
566
|
+
></slot>
|
|
567
|
+
<template v-if="!column.slotColumnHeader && isShow">
|
|
568
|
+
<div
|
|
569
|
+
class="slot_header_class"
|
|
570
|
+
>
|
|
571
|
+
<!-- style="display: flex;" -->
|
|
572
|
+
<span
|
|
573
|
+
class="table-header-isRequire"
|
|
574
|
+
v-if="column.isRequire"
|
|
575
|
+
>*</span>
|
|
576
|
+
<span>{{ column.label }}</span>
|
|
577
|
+
<span class="hide">
|
|
578
|
+
<i
|
|
579
|
+
class="iconfont icon-help icon_describe"
|
|
580
|
+
:title="column.headerDescribe"
|
|
581
|
+
v-if="column.headerDescribe"
|
|
582
|
+
></i>
|
|
583
|
+
<!--<span v-if="column.headerFilterSort">-->
|
|
584
|
+
<!--<i class="el-icon-sort-up" title="升序" @click="handleCommand(column.prop, index, {command: 'ascending'})"></i>-->
|
|
585
|
+
<!--<i class="el-icon-sort-down" title="降序" @click="handleCommand(column.prop, index, {command: 'descending'})"></i>-->
|
|
586
|
+
<!--</span>-->
|
|
587
|
+
<span
|
|
588
|
+
:class="{ 'ascending': sortVal === column.prop + 'ascending', 'descending': sortVal === column.prop + 'descending' }"
|
|
589
|
+
class="caret-wrapper"
|
|
590
|
+
v-if="column.headerFilterSort"
|
|
591
|
+
>
|
|
592
|
+
<i
|
|
593
|
+
@click="handleCommand(column.prop, index, { command: 'ascending' })"
|
|
594
|
+
class="sort-caret ascending"
|
|
595
|
+
title="升序"
|
|
596
|
+
></i>
|
|
597
|
+
<i
|
|
598
|
+
@click="handleCommand(column.prop, index, { command: 'descending' })"
|
|
599
|
+
class="sort-caret descending"
|
|
600
|
+
title="降序"
|
|
601
|
+
></i>
|
|
602
|
+
</span>
|
|
603
|
+
</span>
|
|
604
|
+
</div>
|
|
605
|
+
</template>
|
|
606
|
+
</template>
|
|
607
|
+
<!--表体-->
|
|
608
|
+
<template slot-scope="scope">
|
|
609
|
+
<slot
|
|
610
|
+
:index="scope.$index"
|
|
611
|
+
:name="column.slotCell"
|
|
612
|
+
:row="scope.row"
|
|
613
|
+
v-if="column.slotCell"
|
|
614
|
+
></slot>
|
|
615
|
+
<template v-else>
|
|
616
|
+
<el-tooltip :content="scope.row[column.prop]" placement="top" effect="light" popper-class="over_popper">
|
|
617
|
+
<span class="over_title">{{ scope.row[column.prop] }}</span>
|
|
618
|
+
</el-tooltip>
|
|
619
|
+
</template>
|
|
620
|
+
</template>
|
|
621
|
+
</el-table-column>
|
|
622
|
+
</template>
|
|
623
|
+
</el-table>
|
|
624
|
+
<div
|
|
625
|
+
class="pagination-box"
|
|
626
|
+
v-if="page && page.total > 0"
|
|
627
|
+
>
|
|
628
|
+
<!-- 是否调用分页 -->
|
|
629
|
+
<el-pagination
|
|
630
|
+
:current-page="page.current"
|
|
631
|
+
:layout="page.layout ? page.layout : 'total, sizes, prev, pager, next, jumper'"
|
|
632
|
+
:page-size="page.size"
|
|
633
|
+
:page-sizes="page.pageSizes"
|
|
634
|
+
:total="page.total"
|
|
635
|
+
:page-count="page.pageCount"
|
|
636
|
+
:pager-count="page.pagerCount"
|
|
637
|
+
@current-change="currentChange"
|
|
638
|
+
@size-change="sizeChange"
|
|
639
|
+
background
|
|
640
|
+
></el-pagination>
|
|
641
|
+
</div>
|
|
642
|
+
<!-- 显示/隐藏列 -->
|
|
643
|
+
</div>
|
|
644
|
+
</template>
|
|
645
|
+
|
|
646
|
+
<script>
|
|
647
|
+
import { deepClone } from 'sone-ui-component/src/utils/util'
|
|
648
|
+
import columnTransfer from './columnTransferNew.vue'
|
|
649
|
+
import Sortable from 'sortablejs'
|
|
650
|
+
import IconButton from "sone-ui-component/packages/IconButton/index.vue";
|
|
651
|
+
export default {
|
|
652
|
+
name: "SoneTable",
|
|
653
|
+
components: { columnTransfer,IconButton },
|
|
654
|
+
props: {
|
|
655
|
+
showMenuLeft: {
|
|
656
|
+
type: Boolean,
|
|
657
|
+
default: false
|
|
658
|
+
},
|
|
659
|
+
showMenuRight: {
|
|
660
|
+
type: Boolean,
|
|
661
|
+
default: true
|
|
662
|
+
},
|
|
663
|
+
showColumnHandleBtn: {
|
|
664
|
+
type: Boolean,
|
|
665
|
+
default: true
|
|
666
|
+
},
|
|
667
|
+
hideButtonMode: {
|
|
668
|
+
type: Boolean,
|
|
669
|
+
default: false
|
|
670
|
+
},
|
|
671
|
+
tabelRef: {
|
|
672
|
+
type: String,
|
|
673
|
+
default: 'tableDataRef'
|
|
674
|
+
},
|
|
675
|
+
loading: {
|
|
676
|
+
type: Boolean,
|
|
677
|
+
default: false,
|
|
678
|
+
},
|
|
679
|
+
showHeader: {
|
|
680
|
+
type: Boolean,
|
|
681
|
+
default: true,
|
|
682
|
+
},
|
|
683
|
+
stripe: {
|
|
684
|
+
type: Boolean,
|
|
685
|
+
default: true,
|
|
686
|
+
},
|
|
687
|
+
border: {
|
|
688
|
+
type: Boolean,
|
|
689
|
+
default: true,
|
|
690
|
+
},
|
|
691
|
+
onlyLeaf: {
|
|
692
|
+
type: Boolean,
|
|
693
|
+
default: false,
|
|
694
|
+
},
|
|
695
|
+
onlyCur: {
|
|
696
|
+
type: Boolean,
|
|
697
|
+
default: false,
|
|
698
|
+
},
|
|
699
|
+
lazy: {
|
|
700
|
+
type: Boolean,
|
|
701
|
+
default: false,
|
|
702
|
+
},
|
|
703
|
+
option: {
|
|
704
|
+
type: Object,
|
|
705
|
+
default: () => {
|
|
706
|
+
return {
|
|
707
|
+
index: true,
|
|
708
|
+
indexWidth: 70,
|
|
709
|
+
height: 'auto',
|
|
710
|
+
maxHeight: 'auto',
|
|
711
|
+
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
operation: {
|
|
716
|
+
type: [Object, Boolean],
|
|
717
|
+
default: () => {
|
|
718
|
+
return {
|
|
719
|
+
width: 82,
|
|
720
|
+
label: '操作',
|
|
721
|
+
buttonList: [
|
|
722
|
+
{
|
|
723
|
+
label: '删除',
|
|
724
|
+
icon: 'el-icon-remove-outline',
|
|
725
|
+
function: 'handDetele',
|
|
726
|
+
tooltipContent: '删除',
|
|
727
|
+
color: 'red'
|
|
728
|
+
}, {
|
|
729
|
+
label: '添加',
|
|
730
|
+
icon: 'el-icon-circle-plus-outline',
|
|
731
|
+
function: 'hand',
|
|
732
|
+
tooltipContent: '删除',
|
|
733
|
+
color: 'red'
|
|
734
|
+
}
|
|
735
|
+
]
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
},
|
|
739
|
+
page: {
|
|
740
|
+
type: Object,
|
|
741
|
+
},
|
|
742
|
+
columns: {
|
|
743
|
+
type: Array,
|
|
744
|
+
default: () => []
|
|
745
|
+
},
|
|
746
|
+
tableData: {
|
|
747
|
+
type: Array,
|
|
748
|
+
default: () => []
|
|
749
|
+
},
|
|
750
|
+
// 默认选中的复选值
|
|
751
|
+
defaultCheckedList: {
|
|
752
|
+
type: Array,
|
|
753
|
+
default: () => []
|
|
754
|
+
},
|
|
755
|
+
// 是否开启行拖拽
|
|
756
|
+
isRowDrop: {
|
|
757
|
+
type: Boolean,
|
|
758
|
+
default: false
|
|
759
|
+
},
|
|
760
|
+
// 行拖拽是否更改表格数据
|
|
761
|
+
isUpdateData:{
|
|
762
|
+
type:Boolean,
|
|
763
|
+
default:true
|
|
764
|
+
},
|
|
765
|
+
// 定义是否列表单元是否可以在列表容器内进行拖拽排序
|
|
766
|
+
dropSort:{
|
|
767
|
+
type:Boolean,
|
|
768
|
+
default:true
|
|
769
|
+
},
|
|
770
|
+
// 表格className
|
|
771
|
+
className:{
|
|
772
|
+
type:String,
|
|
773
|
+
default:''
|
|
774
|
+
},
|
|
775
|
+
/* 表格多级表头 */
|
|
776
|
+
isMultipleHeader: {
|
|
777
|
+
type: Boolean,
|
|
778
|
+
default: false
|
|
779
|
+
},
|
|
780
|
+
// 合计小数位数
|
|
781
|
+
summaryToFixed:{
|
|
782
|
+
type:[Number, String],
|
|
783
|
+
default:''
|
|
784
|
+
},
|
|
785
|
+
spanMethod: Function,
|
|
786
|
+
indexMethod: Function,
|
|
787
|
+
load: Function,
|
|
788
|
+
// 默认显示按钮图标加提示,
|
|
789
|
+
tooltipDisabled: {
|
|
790
|
+
type: Boolean,
|
|
791
|
+
default: false,
|
|
792
|
+
},
|
|
793
|
+
},
|
|
794
|
+
data() {
|
|
795
|
+
return {
|
|
796
|
+
// 单选
|
|
797
|
+
radioRow: '',
|
|
798
|
+
// 复选
|
|
799
|
+
checkAll: false,
|
|
800
|
+
checkIndeterminate: false,
|
|
801
|
+
//多选的列表
|
|
802
|
+
checkList: this.defaultCheckedList,
|
|
803
|
+
|
|
804
|
+
sortable: {},
|
|
805
|
+
internalColumns: deepClone(this.columns).filter(d => d && !d.isHidden),
|
|
806
|
+
sortVal: '', // 排序
|
|
807
|
+
isShow: true,
|
|
808
|
+
|
|
809
|
+
isTable: true
|
|
810
|
+
}
|
|
811
|
+
},
|
|
812
|
+
|
|
813
|
+
watch: {
|
|
814
|
+
// // 监听 - 复选框刷新
|
|
815
|
+
defaultCheckedList() {
|
|
816
|
+
if (!this.defaultCheckedList || this.defaultCheckedList.length < 1) {
|
|
817
|
+
this.checkList = []
|
|
818
|
+
this.checkAll = false
|
|
819
|
+
this.checkIndeterminate = false
|
|
820
|
+
}
|
|
821
|
+
},
|
|
822
|
+
columns: {
|
|
823
|
+
deep: true,
|
|
824
|
+
handler() {
|
|
825
|
+
this.internalColumns = deepClone(this.columns).filter(d => d && !d.isHidden);
|
|
826
|
+
}
|
|
827
|
+
},
|
|
828
|
+
internalColumns: {
|
|
829
|
+
deep: true,
|
|
830
|
+
handler() {
|
|
831
|
+
this.isShow = false
|
|
832
|
+
this.$nextTick(() => { //不放在这里面会导致视图不刷新
|
|
833
|
+
this.isShow = true;
|
|
834
|
+
})
|
|
835
|
+
this.$refs[this.tabelRef] && this.$refs[this.tabelRef].doLayout();
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
},
|
|
839
|
+
|
|
840
|
+
mounted() {
|
|
841
|
+
|
|
842
|
+
if (this.isRowDrop) this.rowDrop() // 开启行拖拽
|
|
843
|
+
// this.columnDrop()
|
|
844
|
+
},
|
|
845
|
+
|
|
846
|
+
methods: {
|
|
847
|
+
columnsCheckList(valArr) {
|
|
848
|
+
this.internalColumns.forEach(i => {
|
|
849
|
+
if (valArr.includes(i.label)) {
|
|
850
|
+
this.$set(i, 'istrue', true)
|
|
851
|
+
} else {
|
|
852
|
+
this.$set(i, 'istrue', false)
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
this.$nextTick(() => {
|
|
856
|
+
this.$refs[this.tabelRef] && this.$refs[this.tabelRef].doLayout();
|
|
857
|
+
});
|
|
858
|
+
},
|
|
859
|
+
selectFixed(items) {
|
|
860
|
+
this.internalColumns = deepClone(items);
|
|
861
|
+
this.$nextTick(() => {
|
|
862
|
+
this.$refs[this.tabelRef] && this.$refs[this.tabelRef].doLayout();
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
},
|
|
866
|
+
handleCheckedColumnChange(data, internalColumns) {
|
|
867
|
+
if(data){
|
|
868
|
+
this.columnsCheckList(data)
|
|
869
|
+
}
|
|
870
|
+
if(internalColumns && internalColumns.length){
|
|
871
|
+
this.$nextTick(() => {
|
|
872
|
+
this.internalColumns = deepClone(internalColumns);
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
},
|
|
876
|
+
dropdownList(itemset) {
|
|
877
|
+
this.internalColumns = deepClone(itemset);
|
|
878
|
+
this.isTable = false
|
|
879
|
+
this.$nextTick(() => {
|
|
880
|
+
this.isTable = true
|
|
881
|
+
})
|
|
882
|
+
},
|
|
883
|
+
|
|
884
|
+
deleteRow(index, rows) {
|
|
885
|
+
rows.splice(index, 1);
|
|
886
|
+
},
|
|
887
|
+
/** 单选 **/
|
|
888
|
+
handleRadioChange(row, index) {
|
|
889
|
+
this.radioRow = row[this.option.rowKey];
|
|
890
|
+
this.$emit('handleRadio', row, index)
|
|
891
|
+
},
|
|
892
|
+
/** 复选 **/
|
|
893
|
+
// 全选/取消全选-复选框
|
|
894
|
+
handleCheckAllChange(val) {
|
|
895
|
+
let data = deepClone(this.tableData)
|
|
896
|
+
let aCheckedData = [];
|
|
897
|
+
this.checkAll = val
|
|
898
|
+
this.checkIndeterminate = false
|
|
899
|
+
let _this = this;
|
|
900
|
+
if (val) {
|
|
901
|
+
this.checkList = [];
|
|
902
|
+
checkedAll(data);
|
|
903
|
+
} else {
|
|
904
|
+
cancelCheckedAll(data);
|
|
905
|
+
this.checkList = [];
|
|
906
|
+
aCheckedData = [];
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
//懒得优化就这样。。。
|
|
910
|
+
function checkedAll(d){
|
|
911
|
+
d.forEach(item => {
|
|
912
|
+
if(_this.onlyLeaf){//只需要叶子节点
|
|
913
|
+
if(!item.hasOwnProperty('children')){
|
|
914
|
+
aCheckedData.push(item);
|
|
915
|
+
_this.checkList.push(item[_this.option.rowKey]);
|
|
916
|
+
}
|
|
917
|
+
}else{
|
|
918
|
+
aCheckedData.push(item);
|
|
919
|
+
_this.checkList.push(item[_this.option.rowKey]);
|
|
920
|
+
}
|
|
921
|
+
item.checked = true;
|
|
922
|
+
item.indeterminate = false;
|
|
923
|
+
if(item.children && item.children.length > 0) {
|
|
924
|
+
checkedAll(item.children);
|
|
925
|
+
}
|
|
926
|
+
})
|
|
927
|
+
}
|
|
928
|
+
function cancelCheckedAll(d){
|
|
929
|
+
d.forEach(item => {
|
|
930
|
+
item.checked = false;
|
|
931
|
+
if(item.children && item.children.length > 0) {
|
|
932
|
+
item.indeterminate = false;
|
|
933
|
+
cancelCheckedAll(item.children);
|
|
934
|
+
}
|
|
935
|
+
})
|
|
936
|
+
}
|
|
937
|
+
this.$emit('handleChecked', true, this.checkList, aCheckedData, null, val)
|
|
938
|
+
this.$emit('update:tableData', data);
|
|
939
|
+
},
|
|
940
|
+
|
|
941
|
+
// 复选框-选择
|
|
942
|
+
handleCheckedChange(isChecked, row, index) {
|
|
943
|
+
let _this = this;
|
|
944
|
+
if(row.indeterminate){
|
|
945
|
+
row.checked = true;
|
|
946
|
+
}else{
|
|
947
|
+
row.checked = !row.checked;
|
|
948
|
+
}
|
|
949
|
+
if(row.children && row.children.length > 0 && !this.onlyCur){
|
|
950
|
+
row.indeterminate = false;
|
|
951
|
+
row.checked ? checkedAll(row.children) : cancelCheckedAll(row.children);
|
|
952
|
+
}
|
|
953
|
+
//懒得优化就这样。。。
|
|
954
|
+
function checkedAll(d){
|
|
955
|
+
d.forEach(item => {
|
|
956
|
+
item.checked = true;
|
|
957
|
+
let i = _this.checkList.findIndex(t => t === item[_this.option.rowKey]);
|
|
958
|
+
if(!i || i === -1) _this.checkList.push(item[_this.option.rowKey]);
|
|
959
|
+
if(item.children && item.children.length > 0) {
|
|
960
|
+
item.indeterminate = false;
|
|
961
|
+
checkedAll(item.children);
|
|
962
|
+
}
|
|
963
|
+
})
|
|
964
|
+
}
|
|
965
|
+
function cancelCheckedAll(d){
|
|
966
|
+
d.forEach(item => {
|
|
967
|
+
item.checked = false;
|
|
968
|
+
let i = _this.checkList.findIndex(t => t === item[_this.option.rowKey]);
|
|
969
|
+
_this.checkList.splice(i, 1);
|
|
970
|
+
if(item.children && item.children.length > 0) {
|
|
971
|
+
item.indeterminate = false;
|
|
972
|
+
cancelCheckedAll(item.children);
|
|
973
|
+
}
|
|
974
|
+
})
|
|
975
|
+
}
|
|
976
|
+
//树形层次较深时找到父级半选中
|
|
977
|
+
let parent = this.setParentCheck(this.tableData, row[this.option.rowKey]);
|
|
978
|
+
let checkList = this.checkList.concat(parent);
|
|
979
|
+
checkList = checkList.reduce((prev, cur) => { //去重
|
|
980
|
+
prev.indexOf(cur) === -1 && prev.push(cur);
|
|
981
|
+
return prev;
|
|
982
|
+
},[]);
|
|
983
|
+
this.checkList = checkList;
|
|
984
|
+
this.getPageCheckStatus()
|
|
985
|
+
this.$emit('handleChecked', false, this.checkList, row, index, row.checked)
|
|
986
|
+
},
|
|
987
|
+
setParentCheck(data, id) {
|
|
988
|
+
for (const i in data) {
|
|
989
|
+
if (data[i][this.option.rowKey] === id) {
|
|
990
|
+
return [data[i][this.option.rowKey]]
|
|
991
|
+
}
|
|
992
|
+
if (data[i].children) {
|
|
993
|
+
const result = this.setParentCheck(data[i].children, id)
|
|
994
|
+
if (result !== undefined && !this.onlyCur) {
|
|
995
|
+
data[i].indeterminate = true;
|
|
996
|
+
data[i].checked = true;
|
|
997
|
+
return result.concat(data[i][this.option.rowKey])
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
},
|
|
1002
|
+
// 判断当前页是否全/半选
|
|
1003
|
+
getPageCheckStatus() {
|
|
1004
|
+
let data = deepClone(this.tableData)
|
|
1005
|
+
if (this.checkList.length < 1 || data.length < 1) {
|
|
1006
|
+
this.checkAll = false
|
|
1007
|
+
this.checkIndeterminate = false
|
|
1008
|
+
return
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
let dataLength = 0;
|
|
1012
|
+
let _this = this;
|
|
1013
|
+
calcLength(data);
|
|
1014
|
+
|
|
1015
|
+
function calcLength(d){
|
|
1016
|
+
d.forEach(item => {
|
|
1017
|
+
if(_this.onlyLeaf){
|
|
1018
|
+
if(!item.hasOwnProperty('children')) dataLength++;
|
|
1019
|
+
else{
|
|
1020
|
+
if(_this.onlyCur) dataLength++;
|
|
1021
|
+
}
|
|
1022
|
+
}else{
|
|
1023
|
+
dataLength++;
|
|
1024
|
+
}
|
|
1025
|
+
if(item.children && item.children.length > 0){
|
|
1026
|
+
calcLength(item.children);
|
|
1027
|
+
}
|
|
1028
|
+
})
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
//父级下子集如果全部选中则取消父级半选中, 懒得优化了。。
|
|
1032
|
+
if(!this.onlyCur){
|
|
1033
|
+
this.calcCheck(data);
|
|
1034
|
+
this.calcHalfCheck(data);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
this.checkList = [];
|
|
1038
|
+
this.calcCheckList(data);
|
|
1039
|
+
|
|
1040
|
+
// 显示本页选中状态
|
|
1041
|
+
if (this.checkList.length === dataLength) {
|
|
1042
|
+
this.checkAll = true
|
|
1043
|
+
this.checkIndeterminate = false
|
|
1044
|
+
} else if (this.checkList.length === 0) {
|
|
1045
|
+
this.checkAll = false
|
|
1046
|
+
this.checkIndeterminate = false
|
|
1047
|
+
} else {
|
|
1048
|
+
this.checkAll = false
|
|
1049
|
+
this.checkIndeterminate = true
|
|
1050
|
+
}
|
|
1051
|
+
this.$emit('update:tableData', data)
|
|
1052
|
+
},
|
|
1053
|
+
//神TMcheckbox要放在序号上的需求。
|
|
1054
|
+
calcCheck(data){
|
|
1055
|
+
let checkedCount = 0;
|
|
1056
|
+
data.forEach(d => {
|
|
1057
|
+
if(d.checked && !d.indeterminate) checkedCount++; //选中且非半选
|
|
1058
|
+
if(d.indeterminate && d.children && d.children.length > 0){//半选有子集
|
|
1059
|
+
if(d.children.length === this.calcCheck(d.children)){//子集全部选中
|
|
1060
|
+
d.indeterminate = false; //关闭父级的半选
|
|
1061
|
+
}else{
|
|
1062
|
+
if(this.calcCheck(d.children) === 0){//子集全部未选中
|
|
1063
|
+
d.checked = false; //父级取消选中
|
|
1064
|
+
d.indeterminate = false; //父级隐藏半选
|
|
1065
|
+
checkedCount = checkedCount - 1;
|
|
1066
|
+
}else{//子集部分选中
|
|
1067
|
+
d.indeterminate = true; //父级半选
|
|
1068
|
+
d.checked = true; //父级选中
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
})
|
|
1073
|
+
return checkedCount;
|
|
1074
|
+
},
|
|
1075
|
+
calcHalfCheck(data){
|
|
1076
|
+
data.forEach(d => {
|
|
1077
|
+
if(d.children && d.children.length > 0){
|
|
1078
|
+
let hasHalf = d.children.find(t => t.checked && t.indeterminate);
|
|
1079
|
+
if(hasHalf){
|
|
1080
|
+
d.indeterminate = true;
|
|
1081
|
+
d.checked = true;
|
|
1082
|
+
}else{
|
|
1083
|
+
let noCheck = d.children.find(t => !t.checked);
|
|
1084
|
+
if(!noCheck){
|
|
1085
|
+
d.indeterminate = false;
|
|
1086
|
+
d.checked = true;
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
this.calcHalfCheck(d.children);
|
|
1090
|
+
}
|
|
1091
|
+
});
|
|
1092
|
+
},
|
|
1093
|
+
calcCheckList(data){
|
|
1094
|
+
data.forEach(d => {
|
|
1095
|
+
if(d.checked){
|
|
1096
|
+
if(this.onlyLeaf){
|
|
1097
|
+
if(!d.hasOwnProperty('children')) this.checkList.push(d[this.option.rowKey]);
|
|
1098
|
+
else{
|
|
1099
|
+
if(this.onlyCur) this.checkList.push(d[this.option.rowKey]);
|
|
1100
|
+
}
|
|
1101
|
+
}else{
|
|
1102
|
+
this.checkList.push(d[this.option.rowKey]);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
if(d.children && d.children.length > 0) this.calcCheckList(d.children);
|
|
1106
|
+
})
|
|
1107
|
+
},
|
|
1108
|
+
// 下拉button
|
|
1109
|
+
handleCommand(columnName, columnIndex, data) {
|
|
1110
|
+
let tableData = deepClone(this.tableData)
|
|
1111
|
+
if (data.command === "ascending" || data.command === "descending") {
|
|
1112
|
+
if (this.sortVal && this.sortVal.indexOf(data.command) > -1) {
|
|
1113
|
+
this.sortVal = ''
|
|
1114
|
+
} else {
|
|
1115
|
+
this.sortVal = columnName + data.command
|
|
1116
|
+
}
|
|
1117
|
+
if (this.option.defineSort) {
|
|
1118
|
+
this.$emit('handleColumnFilter', columnName, columnIndex, data, !!!this.sortVal)
|
|
1119
|
+
} else {
|
|
1120
|
+
let isIncludeNaN = tableData.some(item => isNaN(Number(item[columnName])))
|
|
1121
|
+
if ( isIncludeNaN ) { // 数据非纯数字使用原生ele方法
|
|
1122
|
+
if(this.sortVal){
|
|
1123
|
+
this.$refs[this.tabelRef].sort(columnName, data.command);
|
|
1124
|
+
} else {
|
|
1125
|
+
this.$refs[this.tabelRef].clearSort();
|
|
1126
|
+
}
|
|
1127
|
+
} else { // 纯数字使用sort排序
|
|
1128
|
+
tableData.sort((a, b) => {
|
|
1129
|
+
return data.command === 'ascending' ? a[columnName] - b[columnName] : b[columnName] - a[columnName]
|
|
1130
|
+
})
|
|
1131
|
+
this.$emit('update:tableData', tableData)
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
} else {
|
|
1135
|
+
this.$emit('handleColumnFilter', columnName, columnIndex, data)
|
|
1136
|
+
}
|
|
1137
|
+
},
|
|
1138
|
+
// 翻页
|
|
1139
|
+
sizeChange(val) {
|
|
1140
|
+
this.$emit('sizeChange', val)
|
|
1141
|
+
},
|
|
1142
|
+
currentChange(val) {
|
|
1143
|
+
this.$emit('currentChange', val)
|
|
1144
|
+
},
|
|
1145
|
+
// 合计
|
|
1146
|
+
summaryMethod({ columns, data }) {
|
|
1147
|
+
if (this.option.summaryMethod) {
|
|
1148
|
+
return this.option.summaryMethod({ columns, data })
|
|
1149
|
+
}
|
|
1150
|
+
let _columns = deepClone(this.internalColumns);
|
|
1151
|
+
const sums = [];
|
|
1152
|
+
// 固定列会导致窜行 待改
|
|
1153
|
+
if ( !!this.operation ) sums.push(this.option.sumText || '合计')
|
|
1154
|
+
if ( this.option.indexCheck || this.option.index ) {
|
|
1155
|
+
!!this.operation ? sums.push('') : sums.push('合计')
|
|
1156
|
+
}
|
|
1157
|
+
if ( this.isMultipleHeader ) { // 多级表头 只拿底层表头进行合计
|
|
1158
|
+
_columns = []
|
|
1159
|
+
this.internalColumns.forEach(item => {
|
|
1160
|
+
item.children.forEach(item2 => {
|
|
1161
|
+
_columns.push(item2)
|
|
1162
|
+
})
|
|
1163
|
+
})
|
|
1164
|
+
}
|
|
1165
|
+
_columns.forEach((column, index) => {
|
|
1166
|
+
if ( column.istrue ) {
|
|
1167
|
+
let num = 0
|
|
1168
|
+
data.forEach(item => num += Number(item[column.prop]))
|
|
1169
|
+
if ( isNaN(num) || !column.summary ) {
|
|
1170
|
+
sums.push('')
|
|
1171
|
+
} else if ( String(num).indexOf('.') != -1 && this.summaryToFixed ) {
|
|
1172
|
+
sums.push(num.toFixed(this.summaryToFixed))
|
|
1173
|
+
} else {
|
|
1174
|
+
sums.push(num)
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
// const columnObj = _columns.find(d => d.prop === column.property);
|
|
1178
|
+
// if (!columnObj || !columnObj.summary) return;
|
|
1179
|
+
// const values = data.map(item => Number(item[column.property]));
|
|
1180
|
+
// if (!values.every(value => isNaN(value))) {
|
|
1181
|
+
// sums[index] = values.reduce((prev, curr) => {
|
|
1182
|
+
// const value = Number(curr);
|
|
1183
|
+
// if (!isNaN(value)) {
|
|
1184
|
+
// return prev + curr;
|
|
1185
|
+
// } else {
|
|
1186
|
+
// return prev;
|
|
1187
|
+
// }
|
|
1188
|
+
// }, 0);
|
|
1189
|
+
// sums[index] += '';
|
|
1190
|
+
// } else {
|
|
1191
|
+
// sums[index] = '';
|
|
1192
|
+
// }
|
|
1193
|
+
});
|
|
1194
|
+
// console.log('sums:',sums)
|
|
1195
|
+
return sums;
|
|
1196
|
+
},
|
|
1197
|
+
|
|
1198
|
+
// 单元格移入移出
|
|
1199
|
+
cellMouseEnter(row, column, cell, event) {
|
|
1200
|
+
this.$emit('cellMouseEnter', row, column, cell, event)
|
|
1201
|
+
},
|
|
1202
|
+
cellMouseLeave(row, column, cell, event) {
|
|
1203
|
+
this.$emit('cellMouseLeave', row, column, cell, event)
|
|
1204
|
+
},
|
|
1205
|
+
// 行点击
|
|
1206
|
+
rowClick(row, column, event) {
|
|
1207
|
+
// 判断点击行是否联动选择复选框
|
|
1208
|
+
if (!this.option.clickRowNoCheck) {
|
|
1209
|
+
if (this.option.indexCheck) {
|
|
1210
|
+
// 有复选框-行点击选中/取消选中
|
|
1211
|
+
if (this.checkList.indexOf(row[this.option.rowKey]) > -1) {
|
|
1212
|
+
this.checkList.splice(this.checkList.indexOf(row[this.option.rowKey]), 1)
|
|
1213
|
+
} else {
|
|
1214
|
+
this.checkList.push(row[this.option.rowKey])
|
|
1215
|
+
}
|
|
1216
|
+
// 全选/半全选标记
|
|
1217
|
+
this.handleCheckedChange(row.checked, row)
|
|
1218
|
+
} else if (this.option.indexRadio) {
|
|
1219
|
+
this.radioRow = row[this.option.rowKey]
|
|
1220
|
+
this.handleRadioChange(row)
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
//
|
|
1224
|
+
this.$emit('rowClick', row, column, event)
|
|
1225
|
+
},
|
|
1226
|
+
|
|
1227
|
+
// 行双击
|
|
1228
|
+
rowDblclick(row, column, event) {
|
|
1229
|
+
this.$emit('rowDblclick', row, column, event)
|
|
1230
|
+
},
|
|
1231
|
+
|
|
1232
|
+
// 行拖拽
|
|
1233
|
+
rowDrop() {
|
|
1234
|
+
const tbody = document.querySelector(`.${!!this.className ? this.className : 'sone-table'} .el-table__body-wrapper tbody`)
|
|
1235
|
+
// console.log('tbody:', tbody)
|
|
1236
|
+
const _this = this
|
|
1237
|
+
Sortable.create(tbody, {
|
|
1238
|
+
sort:_this.dropSort,
|
|
1239
|
+
onEnd ( obj ) {
|
|
1240
|
+
let currRow = {}
|
|
1241
|
+
let { newIndex, oldIndex } = obj
|
|
1242
|
+
let tableData = deepClone(_this.tableData)
|
|
1243
|
+
let isTreeTable = tableData.filter(item => Array.isArray(item.children) && item.children.length != 0)
|
|
1244
|
+
if ( isTreeTable.length == 0 ) { // 普通表格
|
|
1245
|
+
if ( _this.isUpdateData ) {
|
|
1246
|
+
currRow = _this.tableData.splice(oldIndex, 1)[0]
|
|
1247
|
+
_this.tableData.splice(newIndex, 0, currRow)
|
|
1248
|
+
}
|
|
1249
|
+
} else { // 树形表格
|
|
1250
|
+
let tableDataList = []
|
|
1251
|
+
function recursionData(data) {
|
|
1252
|
+
data.forEach(item => {
|
|
1253
|
+
tableDataList.push(item)
|
|
1254
|
+
if ( Array.isArray(item.children) && item.children.length != 0 ) {
|
|
1255
|
+
recursionData(item.children)
|
|
1256
|
+
}
|
|
1257
|
+
})
|
|
1258
|
+
}
|
|
1259
|
+
recursionData(tableData)
|
|
1260
|
+
currRow = tableDataList[newIndex]
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
_this.$emit('dropRow', _this.tableData, currRow, newIndex, oldIndex, obj)
|
|
1264
|
+
}
|
|
1265
|
+
})
|
|
1266
|
+
},
|
|
1267
|
+
|
|
1268
|
+
// 当某一列的表头被点击时
|
|
1269
|
+
headerClick(column, event) {
|
|
1270
|
+
this.$emit('rowContextmenu', column, event)
|
|
1271
|
+
},
|
|
1272
|
+
// 当某一列的表头被鼠标右键点击时
|
|
1273
|
+
headerContextmenu(column, event) {
|
|
1274
|
+
this.$emit('headerContextmenu', column, event)
|
|
1275
|
+
},
|
|
1276
|
+
// 行被鼠标右键点击时
|
|
1277
|
+
rowContextmenu(row, column, event) {
|
|
1278
|
+
this.$emit('rowContextmenu', row, column, event)
|
|
1279
|
+
},
|
|
1280
|
+
filterChange(filters) {
|
|
1281
|
+
let data = deepClone(this.tableData)
|
|
1282
|
+
// 判断是哪一列筛选
|
|
1283
|
+
if (filters.name) {
|
|
1284
|
+
data.name = filters.name[0]
|
|
1285
|
+
}
|
|
1286
|
+
this.$emit('update:tableData', data)
|
|
1287
|
+
// this.getTableList(); // 通过接口获取数据的方法
|
|
1288
|
+
},
|
|
1289
|
+
formatter(row, column) {
|
|
1290
|
+
return row.address;
|
|
1291
|
+
},
|
|
1292
|
+
|
|
1293
|
+
filterTag(value, row) {
|
|
1294
|
+
return row.tag === value;
|
|
1295
|
+
},
|
|
1296
|
+
//过滤
|
|
1297
|
+
filterHandler(value, row, column) {
|
|
1298
|
+
const property = column['property'];
|
|
1299
|
+
return row[property] === value;
|
|
1300
|
+
},
|
|
1301
|
+
|
|
1302
|
+
// class
|
|
1303
|
+
tableRowClassName({ row, rowIndex }) {
|
|
1304
|
+
let rowClass = ''
|
|
1305
|
+
if (this.option.rowClassName) {
|
|
1306
|
+
rowClass = this.option.rowClassName({ row, rowIndex })
|
|
1307
|
+
}
|
|
1308
|
+
// if (this.checkList.indexOf(row[this.option.rowKey]) > -1 || this.radioRow === row[this.option.rowKey]) {
|
|
1309
|
+
// return (rowClass + ' table-row-checked')
|
|
1310
|
+
// } else {
|
|
1311
|
+
// return rowClass
|
|
1312
|
+
// }
|
|
1313
|
+
|
|
1314
|
+
if(this.option.indexRadio === true && this.radioRow === row[this.option.rowKey]){
|
|
1315
|
+
return `current-row ${rowClass}`;
|
|
1316
|
+
}
|
|
1317
|
+
if(this.option.indexCheck === true && row.checked === true && !this.option['clickRowNoCheck']){
|
|
1318
|
+
return `current-row ${rowClass}`;
|
|
1319
|
+
}
|
|
1320
|
+
return rowClass;
|
|
1321
|
+
},
|
|
1322
|
+
|
|
1323
|
+
handButton(functionName, scope, id) {
|
|
1324
|
+
this.$emit(functionName, scope, id)
|
|
1325
|
+
},
|
|
1326
|
+
doLayout() {
|
|
1327
|
+
this.$refs[this.tabelRef].doLayout();
|
|
1328
|
+
},
|
|
1329
|
+
/* 表格-列显隐-下拉菜单 */
|
|
1330
|
+
onColumnVisibleMenu(flag){
|
|
1331
|
+
let arr = [
|
|
1332
|
+
...this.$refs['column-transfer'].leftColumns,
|
|
1333
|
+
...this.$refs['column-transfer'].noColumns,
|
|
1334
|
+
...this.$refs['column-transfer'].rightColumns
|
|
1335
|
+
]
|
|
1336
|
+
// this.$emit('columnsVisibleMenu', flag, this.internalColumns );
|
|
1337
|
+
this.$emit('columnsVisibleMenu', flag, arr );
|
|
1338
|
+
},
|
|
1339
|
+
/* 当拖动表头改变了列的宽度的时候会触发该事件 */
|
|
1340
|
+
onHeaderDragend(newWidth, oldWidth, column, event){
|
|
1341
|
+
let arr = [
|
|
1342
|
+
...this.$refs['column-transfer'].leftColumns,
|
|
1343
|
+
...this.$refs['column-transfer'].noColumns,
|
|
1344
|
+
...this.$refs['column-transfer'].rightColumns
|
|
1345
|
+
]
|
|
1346
|
+
this.$emit('headerDragend', newWidth, oldWidth, column, arr, event);
|
|
1347
|
+
},
|
|
1348
|
+
save(arr){
|
|
1349
|
+
this.internalColumns = deepClone(arr);
|
|
1350
|
+
this.isTable = false
|
|
1351
|
+
this.$nextTick(() => {
|
|
1352
|
+
this.isTable = true
|
|
1353
|
+
})
|
|
1354
|
+
this.$emit('save', arr);
|
|
1355
|
+
},
|
|
1356
|
+
/* 用于单选表格,设定某一行为选中行,如果调用时不加参数,则会取消目前高亮行的选中状态。 */
|
|
1357
|
+
setCurrentRow(row){
|
|
1358
|
+
this.$refs[this.tabelRef] && this.$refs[this.tabelRef].setCurrentRow(row);
|
|
1359
|
+
this.$emit('setCurrentRow', row);
|
|
1360
|
+
},
|
|
1361
|
+
updateColumn(){
|
|
1362
|
+
|
|
1363
|
+
},
|
|
1364
|
+
expandChange(row, expend){
|
|
1365
|
+
this.$emit('expandChange', row, expend)
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
}
|
|
1369
|
+
</script>
|