wkjp-list-page 1.0.16 → 1.0.17
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/README.md +2 -1
- package/package.json +1 -1
- package/src/components/CommonListPage.vue +125 -12
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ deviceListApi(params) {
|
|
|
89
89
|
**情况:** 运营想自定义表头、列太多想藏起来。
|
|
90
90
|
**默认:** **`columns` 达到 10 列及以上**(可用 **`column-config-auto-min`** 改阈值)时,表格最右侧自动出现 **表头设置** 齿轮;悬停齿轮显示 **「配置字段」** 提示(可用 **`column-config-tooltip`** 修改)。
|
|
91
91
|
**可选:** `:enable-column-config="true"` 强制开启;`:enable-column-config="false"` 强制关闭。
|
|
92
|
-
**作用:** 弹层内可 **搜索字段**、**显示/未显示**
|
|
92
|
+
**作用:** 弹层内可 **搜索字段**、**显示/未显示** 分组、开关显隐、拖拽排序;**复选框列(`type: selection`)不出现在设置里**且表格始终保留;**固定列**左侧显示「固定」且不可拖不可关。点 **确认** 后才会作用到表格并触发 **`columns-change`**,点 **取消** / 关闭 / 再次点齿轮则放弃本次修改。
|
|
93
93
|
|
|
94
94
|
### 2.2 不想要「查询」按钮,或想改按钮上的字
|
|
95
95
|
|
|
@@ -280,6 +280,7 @@ deviceListTransformList(list) {
|
|
|
280
280
|
| `columnConfigTooltip` | `配置字段` | 表头设置齿轮图标悬停提示文案。 |
|
|
281
281
|
| `columnConfigConfirmText` | `确认` | 表头设置弹层确认按钮文案。 |
|
|
282
282
|
| `columnConfigCancelText` | `取消` | 表头设置弹层取消按钮文案。 |
|
|
283
|
+
| `columnConfigFixedText` | `固定` | 固定列在拖拽图标位显示的文案。 |
|
|
283
284
|
| `columnConfigTitle` | `表头设置` | 表头设置弹层标题。 |
|
|
284
285
|
| `columnConfigSearchPlaceholder` | `搜索添加更多字段` | 表头设置内搜索框占位。 |
|
|
285
286
|
| `showExport` | `false` | 为 `true` 且提供 `exportApi` 时,在搜索区右侧显示内置 **`exportFile`** 导出按钮。 |
|
package/package.json
CHANGED
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
</el-form>
|
|
101
101
|
|
|
102
102
|
<el-table
|
|
103
|
+
ref="listTable"
|
|
103
104
|
:data="innerTableData"
|
|
104
105
|
v-loading="innerLoading"
|
|
105
106
|
v-bind="tableAttrs"
|
|
@@ -165,9 +166,9 @@
|
|
|
165
166
|
:append-to-body="true"
|
|
166
167
|
:popper-options="columnConfigPopperOptions"
|
|
167
168
|
popper-class="common-list-page-column-config-popper"
|
|
168
|
-
@show="
|
|
169
|
+
@show="handleColumnConfigShow"
|
|
169
170
|
>
|
|
170
|
-
<div class="column-config-panel">
|
|
171
|
+
<div class="column-config-panel" :style="columnConfigPanelStyle">
|
|
171
172
|
<div class="column-config-panel__head">
|
|
172
173
|
<span class="column-config-panel__title">{{ columnConfigTitle }}</span>
|
|
173
174
|
<i class="el-icon-close column-config-panel__close" @click="cancelColumnConfig"></i>
|
|
@@ -195,9 +196,13 @@
|
|
|
195
196
|
'column-config-panel__item--drag-over': dragOverIndex === idx
|
|
196
197
|
}"
|
|
197
198
|
>
|
|
199
|
+
<span
|
|
200
|
+
v-if="isFixedColumn(configColumns[idx])"
|
|
201
|
+
class="column-config-panel__fixed-tag"
|
|
202
|
+
>{{ columnConfigFixedText }}</span>
|
|
198
203
|
<i
|
|
204
|
+
v-else
|
|
199
205
|
class="column-config-panel__drag el-icon-rank"
|
|
200
|
-
:class="{ 'is-disabled': !canDragConfigIndex(idx) }"
|
|
201
206
|
@mousedown.prevent="onDragMouseDown(idx)"
|
|
202
207
|
></i>
|
|
203
208
|
<span class="column-config-panel__label">{{ columnConfigLabel(configColumns[idx]) }}</span>
|
|
@@ -311,6 +316,8 @@ export default {
|
|
|
311
316
|
columnConfigTooltip: { type: String, default: "配置字段" },
|
|
312
317
|
columnConfigConfirmText: { type: String, default: "确认" },
|
|
313
318
|
columnConfigCancelText: { type: String, default: "取消" },
|
|
319
|
+
/** 表头设置中固定列在拖拽位显示的文案 */
|
|
320
|
+
columnConfigFixedText: { type: String, default: "固定" },
|
|
314
321
|
/** 表头设置弹层标题 */
|
|
315
322
|
columnConfigTitle: { type: String, default: "表头设置" },
|
|
316
323
|
/** 表头设置内搜索框占位 */
|
|
@@ -371,6 +378,7 @@ export default {
|
|
|
371
378
|
columnConfigKeyword: "",
|
|
372
379
|
dragFromIndex: -1,
|
|
373
380
|
dragOverIndex: -1,
|
|
381
|
+
columnConfigPanelMaxHeight: null,
|
|
374
382
|
configColumns: [],
|
|
375
383
|
appliedColumns: [],
|
|
376
384
|
/** 进入页时 filters 的快照,用于「清除查询」 */
|
|
@@ -392,12 +400,17 @@ export default {
|
|
|
392
400
|
},
|
|
393
401
|
visibleColumns() {
|
|
394
402
|
const source = this.showColumnConfig ? this.appliedColumns : this.columns;
|
|
395
|
-
return source.filter((item) =>
|
|
403
|
+
return source.filter((item) => {
|
|
404
|
+
if (!item) return false;
|
|
405
|
+
if (item.type === "selection") return true;
|
|
406
|
+
return item.hidden !== true && item._visible !== false;
|
|
407
|
+
});
|
|
396
408
|
},
|
|
397
409
|
visibleConfigIndexes() {
|
|
398
410
|
const indexes = [];
|
|
399
411
|
for (let i = 0; i < this.configColumns.length; i++) {
|
|
400
412
|
const col = this.configColumns[i];
|
|
413
|
+
if (!this.isConfigPanelColumn(col)) continue;
|
|
401
414
|
if (col._visible !== false && this.matchesColumnConfigSearch(col)) indexes.push(i);
|
|
402
415
|
}
|
|
403
416
|
return indexes;
|
|
@@ -406,12 +419,21 @@ export default {
|
|
|
406
419
|
const indexes = [];
|
|
407
420
|
for (let i = 0; i < this.configColumns.length; i++) {
|
|
408
421
|
const col = this.configColumns[i];
|
|
422
|
+
if (!this.isConfigPanelColumn(col)) continue;
|
|
409
423
|
if (col._visible === false && this.matchesColumnConfigSearch(col)) indexes.push(i);
|
|
410
424
|
}
|
|
411
425
|
return indexes;
|
|
412
426
|
},
|
|
413
427
|
columnConfigPopperOptions() {
|
|
414
|
-
return {
|
|
428
|
+
return {
|
|
429
|
+
boundariesElement: "body",
|
|
430
|
+
gpuAcceleration: false,
|
|
431
|
+
positionFixed: true
|
|
432
|
+
};
|
|
433
|
+
},
|
|
434
|
+
columnConfigPanelStyle() {
|
|
435
|
+
if (!this.columnConfigPanelMaxHeight) return {};
|
|
436
|
+
return { maxHeight: this.columnConfigPanelMaxHeight + "px" };
|
|
415
437
|
},
|
|
416
438
|
columnConfigSearchActive() {
|
|
417
439
|
return String(this.columnConfigKeyword || "").trim() !== "";
|
|
@@ -557,6 +579,7 @@ export default {
|
|
|
557
579
|
},
|
|
558
580
|
beforeDestroy() {
|
|
559
581
|
this.removeColumnDragListeners();
|
|
582
|
+
this.unbindColumnConfigResize();
|
|
560
583
|
},
|
|
561
584
|
methods: {
|
|
562
585
|
forwardSelectionChange(selection) {
|
|
@@ -565,6 +588,10 @@ export default {
|
|
|
565
588
|
isBuiltinCellColumn(col) {
|
|
566
589
|
return col && ["selection", "index", "expand"].indexOf(col.type) !== -1;
|
|
567
590
|
},
|
|
591
|
+
/** 复选框列不参与表头设置 */
|
|
592
|
+
isConfigPanelColumn(col) {
|
|
593
|
+
return col && col.type !== "selection";
|
|
594
|
+
},
|
|
568
595
|
tableColumnBind(col) {
|
|
569
596
|
var omit = ["valueGetter", "textFormatter", "defaultText", "emptyText", "hidden", "_visible", "_configKey"];
|
|
570
597
|
var rest = {};
|
|
@@ -842,7 +869,7 @@ export default {
|
|
|
842
869
|
const mapped = cols.map((col, index) =>
|
|
843
870
|
Object.assign({}, col, {
|
|
844
871
|
_configKey: this.buildConfigKey(col, index),
|
|
845
|
-
_visible: col.hidden !== true
|
|
872
|
+
_visible: col.type === "selection" ? true : col.hidden !== true
|
|
846
873
|
})
|
|
847
874
|
);
|
|
848
875
|
const sorted = this.sortConfigColumns(mapped);
|
|
@@ -863,7 +890,8 @@ export default {
|
|
|
863
890
|
return this.sortConfigColumns(
|
|
864
891
|
(source || []).map((col) =>
|
|
865
892
|
Object.assign({}, col, {
|
|
866
|
-
_visible:
|
|
893
|
+
_visible:
|
|
894
|
+
col.type === "selection" ? true : col._visible !== false && col.hidden !== true
|
|
867
895
|
})
|
|
868
896
|
)
|
|
869
897
|
);
|
|
@@ -873,10 +901,26 @@ export default {
|
|
|
873
901
|
this.columnConfigKeyword = "";
|
|
874
902
|
this.dragFromIndex = -1;
|
|
875
903
|
this.dragOverIndex = -1;
|
|
904
|
+
this.columnConfigPanelMaxHeight = null;
|
|
876
905
|
this.removeColumnDragListeners();
|
|
906
|
+
this.unbindColumnConfigResize();
|
|
877
907
|
const pop = this.$refs.columnConfigPopover;
|
|
878
908
|
if (pop && typeof pop.doClose === "function") pop.doClose();
|
|
879
909
|
},
|
|
910
|
+
bindColumnConfigResize() {
|
|
911
|
+
if (this._columnConfigResizeHandler || typeof window === "undefined") return;
|
|
912
|
+
this._columnConfigResizeHandler = () => {
|
|
913
|
+
if (this.columnConfigVisible) this.applyColumnConfigPopoverPosition();
|
|
914
|
+
};
|
|
915
|
+
window.addEventListener("resize", this._columnConfigResizeHandler);
|
|
916
|
+
window.addEventListener("scroll", this._columnConfigResizeHandler, true);
|
|
917
|
+
},
|
|
918
|
+
unbindColumnConfigResize() {
|
|
919
|
+
if (!this._columnConfigResizeHandler || typeof window === "undefined") return;
|
|
920
|
+
window.removeEventListener("resize", this._columnConfigResizeHandler);
|
|
921
|
+
window.removeEventListener("scroll", this._columnConfigResizeHandler, true);
|
|
922
|
+
this._columnConfigResizeHandler = null;
|
|
923
|
+
},
|
|
880
924
|
toggleColumnConfig() {
|
|
881
925
|
if (this.columnConfigVisible) {
|
|
882
926
|
this.cancelColumnConfig();
|
|
@@ -886,6 +930,12 @@ export default {
|
|
|
886
930
|
this.columnConfigVisible = true;
|
|
887
931
|
const pop = this.$refs.columnConfigPopover;
|
|
888
932
|
if (pop && typeof pop.doShow === "function") pop.doShow();
|
|
933
|
+
this.alignColumnConfigPopover();
|
|
934
|
+
},
|
|
935
|
+
handleColumnConfigShow() {
|
|
936
|
+
this.onColumnConfigShow();
|
|
937
|
+
this.alignColumnConfigPopover();
|
|
938
|
+
this.bindColumnConfigResize();
|
|
889
939
|
},
|
|
890
940
|
onColumnConfigShow() {
|
|
891
941
|
this.columnConfigKeyword = "";
|
|
@@ -893,6 +943,55 @@ export default {
|
|
|
893
943
|
this.dragOverIndex = -1;
|
|
894
944
|
this.configColumns = this.cloneConfigColumnsFrom(this.appliedColumns);
|
|
895
945
|
},
|
|
946
|
+
/** 弹层右缘与表格右缘对齐 */
|
|
947
|
+
alignColumnConfigPopover() {
|
|
948
|
+
const apply = () => this.applyColumnConfigPopoverPosition();
|
|
949
|
+
this.$nextTick(() => {
|
|
950
|
+
apply();
|
|
951
|
+
if (typeof window !== "undefined" && window.requestAnimationFrame) {
|
|
952
|
+
window.requestAnimationFrame(apply);
|
|
953
|
+
} else {
|
|
954
|
+
this.$nextTick(apply);
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
},
|
|
958
|
+
getTableHeaderAnchorRect(tableEl) {
|
|
959
|
+
if (!tableEl) return null;
|
|
960
|
+
const header =
|
|
961
|
+
tableEl.querySelector(".el-table__header-wrapper") ||
|
|
962
|
+
tableEl.querySelector(".el-table__header");
|
|
963
|
+
if (header) return header.getBoundingClientRect();
|
|
964
|
+
return tableEl.getBoundingClientRect();
|
|
965
|
+
},
|
|
966
|
+
applyColumnConfigPopoverPosition() {
|
|
967
|
+
const pop = this.$refs.columnConfigPopover;
|
|
968
|
+
const table = this.$refs.listTable;
|
|
969
|
+
if (!pop || !table || !table.$el) return;
|
|
970
|
+
const popper = pop.popperElm;
|
|
971
|
+
if (!popper) return;
|
|
972
|
+
const anchor = this.getTableHeaderAnchorRect(table.$el);
|
|
973
|
+
if (!anchor) return;
|
|
974
|
+
const viewportH =
|
|
975
|
+
(typeof window !== "undefined" && window.innerHeight) ||
|
|
976
|
+
(document.documentElement && document.documentElement.clientHeight) ||
|
|
977
|
+
0;
|
|
978
|
+
const viewportPadding = 12;
|
|
979
|
+
const popperPadV = 24;
|
|
980
|
+
const maxPopperHeight = Math.max(160, viewportH - anchor.bottom - viewportPadding);
|
|
981
|
+
const popperWidth = popper.offsetWidth || 320;
|
|
982
|
+
const left = Math.max(8, anchor.right - popperWidth);
|
|
983
|
+
this.columnConfigPanelMaxHeight = Math.max(120, maxPopperHeight - popperPadV);
|
|
984
|
+
popper.style.position = "fixed";
|
|
985
|
+
popper.style.left = left + "px";
|
|
986
|
+
popper.style.top = anchor.bottom + "px";
|
|
987
|
+
popper.style.right = "auto";
|
|
988
|
+
popper.style.bottom = "auto";
|
|
989
|
+
popper.style.margin = "0";
|
|
990
|
+
popper.style.transform = "none";
|
|
991
|
+
popper.style.maxHeight = maxPopperHeight + "px";
|
|
992
|
+
popper.style.overflow = "hidden";
|
|
993
|
+
popper.style.boxSizing = "border-box";
|
|
994
|
+
},
|
|
896
995
|
cancelColumnConfig() {
|
|
897
996
|
this.configColumns = this.cloneConfigColumnsFrom(this.appliedColumns);
|
|
898
997
|
this.closeColumnConfigPopover();
|
|
@@ -962,7 +1061,8 @@ export default {
|
|
|
962
1061
|
applyColumnConfig() {
|
|
963
1062
|
this.appliedColumns = this.configColumns.map((col) =>
|
|
964
1063
|
Object.assign({}, col, {
|
|
965
|
-
|
|
1064
|
+
_visible: col.type === "selection" ? true : col._visible !== false,
|
|
1065
|
+
hidden: col.type === "selection" ? false : col._visible === false
|
|
966
1066
|
})
|
|
967
1067
|
);
|
|
968
1068
|
this.$emit("columns-change", this.appliedColumns);
|
|
@@ -1401,7 +1501,8 @@ export default {
|
|
|
1401
1501
|
display: flex;
|
|
1402
1502
|
flex-direction: column;
|
|
1403
1503
|
box-sizing: border-box;
|
|
1404
|
-
|
|
1504
|
+
min-height: 0;
|
|
1505
|
+
overflow: hidden;
|
|
1405
1506
|
}
|
|
1406
1507
|
|
|
1407
1508
|
.column-config-panel__body {
|
|
@@ -1414,6 +1515,7 @@ export default {
|
|
|
1414
1515
|
|
|
1415
1516
|
.column-config-panel__head {
|
|
1416
1517
|
display: flex;
|
|
1518
|
+
flex-shrink: 0;
|
|
1417
1519
|
align-items: center;
|
|
1418
1520
|
justify-content: space-between;
|
|
1419
1521
|
margin-bottom: 12px;
|
|
@@ -1436,6 +1538,7 @@ export default {
|
|
|
1436
1538
|
}
|
|
1437
1539
|
|
|
1438
1540
|
.column-config-panel__search {
|
|
1541
|
+
flex-shrink: 0;
|
|
1439
1542
|
margin-bottom: 12px;
|
|
1440
1543
|
}
|
|
1441
1544
|
|
|
@@ -1495,11 +1598,20 @@ export default {
|
|
|
1495
1598
|
cursor: grabbing;
|
|
1496
1599
|
}
|
|
1497
1600
|
|
|
1498
|
-
.column-config-panel__drag.is-disabled,
|
|
1499
1601
|
.column-config-panel__drag--placeholder {
|
|
1500
1602
|
visibility: hidden;
|
|
1501
1603
|
}
|
|
1502
1604
|
|
|
1605
|
+
.column-config-panel__fixed-tag {
|
|
1606
|
+
flex-shrink: 0;
|
|
1607
|
+
width: 28px;
|
|
1608
|
+
font-size: 12px;
|
|
1609
|
+
line-height: 1;
|
|
1610
|
+
color: #909399;
|
|
1611
|
+
text-align: center;
|
|
1612
|
+
user-select: none;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1503
1615
|
.column-config-panel__label {
|
|
1504
1616
|
flex: 1;
|
|
1505
1617
|
min-width: 0;
|
|
@@ -1533,8 +1645,9 @@ export default {
|
|
|
1533
1645
|
padding: 12px 14px !important;
|
|
1534
1646
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12) !important;
|
|
1535
1647
|
z-index: 3000 !important;
|
|
1536
|
-
|
|
1537
|
-
|
|
1648
|
+
overflow: hidden !important;
|
|
1649
|
+
margin: 0 !important;
|
|
1650
|
+
box-sizing: border-box !important;
|
|
1538
1651
|
}
|
|
1539
1652
|
|
|
1540
1653
|
.common-list-page-column-config-popper .el-switch {
|