vue-super-crud 1.7.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/.browserslistrc +3 -0
- package/.versionrc.json +36 -0
- package/CHANGELOG.md +232 -0
- package/LICENSE +201 -0
- package/README.md +46 -0
- package/babel.config.js +12 -0
- package/build/alias.js +10 -0
- package/build/build.js +52 -0
- package/build/config.js +70 -0
- package/deploy.bat +14 -0
- package/docs/.vuepress/components/button/base.vue +88 -0
- package/docs/.vuepress/components/common/code-format.vue +331 -0
- package/docs/.vuepress/components/commonConfig/presetCodeTemplate/base.vue +68 -0
- package/docs/.vuepress/components/commonConfig/presetCodeTemplate/customParams.vue +73 -0
- package/docs/.vuepress/components/commonConfig/renderType/component.vue +160 -0
- package/docs/.vuepress/components/commonConfig/renderType/formatter.vue +49 -0
- package/docs/.vuepress/components/commonConfig/renderType/render.vue +91 -0
- package/docs/.vuepress/components/commonConfig/renderType/slot.vue +63 -0
- package/docs/.vuepress/components/crud/baseUse/baseUse.vue +98 -0
- package/docs/.vuepress/components/crud/baseUse/columnAction.vue +72 -0
- package/docs/.vuepress/components/crud/baseUse/columnWidth.vue +107 -0
- package/docs/.vuepress/components/crud/baseUse/handleRow.vue +65 -0
- package/docs/.vuepress/components/crud/baseUse/height.vue +82 -0
- package/docs/.vuepress/components/crud/baseUse/index.vue +54 -0
- package/docs/.vuepress/components/crud/baseUse/loading.vue +70 -0
- package/docs/.vuepress/components/crud/baseUse/pagination.vue +108 -0
- package/docs/.vuepress/components/crud/baseUse/selection.vue +114 -0
- package/docs/.vuepress/components/crud/baseUse/summaryMethod.vue +118 -0
- package/docs/.vuepress/components/crud/baseUse/title.vue +54 -0
- package/docs/.vuepress/components/crud/baseUse/toolbar.vue +69 -0
- package/docs/.vuepress/components/crud/buttons/common.vue +115 -0
- package/docs/.vuepress/components/crud/buttons/fast.vue +82 -0
- package/docs/.vuepress/components/crud/contextMenu/base.vue +72 -0
- package/docs/.vuepress/components/crud/copy.vue +52 -0
- package/docs/.vuepress/components/crud/crudEvents/api.vue +157 -0
- package/docs/.vuepress/components/crud/crudEvents/deleteTip.vue +93 -0
- package/docs/.vuepress/components/crud/crudEvents/events.vue +188 -0
- package/docs/.vuepress/components/crud/dataSort/base.vue +142 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/base.vue +53 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/dynamicAndFixed.vue +111 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/treeDynamic.vue +68 -0
- package/docs/.vuepress/components/crud/handleBar/handleRow.vue +65 -0
- package/docs/.vuepress/components/crud/handleBar/toolbar.vue +69 -0
- package/docs/.vuepress/components/crud/renderType/1.vue +57 -0
- package/docs/.vuepress/components/crud/renderType/2.vue +63 -0
- package/docs/.vuepress/components/crud/renderType/3.vue +105 -0
- package/docs/.vuepress/components/crud/renderType/5.vue +91 -0
- package/docs/.vuepress/components/crud/search/1.vue +90 -0
- package/docs/.vuepress/components/crud/search/2.vue +78 -0
- package/docs/.vuepress/components/crud/search/3.vue +107 -0
- package/docs/.vuepress/components/crud/search/base.vue +123 -0
- package/docs/.vuepress/components/crud/search/localSearch.vue +124 -0
- package/docs/.vuepress/components/crud/search/special.vue +148 -0
- package/docs/.vuepress/components/crud/selection/events.vue +47 -0
- package/docs/.vuepress/components/crud/selection/pagination.vue +94 -0
- package/docs/.vuepress/components/crud/selection/singleSelection.vue +64 -0
- package/docs/.vuepress/components/crud/span/base.vue +69 -0
- package/docs/.vuepress/components/crud/span/special.vue +75 -0
- package/docs/.vuepress/components/crud/summary/base.vue +99 -0
- package/docs/.vuepress/components/crud/tableEdit/addDeleteBtn.vue +174 -0
- package/docs/.vuepress/components/crud/tableEdit/cellEdit.vue +194 -0
- package/docs/.vuepress/components/crud/tableEdit/controlEdit.vue +219 -0
- package/docs/.vuepress/components/crud/tableEdit/dialog.vue +172 -0
- package/docs/.vuepress/components/crud/tableEdit/free.vue +88 -0
- package/docs/.vuepress/components/crud/tableEdit/freeColumn.vue +82 -0
- package/docs/.vuepress/components/crud/tableEdit/methods.vue +154 -0
- package/docs/.vuepress/components/crud/tableEdit/rowAction.vue +107 -0
- package/docs/.vuepress/components/crud/tableEdit/rowBatch.vue +116 -0
- package/docs/.vuepress/components/crud/tableEdit/rowClick.vue +98 -0
- package/docs/.vuepress/components/crud/validate/base.vue +122 -0
- package/docs/.vuepress/components/crud/validate/custom.vue +82 -0
- package/docs/.vuepress/components/crud/validate/regulars.vue +88 -0
- package/docs/.vuepress/components/crud/validate/relation.vue +91 -0
- package/docs/.vuepress/components/crud/validate/tree.vue +82 -0
- package/docs/.vuepress/components/dialog/baseUse/base.vue +92 -0
- package/docs/.vuepress/components/dialog/baseUse/beforeConfirm.vue +78 -0
- package/docs/.vuepress/components/dialog/baseUse/control.vue +79 -0
- package/docs/.vuepress/components/dialog/baseUse/drawer.vue +59 -0
- package/docs/.vuepress/components/dialog/baseUse/footer.vue +87 -0
- package/docs/.vuepress/components/dialog/baseUse/insertSlot.vue +79 -0
- package/docs/.vuepress/components/dict/DictLinkage.vue +91 -0
- package/docs/.vuepress/components/dict/baseUse.vue +72 -0
- package/docs/.vuepress/components/dict/component.vue +82 -0
- package/docs/.vuepress/components/dict/localDict.vue +68 -0
- package/docs/.vuepress/components/form/baseUse/base.vue +48 -0
- package/docs/.vuepress/components/form/baseUse/dataFormat.vue +92 -0
- package/docs/.vuepress/components/form/baseUse/deep.vue +57 -0
- package/docs/.vuepress/components/form/baseUse/gridLayout.vue +47 -0
- package/docs/.vuepress/components/form/baseUse/group.vue +66 -0
- package/docs/.vuepress/components/form/baseUse/hidden.vue +40 -0
- package/docs/.vuepress/components/form/baseUse/inlineLayout.vue +48 -0
- package/docs/.vuepress/components/form/baseUse/label.vue +51 -0
- package/docs/.vuepress/components/form/baseUse/tooltip.vue +40 -0
- package/docs/.vuepress/components/form/baseUse/validate.vue +52 -0
- package/docs/.vuepress/components/form/detail/base.vue +78 -0
- package/docs/.vuepress/components/form/detail/border.vue +90 -0
- package/docs/.vuepress/components/form/detail/singleDetail.vue +72 -0
- package/docs/.vuepress/components/formatData/baseUse.vue +131 -0
- package/docs/.vuepress/components/mock/index.js +347 -0
- package/docs/.vuepress/components/mockData/custom.vue +69 -0
- package/docs/.vuepress/components/mockData/example.vue +290 -0
- package/docs/.vuepress/components/positionSlot/base.vue +24 -0
- package/docs/.vuepress/components/positionSlot/form.vue +71 -0
- package/docs/.vuepress/components/positionSlot/table.vue +85 -0
- package/docs/.vuepress/components/tabs/base.vue +57 -0
- package/docs/.vuepress/components/temp.js +195 -0
- package/docs/.vuepress/config.js +146 -0
- package/docs/.vuepress/enhanceApp.js +142 -0
- package/docs/.vuepress/public/favicon.ico +0 -0
- package/docs/.vuepress/public/super.png +0 -0
- package/docs/.vuepress/styles/index.styl +25 -0
- package/docs/.vuepress/styles/palette.styl +6 -0
- package/docs/README.md +14 -0
- package/docs/guide/button/base.md +31 -0
- package/docs/guide/commonConfig/jsx.md +166 -0
- package/docs/guide/commonConfig/presetCodeTemplate.md +68 -0
- package/docs/guide/commonConfig/renderType.md +181 -0
- package/docs/guide/crud/baseUse.md +120 -0
- package/docs/guide/crud/buttons.md +18 -0
- package/docs/guide/crud/config.md +217 -0
- package/docs/guide/crud/contextMenu.md +18 -0
- package/docs/guide/crud/dataSort.md +66 -0
- package/docs/guide/crud/genDynamicColumns.md +145 -0
- package/docs/guide/crud/handleBar.md +26 -0
- package/docs/guide/crud/renderType.md +4 -0
- package/docs/guide/crud/search.md +150 -0
- package/docs/guide/crud/selection.md +73 -0
- package/docs/guide/crud/span.md +98 -0
- package/docs/guide/crud/summary.md +167 -0
- package/docs/guide/crud/tableEdit.md +377 -0
- package/docs/guide/crud/validate.md +158 -0
- package/docs/guide/dialog/baseUse.md +81 -0
- package/docs/guide/dict/baseUse.md +174 -0
- package/docs/guide/dict/component.md +88 -0
- package/docs/guide/dict/config.md +44 -0
- package/docs/guide/form/baseUse.md +142 -0
- package/docs/guide/form/detail.md +38 -0
- package/docs/guide/formatData/baseUse.md +98 -0
- package/docs/guide/formatData/config.md +142 -0
- package/docs/guide/mockData/base.md +26 -0
- package/docs/guide/positionSlot/base.md +41 -0
- package/docs/guide/question/base.md +44 -0
- package/docs/guide/start/base.md +30 -0
- package/docs/guide/tabs/base.md +63 -0
- package/examples/App.vue +52 -0
- package/examples/Layout/components/AppMain.vue +40 -0
- package/examples/Layout/components/Item.vue +29 -0
- package/examples/Layout/components/Link.vue +44 -0
- package/examples/Layout/components/SidebarItem.vue +93 -0
- package/examples/Layout/index.vue +69 -0
- package/examples/assets/logo.png +0 -0
- package/examples/favicon.ico +0 -0
- package/examples/index.html +18 -0
- package/examples/main.js +54 -0
- package/examples/router/index.js +140 -0
- package/examples/store/index.js +0 -0
- package/examples/styles/index.scss +63 -0
- package/examples/styles/sidebar.scss +226 -0
- package/examples/styles/transition.scss +48 -0
- package/examples/styles/variables.scss +25 -0
- package/examples/views/crud/base.vue +68 -0
- package/examples/views/crud/handleRow.vue +84 -0
- package/examples/views/crud/search.vue +116 -0
- package/examples/views/dashboard/index.vue +244 -0
- package/examples/views/dashboard/index1.vue +234 -0
- package/examples/views/dashboard/test.vue +9 -0
- package/examples/views/formTest/index.vue +168 -0
- package/examples/views/nested/menu1/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-1/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-2/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-2/menu1-2-1/index.vue +5 -0
- package/examples/views/nested/menu1/menu1-2/menu1-2-2/index.vue +5 -0
- package/examples/views/nested/menu1/menu1-3/index.vue +5 -0
- package/examples/views/nested/menu2/index.vue +5 -0
- package/gulpfile.js +84 -0
- package/lib/index.css +1 -0
- package/lib/super-crud.min.js +15 -0
- package/package.json +66 -0
- package/packages/button/index.vue +189 -0
- package/packages/core/components/comp.vue +223 -0
- package/packages/core/components/position.vue +135 -0
- package/packages/core/components/render.vue +460 -0
- package/packages/core/configManager.js +302 -0
- package/packages/core/create.js +8 -0
- package/packages/core/defaultRender.js +64 -0
- package/packages/core/dict/global.js +10 -0
- package/packages/core/dict/index.js +432 -0
- package/packages/core/dict/mixin.js +94 -0
- package/packages/core/event.js +60 -0
- package/packages/core/index.js +6 -0
- package/packages/core/init.js +122 -0
- package/packages/core/mock/genConfig.js +228 -0
- package/packages/core/mock/genData.js +422 -0
- package/packages/core/mock/index.js +4 -0
- package/packages/core/rules.js +111 -0
- package/packages/crud/column.vue +205 -0
- package/packages/crud/columnAction.vue +207 -0
- package/packages/crud/columnCell.vue +146 -0
- package/packages/crud/defaultColumn.vue +130 -0
- package/packages/crud/drawerColumn.vue +225 -0
- package/packages/crud/form.vue +69 -0
- package/packages/crud/index.vue +564 -0
- package/packages/crud/menuBar.vue +298 -0
- package/packages/crud/mixins/cacheHandler.js +36 -0
- package/packages/crud/mixins/calcColumnWidth.js +79 -0
- package/packages/crud/mixins/calcHeight.js +105 -0
- package/packages/crud/mixins/columnHandler.js +128 -0
- package/packages/crud/mixins/contextMenu.js +98 -0
- package/packages/crud/mixins/dataProcessor.js +202 -0
- package/packages/crud/mixins/dialog.js +109 -0
- package/packages/crud/mixins/excelHandler.js +150 -0
- package/packages/crud/mixins/exposeMethods.js +107 -0
- package/packages/crud/mixins/generateDynamicColumns.js +250 -0
- package/packages/crud/mixins/props.js +38 -0
- package/packages/crud/mixins/searchHandler.js +151 -0
- package/packages/crud/mixins/select.js +359 -0
- package/packages/crud/mixins/spanMethod.js +288 -0
- package/packages/crud/mixins/summary.js +177 -0
- package/packages/crud/mixins/tableEdit.js +547 -0
- package/packages/crud/mixins/validate.js +219 -0
- package/packages/crud/pagination.vue +110 -0
- package/packages/crud/search.vue +119 -0
- package/packages/crud/searchHeader.vue +231 -0
- package/packages/crud/selectBanner.vue +138 -0
- package/packages/crud/utils/EditState.js +319 -0
- package/packages/crud/utils/excelExport.js +112 -0
- package/packages/crud/utils/excelImport.js +112 -0
- package/packages/crud/utils/index.js +98 -0
- package/packages/dialog/dialog.js +233 -0
- package/packages/dialog/dialog.vue +15 -0
- package/packages/dialog/index.js +22 -0
- package/packages/dict/cascadeFormat.vue +179 -0
- package/packages/dict/dateFormat.vue +40 -0
- package/packages/dict/form/cascade.vue +61 -0
- package/packages/dict/form/checkbox.vue +90 -0
- package/packages/dict/form/extendMethod.js +22 -0
- package/packages/dict/form/input-base.js +31 -0
- package/packages/dict/form/input.js +20 -0
- package/packages/dict/form/radio.vue +69 -0
- package/packages/dict/form/select.vue +118 -0
- package/packages/dict/form/switch.vue +75 -0
- package/packages/dict/valueFormat.vue +188 -0
- package/packages/directive/dialog/drag.js +86 -0
- package/packages/directive/dialog/dragSize.js +42 -0
- package/packages/directive/index.js +9 -0
- package/packages/directive/insertSlot.js +10 -0
- package/packages/form/contextMenu.js +192 -0
- package/packages/form/draftDrawer.vue +391 -0
- package/packages/form/formAction.vue +97 -0
- package/packages/form/formItem.vue +259 -0
- package/packages/form/index.vue +451 -0
- package/packages/form/props.js +15 -0
- package/packages/grid/cell.vue +65 -0
- package/packages/grid/index.vue +130 -0
- package/packages/group/index.vue +96 -0
- package/packages/tabs/index.vue +290 -0
- package/packages/tooltip/index.js +9 -0
- package/packages/tooltip/tooltip.vue +32 -0
- package/packages/tooltip/tooltipComponent.js +38 -0
- package/packages/verifyInput/index.vue +131 -0
- package/src/config/common.js +88 -0
- package/src/config/crud.js +567 -0
- package/src/config/dialog.js +87 -0
- package/src/config/form.js +215 -0
- package/src/config/index.js +9 -0
- package/src/constants/index.js +72 -0
- package/src/index.js +67 -0
- package/src/template/btn/crud.js +6 -0
- package/src/template/btn/dialog.js +1 -0
- package/src/template/btn/form.js +3 -0
- package/src/template/btn/index.js +9 -0
- package/src/template/dicts.js +1 -0
- package/src/template/formatData.js +507 -0
- package/src/template/index.js +19 -0
- package/src/template/render.js +124 -0
- package/src/template/rules.js +53 -0
- package/src/utils/bem.js +49 -0
- package/src/utils/cache.js +77 -0
- package/src/utils/getType.js +34 -0
- package/src/utils/index.js +212 -0
- package/src/utils/mergeTemp.js +124 -0
- package/styles/button.scss +3 -0
- package/styles/crud.scss +425 -0
- package/styles/dialog.scss +95 -0
- package/styles/form.scss +532 -0
- package/styles/group.scss +78 -0
- package/styles/index.scss +94 -0
- package/styles/tabs.scss +139 -0
- package/styles/verifyInput.scss +56 -0
- package/vue-jsx-sync.js +90 -0
- package/vue.config.js +54 -0
@@ -0,0 +1,359 @@
|
|
1
|
+
import { checkVisibility } from "utils";
|
2
|
+
import { isFunction, merge } from "lodash-es";
|
3
|
+
|
4
|
+
export default {
|
5
|
+
props: {
|
6
|
+
selected: {
|
7
|
+
type: [Object, Array],
|
8
|
+
},
|
9
|
+
},
|
10
|
+
data() {
|
11
|
+
return {
|
12
|
+
singleSelect: null,
|
13
|
+
selectionRow: [],
|
14
|
+
shiftOrAltDown: false,
|
15
|
+
CtrlDown: false,
|
16
|
+
};
|
17
|
+
},
|
18
|
+
mounted() {
|
19
|
+
if (this.selection) {
|
20
|
+
window.addEventListener("keydown", this.keyDown, false);
|
21
|
+
window.addEventListener("keyup", this.keyUp, false);
|
22
|
+
}
|
23
|
+
},
|
24
|
+
beforeDestroy() {
|
25
|
+
window.removeEventListener("keydown", this.keyDown);
|
26
|
+
window.removeEventListener("keyup", this.keyUp);
|
27
|
+
},
|
28
|
+
watch: {
|
29
|
+
// 监听外部传入的选中值变化
|
30
|
+
selected: {
|
31
|
+
handler(newVal, oldVal) {
|
32
|
+
// 是否完全更新数据
|
33
|
+
const isUpdated = newVal !== oldVal;
|
34
|
+
if (isUpdated && this.showSelection) {
|
35
|
+
this.$nextTick(() => {
|
36
|
+
this.updateSelection();
|
37
|
+
});
|
38
|
+
} else if (newVal && this.showSingleSelection) {
|
39
|
+
this.singleSelect = newVal[this.operateKey];
|
40
|
+
}
|
41
|
+
},
|
42
|
+
immediate: true,
|
43
|
+
},
|
44
|
+
},
|
45
|
+
computed: {
|
46
|
+
showSelection() {
|
47
|
+
return checkVisibility(this.crudOptions.selection);
|
48
|
+
},
|
49
|
+
showSingleSelection() {
|
50
|
+
return checkVisibility(this.crudOptions.singleSelection);
|
51
|
+
},
|
52
|
+
selection() {
|
53
|
+
return this.crudOptions.selection;
|
54
|
+
},
|
55
|
+
singleSelection() {
|
56
|
+
return this.crudOptions.singleSelection;
|
57
|
+
},
|
58
|
+
maxSelectionRow() {
|
59
|
+
if (this.selectionRow.length == 0) return null;
|
60
|
+
return this.selectionRow.reduce((start, end) => {
|
61
|
+
return start.$index > end.$index ? start : end;
|
62
|
+
});
|
63
|
+
},
|
64
|
+
minSelectionRow() {
|
65
|
+
if (this.selectionRow.length == 0) return null;
|
66
|
+
return this.selectionRow.reduce((start, end) => {
|
67
|
+
return start.$index < end.$index ? start : end;
|
68
|
+
});
|
69
|
+
},
|
70
|
+
operateKey() {
|
71
|
+
return this.selection.spanProp || this.valueKey;
|
72
|
+
},
|
73
|
+
selectedOperateKeys() {
|
74
|
+
return this.selected.map((item) => item[this.operateKey]);
|
75
|
+
},
|
76
|
+
},
|
77
|
+
methods: {
|
78
|
+
keyDown(event) {
|
79
|
+
let key = event.keyCode;
|
80
|
+
switch (key) {
|
81
|
+
case 17:
|
82
|
+
this.CtrlDown = true;
|
83
|
+
// 改变鼠标样式为指针
|
84
|
+
document.body.style.cursor = "pointer";
|
85
|
+
break;
|
86
|
+
case 16 || 18:
|
87
|
+
this.shiftOrAltDown = true;
|
88
|
+
// 改变鼠标样式为多选
|
89
|
+
document.body.style.cursor = "cell";
|
90
|
+
// 禁止文本选中
|
91
|
+
document.onselectstart = () => false;
|
92
|
+
document.body.style.userSelect = "none";
|
93
|
+
break;
|
94
|
+
case 27:
|
95
|
+
this.EscDown = true;
|
96
|
+
break;
|
97
|
+
}
|
98
|
+
},
|
99
|
+
|
100
|
+
keyUp(event) {
|
101
|
+
let key = event.keyCode;
|
102
|
+
switch (key) {
|
103
|
+
case 17:
|
104
|
+
this.CtrlDown = false;
|
105
|
+
// 恢复默认鼠标样式
|
106
|
+
document.body.style.cursor = "";
|
107
|
+
break;
|
108
|
+
case 16 || 18:
|
109
|
+
this.shiftOrAltDown = false;
|
110
|
+
// 恢复默认鼠标样式
|
111
|
+
document.body.style.cursor = "";
|
112
|
+
// 恢复文本选中
|
113
|
+
document.onselectstart = null;
|
114
|
+
document.body.style.userSelect = "";
|
115
|
+
break;
|
116
|
+
case 27:
|
117
|
+
this.EscDown = false;
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
},
|
121
|
+
rowClassName_({ row, rowIndex, column, columnIndex }) {
|
122
|
+
let rowName = this.crudOptions.rowClassName
|
123
|
+
? this.crudOptions.rowClassName.call(null, {
|
124
|
+
row,
|
125
|
+
column,
|
126
|
+
rowIndex,
|
127
|
+
columnIndex,
|
128
|
+
})
|
129
|
+
: "";
|
130
|
+
// var findRow = this.selectionRow.find((c) => c.$index == row.$index);
|
131
|
+
// if (findRow) {
|
132
|
+
// rowName = "current-row " + rowName;
|
133
|
+
// }
|
134
|
+
return rowName;
|
135
|
+
},
|
136
|
+
selectRowClick(row, column, event) {
|
137
|
+
if (
|
138
|
+
this.showSingleSelection &&
|
139
|
+
this.singleSelection.ctrlSelect !== false &&
|
140
|
+
this.CtrlDown
|
141
|
+
) {
|
142
|
+
if (isFunction(this.singleSelection.selectable)) {
|
143
|
+
const selectable = this.singleSelection.selectable(row, row.$index);
|
144
|
+
if (!selectable) {
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
this.singleSelect = row[this.operateKey];
|
149
|
+
this.$emit("update:selected", row);
|
150
|
+
return;
|
151
|
+
}
|
152
|
+
if (!this.showSelection) return;
|
153
|
+
|
154
|
+
if (!this.selectionSelectable(row, row.$index)) {
|
155
|
+
return;
|
156
|
+
}
|
157
|
+
|
158
|
+
let refsElTable = this.$refs.tableRef;
|
159
|
+
if (this.selection.ctrlSelect !== false && this.CtrlDown) {
|
160
|
+
refsElTable.toggleRowSelection(row);
|
161
|
+
this.select(this.selectionRow, row);
|
162
|
+
return;
|
163
|
+
}
|
164
|
+
|
165
|
+
if (this.selection.shiftSelect !== false && this.shiftOrAltDown) {
|
166
|
+
let maxAndmin = this.getmaxAndminObj(
|
167
|
+
row.$index,
|
168
|
+
this.maxSelectionRow?.$index ?? row.$index,
|
169
|
+
this.minSelectionRow?.$index ?? 0
|
170
|
+
);
|
171
|
+
refsElTable.clearSelection();
|
172
|
+
this.clearSelection();
|
173
|
+
for (let index = maxAndmin.min; index <= maxAndmin.max; index++) {
|
174
|
+
refsElTable.toggleRowSelection(this.list[index], true);
|
175
|
+
}
|
176
|
+
this.select(this.selectionRow, row);
|
177
|
+
this.shiftOrAltDown = false;
|
178
|
+
}
|
179
|
+
},
|
180
|
+
getmaxAndminObj(cur = 0, max, min) {
|
181
|
+
let n = cur,
|
182
|
+
mx = max,
|
183
|
+
mi = min;
|
184
|
+
if (n > mx) {
|
185
|
+
return {
|
186
|
+
min: mi,
|
187
|
+
max: n,
|
188
|
+
};
|
189
|
+
} else if (n < mx && n > mi) {
|
190
|
+
return {
|
191
|
+
min: mi,
|
192
|
+
max: n,
|
193
|
+
};
|
194
|
+
} else if (n < mi) {
|
195
|
+
return {
|
196
|
+
min: n,
|
197
|
+
max: mx,
|
198
|
+
};
|
199
|
+
} else if (n == mi || n == mx) {
|
200
|
+
return {
|
201
|
+
min: mi,
|
202
|
+
max: mx,
|
203
|
+
};
|
204
|
+
}
|
205
|
+
},
|
206
|
+
// 更新选中状态
|
207
|
+
updateSelection() {
|
208
|
+
if (!this.$refs.tableRef) return;
|
209
|
+
|
210
|
+
// this.$refs.tableRef.clearSelection();
|
211
|
+
if (!this.selected?.length) return;
|
212
|
+
|
213
|
+
const updatedSelected = [];
|
214
|
+
this.list.forEach((row, index) => {
|
215
|
+
const selectedIndex = this.selectedOperateKeys.indexOf(
|
216
|
+
row[this.operateKey]
|
217
|
+
);
|
218
|
+
if (selectedIndex > -1) {
|
219
|
+
if (this.crudOptions.dataSyncSelected) {
|
220
|
+
merge(row, this.selected[selectedIndex]);
|
221
|
+
}
|
222
|
+
updatedSelected.push(row);
|
223
|
+
// 同步选中状态
|
224
|
+
this.$refs.tableRef.toggleRowSelection(row, true);
|
225
|
+
}
|
226
|
+
});
|
227
|
+
|
228
|
+
// 保留不在当前页的选中项
|
229
|
+
this.selected.forEach((item) => {
|
230
|
+
const inCurrentPage = this.list.some(
|
231
|
+
(row) => row[this.operateKey] === item[this.operateKey]
|
232
|
+
);
|
233
|
+
if (!inCurrentPage) {
|
234
|
+
updatedSelected.push(item);
|
235
|
+
}
|
236
|
+
});
|
237
|
+
|
238
|
+
// 更新选中数组
|
239
|
+
this.selected.splice(0, this.selected.length, ...updatedSelected);
|
240
|
+
},
|
241
|
+
selectionChange(arr) {
|
242
|
+
this.selectionRow = arr;
|
243
|
+
},
|
244
|
+
select(selection, row) {
|
245
|
+
if (!this.selected) return;
|
246
|
+
if (row[this.operateKey] === undefined) {
|
247
|
+
console.error(
|
248
|
+
`[CRUD Error] row.${this.operateKey}不存在,没有唯一值无法进行选中数据绑定,请设置正确的valueKey`
|
249
|
+
);
|
250
|
+
return;
|
251
|
+
}
|
252
|
+
if (selection.indexOf(row) > -1) {
|
253
|
+
this.addSelection(row);
|
254
|
+
} else {
|
255
|
+
this.removeSelection(row);
|
256
|
+
}
|
257
|
+
},
|
258
|
+
selectAll(selection) {
|
259
|
+
if (!this.selected) return;
|
260
|
+
const isAllSelected = this.$refs.tableRef.store.states.isAllSelected;
|
261
|
+
const currentPageKeys = new Set(
|
262
|
+
this.list.map((item) => item[this.operateKey])
|
263
|
+
);
|
264
|
+
if (isAllSelected) {
|
265
|
+
selection.forEach((row) => {
|
266
|
+
if (this.selected.indexOf(row) === -1) {
|
267
|
+
this.selected.push(row);
|
268
|
+
}
|
269
|
+
});
|
270
|
+
}
|
271
|
+
// 取消全选当前页
|
272
|
+
else {
|
273
|
+
// 只移除当前页的数据
|
274
|
+
for (let i = this.selected.length - 1; i >= 0; i--) {
|
275
|
+
if (currentPageKeys.has(this.selected[i][this.operateKey])) {
|
276
|
+
if (
|
277
|
+
this.selectionSelectable(
|
278
|
+
this.selected[i],
|
279
|
+
this.selected[i].$index
|
280
|
+
)
|
281
|
+
) {
|
282
|
+
this.selected.splice(i, 1);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
}
|
286
|
+
}
|
287
|
+
},
|
288
|
+
addSelection(row) {
|
289
|
+
if (!this.selected) return;
|
290
|
+
if (this.selection.spanProp) {
|
291
|
+
this.removeSelection(row);
|
292
|
+
this.list.forEach((item) => {
|
293
|
+
if (item[this.operateKey] === row[this.operateKey]) {
|
294
|
+
this.selected.push(item);
|
295
|
+
this.$refs.tableRef.toggleRowSelection(item, true);
|
296
|
+
}
|
297
|
+
});
|
298
|
+
} else {
|
299
|
+
if (this.selectedOperateKeys.indexOf(row[this.operateKey]) === -1) {
|
300
|
+
this.selected.push(row);
|
301
|
+
this.$refs.tableRef.toggleRowSelection(row, true);
|
302
|
+
}
|
303
|
+
}
|
304
|
+
},
|
305
|
+
removeSelection(row) {
|
306
|
+
if (!this.selectionSelectable(row, row.$index)) {
|
307
|
+
return;
|
308
|
+
}
|
309
|
+
if (!this.selected) return;
|
310
|
+
if (this.selection.spanProp) {
|
311
|
+
for (let i = this.selected.length - 1; i >= 0; i--) {
|
312
|
+
const item = this.selected[i];
|
313
|
+
if (item[this.operateKey] === row[this.operateKey]) {
|
314
|
+
this.selected.splice(i, 1);
|
315
|
+
this.$refs.tableRef.toggleRowSelection(item, false);
|
316
|
+
}
|
317
|
+
}
|
318
|
+
} else {
|
319
|
+
const index = this.selectedOperateKeys.indexOf(row[this.operateKey]);
|
320
|
+
if (index > -1) {
|
321
|
+
this.selected.splice(index, 1);
|
322
|
+
this.$refs.tableRef.toggleRowSelection(row, false);
|
323
|
+
}
|
324
|
+
}
|
325
|
+
},
|
326
|
+
removeSingleSelection() {
|
327
|
+
this.$emit("update:selected", null);
|
328
|
+
this.singleSelect = null;
|
329
|
+
},
|
330
|
+
clearSelection() {
|
331
|
+
this.$refs.tableRef.clearSelection();
|
332
|
+
this.selectionRow = [];
|
333
|
+
if (!this.selected) return;
|
334
|
+
// 获取禁用的选中数据
|
335
|
+
const disabledSelection = this.selected.filter((item) => {
|
336
|
+
if (!this.selectionSelectable(item, item.$index)) {
|
337
|
+
return true;
|
338
|
+
}
|
339
|
+
});
|
340
|
+
this.selected.splice(0, this.selected.length, ...disabledSelection);
|
341
|
+
|
342
|
+
// 恢复禁用的选中数据
|
343
|
+
if (disabledSelection.length) {
|
344
|
+
disabledSelection.forEach((item) => {
|
345
|
+
this.$refs.tableRef.toggleRowSelection(item, true);
|
346
|
+
});
|
347
|
+
}
|
348
|
+
},
|
349
|
+
selectionSelectable(row, index) {
|
350
|
+
if (isFunction(this.selection.selectable)) {
|
351
|
+
const selectable = this.selection.selectable(row, index);
|
352
|
+
if (!selectable) {
|
353
|
+
return false;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
return true;
|
357
|
+
},
|
358
|
+
},
|
359
|
+
};
|
@@ -0,0 +1,288 @@
|
|
1
|
+
import { isFunction } from "lodash-es";
|
2
|
+
|
3
|
+
export default {
|
4
|
+
computed: {
|
5
|
+
sameRowMap() {
|
6
|
+
const sameRowSpans = Array.from(new Set(this.sameRowSpans));
|
7
|
+
if (!sameRowSpans.length) return {};
|
8
|
+
const map = {};
|
9
|
+
sameRowSpans.forEach((field) => {
|
10
|
+
const groupMap = this.createGroupMap(this.list, field, sameRowSpans);
|
11
|
+
this.addSpanIndex(groupMap);
|
12
|
+
map[field] = groupMap;
|
13
|
+
});
|
14
|
+
return map;
|
15
|
+
},
|
16
|
+
sumColumnList() {
|
17
|
+
return this.trueRenderColumns.filter((item) => item.summary);
|
18
|
+
},
|
19
|
+
showSummary() {
|
20
|
+
return (
|
21
|
+
this.crudOptions.showSummary ||
|
22
|
+
this.crudOptions.showSummary === "" ||
|
23
|
+
this._showSummary ||
|
24
|
+
isFunction(this.crudOptions.summaryMethod)
|
25
|
+
);
|
26
|
+
},
|
27
|
+
},
|
28
|
+
methods: {
|
29
|
+
// 分组排序索引
|
30
|
+
addSpanIndex(groupMap) {
|
31
|
+
if (!groupMap) return;
|
32
|
+
|
33
|
+
// 收集所有分组
|
34
|
+
const allGroups = [];
|
35
|
+
Object.keys(groupMap).forEach((key) => {
|
36
|
+
groupMap[key].forEach((group) => {
|
37
|
+
allGroups.push(group);
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
// 按 firstIndex 排序
|
42
|
+
allGroups.sort((a, b) => a.firstIndex - b.firstIndex);
|
43
|
+
|
44
|
+
// 添加 spanIndex
|
45
|
+
allGroups.forEach((group, index) => {
|
46
|
+
group.spanIndex = index;
|
47
|
+
});
|
48
|
+
},
|
49
|
+
// 多级排序实现
|
50
|
+
_sortedData(data, props) {
|
51
|
+
const sortProps = [
|
52
|
+
...(props || this.crudOptions.sortProps || this.sameRowSpans),
|
53
|
+
];
|
54
|
+
if (!sortProps.length) return;
|
55
|
+
|
56
|
+
// 逐级排序
|
57
|
+
sortProps.forEach((currentProp, index) => {
|
58
|
+
// 获取当前级别之前的所有字段
|
59
|
+
const previousFields = sortProps
|
60
|
+
.slice(0, index)
|
61
|
+
.map((prop) => (typeof prop === "string" ? prop : prop.prop));
|
62
|
+
|
63
|
+
// 获取当前字段
|
64
|
+
const currentField =
|
65
|
+
typeof currentProp === "string" ? currentProp : currentProp.prop;
|
66
|
+
|
67
|
+
// 对数据进行分组排序
|
68
|
+
this.sortByFieldWithinGroups(
|
69
|
+
currentField,
|
70
|
+
previousFields,
|
71
|
+
currentProp,
|
72
|
+
data
|
73
|
+
);
|
74
|
+
});
|
75
|
+
},
|
76
|
+
|
77
|
+
// 在已有分组内进行排序
|
78
|
+
sortByFieldWithinGroups(currentField, previousFields, currentProp, data) {
|
79
|
+
if (!previousFields.length) {
|
80
|
+
// 第一个字段直接排序
|
81
|
+
this.sortByField(currentField, currentProp, data);
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
|
85
|
+
// 根据之前的字段分组
|
86
|
+
const groups = this.groupByFields(data, previousFields);
|
87
|
+
|
88
|
+
// 记录每组的起始索引
|
89
|
+
let currentIndex = 0;
|
90
|
+
|
91
|
+
// 对每个分组内部进行排序并更新原数组
|
92
|
+
Object.values(groups).forEach((group) => {
|
93
|
+
// 对当前组按字段排序
|
94
|
+
group.sort((a, b) =>
|
95
|
+
this.compareValue(
|
96
|
+
a,
|
97
|
+
b,
|
98
|
+
currentField,
|
99
|
+
this.getSortOptions(currentField, currentProp)
|
100
|
+
)
|
101
|
+
);
|
102
|
+
|
103
|
+
// 将排序后的组数据写回原数组
|
104
|
+
group.forEach((item, i) => {
|
105
|
+
data[currentIndex + i] = item;
|
106
|
+
});
|
107
|
+
|
108
|
+
currentIndex += group.length;
|
109
|
+
});
|
110
|
+
},
|
111
|
+
|
112
|
+
// 根据多个字段进行分组
|
113
|
+
groupByFields(data, fields) {
|
114
|
+
return data.reduce((groups, item) => {
|
115
|
+
// 使用所有分组字段的值组合作为key
|
116
|
+
const groupKey = fields.map((field) => item[field]).join("_");
|
117
|
+
if (!groups[groupKey]) {
|
118
|
+
groups[groupKey] = [];
|
119
|
+
}
|
120
|
+
groups[groupKey].push(item);
|
121
|
+
return groups;
|
122
|
+
}, {});
|
123
|
+
},
|
124
|
+
|
125
|
+
// 单字段排序 - 直接修改原数组
|
126
|
+
sortByField(field, propConfig, data) {
|
127
|
+
const sortOptions = this.getSortOptions(field, propConfig);
|
128
|
+
data.sort((a, b) => this.compareValue(a, b, field, sortOptions));
|
129
|
+
},
|
130
|
+
|
131
|
+
// 获取字段的排序选项
|
132
|
+
getSortOptions(field, propConfig) {
|
133
|
+
// 如果传入了配置对象,从中获取排序选项
|
134
|
+
if (typeof propConfig === "object" && propConfig !== null) {
|
135
|
+
return {
|
136
|
+
order: propConfig.order || "asc",
|
137
|
+
nullsPosition: propConfig.nullsPosition || "last",
|
138
|
+
...propConfig,
|
139
|
+
};
|
140
|
+
}
|
141
|
+
},
|
142
|
+
// 通用比较函数
|
143
|
+
compareValue(a, b, field, sortOptions = {}) {
|
144
|
+
// 检查是否有自定义排序
|
145
|
+
const sortMethod = sortOptions.sortMethod;
|
146
|
+
if (sortMethod) {
|
147
|
+
const result = sortMethod(a, b, sortOptions);
|
148
|
+
if (result !== undefined) return result;
|
149
|
+
}
|
150
|
+
|
151
|
+
const { order = "asc", nullsPosition = "last" } = sortOptions;
|
152
|
+
const aValue = a[field];
|
153
|
+
const bValue = b[field];
|
154
|
+
|
155
|
+
// 处理空值
|
156
|
+
const aIsEmpty = aValue === null || aValue === undefined || aValue === "";
|
157
|
+
const bIsEmpty = bValue === null || bValue === undefined || bValue === "";
|
158
|
+
|
159
|
+
if (aIsEmpty && bIsEmpty) return 0;
|
160
|
+
if (aIsEmpty) return nullsPosition === "first" ? -1 : 1;
|
161
|
+
if (bIsEmpty) return nullsPosition === "first" ? 1 : -1;
|
162
|
+
|
163
|
+
// 数字比较
|
164
|
+
if (!isNaN(aValue) && !isNaN(bValue)) {
|
165
|
+
return order === "asc"
|
166
|
+
? Number(aValue) - Number(bValue)
|
167
|
+
: Number(bValue) - Number(aValue);
|
168
|
+
}
|
169
|
+
|
170
|
+
// 字符串比较
|
171
|
+
return order === "asc"
|
172
|
+
? String(aValue).localeCompare(String(bValue))
|
173
|
+
: String(bValue).localeCompare(String(aValue));
|
174
|
+
},
|
175
|
+
spanMethod(params) {
|
176
|
+
const { row, column, rowIndex } = params;
|
177
|
+
const col = column.col;
|
178
|
+
const options = column.options;
|
179
|
+
if (!col && !options) return;
|
180
|
+
|
181
|
+
if (options?.spanMethod) {
|
182
|
+
const result = options.spanMethod(params);
|
183
|
+
if (result) return result;
|
184
|
+
}
|
185
|
+
|
186
|
+
if (col.spanMethod) {
|
187
|
+
return col.spanMethod(params);
|
188
|
+
}
|
189
|
+
const span = col.spanProp || col.sameRowSpan;
|
190
|
+
if (span) {
|
191
|
+
const field = typeof span === "string" ? span : col.prop;
|
192
|
+
const map = this.sameRowMap[field];
|
193
|
+
|
194
|
+
if (map) {
|
195
|
+
// 查找当前行所在的分组
|
196
|
+
const groupKey = row[field];
|
197
|
+
const groups = map[groupKey] || [];
|
198
|
+
|
199
|
+
// 查找包含当前行索引的分组
|
200
|
+
const group = groups.find(
|
201
|
+
(g) => rowIndex >= g.firstIndex && rowIndex < g.firstIndex + g.span
|
202
|
+
);
|
203
|
+
|
204
|
+
if (group) {
|
205
|
+
if (rowIndex === group.firstIndex) {
|
206
|
+
// 分组的第一行显示,并跨越整个分组
|
207
|
+
return {
|
208
|
+
rowspan: group.span,
|
209
|
+
colspan: 1,
|
210
|
+
};
|
211
|
+
} else {
|
212
|
+
// 其他行隐藏
|
213
|
+
return {
|
214
|
+
rowspan: 0,
|
215
|
+
colspan: 0,
|
216
|
+
};
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
},
|
222
|
+
// 创建分组映射
|
223
|
+
createGroupMap(data, currentField, allFields) {
|
224
|
+
const map = {};
|
225
|
+
let currentGroup = [];
|
226
|
+
let currentValues = {};
|
227
|
+
|
228
|
+
// 遍历数据,按照所有合并字段的值组合来分组
|
229
|
+
data.forEach((item, index) => {
|
230
|
+
const groupChanged = this.isGroupChanged(
|
231
|
+
item,
|
232
|
+
currentValues,
|
233
|
+
allFields,
|
234
|
+
currentField
|
235
|
+
);
|
236
|
+
|
237
|
+
if (groupChanged) {
|
238
|
+
// 如果组发生变化,处理前一组数据
|
239
|
+
if (currentGroup.length > 0) {
|
240
|
+
this.processGroup(map, currentGroup, currentValues[currentField]);
|
241
|
+
}
|
242
|
+
// 开始新的一组
|
243
|
+
currentGroup = [{ item, index }];
|
244
|
+
// 更新当前值
|
245
|
+
allFields.forEach((field) => {
|
246
|
+
currentValues[field] = item[field];
|
247
|
+
});
|
248
|
+
} else {
|
249
|
+
// 继续添加到当前组
|
250
|
+
currentGroup.push({ item, index });
|
251
|
+
}
|
252
|
+
});
|
253
|
+
|
254
|
+
// 处理最后一组
|
255
|
+
if (currentGroup.length > 0) {
|
256
|
+
this.processGroup(map, currentGroup, currentValues[currentField]);
|
257
|
+
}
|
258
|
+
|
259
|
+
return map;
|
260
|
+
},
|
261
|
+
// 判断是否需要开始新的分组
|
262
|
+
isGroupChanged(item, currentValues, allFields, currentField) {
|
263
|
+
if (Object.keys(currentValues).length === 0) return true;
|
264
|
+
|
265
|
+
// 检查当前字段之前的所有字段值是否相同
|
266
|
+
const fieldIndex = allFields.indexOf(currentField);
|
267
|
+
for (let i = 0; i <= fieldIndex; i++) {
|
268
|
+
const field = allFields[i];
|
269
|
+
if (item[field] !== currentValues[field]) {
|
270
|
+
return true;
|
271
|
+
}
|
272
|
+
}
|
273
|
+
return false;
|
274
|
+
},
|
275
|
+
|
276
|
+
// 处理分组数据
|
277
|
+
processGroup(map, group, key) {
|
278
|
+
if (!map[key]) {
|
279
|
+
map[key] = [];
|
280
|
+
}
|
281
|
+
map[key].push({
|
282
|
+
firstIndex: group[0].index,
|
283
|
+
span: group.length,
|
284
|
+
items: group.map((g) => g.item),
|
285
|
+
});
|
286
|
+
},
|
287
|
+
},
|
288
|
+
};
|