vue-super-crud 1.7.1 → 1.7.2

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.
Files changed (269) hide show
  1. package/README.md +42 -10
  2. package/lib/index.css +1 -1
  3. package/lib/super-crud.min.js +2 -2
  4. package/package.json +21 -16
  5. package/.browserslistrc +0 -3
  6. package/.versionrc.json +0 -36
  7. package/CHANGELOG.md +0 -232
  8. package/babel.config.js +0 -12
  9. package/build/alias.js +0 -10
  10. package/build/build.js +0 -52
  11. package/build/config.js +0 -70
  12. package/deploy.bat +0 -14
  13. package/docs/.vuepress/components/button/base.vue +0 -88
  14. package/docs/.vuepress/components/common/code-format.vue +0 -331
  15. package/docs/.vuepress/components/commonConfig/presetCodeTemplate/base.vue +0 -68
  16. package/docs/.vuepress/components/commonConfig/presetCodeTemplate/customParams.vue +0 -73
  17. package/docs/.vuepress/components/commonConfig/renderType/component.vue +0 -160
  18. package/docs/.vuepress/components/commonConfig/renderType/formatter.vue +0 -49
  19. package/docs/.vuepress/components/commonConfig/renderType/render.vue +0 -91
  20. package/docs/.vuepress/components/commonConfig/renderType/slot.vue +0 -63
  21. package/docs/.vuepress/components/crud/baseUse/baseUse.vue +0 -98
  22. package/docs/.vuepress/components/crud/baseUse/columnAction.vue +0 -72
  23. package/docs/.vuepress/components/crud/baseUse/columnWidth.vue +0 -107
  24. package/docs/.vuepress/components/crud/baseUse/handleRow.vue +0 -65
  25. package/docs/.vuepress/components/crud/baseUse/height.vue +0 -82
  26. package/docs/.vuepress/components/crud/baseUse/index.vue +0 -54
  27. package/docs/.vuepress/components/crud/baseUse/loading.vue +0 -70
  28. package/docs/.vuepress/components/crud/baseUse/pagination.vue +0 -108
  29. package/docs/.vuepress/components/crud/baseUse/selection.vue +0 -114
  30. package/docs/.vuepress/components/crud/baseUse/summaryMethod.vue +0 -118
  31. package/docs/.vuepress/components/crud/baseUse/title.vue +0 -54
  32. package/docs/.vuepress/components/crud/baseUse/toolbar.vue +0 -69
  33. package/docs/.vuepress/components/crud/buttons/common.vue +0 -115
  34. package/docs/.vuepress/components/crud/buttons/fast.vue +0 -82
  35. package/docs/.vuepress/components/crud/contextMenu/base.vue +0 -72
  36. package/docs/.vuepress/components/crud/copy.vue +0 -52
  37. package/docs/.vuepress/components/crud/crudEvents/api.vue +0 -157
  38. package/docs/.vuepress/components/crud/crudEvents/deleteTip.vue +0 -93
  39. package/docs/.vuepress/components/crud/crudEvents/events.vue +0 -188
  40. package/docs/.vuepress/components/crud/dataSort/base.vue +0 -142
  41. package/docs/.vuepress/components/crud/genDynamicColumns/base.vue +0 -53
  42. package/docs/.vuepress/components/crud/genDynamicColumns/dynamicAndFixed.vue +0 -111
  43. package/docs/.vuepress/components/crud/genDynamicColumns/treeDynamic.vue +0 -68
  44. package/docs/.vuepress/components/crud/handleBar/handleRow.vue +0 -65
  45. package/docs/.vuepress/components/crud/handleBar/toolbar.vue +0 -69
  46. package/docs/.vuepress/components/crud/renderType/1.vue +0 -57
  47. package/docs/.vuepress/components/crud/renderType/2.vue +0 -63
  48. package/docs/.vuepress/components/crud/renderType/3.vue +0 -105
  49. package/docs/.vuepress/components/crud/renderType/5.vue +0 -91
  50. package/docs/.vuepress/components/crud/search/1.vue +0 -90
  51. package/docs/.vuepress/components/crud/search/2.vue +0 -78
  52. package/docs/.vuepress/components/crud/search/3.vue +0 -107
  53. package/docs/.vuepress/components/crud/search/base.vue +0 -123
  54. package/docs/.vuepress/components/crud/search/localSearch.vue +0 -124
  55. package/docs/.vuepress/components/crud/search/special.vue +0 -148
  56. package/docs/.vuepress/components/crud/selection/events.vue +0 -47
  57. package/docs/.vuepress/components/crud/selection/pagination.vue +0 -94
  58. package/docs/.vuepress/components/crud/selection/singleSelection.vue +0 -64
  59. package/docs/.vuepress/components/crud/span/base.vue +0 -69
  60. package/docs/.vuepress/components/crud/span/special.vue +0 -75
  61. package/docs/.vuepress/components/crud/summary/base.vue +0 -99
  62. package/docs/.vuepress/components/crud/tableEdit/addDeleteBtn.vue +0 -174
  63. package/docs/.vuepress/components/crud/tableEdit/cellEdit.vue +0 -194
  64. package/docs/.vuepress/components/crud/tableEdit/controlEdit.vue +0 -219
  65. package/docs/.vuepress/components/crud/tableEdit/dialog.vue +0 -172
  66. package/docs/.vuepress/components/crud/tableEdit/free.vue +0 -88
  67. package/docs/.vuepress/components/crud/tableEdit/freeColumn.vue +0 -82
  68. package/docs/.vuepress/components/crud/tableEdit/methods.vue +0 -154
  69. package/docs/.vuepress/components/crud/tableEdit/rowAction.vue +0 -107
  70. package/docs/.vuepress/components/crud/tableEdit/rowBatch.vue +0 -116
  71. package/docs/.vuepress/components/crud/tableEdit/rowClick.vue +0 -98
  72. package/docs/.vuepress/components/crud/validate/base.vue +0 -122
  73. package/docs/.vuepress/components/crud/validate/custom.vue +0 -82
  74. package/docs/.vuepress/components/crud/validate/regulars.vue +0 -88
  75. package/docs/.vuepress/components/crud/validate/relation.vue +0 -91
  76. package/docs/.vuepress/components/crud/validate/tree.vue +0 -82
  77. package/docs/.vuepress/components/dialog/baseUse/base.vue +0 -92
  78. package/docs/.vuepress/components/dialog/baseUse/beforeConfirm.vue +0 -78
  79. package/docs/.vuepress/components/dialog/baseUse/control.vue +0 -79
  80. package/docs/.vuepress/components/dialog/baseUse/drawer.vue +0 -59
  81. package/docs/.vuepress/components/dialog/baseUse/footer.vue +0 -87
  82. package/docs/.vuepress/components/dialog/baseUse/insertSlot.vue +0 -79
  83. package/docs/.vuepress/components/dict/DictLinkage.vue +0 -91
  84. package/docs/.vuepress/components/dict/baseUse.vue +0 -72
  85. package/docs/.vuepress/components/dict/component.vue +0 -82
  86. package/docs/.vuepress/components/dict/localDict.vue +0 -68
  87. package/docs/.vuepress/components/form/baseUse/base.vue +0 -48
  88. package/docs/.vuepress/components/form/baseUse/dataFormat.vue +0 -92
  89. package/docs/.vuepress/components/form/baseUse/deep.vue +0 -57
  90. package/docs/.vuepress/components/form/baseUse/gridLayout.vue +0 -47
  91. package/docs/.vuepress/components/form/baseUse/group.vue +0 -66
  92. package/docs/.vuepress/components/form/baseUse/hidden.vue +0 -40
  93. package/docs/.vuepress/components/form/baseUse/inlineLayout.vue +0 -48
  94. package/docs/.vuepress/components/form/baseUse/label.vue +0 -51
  95. package/docs/.vuepress/components/form/baseUse/tooltip.vue +0 -40
  96. package/docs/.vuepress/components/form/baseUse/validate.vue +0 -52
  97. package/docs/.vuepress/components/form/detail/base.vue +0 -78
  98. package/docs/.vuepress/components/form/detail/border.vue +0 -90
  99. package/docs/.vuepress/components/form/detail/singleDetail.vue +0 -72
  100. package/docs/.vuepress/components/formatData/baseUse.vue +0 -131
  101. package/docs/.vuepress/components/mock/index.js +0 -347
  102. package/docs/.vuepress/components/mockData/custom.vue +0 -69
  103. package/docs/.vuepress/components/mockData/example.vue +0 -290
  104. package/docs/.vuepress/components/positionSlot/base.vue +0 -24
  105. package/docs/.vuepress/components/positionSlot/form.vue +0 -71
  106. package/docs/.vuepress/components/positionSlot/table.vue +0 -85
  107. package/docs/.vuepress/components/tabs/base.vue +0 -57
  108. package/docs/.vuepress/components/temp.js +0 -195
  109. package/docs/.vuepress/config.js +0 -146
  110. package/docs/.vuepress/enhanceApp.js +0 -142
  111. package/docs/.vuepress/public/favicon.ico +0 -0
  112. package/docs/.vuepress/public/super.png +0 -0
  113. package/docs/.vuepress/styles/index.styl +0 -25
  114. package/docs/.vuepress/styles/palette.styl +0 -6
  115. package/docs/README.md +0 -14
  116. package/docs/guide/button/base.md +0 -31
  117. package/docs/guide/commonConfig/jsx.md +0 -166
  118. package/docs/guide/commonConfig/presetCodeTemplate.md +0 -68
  119. package/docs/guide/commonConfig/renderType.md +0 -181
  120. package/docs/guide/crud/baseUse.md +0 -120
  121. package/docs/guide/crud/buttons.md +0 -18
  122. package/docs/guide/crud/config.md +0 -217
  123. package/docs/guide/crud/contextMenu.md +0 -18
  124. package/docs/guide/crud/dataSort.md +0 -66
  125. package/docs/guide/crud/genDynamicColumns.md +0 -145
  126. package/docs/guide/crud/handleBar.md +0 -26
  127. package/docs/guide/crud/renderType.md +0 -4
  128. package/docs/guide/crud/search.md +0 -150
  129. package/docs/guide/crud/selection.md +0 -73
  130. package/docs/guide/crud/span.md +0 -98
  131. package/docs/guide/crud/summary.md +0 -167
  132. package/docs/guide/crud/tableEdit.md +0 -377
  133. package/docs/guide/crud/validate.md +0 -158
  134. package/docs/guide/dialog/baseUse.md +0 -81
  135. package/docs/guide/dict/baseUse.md +0 -174
  136. package/docs/guide/dict/component.md +0 -88
  137. package/docs/guide/dict/config.md +0 -44
  138. package/docs/guide/form/baseUse.md +0 -142
  139. package/docs/guide/form/detail.md +0 -38
  140. package/docs/guide/formatData/baseUse.md +0 -98
  141. package/docs/guide/formatData/config.md +0 -142
  142. package/docs/guide/mockData/base.md +0 -26
  143. package/docs/guide/positionSlot/base.md +0 -41
  144. package/docs/guide/question/base.md +0 -44
  145. package/docs/guide/start/base.md +0 -30
  146. package/docs/guide/tabs/base.md +0 -63
  147. package/examples/App.vue +0 -52
  148. package/examples/Layout/components/AppMain.vue +0 -40
  149. package/examples/Layout/components/Item.vue +0 -29
  150. package/examples/Layout/components/Link.vue +0 -44
  151. package/examples/Layout/components/SidebarItem.vue +0 -93
  152. package/examples/Layout/index.vue +0 -69
  153. package/examples/assets/logo.png +0 -0
  154. package/examples/favicon.ico +0 -0
  155. package/examples/index.html +0 -18
  156. package/examples/main.js +0 -54
  157. package/examples/router/index.js +0 -140
  158. package/examples/store/index.js +0 -0
  159. package/examples/styles/index.scss +0 -63
  160. package/examples/styles/sidebar.scss +0 -226
  161. package/examples/styles/transition.scss +0 -48
  162. package/examples/styles/variables.scss +0 -25
  163. package/examples/views/crud/base.vue +0 -68
  164. package/examples/views/crud/handleRow.vue +0 -84
  165. package/examples/views/crud/search.vue +0 -116
  166. package/examples/views/dashboard/index.vue +0 -244
  167. package/examples/views/dashboard/index1.vue +0 -234
  168. package/examples/views/dashboard/test.vue +0 -9
  169. package/examples/views/formTest/index.vue +0 -168
  170. package/examples/views/nested/menu1/index.vue +0 -7
  171. package/examples/views/nested/menu1/menu1-1/index.vue +0 -7
  172. package/examples/views/nested/menu1/menu1-2/index.vue +0 -7
  173. package/examples/views/nested/menu1/menu1-2/menu1-2-1/index.vue +0 -5
  174. package/examples/views/nested/menu1/menu1-2/menu1-2-2/index.vue +0 -5
  175. package/examples/views/nested/menu1/menu1-3/index.vue +0 -5
  176. package/examples/views/nested/menu2/index.vue +0 -5
  177. package/gulpfile.js +0 -84
  178. package/packages/button/index.vue +0 -189
  179. package/packages/core/components/comp.vue +0 -223
  180. package/packages/core/components/position.vue +0 -135
  181. package/packages/core/components/render.vue +0 -460
  182. package/packages/core/configManager.js +0 -302
  183. package/packages/core/create.js +0 -8
  184. package/packages/core/defaultRender.js +0 -64
  185. package/packages/core/dict/global.js +0 -10
  186. package/packages/core/dict/index.js +0 -432
  187. package/packages/core/dict/mixin.js +0 -94
  188. package/packages/core/event.js +0 -60
  189. package/packages/core/index.js +0 -6
  190. package/packages/core/init.js +0 -122
  191. package/packages/core/mock/genConfig.js +0 -228
  192. package/packages/core/mock/genData.js +0 -422
  193. package/packages/core/mock/index.js +0 -4
  194. package/packages/core/rules.js +0 -111
  195. package/packages/crud/column.vue +0 -205
  196. package/packages/crud/columnAction.vue +0 -207
  197. package/packages/crud/columnCell.vue +0 -146
  198. package/packages/crud/defaultColumn.vue +0 -130
  199. package/packages/crud/drawerColumn.vue +0 -225
  200. package/packages/crud/form.vue +0 -69
  201. package/packages/crud/index.vue +0 -564
  202. package/packages/crud/menuBar.vue +0 -298
  203. package/packages/crud/mixins/cacheHandler.js +0 -36
  204. package/packages/crud/mixins/calcColumnWidth.js +0 -79
  205. package/packages/crud/mixins/calcHeight.js +0 -105
  206. package/packages/crud/mixins/columnHandler.js +0 -128
  207. package/packages/crud/mixins/contextMenu.js +0 -98
  208. package/packages/crud/mixins/dataProcessor.js +0 -202
  209. package/packages/crud/mixins/dialog.js +0 -109
  210. package/packages/crud/mixins/excelHandler.js +0 -150
  211. package/packages/crud/mixins/exposeMethods.js +0 -107
  212. package/packages/crud/mixins/generateDynamicColumns.js +0 -250
  213. package/packages/crud/mixins/props.js +0 -38
  214. package/packages/crud/mixins/searchHandler.js +0 -151
  215. package/packages/crud/mixins/select.js +0 -359
  216. package/packages/crud/mixins/spanMethod.js +0 -288
  217. package/packages/crud/mixins/summary.js +0 -177
  218. package/packages/crud/mixins/tableEdit.js +0 -547
  219. package/packages/crud/mixins/validate.js +0 -219
  220. package/packages/crud/pagination.vue +0 -110
  221. package/packages/crud/search.vue +0 -119
  222. package/packages/crud/searchHeader.vue +0 -231
  223. package/packages/crud/selectBanner.vue +0 -138
  224. package/packages/crud/utils/EditState.js +0 -319
  225. package/packages/crud/utils/excelExport.js +0 -112
  226. package/packages/crud/utils/excelImport.js +0 -112
  227. package/packages/crud/utils/index.js +0 -98
  228. package/packages/dialog/dialog.js +0 -233
  229. package/packages/dialog/dialog.vue +0 -15
  230. package/packages/dialog/index.js +0 -22
  231. package/packages/dict/cascadeFormat.vue +0 -179
  232. package/packages/dict/dateFormat.vue +0 -40
  233. package/packages/dict/form/cascade.vue +0 -61
  234. package/packages/dict/form/checkbox.vue +0 -90
  235. package/packages/dict/form/extendMethod.js +0 -22
  236. package/packages/dict/form/input-base.js +0 -31
  237. package/packages/dict/form/input.js +0 -20
  238. package/packages/dict/form/radio.vue +0 -69
  239. package/packages/dict/form/select.vue +0 -118
  240. package/packages/dict/form/switch.vue +0 -75
  241. package/packages/dict/valueFormat.vue +0 -188
  242. package/packages/directive/dialog/drag.js +0 -86
  243. package/packages/directive/dialog/dragSize.js +0 -42
  244. package/packages/directive/index.js +0 -9
  245. package/packages/directive/insertSlot.js +0 -10
  246. package/packages/form/contextMenu.js +0 -192
  247. package/packages/form/draftDrawer.vue +0 -391
  248. package/packages/form/formAction.vue +0 -97
  249. package/packages/form/formItem.vue +0 -259
  250. package/packages/form/index.vue +0 -451
  251. package/packages/form/props.js +0 -15
  252. package/packages/grid/cell.vue +0 -65
  253. package/packages/grid/index.vue +0 -130
  254. package/packages/group/index.vue +0 -96
  255. package/packages/tabs/index.vue +0 -290
  256. package/packages/tooltip/index.js +0 -9
  257. package/packages/tooltip/tooltip.vue +0 -32
  258. package/packages/tooltip/tooltipComponent.js +0 -38
  259. package/packages/verifyInput/index.vue +0 -131
  260. package/styles/button.scss +0 -3
  261. package/styles/crud.scss +0 -425
  262. package/styles/dialog.scss +0 -95
  263. package/styles/form.scss +0 -532
  264. package/styles/group.scss +0 -78
  265. package/styles/index.scss +0 -94
  266. package/styles/tabs.scss +0 -139
  267. package/styles/verifyInput.scss +0 -56
  268. package/vue-jsx-sync.js +0 -90
  269. package/vue.config.js +0 -54
@@ -1,359 +0,0 @@
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
- };
@@ -1,288 +0,0 @@
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
- };