@lx-frontend/wrap-element-ui 1.0.0-beta.7 → 1.0.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/components/AddMembers/index.vue +40 -32
- package/src/components/EditableTable/index.less +26 -34
- package/src/components/EditableTable/index.vue +35 -108
- package/src/components/EditableTable/types.ts +10 -32
- package/src/components/EditableTable/useColumnHeaderOperation.ts +28 -166
- package/src/components/EditableTable/useDefaultOperation.ts +10 -10
- package/src/components/EditableTable/useDragSort.ts +5 -4
- package/src/components/EditableTable/usePagination.ts +7 -4
- package/src/components/EditableTable/useRowBgColor.ts +3 -3
- package/src/components/EditableTable/useViewSetting.ts +1 -53
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lx-frontend/wrap-element-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta.1",
|
|
4
4
|
"description": "wrap-element-ui",
|
|
5
5
|
"author": "",
|
|
6
|
-
"main": "
|
|
6
|
+
"main": "dist/index.mjs",
|
|
7
7
|
"private": false,
|
|
8
8
|
"scripts": {
|
|
9
9
|
"clean": "rimraf dist",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"lint": "eslint src"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
|
+
"dist",
|
|
21
22
|
"README.md",
|
|
22
23
|
"package.json",
|
|
23
24
|
"src/components"
|
|
@@ -4,37 +4,40 @@
|
|
|
4
4
|
:title="title"
|
|
5
5
|
:with-submit-btn="false"
|
|
6
6
|
:width="360"
|
|
7
|
-
@on-change="
|
|
7
|
+
@on-change="handleCloseSelectPopup"
|
|
8
8
|
>
|
|
9
9
|
<div
|
|
10
10
|
slot="form"
|
|
11
|
-
class="team-
|
|
11
|
+
class="team-setting__members-popover"
|
|
12
12
|
>
|
|
13
|
-
<div class="team-
|
|
13
|
+
<div class="team-setting__members-select">
|
|
14
14
|
<el-input
|
|
15
|
-
v-model="
|
|
15
|
+
v-model="searchQuery"
|
|
16
16
|
placeholder="请输入姓名"
|
|
17
|
-
@input="
|
|
17
|
+
@input="handleInputSearch(searchQuery, $attrs.keyId)"
|
|
18
18
|
/>
|
|
19
19
|
</div>
|
|
20
20
|
<div
|
|
21
|
-
v-if="
|
|
22
|
-
class="team-setting__empty-
|
|
21
|
+
v-if="searchQuery && !options.length && !fetchLoading"
|
|
22
|
+
class="team-setting__empty-members-options"
|
|
23
23
|
>
|
|
24
24
|
{{ $attrs.empty || '系统未登记该员工,请先添加员工账号' }}
|
|
25
25
|
</div>
|
|
26
26
|
<ul
|
|
27
27
|
v-else
|
|
28
|
-
class="team-
|
|
28
|
+
class="team-setting__members-options"
|
|
29
29
|
>
|
|
30
30
|
<li
|
|
31
|
-
class="team-
|
|
32
|
-
v-for="item in
|
|
31
|
+
class="team-setting__members-option"
|
|
32
|
+
v-for="item in options"
|
|
33
33
|
:key="item[$attrs.showConfig.id]"
|
|
34
34
|
>
|
|
35
|
-
<div class="team-
|
|
35
|
+
<div class="team-setting__members-option-left" v-if="isShowRoles">
|
|
36
36
|
{{ `${item[$attrs.showConfig.name]} | ${item.roles}` }}
|
|
37
37
|
</div>
|
|
38
|
+
<div class="team-setting__members-option-left" v-else>
|
|
39
|
+
{{item[$attrs.showConfig.name]}}
|
|
40
|
+
</div>
|
|
38
41
|
<el-button
|
|
39
42
|
v-if="item.is_selected"
|
|
40
43
|
type="text"
|
|
@@ -45,7 +48,7 @@
|
|
|
45
48
|
<el-button
|
|
46
49
|
v-else
|
|
47
50
|
type="text"
|
|
48
|
-
@click="
|
|
51
|
+
@click="handleAdd($attrs.keyId, item)"
|
|
49
52
|
>
|
|
50
53
|
添加
|
|
51
54
|
</el-button>
|
|
@@ -80,26 +83,31 @@ export default {
|
|
|
80
83
|
type: String,
|
|
81
84
|
default: '添加成员',
|
|
82
85
|
},
|
|
86
|
+
/** 角色名称展示 */
|
|
87
|
+
isShowRoles: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: true,
|
|
90
|
+
},
|
|
83
91
|
},
|
|
84
92
|
data() {
|
|
85
93
|
return {
|
|
86
|
-
|
|
94
|
+
searchQuery: '',
|
|
87
95
|
}
|
|
88
96
|
},
|
|
89
97
|
watch: {
|
|
90
98
|
},
|
|
91
99
|
methods: {
|
|
92
|
-
|
|
100
|
+
handleCloseSelectPopup(show) {
|
|
93
101
|
if (show) return;
|
|
94
|
-
this.
|
|
95
|
-
this.$emit('update:
|
|
102
|
+
this.searchQuery = '';
|
|
103
|
+
this.$emit('update:options', []);
|
|
96
104
|
},
|
|
97
|
-
|
|
98
|
-
this.$emit('
|
|
105
|
+
handleInputSearch(query, keyId) {
|
|
106
|
+
this.$emit('fetchMethods', { query, keyId });
|
|
99
107
|
},
|
|
100
|
-
|
|
108
|
+
handleAdd(id, item) {
|
|
101
109
|
const query = { id, item };
|
|
102
|
-
this.$emit('
|
|
110
|
+
this.$emit('handleAdd', query);
|
|
103
111
|
},
|
|
104
112
|
},
|
|
105
113
|
};
|
|
@@ -107,25 +115,25 @@ export default {
|
|
|
107
115
|
|
|
108
116
|
<style lang="less">
|
|
109
117
|
.team-setting {
|
|
110
|
-
&
|
|
111
|
-
padding: 20px;
|
|
118
|
+
&__members-popover {
|
|
119
|
+
padding: 20px 0;
|
|
120
|
+
margin: 0 20px;
|
|
112
121
|
height: 350px;
|
|
113
122
|
overflow-y: auto;
|
|
114
123
|
}
|
|
115
|
-
&
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
margin-top: 10px;
|
|
124
|
+
&__empty-members {
|
|
125
|
+
&-options {
|
|
126
|
+
font-size: 12px;
|
|
127
|
+
color: #80838e;
|
|
128
|
+
text-align: center;
|
|
129
|
+
margin-top: 10px;
|
|
130
|
+
}
|
|
123
131
|
}
|
|
124
|
-
&
|
|
132
|
+
&__members-options {
|
|
125
133
|
display: flex;
|
|
126
134
|
flex-direction: column;
|
|
127
135
|
}
|
|
128
|
-
&
|
|
136
|
+
&__members-option {
|
|
129
137
|
display: flex;
|
|
130
138
|
justify-content: space-between;
|
|
131
139
|
align-items: center;
|
|
@@ -180,31 +180,6 @@
|
|
|
180
180
|
border-right: 2px #e4e8ef solid;
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
|
|
184
|
-
.el-table-filter,
|
|
185
|
-
th.el-table__cell .el-table__column-filter-trigger,
|
|
186
|
-
th.is-sortable .caret-wrapper {
|
|
187
|
-
display: none;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
.el-table__body tr.current-row > td,
|
|
191
|
-
.el-table__body tr.hover-row > td {
|
|
192
|
-
background-color: #fafafa;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
table tbody tr td {
|
|
196
|
-
& .el-date-editor.el-input {
|
|
197
|
-
width: 100%;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
& .cell {
|
|
201
|
-
font-size: 14px;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
.el-table__fixed-body-wrapper {
|
|
206
|
-
background: #fff;
|
|
207
|
-
}
|
|
208
183
|
}
|
|
209
184
|
|
|
210
185
|
.view-setting {
|
|
@@ -232,7 +207,7 @@
|
|
|
232
207
|
padding: 0px;
|
|
233
208
|
|
|
234
209
|
.el-dialog__body {
|
|
235
|
-
max-height:
|
|
210
|
+
max-height: 800px;
|
|
236
211
|
}
|
|
237
212
|
|
|
238
213
|
.el-dialog__body {
|
|
@@ -522,12 +497,6 @@
|
|
|
522
497
|
background-color: @--theme-blue--;
|
|
523
498
|
border-color: @--theme-blue--;
|
|
524
499
|
}
|
|
525
|
-
|
|
526
|
-
.el-checkbox__input.is-checked .el-checkbox__inner,
|
|
527
|
-
.el-radio__input.is-checked .el-radio__inner {
|
|
528
|
-
background: #2468f2;
|
|
529
|
-
border-color: #2468f2;
|
|
530
|
-
}
|
|
531
500
|
}
|
|
532
501
|
|
|
533
502
|
.btn-pointer {
|
|
@@ -607,8 +576,6 @@
|
|
|
607
576
|
margin-top: 12px;
|
|
608
577
|
|
|
609
578
|
& .el-pagination {
|
|
610
|
-
padding: 0;
|
|
611
|
-
|
|
612
579
|
.el-pager li.number {
|
|
613
580
|
background-color: #fff;
|
|
614
581
|
border: 1px solid #d6dbe3;
|
|
@@ -638,7 +605,26 @@
|
|
|
638
605
|
}
|
|
639
606
|
}
|
|
640
607
|
|
|
608
|
+
.el-table__body tr.current-row > td,
|
|
609
|
+
.el-table__body tr.hover-row > td {
|
|
610
|
+
background-color: #fafafa;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
.el-table-filter,
|
|
614
|
+
th.el-table__cell .el-table__column-filter-trigger,
|
|
615
|
+
th.is-sortable .caret-wrapper {
|
|
616
|
+
display: none;
|
|
617
|
+
}
|
|
641
618
|
|
|
619
|
+
table tbody tr td {
|
|
620
|
+
& .el-date-editor.el-input {
|
|
621
|
+
width: 100%;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
& .cell {
|
|
625
|
+
font-size: 14px;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
642
628
|
|
|
643
629
|
.editable-table {
|
|
644
630
|
& table th {
|
|
@@ -688,6 +674,12 @@
|
|
|
688
674
|
}
|
|
689
675
|
}
|
|
690
676
|
|
|
677
|
+
.el-select-dropdown {
|
|
678
|
+
&__item {
|
|
679
|
+
text-align: center;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
691
683
|
.el-dialog__header {
|
|
692
684
|
display: flex;
|
|
693
685
|
justify-content: space-between;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="editable-table">
|
|
3
3
|
<div class="view-setting">
|
|
4
|
-
<div
|
|
5
|
-
v-if="!hideViewSettingBtn"
|
|
6
|
-
class="view-setting__btn-wrapper"
|
|
7
|
-
>
|
|
4
|
+
<div class="view-setting__btn-wrapper">
|
|
8
5
|
<div
|
|
9
6
|
class="view-setting__btn btn-pointer"
|
|
10
7
|
@click="handleViewSettingShow"
|
|
@@ -20,7 +17,6 @@
|
|
|
20
17
|
title="显示设置"
|
|
21
18
|
:visible.sync="viewSettingVisible"
|
|
22
19
|
width="750px"
|
|
23
|
-
top="12vh"
|
|
24
20
|
:close-on-click-modal="false"
|
|
25
21
|
:append-to-body="true"
|
|
26
22
|
custom-class="view-setting__dialog"
|
|
@@ -55,9 +51,8 @@
|
|
|
55
51
|
<div class="view-setting__content-right-frize">
|
|
56
52
|
冻结前
|
|
57
53
|
<el-input
|
|
54
|
+
v-model="leftFixedColumnCount"
|
|
58
55
|
class="view-setting__content-right-input"
|
|
59
|
-
:value="tempLeftFixedColumnCount"
|
|
60
|
-
@input="handleInputTempLeftFixedColumnCount"
|
|
61
56
|
/>
|
|
62
57
|
列
|
|
63
58
|
</div>
|
|
@@ -223,7 +218,7 @@
|
|
|
223
218
|
:key="column.prop + index"
|
|
224
219
|
resizable
|
|
225
220
|
class-name="editable-table__data-column"
|
|
226
|
-
:filtered-value="
|
|
221
|
+
:filtered-value="filteredValue[column.prop] || []"
|
|
227
222
|
v-bind="getColumnBindProps(column)"
|
|
228
223
|
>
|
|
229
224
|
<template
|
|
@@ -272,7 +267,7 @@
|
|
|
272
267
|
</div>
|
|
273
268
|
</div>
|
|
274
269
|
<div
|
|
275
|
-
v-if="column.
|
|
270
|
+
v-if="column.isColumnSearchAble"
|
|
276
271
|
class="sort-filter__search"
|
|
277
272
|
>
|
|
278
273
|
<div class="sort-filter__search-title">
|
|
@@ -284,41 +279,19 @@
|
|
|
284
279
|
placeholder="请输入内容"
|
|
285
280
|
/>
|
|
286
281
|
</div>
|
|
287
|
-
|
|
288
282
|
<div
|
|
289
|
-
v-if="column.
|
|
290
|
-
class="sort-filter__search"
|
|
291
|
-
style="display: flex;flex-direction: column;gap: 12px;"
|
|
292
|
-
>
|
|
293
|
-
<div
|
|
294
|
-
v-for="item in column.search"
|
|
295
|
-
:key="item.prop"
|
|
296
|
-
>
|
|
297
|
-
<div class="sort-filter__search-title">
|
|
298
|
-
{{ item.label }}
|
|
299
|
-
</div>
|
|
300
|
-
<el-input
|
|
301
|
-
v-model="tempSearchValue[item.prop]"
|
|
302
|
-
class="sort-filter__search-input"
|
|
303
|
-
placeholder="请输入内容"
|
|
304
|
-
/>
|
|
305
|
-
</div>
|
|
306
|
-
</div>
|
|
307
|
-
|
|
308
|
-
<div
|
|
309
|
-
v-if="column.filters && ((Array.isArray(column.filters) ? column.filters : column.filters.options).length > 0)"
|
|
283
|
+
v-if="column.filters && column.filters.length > 0"
|
|
310
284
|
class="sort-filter__filter"
|
|
311
285
|
>
|
|
312
286
|
<div class="sort-filter__filter-title">
|
|
313
287
|
筛选
|
|
314
288
|
</div>
|
|
315
289
|
<el-checkbox-group
|
|
316
|
-
v-if="column.filters && (Array.isArray(column.filters) || column.filters.type === 'checkbox')"
|
|
317
290
|
v-model="tempFilteredValue[column.prop]"
|
|
318
291
|
class="sort-filter__filter-checkbox-group"
|
|
319
292
|
>
|
|
320
293
|
<el-checkbox
|
|
321
|
-
v-for="item in
|
|
294
|
+
v-for="item in column.filters"
|
|
322
295
|
:key="item.value"
|
|
323
296
|
:label="item.value"
|
|
324
297
|
class="sort-filter__filter-checkbox"
|
|
@@ -331,25 +304,6 @@
|
|
|
331
304
|
</slot>
|
|
332
305
|
</el-checkbox>
|
|
333
306
|
</el-checkbox-group>
|
|
334
|
-
|
|
335
|
-
<el-radio-group
|
|
336
|
-
v-if="column.filters && !Array.isArray(column.filters) && column.filters.type === 'radio'"
|
|
337
|
-
v-model="tempFilteredValue[column.prop]"
|
|
338
|
-
style="display: flex;flex-direction: column;gap: 6px;"
|
|
339
|
-
>
|
|
340
|
-
<el-radio
|
|
341
|
-
v-for="item in column.filters.options"
|
|
342
|
-
:key="item.value"
|
|
343
|
-
:label="item.value"
|
|
344
|
-
>
|
|
345
|
-
<slot
|
|
346
|
-
:name="column.prop + '-filter-item'"
|
|
347
|
-
v-bind="item"
|
|
348
|
-
>
|
|
349
|
-
{{ item.text }}
|
|
350
|
-
</slot>
|
|
351
|
-
</el-radio>
|
|
352
|
-
</el-radio-group>
|
|
353
307
|
</div>
|
|
354
308
|
<div
|
|
355
309
|
v-if="column.summary"
|
|
@@ -385,7 +339,7 @@
|
|
|
385
339
|
<el-button
|
|
386
340
|
class="sort-filter__confirm-btn"
|
|
387
341
|
type="primary"
|
|
388
|
-
@click="handleHeaderOperationConfirm(
|
|
342
|
+
@click="handleHeaderOperationConfirm(scope)"
|
|
389
343
|
>
|
|
390
344
|
确定
|
|
391
345
|
</el-button>
|
|
@@ -584,7 +538,7 @@
|
|
|
584
538
|
:page-sizes="[10, 15, 30, 60, 100]"
|
|
585
539
|
:page-size.sync="pageSize"
|
|
586
540
|
:pager-count="11"
|
|
587
|
-
:current-page="currentPage"
|
|
541
|
+
:current-page.sync="currentPage"
|
|
588
542
|
:total="total"
|
|
589
543
|
@size-change="handlePageSizeChange"
|
|
590
544
|
@current-change="handleCurrPageChange"
|
|
@@ -611,7 +565,7 @@ interface IProps {
|
|
|
611
565
|
dataList: ITableDataItem[];
|
|
612
566
|
/** 列配置 */
|
|
613
567
|
columnConfig: IColumnConfig[];
|
|
614
|
-
/** 是否展示展开行 */
|
|
568
|
+
/** 是否展示展开行 */
|
|
615
569
|
hasExpandRow?: boolean;
|
|
616
570
|
/** 是否展示序号 */
|
|
617
571
|
hasIndexColumn?: boolean;
|
|
@@ -631,16 +585,6 @@ interface IProps {
|
|
|
631
585
|
dragSemiRange?: number;
|
|
632
586
|
/** 是否显示加载 */
|
|
633
587
|
loading?: boolean;
|
|
634
|
-
/** 是否隐藏显示设置按钮 */
|
|
635
|
-
hideViewSettingBtn?: boolean
|
|
636
|
-
/** 设置的缓存的key */
|
|
637
|
-
settingStorgeKey?: string
|
|
638
|
-
/** 前端排序,默认关闭 */
|
|
639
|
-
localSort?: boolean
|
|
640
|
-
/** 前端过滤,默认关闭 */
|
|
641
|
-
localFilter?: boolean
|
|
642
|
-
/** 页码 */
|
|
643
|
-
currentPage: number
|
|
644
588
|
}
|
|
645
589
|
|
|
646
590
|
interface IEmits {
|
|
@@ -662,10 +606,6 @@ interface IEmits {
|
|
|
662
606
|
(e: 'row-edit-cancel', param: { row: any; page: number; size: number;}): void
|
|
663
607
|
/** 页码改变 */
|
|
664
608
|
(e: 'page-change', param: { page: number, size: number }): void
|
|
665
|
-
/** 查询 */
|
|
666
|
-
(e: 'search', param: Record<string, any>): void
|
|
667
|
-
/** 排序 */
|
|
668
|
-
(e: 'sort-change', param: { order: 'descending' | 'ascending' | null, prop: string }): void
|
|
669
609
|
}
|
|
670
610
|
|
|
671
611
|
const props = withDefaults(defineProps<IProps>(), {
|
|
@@ -680,12 +620,7 @@ const props = withDefaults(defineProps<IProps>(), {
|
|
|
680
620
|
colorList: () => [],
|
|
681
621
|
leftFixedCount: 1,
|
|
682
622
|
dragSemiRange: 15,
|
|
683
|
-
loading: false
|
|
684
|
-
hideViewSettingBtn: false,
|
|
685
|
-
settingStorgeKey: '',
|
|
686
|
-
localSort: false,
|
|
687
|
-
localFilter: false,
|
|
688
|
-
currentPage: 1,
|
|
623
|
+
loading: false
|
|
689
624
|
})
|
|
690
625
|
|
|
691
626
|
// 同defineProps一样,不支持泛型参数从外部导入
|
|
@@ -705,14 +640,16 @@ const actualColumns = computed(() => {
|
|
|
705
640
|
isColumnSortable: rawItem.sortable,
|
|
706
641
|
sortable: inSorting.value ? rawItem.sortable : false
|
|
707
642
|
};
|
|
708
|
-
if (
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
643
|
+
if (item) {
|
|
644
|
+
if (cnt > 0) {
|
|
645
|
+
item.fixed = 'left';
|
|
646
|
+
// eslint-disable-next-line no-plusplus
|
|
647
|
+
cnt--;
|
|
648
|
+
} else {
|
|
649
|
+
item.fixed = undefined;
|
|
650
|
+
}
|
|
651
|
+
res.push(item);
|
|
714
652
|
}
|
|
715
|
-
res.push(item);
|
|
716
653
|
}
|
|
717
654
|
|
|
718
655
|
// 使用默认操作项,添加默认操作列。该列在编辑模式下隐藏
|
|
@@ -738,8 +675,9 @@ const beforePageChange = () => {
|
|
|
738
675
|
}
|
|
739
676
|
const {
|
|
740
677
|
pageSize,
|
|
678
|
+
currentPage,
|
|
741
679
|
handleCurrPageChange,
|
|
742
|
-
handlePageSizeChange
|
|
680
|
+
handlePageSizeChange
|
|
743
681
|
} = usePagination({
|
|
744
682
|
emit,
|
|
745
683
|
beforePageChange
|
|
@@ -779,7 +717,7 @@ const {
|
|
|
779
717
|
emit,
|
|
780
718
|
tableDomRef,
|
|
781
719
|
pageSize,
|
|
782
|
-
|
|
720
|
+
currentPage,
|
|
783
721
|
hasExpandRow: props.hasExpandRow
|
|
784
722
|
})
|
|
785
723
|
|
|
@@ -789,8 +727,6 @@ const {
|
|
|
789
727
|
columnsToBeShown,
|
|
790
728
|
viewSettingVisible,
|
|
791
729
|
leftFixedColumnCount,
|
|
792
|
-
tempLeftFixedColumnCount,
|
|
793
|
-
handleInputTempLeftFixedColumnCount,
|
|
794
730
|
handleViewSettingShow,
|
|
795
731
|
handleViewSettingClose,
|
|
796
732
|
handleViewSettingConfirm
|
|
@@ -803,9 +739,6 @@ const {
|
|
|
803
739
|
|
|
804
740
|
/************ 列头部操作相关 ************ */
|
|
805
741
|
const {
|
|
806
|
-
setSort,
|
|
807
|
-
clearSort,
|
|
808
|
-
setSearchParams,
|
|
809
742
|
isColumnHeadActive,
|
|
810
743
|
handleSort,
|
|
811
744
|
handleHeaderPopoverShow,
|
|
@@ -823,13 +756,11 @@ const {
|
|
|
823
756
|
sortingColumn,
|
|
824
757
|
isColumnFiltering,
|
|
825
758
|
searchValue,
|
|
826
|
-
inSorting
|
|
759
|
+
inSorting
|
|
827
760
|
} = useColumnHeaderOperation({
|
|
828
761
|
tableDomRef,
|
|
829
762
|
sortFilterPopoverRef,
|
|
830
|
-
props
|
|
831
|
-
emit,
|
|
832
|
-
showingColumns,
|
|
763
|
+
props
|
|
833
764
|
})
|
|
834
765
|
|
|
835
766
|
/************ 表格行拖拽和显示设置列拖拽 ************ */
|
|
@@ -856,6 +787,7 @@ useDragSort({
|
|
|
856
787
|
props,
|
|
857
788
|
viewSettingDragSortOptions,
|
|
858
789
|
beforeDragStart,
|
|
790
|
+
currentPage,
|
|
859
791
|
pageSize,
|
|
860
792
|
currScope,
|
|
861
793
|
tableDomRef,
|
|
@@ -866,10 +798,18 @@ const doTableLayout = async () => {
|
|
|
866
798
|
tableDomRef.value?.doLayout();
|
|
867
799
|
}
|
|
868
800
|
|
|
801
|
+
watch(
|
|
802
|
+
() => props.columnConfig,
|
|
803
|
+
(val) => {
|
|
804
|
+
showingColumns.value = val.map(c => c.prop);
|
|
805
|
+
},
|
|
806
|
+
{ immediate: true }
|
|
807
|
+
)
|
|
808
|
+
|
|
869
809
|
// 过滤出自定义属性,将其它属性全部透传给 el-table-column
|
|
870
810
|
const getColumnBindProps = (column: IColumnConfig) => {
|
|
871
811
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
872
|
-
const { editAble, editType, slotName, inputType, options,
|
|
812
|
+
const { editAble, editType, slotName, inputType, options, ...rest } = column;
|
|
873
813
|
return rest;
|
|
874
814
|
}
|
|
875
815
|
|
|
@@ -892,20 +832,7 @@ const handleColumnClose = (item) => {
|
|
|
892
832
|
|
|
893
833
|
defineExpose({
|
|
894
834
|
closeAllExpandedRows,
|
|
895
|
-
|
|
896
|
-
elTableRef: tableDomRef,
|
|
897
|
-
setSort,
|
|
898
|
-
clearSort,
|
|
899
|
-
setSearchParams,
|
|
900
|
-
})
|
|
901
|
-
|
|
902
|
-
// loading 结束和页码变化时滚动到顶部
|
|
903
|
-
watch([
|
|
904
|
-
() => props.loading,
|
|
905
|
-
() => props.currentPage,
|
|
906
|
-
], ([loading]) => {
|
|
907
|
-
if (loading) return;
|
|
908
|
-
tableDomRef.value.$el.querySelector('.el-table__body-wrapper').scrollTop = 0
|
|
835
|
+
elTableRef: tableDomRef
|
|
909
836
|
})
|
|
910
837
|
|
|
911
838
|
</script>
|
|
@@ -11,40 +11,24 @@ export interface IColumnConfigRequired {
|
|
|
11
11
|
sortable?: boolean; // 该列是否允许排序,ture则表头弹窗会显示升降序按钮
|
|
12
12
|
slotName?: string; // 如果要自定义,传入 slotName
|
|
13
13
|
isAlwaysShow?: boolean; // 不可隐藏,显示设置中,该列不允许隐藏
|
|
14
|
-
|
|
15
|
-
defaultHide?: boolean;
|
|
16
|
-
/** 列是否允许搜索,true则表头弹窗会多一个搜索框,一列中有多个搜索字段时传数组进行配置 */
|
|
17
|
-
search?: boolean | ISearchOptions
|
|
14
|
+
isColumnSearchAble?: boolean; // 列是否允许搜索,true则表头弹窗会多一个搜索框
|
|
18
15
|
summary?: boolean; // 是否可以显示该列的统计
|
|
19
16
|
summaryMethod?: (values: any[]) => string | number; // 这一列的统计方法,values为该列的所有值
|
|
20
|
-
|
|
21
|
-
filters?: {
|
|
22
|
-
type?: 'checkbox' | 'radio',
|
|
23
|
-
options: FiltersOption[]
|
|
24
|
-
default?: string | number | string[] | number[]
|
|
25
|
-
} | FiltersOption[]
|
|
17
|
+
// filters?: {value: string | number; text: string; [key: string]: any}[];
|
|
26
18
|
// 透传el-table column有的属性, https://element.eleme.cn/#/en-US/component/table#table-column-attributes
|
|
27
19
|
[key: string]: any;
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
type FiltersOption = { value: string | number; text: string; [key: string]: any }
|
|
31
|
-
|
|
32
|
-
type ISearchOptions = {
|
|
33
|
-
prop: string,
|
|
34
|
-
label: string,
|
|
35
|
-
validator?: (value: string) => boolean
|
|
36
|
-
}[]
|
|
37
|
-
|
|
38
22
|
type IInputColumn = IColumnConfigRequired & {
|
|
39
23
|
inputType: string | number;
|
|
40
24
|
}
|
|
41
25
|
|
|
42
26
|
type ISelectColumn = IColumnConfigRequired & {
|
|
43
|
-
options: {
|
|
27
|
+
options: {key: string; value: string | number; [key: string]: any}[];
|
|
44
28
|
}
|
|
45
29
|
|
|
46
|
-
type IDateOnlyColumn = IColumnConfigRequired
|
|
47
|
-
type IDateTimeColumn = IColumnConfigRequired
|
|
30
|
+
type IDateOnlyColumn = IColumnConfigRequired & {}
|
|
31
|
+
type IDateTimeColumn = IColumnConfigRequired & {}
|
|
48
32
|
|
|
49
33
|
export type IColumnConfig = IInputColumn | ISelectColumn | IDateOnlyColumn | IDateTimeColumn
|
|
50
34
|
|
|
@@ -95,22 +79,16 @@ export interface IProps {
|
|
|
95
79
|
leftFixedCount?: number;
|
|
96
80
|
dragSemiRange?: number;
|
|
97
81
|
loading?: boolean;
|
|
98
|
-
settingStorgeKey?: string
|
|
99
|
-
localSort?: boolean
|
|
100
|
-
localFilter?: boolean
|
|
101
|
-
currentPage: number
|
|
102
82
|
}
|
|
103
83
|
|
|
104
84
|
export interface IEmits {
|
|
105
85
|
(e: 'selection-change', selection: any): void
|
|
106
|
-
(e: 'row-bg-change', param: {
|
|
107
|
-
(e: 'row-drag-drop', param: { row: any; fromIndex: number; toIndex: number; page: number; size: number;
|
|
86
|
+
(e: 'row-bg-change', param: {colorId: number; row: ITableDataItem; rowIndex: number}): void
|
|
87
|
+
(e: 'row-drag-drop', param: { row: any; fromIndex: number; toIndex: number; page: number; size: number;}): void
|
|
108
88
|
(e: 'row-delete', param: { row: any; index: number; page: number; size: number; }): void
|
|
109
|
-
(e: 'row-edit', param: { row: any, index: number; page: number; size: number;
|
|
110
|
-
(e: 'row-pin-to-top', param: { row: any, rawIndex: number; page: number; size: number;
|
|
89
|
+
(e: 'row-edit', param: { row: any, index: number; page: number; size: number;}): void
|
|
90
|
+
(e: 'row-pin-to-top', param: { row: any, rawIndex: number; page: number; size: number;}): void
|
|
111
91
|
(e: 'row-edit-save', param: { page: number; size: number; row: any; changedData: Record<string, any>; }): void
|
|
112
|
-
(e: 'row-edit-cancel', param: { row: any; page: number; size: number;
|
|
92
|
+
(e: 'row-edit-cancel', param: { row: any; page: number; size: number;}): void
|
|
113
93
|
(e: 'page-change', param: { page: number, size: number }): void
|
|
114
|
-
(e: 'search', param: Record<string, any>): void
|
|
115
|
-
(e: 'sort-change', param: { order: 'descending' | 'ascending' | null, prop: string }): void
|
|
116
94
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { computed, ref, watch, nextTick
|
|
2
|
-
import { IColumnConfig,
|
|
1
|
+
import { computed, ref, watch, nextTick } from "vue"
|
|
2
|
+
import { IColumnConfig, IProps } from './types';
|
|
3
3
|
|
|
4
4
|
interface IUseColumnHeaderOperationParams {
|
|
5
5
|
props: IProps
|
|
6
6
|
tableDomRef: any
|
|
7
7
|
sortFilterPopoverRef: any
|
|
8
|
-
emit: IEmits;
|
|
9
|
-
showingColumns: Ref<string[]>
|
|
10
8
|
}
|
|
11
9
|
|
|
12
|
-
export default function useColumnHeaderOperation({
|
|
10
|
+
export default function useColumnHeaderOperation({props, tableDomRef, sortFilterPopoverRef}: IUseColumnHeaderOperationParams) {
|
|
13
11
|
|
|
14
12
|
// column如果有sortable属性,点击列头部,会直接触发排序,为了在弹窗点确定时再触发排序,需要阻止点击立即排序
|
|
15
13
|
// 所以,初始渲染时,将sortable设置为false,在触发排序逻辑时再设置成真实的值,再利用el-table自身的排序逻辑触发排序
|
|
@@ -24,8 +22,8 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
24
22
|
const tempSortingColumn = ref<IColumnConfig | null>(null);
|
|
25
23
|
|
|
26
24
|
// 生效中的过滤配置 和 临时过滤配置
|
|
27
|
-
const filteredValue = ref<Record<string, string
|
|
28
|
-
const tempFilteredValue = ref<Record<string, string
|
|
25
|
+
const filteredValue = ref<Record<string, string[]>>({});
|
|
26
|
+
const tempFilteredValue = ref<Record<string, string[]>>({});
|
|
29
27
|
|
|
30
28
|
// 生效中的统计配置 和 临时统计配置
|
|
31
29
|
const tempSummaryList = ref<string[]>([]);
|
|
@@ -35,17 +33,14 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
35
33
|
const searchValue = ref<Record<string, string>>({});
|
|
36
34
|
const tempSearchValue = ref<Record<string, string>>({});
|
|
37
35
|
|
|
38
|
-
const isColumnFiltering = computed(() => Object.keys(tempFilteredValue.value).some(k =>
|
|
39
|
-
if (!Array.isArray(tempFilteredValue.value[k])) return tempFilteredValue.value[k]
|
|
40
|
-
return tempFilteredValue.value[k]?.length;
|
|
41
|
-
}));
|
|
36
|
+
const isColumnFiltering = computed(() => Object.keys(tempFilteredValue.value).some(k => tempFilteredValue.value[k]?.length));
|
|
42
37
|
|
|
43
|
-
const showColumnHeadSortIcon = (column: IColumnConfig) => column.filters || column.isColumnSortable || column.
|
|
38
|
+
const showColumnHeadSortIcon = (column: IColumnConfig) => column.filters || column.isColumnSortable || column.isColumnSearchAble || column.summary;
|
|
44
39
|
|
|
45
40
|
watch(
|
|
46
41
|
() => props.columnConfig,
|
|
47
42
|
(val) => {
|
|
48
|
-
filteredValue.value = val.reduce((prev, curr) => ({
|
|
43
|
+
filteredValue.value = val.reduce((prev, curr) => ({...prev, [curr.prop]: []}), {});
|
|
49
44
|
tempFilteredValue.value = { ...filteredValue.value };
|
|
50
45
|
},
|
|
51
46
|
{ immediate: true }
|
|
@@ -68,24 +63,14 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
68
63
|
sums[index] = summaryMethod(values);
|
|
69
64
|
}
|
|
70
65
|
})
|
|
71
|
-
|
|
66
|
+
|
|
72
67
|
return sums
|
|
73
68
|
}
|
|
74
69
|
|
|
75
70
|
const isColumnHeadActive = (column: IColumnConfig) => {
|
|
76
|
-
return
|
|
77
|
-
column.filters && (Array.isArray(column.filters)
|
|
78
|
-
? (filteredValue.value[column.prop] as any[]).length
|
|
79
|
-
: column.filters.type === 'radio'
|
|
80
|
-
? filteredValue.value[column.prop]
|
|
81
|
-
: (filteredValue.value[column.prop] as any[]).length)
|
|
82
|
-
) ||
|
|
83
|
-
(
|
|
84
|
-
column.search
|
|
85
|
-
? Array.isArray(column.search) && column.search?.some(v => searchValue.value[v.prop])
|
|
86
|
-
: searchValue.value[column.prop]
|
|
87
|
-
) ||
|
|
71
|
+
return filteredValue.value[column.prop]?.length ||
|
|
88
72
|
sortingColumn.value?.prop === column.prop ||
|
|
73
|
+
searchValue.value[column.prop] ||
|
|
89
74
|
summaryList.value.includes(column.prop);
|
|
90
75
|
}
|
|
91
76
|
|
|
@@ -97,7 +82,7 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
97
82
|
tempSortType.value = sortType.value;
|
|
98
83
|
tempSortingColumn.value = sortingColumn.value ? { ...sortingColumn.value } as IColumnConfig : null;
|
|
99
84
|
// 临时合计项设置成实际的合计项
|
|
100
|
-
tempSummaryList.value = [...summaryList.value];
|
|
85
|
+
tempSummaryList.value = [ ...summaryList.value ];
|
|
101
86
|
}
|
|
102
87
|
|
|
103
88
|
const closeSortAndFilterPopover = (exceptProp?: string) => {
|
|
@@ -113,81 +98,21 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
113
98
|
tempSortingColumn.value = column;
|
|
114
99
|
}
|
|
115
100
|
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
obj[column.prop] = column
|
|
120
|
-
})
|
|
121
|
-
return obj
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
const emitSearch = () => {
|
|
125
|
-
const params: Record<string, any> = {};
|
|
126
|
-
// 仅提交显示的列的相关数据
|
|
127
|
-
showingColumns.value.forEach(prop => {
|
|
128
|
-
const column = columnMap.value[prop]
|
|
129
|
-
if (column.filters) {
|
|
130
|
-
params[prop] = filteredValue.value[prop]
|
|
131
|
-
}
|
|
132
|
-
if (column.search) {
|
|
133
|
-
if (Array.isArray(column.search)) {
|
|
134
|
-
column.search.forEach(v => {
|
|
135
|
-
params[v.prop] = searchValue.value[v.prop]
|
|
136
|
-
})
|
|
137
|
-
} else {
|
|
138
|
-
params[prop] = searchValue.value[prop]
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
Object.keys(params).forEach(key => {
|
|
144
|
-
if (params[key] === undefined) delete params[key]
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
emit('search', params);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const handleHeaderOperationConfirm = async (column: IColumnConfig, scope) => {
|
|
151
|
-
if (column.search) {
|
|
152
|
-
// 校验
|
|
153
|
-
if (Array.isArray(column.search)) {
|
|
154
|
-
let validate = true;
|
|
155
|
-
column.search.forEach(v => {
|
|
156
|
-
if (!tempSearchValue.value[v.prop]) tempSearchValue.value[v.prop] = ''
|
|
157
|
-
if (!validate) return
|
|
158
|
-
if (v.validator) {
|
|
159
|
-
const result = v.validator(tempSearchValue.value[v.prop]);
|
|
160
|
-
if (validate && !result) validate = false;
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
// 校验未通过
|
|
164
|
-
if (!validate) return
|
|
165
|
-
} else {
|
|
166
|
-
if (!tempSearchValue.value[column.prop]) tempSearchValue.value[column.prop] = ''
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
summaryList.value = [...tempSummaryList.value];
|
|
171
|
-
sortingColumn.value = tempSortingColumn.value ? { ...tempSortingColumn.value } : null;
|
|
101
|
+
const handleHeaderOperationConfirm = async (scope) => {
|
|
102
|
+
summaryList.value = [ ...tempSummaryList.value ];
|
|
103
|
+
sortingColumn.value = tempSortingColumn.value ? {...tempSortingColumn.value} : null;
|
|
172
104
|
sortType.value = tempSortType.value;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
tableDomRef.value?.sort(sortingColumn.value.prop, sortType.value);
|
|
180
|
-
inSorting.value = false
|
|
181
|
-
} else {
|
|
182
|
-
emit('sort-change', { order: sortType.value, prop: sortingColumn.value.prop });
|
|
183
|
-
}
|
|
105
|
+
if (sortingColumn.value) {
|
|
106
|
+
// 恢复列配置的sortable属性,只有列配置的sortable为true,才能用下面的sort方法
|
|
107
|
+
inSorting.value = true;
|
|
108
|
+
await nextTick();
|
|
109
|
+
tableDomRef.value?.sort(sortingColumn.value.prop, sortType.value);
|
|
110
|
+
inSorting.value = false
|
|
184
111
|
}
|
|
185
112
|
|
|
186
113
|
filteredValue.value = { ...tempFilteredValue.value };
|
|
187
114
|
searchValue.value = { ...tempSearchValue.value };
|
|
188
115
|
|
|
189
|
-
emitSearch();
|
|
190
|
-
|
|
191
116
|
filterColumns(scope.store);
|
|
192
117
|
|
|
193
118
|
closeSortAndFilterPopover();
|
|
@@ -195,52 +120,18 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
195
120
|
tableDomRef.value?.doLayout();
|
|
196
121
|
}
|
|
197
122
|
|
|
198
|
-
const
|
|
199
|
-
sortingColumn.value = null;
|
|
200
|
-
sortType.value = null;
|
|
201
|
-
if (props.localSort) { // 前端过滤
|
|
202
|
-
tableDomRef.value?.clearSort();
|
|
203
|
-
} else { // 接口过滤
|
|
204
|
-
emit('sort-change', { order: null, prop: '' });
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const setSort = (params: { order: 'ascending' | 'descending', prop: string }) => {
|
|
209
|
-
const column = props.columnConfig.find(c => c.prop === params.prop);
|
|
210
|
-
if (column) {
|
|
211
|
-
sortingColumn.value = column;
|
|
212
|
-
sortType.value = params.order;
|
|
213
|
-
if (props.localSort) {
|
|
214
|
-
tableDomRef.value?.sort(params.prop, params.order);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const handleHeaderOperationReset = async (column: IColumnConfig, scope) => {
|
|
123
|
+
const handleHeaderOperationReset = async (column, scope) => {
|
|
220
124
|
if (sortingColumn.value && sortingColumn.value.prop === column.prop) {
|
|
221
|
-
clearSort();
|
|
125
|
+
tableDomRef.value?.clearSort();
|
|
126
|
+
sortingColumn.value = null;
|
|
127
|
+
sortType.value = null;
|
|
222
128
|
}
|
|
223
129
|
|
|
224
130
|
// 合计
|
|
225
131
|
summaryList.value = summaryList.value.filter(item => item !== column.prop);
|
|
226
132
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
? []
|
|
230
|
-
: column.filters.default ?? []
|
|
231
|
-
}
|
|
232
|
-
if (column.search) {
|
|
233
|
-
if (!Array.isArray(column.search)) {
|
|
234
|
-
searchValue.value[column.prop] = '';
|
|
235
|
-
} else {
|
|
236
|
-
column.search.forEach(v => {
|
|
237
|
-
searchValue.value[v.prop] = '';
|
|
238
|
-
})
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
emitSearch();
|
|
243
|
-
|
|
133
|
+
filteredValue.value[column.prop] = [];
|
|
134
|
+
searchValue.value[column.prop] = '';
|
|
244
135
|
filterColumns(scope.store);
|
|
245
136
|
|
|
246
137
|
closeSortAndFilterPopover();
|
|
@@ -249,7 +140,6 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
249
140
|
}
|
|
250
141
|
|
|
251
142
|
const filterColumns = (store) => {
|
|
252
|
-
if (!props.localFilter) return
|
|
253
143
|
store.states.columns.forEach(column => {
|
|
254
144
|
if (filteredValue.value[column.property]) {
|
|
255
145
|
store.commit('filterChange', {
|
|
@@ -275,35 +165,7 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
275
165
|
store.states.data = data;
|
|
276
166
|
}
|
|
277
167
|
|
|
278
|
-
const setSearchParams = (params: Record<string, any>) => {
|
|
279
|
-
const _searchValue = {};
|
|
280
|
-
const _filteredValue = {};
|
|
281
|
-
|
|
282
|
-
// 设置搜索和过滤参数时,如果使用 showingColumns 遍历,会导致通过外部设置未显示的列的搜索和过滤参数丢失
|
|
283
|
-
props.columnConfig.forEach(column => {
|
|
284
|
-
if (column.search) {
|
|
285
|
-
if (Array.isArray(column.search)) {
|
|
286
|
-
column.search.forEach(v => {
|
|
287
|
-
_searchValue[v.prop] = params[v.prop];
|
|
288
|
-
});
|
|
289
|
-
} else {
|
|
290
|
-
_searchValue[column.prop] = params[column.prop] ?? '';
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if (column.filters) {
|
|
294
|
-
const value = params[column.prop] ?? (Array.isArray(column.filters) ? [] : column.filters.default);
|
|
295
|
-
_filteredValue[column.prop] = value;
|
|
296
|
-
}
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
searchValue.value = { ...searchValue.value, ..._searchValue }
|
|
300
|
-
filteredValue.value = { ...filteredValue.value, ..._filteredValue }
|
|
301
|
-
}
|
|
302
|
-
|
|
303
168
|
return {
|
|
304
|
-
setSort,
|
|
305
|
-
clearSort,
|
|
306
|
-
setSearchParams,
|
|
307
169
|
isColumnHeadActive,
|
|
308
170
|
handleHeaderPopoverShow,
|
|
309
171
|
handleSort,
|
|
@@ -321,6 +183,6 @@ export default function useColumnHeaderOperation({ props, tableDomRef, sortFilte
|
|
|
321
183
|
sortingColumn,
|
|
322
184
|
isColumnFiltering,
|
|
323
185
|
searchValue,
|
|
324
|
-
inSorting
|
|
186
|
+
inSorting
|
|
325
187
|
}
|
|
326
188
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Ref, ref } from "vue"
|
|
2
|
-
import { IEmits
|
|
2
|
+
import { IEmits } from "./types"
|
|
3
3
|
|
|
4
4
|
interface IParams {
|
|
5
5
|
emit: IEmits;
|
|
6
6
|
pageSize: Ref<number>;
|
|
7
|
-
|
|
7
|
+
currentPage: Ref<number>;
|
|
8
8
|
tableDomRef: Ref<any>;
|
|
9
9
|
hasExpandRow: boolean
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default function useDefaultOperation({
|
|
12
|
+
export default function useDefaultOperation({emit, pageSize, currentPage, tableDomRef, hasExpandRow}: IParams) {
|
|
13
13
|
const operationPopoverRef = ref<any>(null);
|
|
14
14
|
const editingRowData = ref<Record<string, any>>({});
|
|
15
15
|
const editingRowIndex = ref<number>(-1);
|
|
@@ -18,7 +18,7 @@ export default function useDefaultOperation({ emit, pageSize, props, tableDomRef
|
|
|
18
18
|
emit('row-delete', {
|
|
19
19
|
row,
|
|
20
20
|
index,
|
|
21
|
-
page:
|
|
21
|
+
page: currentPage.value,
|
|
22
22
|
size: pageSize.value
|
|
23
23
|
})
|
|
24
24
|
closeOperationPopover();
|
|
@@ -39,9 +39,9 @@ export default function useDefaultOperation({ emit, pageSize, props, tableDomRef
|
|
|
39
39
|
// 折叠所有展开的行
|
|
40
40
|
closeAllExpandedRows();
|
|
41
41
|
const { row, $index: index } = scope;
|
|
42
|
-
editingRowData.value = {
|
|
42
|
+
editingRowData.value = {...row};
|
|
43
43
|
editingRowIndex.value = index;
|
|
44
|
-
emit('row-edit', { row, index, page:
|
|
44
|
+
emit('row-edit', { row, index, page: currentPage.value, size: pageSize.value});
|
|
45
45
|
closeOperationPopover();
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -52,9 +52,9 @@ export default function useDefaultOperation({ emit, pageSize, props, tableDomRef
|
|
|
52
52
|
...dataList.slice(0, index),
|
|
53
53
|
...dataList.slice(index + 1)
|
|
54
54
|
];
|
|
55
|
-
newList.unshift({
|
|
55
|
+
newList.unshift({...row, isPinned: true});
|
|
56
56
|
store.states.data = newList;
|
|
57
|
-
emit('row-pin-to-top', { row, rawIndex: index, page:
|
|
57
|
+
emit('row-pin-to-top', { row, rawIndex: index, page: currentPage.value, size: pageSize.value});
|
|
58
58
|
closeOperationPopover();
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -68,7 +68,7 @@ export default function useDefaultOperation({ emit, pageSize, props, tableDomRef
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
emit('row-edit-save', {
|
|
71
|
-
page:
|
|
71
|
+
page: currentPage.value,
|
|
72
72
|
size: pageSize.value,
|
|
73
73
|
row,
|
|
74
74
|
changedData
|
|
@@ -79,7 +79,7 @@ export default function useDefaultOperation({ emit, pageSize, props, tableDomRef
|
|
|
79
79
|
const handleEditCancel = (row) => {
|
|
80
80
|
editingRowIndex.value = -1;
|
|
81
81
|
editingRowData.value = {};
|
|
82
|
-
emit('row-edit-cancel', { row, page:
|
|
82
|
+
emit('row-edit-cancel', { row, page: currentPage.value, size: pageSize.value});
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
return {
|
|
@@ -8,10 +8,11 @@ interface IUseDragSortParams {
|
|
|
8
8
|
viewSettingDragSortOptions: Ref<IColumnConfig[]>
|
|
9
9
|
beforeDragStart: () => boolean
|
|
10
10
|
currScope: Ref<any>
|
|
11
|
+
currentPage: Ref<number>
|
|
11
12
|
pageSize: Ref<number>
|
|
12
13
|
tableDomRef: Ref<any>
|
|
13
14
|
}
|
|
14
|
-
export default function useDragSort({
|
|
15
|
+
export default function useDragSort({props, emit, viewSettingDragSortOptions, currentPage, pageSize, beforeDragStart, currScope, tableDomRef }: IUseDragSortParams) {
|
|
15
16
|
|
|
16
17
|
const draggingData = ref<IDraggingData>({}); // 拖拽相关数据
|
|
17
18
|
const isMouseDown = ref(false);
|
|
@@ -20,7 +21,7 @@ export default function useDragSort({ props, emit, viewSettingDragSortOptions, p
|
|
|
20
21
|
const isOperating = ref(false);
|
|
21
22
|
|
|
22
23
|
onMounted(() => {
|
|
23
|
-
tableDomRef.value.$el.addEventListener('mousedown', () => {
|
|
24
|
+
tableDomRef.value.$el.addEventListener('mousedown', () => {isOperating.value = true});
|
|
24
25
|
document.addEventListener('mousedown', handleDocumentMouseDown);
|
|
25
26
|
document.addEventListener('mousemove', handleDocumentMouseMove);
|
|
26
27
|
document.addEventListener('mouseup', handleDocumentMouseUp);
|
|
@@ -200,7 +201,7 @@ export default function useDragSort({ props, emit, viewSettingDragSortOptions, p
|
|
|
200
201
|
row: movedRow,
|
|
201
202
|
fromIndex: draggingIndex,
|
|
202
203
|
toIndex: dropIndex,
|
|
203
|
-
page:
|
|
204
|
+
page: currentPage.value,
|
|
204
205
|
size: pageSize.value
|
|
205
206
|
});
|
|
206
207
|
// 清理工作
|
|
@@ -209,7 +210,7 @@ export default function useDragSort({ props, emit, viewSettingDragSortOptions, p
|
|
|
209
210
|
|
|
210
211
|
const handleViewSettingDragMouseDown = (event, index) => {
|
|
211
212
|
const rowDoms = [...document.getElementsByClassName('view-setting-draggable-item')]
|
|
212
|
-
.reduce((pre, item, index) => ({
|
|
213
|
+
.reduce((pre, item, index) => ({...pre, [index]: [item]}), {});
|
|
213
214
|
draggingData.value.isDragging = true;
|
|
214
215
|
draggingData.value.rowDoms = rowDoms;
|
|
215
216
|
draggingData.value.draggingIndex = +index;
|
|
@@ -6,26 +6,29 @@ interface IParams {
|
|
|
6
6
|
beforePageChange: () => void
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export default function usePagination({
|
|
9
|
+
export default function usePagination({emit, beforePageChange}: IParams) {
|
|
10
10
|
|
|
11
11
|
const pageSize = ref(10);
|
|
12
|
+
const currentPage = ref(1);
|
|
12
13
|
|
|
13
14
|
const handlePageSizeChange = (size: number) => {
|
|
14
15
|
pageSize.value = size;
|
|
16
|
+
currentPage.value = 1;
|
|
15
17
|
// searchValue.value = {};
|
|
16
18
|
beforePageChange();
|
|
17
|
-
emit('page-change', {
|
|
19
|
+
emit('page-change', {size, page: currentPage.value});
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
const handleCurrPageChange = (curr: number) => {
|
|
21
23
|
// searchValue.value = {};
|
|
22
24
|
beforePageChange();
|
|
23
|
-
emit('page-change', {
|
|
25
|
+
emit('page-change', {size: pageSize.value, page: curr});
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
return {
|
|
27
29
|
pageSize,
|
|
30
|
+
currentPage,
|
|
28
31
|
handlePageSizeChange,
|
|
29
|
-
handleCurrPageChange
|
|
32
|
+
handleCurrPageChange
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -6,7 +6,7 @@ interface IUseRowBgColorParams {
|
|
|
6
6
|
emit: IEmits;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export default function useRowBgColor({
|
|
9
|
+
export default function useRowBgColor({colorList, emit}: IUseRowBgColorParams) {
|
|
10
10
|
const colorPopoverRef = ref<any>(null);
|
|
11
11
|
|
|
12
12
|
const isDefaultColor = (id: number) => {
|
|
@@ -31,11 +31,11 @@ export default function useRowBgColor({ colorList, emit }: IUseRowBgColorParams)
|
|
|
31
31
|
const handleColorChange = async (colorId: number, scope) => {
|
|
32
32
|
const { row, $index: rowIndex, store } = scope;
|
|
33
33
|
const dataList = store.states.data;
|
|
34
|
-
const curRow = {
|
|
34
|
+
const curRow = {...dataList[rowIndex], colorId: +colorId};
|
|
35
35
|
const newList = [...dataList];
|
|
36
36
|
newList.splice(rowIndex, 1, curRow);
|
|
37
37
|
store.states.data = newList;
|
|
38
|
-
emit('row-bg-change', {
|
|
38
|
+
emit('row-bg-change', {colorId, row, rowIndex});
|
|
39
39
|
await nextTick();
|
|
40
40
|
// TODO: 为什么不是数组?为什么关闭弹窗不生效了?
|
|
41
41
|
colorPopoverRef.value?.doClose();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, nextTick, watch, ComputedRef, Ref, onMounted
|
|
1
|
+
import { ref, nextTick, watch, ComputedRef, Ref, onMounted } from "vue"
|
|
2
2
|
import { IColumnConfig, IProps } from "./types"
|
|
3
3
|
|
|
4
4
|
interface IViewSettingParams {
|
|
@@ -13,53 +13,12 @@ export default function useViewSetting({ tableDomRef, showingColumns, actualColu
|
|
|
13
13
|
const columnsToBeShown = ref<string[]>([]); // 显示设置弹窗中勾选的列
|
|
14
14
|
const viewSettingVisible = ref(false);
|
|
15
15
|
const leftFixedColumnCount = ref(0);
|
|
16
|
-
const tempLeftFixedColumnCount = ref(0);
|
|
17
|
-
|
|
18
|
-
const storageKey = computed(() => `@lx-frontend/wrap-element-ui/table_setting_cloumns/${props.settingStorgeKey || (location.pathname === '/' ? location.hash : location.pathname)}`);
|
|
19
|
-
|
|
20
|
-
const saveSettingToStorge = () => localStorage.setItem(storageKey.value, JSON.stringify({
|
|
21
|
-
showingColumns: showingColumns.value,
|
|
22
|
-
leftFixedColumnCount: leftFixedColumnCount.value
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
watch(
|
|
26
|
-
() => props.columnConfig,
|
|
27
|
-
(val) => {
|
|
28
|
-
const _keys = new Set(props.columnConfig.map(c => (c.prop)));
|
|
29
|
-
const _cache = localStorage.getItem(storageKey.value);
|
|
30
|
-
const setColumns = () => (showingColumns.value = val.filter(v => !v.defaultHide).map(c => c.prop));
|
|
31
|
-
if (!_cache) {
|
|
32
|
-
setColumns();
|
|
33
|
-
leftFixedColumnCount.value = props.leftFixedCount as number;
|
|
34
|
-
} else {
|
|
35
|
-
try {
|
|
36
|
-
// 缓存数据字段可能随着更新导致对不上,清理无效数据,防止出问题
|
|
37
|
-
const cache = JSON.parse(_cache);
|
|
38
|
-
if (!cache.showingColumns || !Array.isArray(cache.showingColumns)) {
|
|
39
|
-
setColumns();
|
|
40
|
-
} else {
|
|
41
|
-
showingColumns.value = cache.showingColumns.filter(key => _keys.has(key));
|
|
42
|
-
}
|
|
43
|
-
const _leftFixedColumnCount = Number(cache?.leftFixedColumnCount)
|
|
44
|
-
leftFixedColumnCount.value = isNaN(_leftFixedColumnCount) ? (props.leftFixedCount as number) : _leftFixedColumnCount;
|
|
45
|
-
// 写入清理后的数据
|
|
46
|
-
saveSettingToStorge();
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error(error);
|
|
49
|
-
localStorage.removeItem(storageKey.value);
|
|
50
|
-
setColumns();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{ immediate: true }
|
|
55
|
-
)
|
|
56
16
|
|
|
57
17
|
watch(
|
|
58
18
|
() => columnsToBeShown.value,
|
|
59
19
|
(val) => {
|
|
60
20
|
viewSettingDragSortOptions.value = props.columnConfig
|
|
61
21
|
.filter(c => val.includes(c.prop));
|
|
62
|
-
if (tempLeftFixedColumnCount.value > val.length) tempLeftFixedColumnCount.value = val.length
|
|
63
22
|
},
|
|
64
23
|
{ immediate: true }
|
|
65
24
|
)
|
|
@@ -80,7 +39,6 @@ export default function useViewSetting({ tableDomRef, showingColumns, actualColu
|
|
|
80
39
|
const handleViewSettingShow = () => {
|
|
81
40
|
viewSettingDragSortOptions.value = actualColumns.value
|
|
82
41
|
.filter(c => columnsToBeShown.value.includes(c.prop));
|
|
83
|
-
tempLeftFixedColumnCount.value = leftFixedColumnCount.value;
|
|
84
42
|
viewSettingVisible.value = true;
|
|
85
43
|
}
|
|
86
44
|
|
|
@@ -93,25 +51,15 @@ export default function useViewSetting({ tableDomRef, showingColumns, actualColu
|
|
|
93
51
|
const handleViewSettingConfirm = async () => {
|
|
94
52
|
viewSettingVisible.value = false;
|
|
95
53
|
showingColumns.value = viewSettingDragSortOptions.value.map(c => c.prop);
|
|
96
|
-
leftFixedColumnCount.value = tempLeftFixedColumnCount.value;
|
|
97
|
-
saveSettingToStorge()
|
|
98
54
|
await nextTick();
|
|
99
55
|
tableDomRef.value?.doLayout();
|
|
100
56
|
}
|
|
101
57
|
|
|
102
|
-
const handleInputTempLeftFixedColumnCount = (value: string) => {
|
|
103
|
-
const _value = Number(value)
|
|
104
|
-
if (isNaN(_value)) return
|
|
105
|
-
tempLeftFixedColumnCount.value = Math.max(0, Math.min(columnsToBeShown.value.length, Math.floor(_value)))
|
|
106
|
-
}
|
|
107
|
-
|
|
108
58
|
return {
|
|
109
59
|
viewSettingDragSortOptions,
|
|
110
60
|
columnsToBeShown,
|
|
111
61
|
viewSettingVisible,
|
|
112
62
|
leftFixedColumnCount,
|
|
113
|
-
tempLeftFixedColumnCount,
|
|
114
|
-
handleInputTempLeftFixedColumnCount,
|
|
115
63
|
handleViewSettingShow,
|
|
116
64
|
handleViewSettingClose,
|
|
117
65
|
handleViewSettingConfirm
|