yy-vue-easytable 2.27.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.
- package/LICENSE +22 -0
- package/README.md +187 -0
- package/libs/font/demo.css +539 -0
- package/libs/font/demo_index.html +400 -0
- package/libs/font/iconfont.css +57 -0
- package/libs/font/iconfont.eot +0 -0
- package/libs/font/iconfont.js +1 -0
- package/libs/font/iconfont.json +79 -0
- package/libs/font/iconfont.svg +56 -0
- package/libs/font/iconfont.ttf +0 -0
- package/libs/font/iconfont.woff +0 -0
- package/libs/font/iconfont.woff2 +0 -0
- package/libs/locale/lang/af-ZA.js +48 -0
- package/libs/locale/lang/en-US.js +48 -0
- package/libs/locale/lang/fr-FR.js +48 -0
- package/libs/locale/lang/ko-KR.js +48 -0
- package/libs/locale/lang/pt-BR.js +48 -0
- package/libs/locale/lang/ru-RU.js +48 -0
- package/libs/locale/lang/zh-CN.js +48 -0
- package/libs/locale/lang/zh-TW.js +48 -0
- package/libs/locale/lang/zu-ZA.js +48 -0
- package/libs/main.js +1 -0
- package/libs/theme-dark/base.css +1 -0
- package/libs/theme-dark/index.css +1253 -0
- package/libs/theme-dark/var.css +7 -0
- package/libs/theme-dark/ve-checkbox.css +150 -0
- package/libs/theme-dark/ve-contextmenu.css +71 -0
- package/libs/theme-dark/ve-dropdown.css +177 -0
- package/libs/theme-dark/ve-icon.css +10 -0
- package/libs/theme-dark/ve-loading.css +218 -0
- package/libs/theme-dark/ve-pagination.css +136 -0
- package/libs/theme-dark/ve-radio.css +111 -0
- package/libs/theme-dark/ve-select.css +50 -0
- package/libs/theme-dark/ve-table.css +385 -0
- package/libs/theme-default/base.css +1 -0
- package/libs/theme-default/index.css +1253 -0
- package/libs/theme-default/var.css +7 -0
- package/libs/theme-default/ve-checkbox.css +150 -0
- package/libs/theme-default/ve-contextmenu.css +71 -0
- package/libs/theme-default/ve-dropdown.css +177 -0
- package/libs/theme-default/ve-icon.css +10 -0
- package/libs/theme-default/ve-loading.css +218 -0
- package/libs/theme-default/ve-pagination.css +136 -0
- package/libs/theme-default/ve-radio.css +111 -0
- package/libs/theme-default/ve-select.css +50 -0
- package/libs/theme-default/ve-table.css +385 -0
- package/libs/umd/index.js +9 -0
- package/libs/ve-checkbox-group.js +1 -0
- package/libs/ve-checkbox.js +1 -0
- package/libs/ve-contextmenu.js +1 -0
- package/libs/ve-dropdown.js +1 -0
- package/libs/ve-icon.js +1 -0
- package/libs/ve-loading.js +1 -0
- package/libs/ve-locale.js +1 -0
- package/libs/ve-pagination.js +1 -0
- package/libs/ve-radio.js +1 -0
- package/libs/ve-select.js +1 -0
- package/libs/ve-table.js +1 -0
- package/package.json +142 -0
- package/packages/font/demo.css +539 -0
- package/packages/font/demo_index.html +400 -0
- package/packages/font/iconfont.css +57 -0
- package/packages/font/iconfont.eot +0 -0
- package/packages/font/iconfont.js +1 -0
- package/packages/font/iconfont.json +79 -0
- package/packages/font/iconfont.svg +56 -0
- package/packages/font/iconfont.ttf +0 -0
- package/packages/font/iconfont.woff +0 -0
- package/packages/font/iconfont.woff2 +0 -0
- package/packages/index.js +75 -0
- package/packages/src/comps/resize-observer/index.js +2 -0
- package/packages/src/comps/resize-observer/src/index.jsx +38 -0
- package/packages/src/directives/clickoutside.js +31 -0
- package/packages/src/directives/events-outside.js +79 -0
- package/packages/src/directives/focus.js +28 -0
- package/packages/src/locale/index.js +27 -0
- package/packages/src/locale/lang/af-ZA.js +29 -0
- package/packages/src/locale/lang/en-US.js +30 -0
- package/packages/src/locale/lang/fr-FR.js +29 -0
- package/packages/src/locale/lang/ko-KR.js +29 -0
- package/packages/src/locale/lang/pt-BR.js +29 -0
- package/packages/src/locale/lang/ru-RU.js +29 -0
- package/packages/src/locale/lang/zh-CN.js +30 -0
- package/packages/src/locale/lang/zh-TW.js +29 -0
- package/packages/src/locale/lang/zu-ZA.js +29 -0
- package/packages/src/mixins/emitter.js +39 -0
- package/packages/src/utils/animation-frame.js +39 -0
- package/packages/src/utils/auto-resize.js +179 -0
- package/packages/src/utils/constant.js +42 -0
- package/packages/src/utils/dom.js +239 -0
- package/packages/src/utils/event-key-codes.js +53 -0
- package/packages/src/utils/hooks-manager.js +76 -0
- package/packages/src/utils/index.js +161 -0
- package/packages/src/utils/mouse-event.js +24 -0
- package/packages/src/utils/random.js +6 -0
- package/packages/src/utils/request-animation-timeout.js +36 -0
- package/packages/src/utils/resize-event.js +40 -0
- package/packages/src/utils/scroll-bar.js +27 -0
- package/packages/style/ve-checkbox.less +179 -0
- package/packages/style/ve-contextmenu.less +76 -0
- package/packages/style/ve-dropdown.less +204 -0
- package/packages/style/ve-icon.less +3 -0
- package/packages/style/ve-loading.less +242 -0
- package/packages/style/ve-pagination.less +153 -0
- package/packages/style/ve-radio.less +126 -0
- package/packages/style/ve-select.less +48 -0
- package/packages/style/ve-table.less +539 -0
- package/packages/theme-dark/base.less +1 -0
- package/packages/theme-dark/index.less +12 -0
- package/packages/theme-dark/var.less +111 -0
- package/packages/theme-dark/ve-checkbox.less +2 -0
- package/packages/theme-dark/ve-contextmenu.less +2 -0
- package/packages/theme-dark/ve-dropdown.less +2 -0
- package/packages/theme-dark/ve-icon.less +2 -0
- package/packages/theme-dark/ve-loading.less +2 -0
- package/packages/theme-dark/ve-pagination.less +2 -0
- package/packages/theme-dark/ve-radio.less +2 -0
- package/packages/theme-dark/ve-select.less +2 -0
- package/packages/theme-dark/ve-table.less +2 -0
- package/packages/theme-default/base.less +1 -0
- package/packages/theme-default/index.less +12 -0
- package/packages/theme-default/var.less +111 -0
- package/packages/theme-default/ve-checkbox.less +2 -0
- package/packages/theme-default/ve-contextmenu.less +2 -0
- package/packages/theme-default/ve-dropdown.less +2 -0
- package/packages/theme-default/ve-icon.less +2 -0
- package/packages/theme-default/ve-loading.less +2 -0
- package/packages/theme-default/ve-pagination.less +2 -0
- package/packages/theme-default/ve-radio.less +2 -0
- package/packages/theme-default/ve-select.less +2 -0
- package/packages/theme-default/ve-table.less +2 -0
- package/packages/ve-checkbox/index.js +7 -0
- package/packages/ve-checkbox/src/index.jsx +175 -0
- package/packages/ve-checkbox/src/util/constant.js +14 -0
- package/packages/ve-checkbox/src/util/index.js +10 -0
- package/packages/ve-checkbox-group/index.js +7 -0
- package/packages/ve-checkbox-group/src/index.jsx +53 -0
- package/packages/ve-checkbox-group/src/util/constant.js +14 -0
- package/packages/ve-checkbox-group/src/util/index.js +10 -0
- package/packages/ve-contextmenu/index.js +7 -0
- package/packages/ve-contextmenu/src/index.jsx +731 -0
- package/packages/ve-contextmenu/src/util/constant.js +29 -0
- package/packages/ve-contextmenu/src/util/index.js +10 -0
- package/packages/ve-dropdown/index.js +7 -0
- package/packages/ve-dropdown/src/index.jsx +720 -0
- package/packages/ve-dropdown/src/util/constant.js +15 -0
- package/packages/ve-dropdown/src/util/index.js +10 -0
- package/packages/ve-icon/index.js +7 -0
- package/packages/ve-icon/src/index.jsx +52 -0
- package/packages/ve-icon/src/util/constant.js +10 -0
- package/packages/ve-icon/src/util/index.js +10 -0
- package/packages/ve-loading/index.js +8 -0
- package/packages/ve-loading/src/bounce.jsx +50 -0
- package/packages/ve-loading/src/flow.jsx +51 -0
- package/packages/ve-loading/src/grid.jsx +57 -0
- package/packages/ve-loading/src/index.js +106 -0
- package/packages/ve-loading/src/loading.jsx +63 -0
- package/packages/ve-loading/src/plane.jsx +38 -0
- package/packages/ve-loading/src/pulse.jsx +38 -0
- package/packages/ve-loading/src/util/constant.js +31 -0
- package/packages/ve-loading/src/util/index.js +10 -0
- package/packages/ve-loading/src/wave.jsx +53 -0
- package/packages/ve-locale/index.js +28 -0
- package/packages/ve-pagination/index.js +7 -0
- package/packages/ve-pagination/src/index.jsx +304 -0
- package/packages/ve-pagination/src/pager.jsx +166 -0
- package/packages/ve-pagination/src/util/constant.js +16 -0
- package/packages/ve-pagination/src/util/index.js +10 -0
- package/packages/ve-radio/index.js +7 -0
- package/packages/ve-radio/src/index.jsx +121 -0
- package/packages/ve-radio/src/util/constant.js +13 -0
- package/packages/ve-radio/src/util/index.js +10 -0
- package/packages/ve-select/index.js +7 -0
- package/packages/ve-select/src/index.jsx +193 -0
- package/packages/ve-select/src/util/constant.js +13 -0
- package/packages/ve-select/src/util/index.js +10 -0
- package/packages/ve-table/index.js +7 -0
- package/packages/ve-table/src/body/body-checkbox-content.jsx +126 -0
- package/packages/ve-table/src/body/body-radio-content.jsx +113 -0
- package/packages/ve-table/src/body/body-td.jsx +671 -0
- package/packages/ve-table/src/body/body-tr-scrolling.jsx +38 -0
- package/packages/ve-table/src/body/body-tr.jsx +383 -0
- package/packages/ve-table/src/body/expand-tr-icon.jsx +80 -0
- package/packages/ve-table/src/body/expand-tr.jsx +147 -0
- package/packages/ve-table/src/body/index.jsx +943 -0
- package/packages/ve-table/src/colgroup/index.jsx +48 -0
- package/packages/ve-table/src/column-resizer/index.jsx +318 -0
- package/packages/ve-table/src/editor/constant.js +5 -0
- package/packages/ve-table/src/editor/index.jsx +533 -0
- package/packages/ve-table/src/footer/footer-td.jsx +396 -0
- package/packages/ve-table/src/footer/footer-tr.jsx +249 -0
- package/packages/ve-table/src/footer/index.jsx +108 -0
- package/packages/ve-table/src/header/header-checkbox-content.jsx +69 -0
- package/packages/ve-table/src/header/header-filter-content.jsx +100 -0
- package/packages/ve-table/src/header/header-filter-custom-content.jsx +110 -0
- package/packages/ve-table/src/header/header-th.jsx +664 -0
- package/packages/ve-table/src/header/header-tr.jsx +255 -0
- package/packages/ve-table/src/header/index.jsx +195 -0
- package/packages/ve-table/src/index.jsx +4196 -0
- package/packages/ve-table/src/selection/constant.js +5 -0
- package/packages/ve-table/src/selection/index.jsx +1643 -0
- package/packages/ve-table/src/util/clipboard.js +428 -0
- package/packages/ve-table/src/util/constant.js +269 -0
- package/packages/ve-table/src/util/index.js +1585 -0
- package/packages/ve-table/src/util/store.js +14 -0
|
@@ -0,0 +1,1585 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PREFIX_CLS,
|
|
3
|
+
CONTEXTMENU_NODE_TYPES,
|
|
4
|
+
COLUMN_FIXED_TYPE,
|
|
5
|
+
AUTOFILLING_DIRECTION,
|
|
6
|
+
} from "./constant";
|
|
7
|
+
import { MOUSE_EVENT_CLICK_TYPE } from "../../../src/utils/constant";
|
|
8
|
+
import {
|
|
9
|
+
isEmptyValue,
|
|
10
|
+
isEmptyArray,
|
|
11
|
+
isFunction,
|
|
12
|
+
} from "../../../src/utils/index";
|
|
13
|
+
import { getRandomId } from "../../../src/utils/random";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @clsName
|
|
17
|
+
* @desc get class name
|
|
18
|
+
* @param {string} cls - class
|
|
19
|
+
*/
|
|
20
|
+
export function clsName(cls) {
|
|
21
|
+
return PREFIX_CLS + cls;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @getRowKey
|
|
26
|
+
* @desc get row key
|
|
27
|
+
* @param {Object} rowData - rowData
|
|
28
|
+
* @param {string} rowKeyFieldName - row key field name
|
|
29
|
+
*/
|
|
30
|
+
export function getRowKey(rowData, rowKeyFieldName) {
|
|
31
|
+
let result = null;
|
|
32
|
+
|
|
33
|
+
if (rowData && rowKeyFieldName) {
|
|
34
|
+
result = rowData[rowKeyFieldName];
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @getColumnByColkey
|
|
41
|
+
* @desc get column by col key
|
|
42
|
+
* @param {string} colKey - column key
|
|
43
|
+
*/
|
|
44
|
+
export function getColumnByColkey(colKey, colgroups) {
|
|
45
|
+
if (colKey) {
|
|
46
|
+
return colgroups.find((x) => x.key === colKey);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @isLastColumnByColKey
|
|
53
|
+
* @desc is last column by column key
|
|
54
|
+
* @param {string} colKey - column key
|
|
55
|
+
*/
|
|
56
|
+
export function isLastColumnByColKey(colKey, colgroups) {
|
|
57
|
+
if (!isEmptyValue(colKey) && !isEmptyArray(colgroups)) {
|
|
58
|
+
return colgroups[colgroups.length - 1].key === colKey;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @isOperationColumn
|
|
65
|
+
* @desc is operation column
|
|
66
|
+
* @param {string} colKey - column key
|
|
67
|
+
* @param {arrat<object>} colgroups - column key
|
|
68
|
+
*/
|
|
69
|
+
export function isOperationColumn(colKey, colgroups) {
|
|
70
|
+
if (!isEmptyValue(colKey) && !isEmptyArray(colgroups)) {
|
|
71
|
+
const firstCol = colgroups[0];
|
|
72
|
+
if (firstCol.key === colKey && firstCol.operationColumn) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @isLastRowByRowKey
|
|
81
|
+
* @desc is last row by row key
|
|
82
|
+
* @param {string} rowKey - row key
|
|
83
|
+
*/
|
|
84
|
+
export function isLastRowByRowKey(rowKey, allRowKeys) {
|
|
85
|
+
if (!isEmptyValue(rowKey) && !isEmptyArray(allRowKeys)) {
|
|
86
|
+
return allRowKeys[allRowKeys.length - 1] === rowKey;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @getDomResizeObserverCompKey
|
|
93
|
+
* @desc get dom resize observer comp key
|
|
94
|
+
* @param {Any} originalKey - original key
|
|
95
|
+
* @param {Number} columnsOptionResetTime - columns option change time
|
|
96
|
+
*/
|
|
97
|
+
export function getDomResizeObserverCompKey(
|
|
98
|
+
originalKey,
|
|
99
|
+
columnsOptionResetTime,
|
|
100
|
+
) {
|
|
101
|
+
let result = originalKey;
|
|
102
|
+
|
|
103
|
+
if (result || result == 0) {
|
|
104
|
+
result = originalKey + "@" + columnsOptionResetTime;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @recursiveRemoveColumnByKey
|
|
112
|
+
* @desc recursive remove column key
|
|
113
|
+
* @param {object} columns - deep clone column
|
|
114
|
+
* @param {any} key - column key
|
|
115
|
+
*/
|
|
116
|
+
export function recursiveRemoveColumnByKey(columns, key) {
|
|
117
|
+
return columns.filter((item) => {
|
|
118
|
+
if ("children" in item) {
|
|
119
|
+
item.children = recursiveRemoveColumnByKey(item.children, key);
|
|
120
|
+
}
|
|
121
|
+
return item.key !== key;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @getFixedTotalWidthByColumnKey
|
|
127
|
+
* @desc get fixed total width by column key
|
|
128
|
+
* @param {object} colgroups - columns info
|
|
129
|
+
* @param {any} colKey - column key
|
|
130
|
+
* @param {string} fixed - left|right
|
|
131
|
+
*/
|
|
132
|
+
export function getFixedTotalWidthByColumnKey({ colgroups, colKey, fixed }) {
|
|
133
|
+
const currentIndex = colgroups.findIndex((x) => x.key === colKey);
|
|
134
|
+
|
|
135
|
+
let result = 0;
|
|
136
|
+
|
|
137
|
+
if (fixed === COLUMN_FIXED_TYPE.LEFT) {
|
|
138
|
+
// 只计算左列固定的
|
|
139
|
+
result = colgroups.reduce((total, currentVal, index) => {
|
|
140
|
+
return index < currentIndex &&
|
|
141
|
+
currentVal.fixed == COLUMN_FIXED_TYPE.LEFT
|
|
142
|
+
? currentVal._realTimeWidth + total
|
|
143
|
+
: total;
|
|
144
|
+
}, 0);
|
|
145
|
+
} else if (fixed === COLUMN_FIXED_TYPE.RIGHT) {
|
|
146
|
+
// 只计算右列固定的
|
|
147
|
+
result = colgroups.reduce((total, currentVal, index) => {
|
|
148
|
+
return index > currentIndex &&
|
|
149
|
+
currentVal.fixed == COLUMN_FIXED_TYPE.RIGHT
|
|
150
|
+
? currentVal._realTimeWidth + total
|
|
151
|
+
: total;
|
|
152
|
+
}, 0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @getNotFixedTotalWidthByColumnKey
|
|
160
|
+
* @desc get not fixed total width by column key
|
|
161
|
+
* @param {object} colgroups - 列信息
|
|
162
|
+
* @param {any} colKey - column key
|
|
163
|
+
* @param {string} direction - left|right
|
|
164
|
+
*/
|
|
165
|
+
export function getNotFixedTotalWidthByColumnKey({ colgroups, colKey, fixed }) {
|
|
166
|
+
const currentIndex = colgroups.findIndex((x) => x.key === colKey);
|
|
167
|
+
|
|
168
|
+
let result = 0;
|
|
169
|
+
|
|
170
|
+
if (fixed === COLUMN_FIXED_TYPE.LEFT) {
|
|
171
|
+
// 只计算左侧非固定列
|
|
172
|
+
result = colgroups.reduce((total, currentVal, index) => {
|
|
173
|
+
return index < currentIndex && !currentVal.fixed
|
|
174
|
+
? currentVal._realTimeWidth + total
|
|
175
|
+
: total;
|
|
176
|
+
}, 0);
|
|
177
|
+
} else if (fixed === COLUMN_FIXED_TYPE.RIGHT) {
|
|
178
|
+
// 只计算右侧非固定列
|
|
179
|
+
result = colgroups.reduce((total, currentVal, index) => {
|
|
180
|
+
return index > currentIndex && !currentVal.fixed
|
|
181
|
+
? currentVal._realTimeWidth + total
|
|
182
|
+
: total;
|
|
183
|
+
}, 0);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @getTotalWidthByColKeys
|
|
191
|
+
* @desc get total width by collumn keys
|
|
192
|
+
* @param {array<T>} colKeys
|
|
193
|
+
* @param {array<object>} colgroups
|
|
194
|
+
* @return {number} width
|
|
195
|
+
*/
|
|
196
|
+
export function getTotalWidthByColKeys({ colKeys, colgroups }) {
|
|
197
|
+
let result = colgroups.reduce((total, currentVal, index) => {
|
|
198
|
+
return colKeys.indexOf(currentVal.key) > -1
|
|
199
|
+
? currentVal._realTimeWidth + total
|
|
200
|
+
: total;
|
|
201
|
+
}, 0);
|
|
202
|
+
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @initGroupColumns
|
|
208
|
+
* @desc int group columns
|
|
209
|
+
* @param {array} cloneColumns - clone columns
|
|
210
|
+
* @return {
|
|
211
|
+
isGroupHeader,
|
|
212
|
+
colgroups,
|
|
213
|
+
groupColumns
|
|
214
|
+
}
|
|
215
|
+
*/
|
|
216
|
+
export function initGroupColumns(cloneColumns) {
|
|
217
|
+
let colgroups = [];
|
|
218
|
+
let groupColumns = [];
|
|
219
|
+
|
|
220
|
+
// set column level
|
|
221
|
+
let maxLevel = 1;
|
|
222
|
+
const setColumnLevel = (column, parent) => {
|
|
223
|
+
if (parent) {
|
|
224
|
+
column._level = parent._level + 1;
|
|
225
|
+
if (maxLevel < column._level) {
|
|
226
|
+
maxLevel = column._level;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (column.children) {
|
|
230
|
+
column.children.forEach((item) => {
|
|
231
|
+
item.fixed = column.fixed;
|
|
232
|
+
setColumnLevel(item, column);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
cloneColumns.forEach((column) => {
|
|
237
|
+
column._level = 1;
|
|
238
|
+
setColumnLevel(column);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// set colspan and rowspan and keys
|
|
242
|
+
const setColspanAndRowspanAndKeys = (column) => {
|
|
243
|
+
if (column.children) {
|
|
244
|
+
let keys = "";
|
|
245
|
+
let colspan = 0;
|
|
246
|
+
column.children.forEach((item) => {
|
|
247
|
+
setColspanAndRowspanAndKeys(item);
|
|
248
|
+
|
|
249
|
+
colspan += item._colspan;
|
|
250
|
+
keys += item._keys.endsWith("|")
|
|
251
|
+
? item._keys
|
|
252
|
+
: item._keys + "|";
|
|
253
|
+
});
|
|
254
|
+
column._keys = keys;
|
|
255
|
+
column._colspan = colspan;
|
|
256
|
+
column._rowspan = 1;
|
|
257
|
+
} else {
|
|
258
|
+
column._keys = column.key;
|
|
259
|
+
column._colspan = 1;
|
|
260
|
+
column._rowspan = maxLevel - column._level + 1;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
cloneColumns.forEach((column) => {
|
|
265
|
+
setColspanAndRowspanAndKeys(column);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// init groupColumns
|
|
269
|
+
for (let i = 0; i < maxLevel; i++) {
|
|
270
|
+
groupColumns.push([]);
|
|
271
|
+
}
|
|
272
|
+
// set colgroups and groupColumns
|
|
273
|
+
const setColgroupsAndGroupColumns = (column) => {
|
|
274
|
+
// column has children || column key is not empty
|
|
275
|
+
if (!isEmptyArray(column.children) || !isEmptyValue(column.key)) {
|
|
276
|
+
// set groupColumns
|
|
277
|
+
const { ...groupColumn } = column;
|
|
278
|
+
groupColumns[column._level - 1].push(groupColumn);
|
|
279
|
+
|
|
280
|
+
if (column.children) {
|
|
281
|
+
column.children.forEach((item) => {
|
|
282
|
+
setColgroupsAndGroupColumns(item);
|
|
283
|
+
});
|
|
284
|
+
} else {
|
|
285
|
+
// set colgroups
|
|
286
|
+
const { ...colgroup } = column;
|
|
287
|
+
colgroup._realTimeWidth = colgroup.width;
|
|
288
|
+
colgroups.push(colgroup);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
cloneColumns.forEach((column) => {
|
|
294
|
+
setColgroupsAndGroupColumns(column);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
// set is group header
|
|
299
|
+
isGroupHeader: maxLevel > 1,
|
|
300
|
+
// set colgroups
|
|
301
|
+
colgroups,
|
|
302
|
+
// set groupColumns
|
|
303
|
+
groupColumns,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// get header contextmenu option collection
|
|
308
|
+
export function getHeaderContextmenuOptionCollection(t) {
|
|
309
|
+
return [
|
|
310
|
+
{
|
|
311
|
+
type: CONTEXTMENU_NODE_TYPES.SEPARATOR,
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
label: t("cut"),
|
|
315
|
+
type: CONTEXTMENU_NODE_TYPES.CUT,
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
label: t("copy"),
|
|
319
|
+
type: CONTEXTMENU_NODE_TYPES.COPY,
|
|
320
|
+
},
|
|
321
|
+
// {
|
|
322
|
+
// label: t("paste"),
|
|
323
|
+
// type: CONTEXTMENU_NODE_TYPES.PASTE,
|
|
324
|
+
// },
|
|
325
|
+
{
|
|
326
|
+
label: t("removeColumn"),
|
|
327
|
+
type: CONTEXTMENU_NODE_TYPES.REMOVE_COLUMN,
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
label: t("emptyColumn"),
|
|
331
|
+
type: CONTEXTMENU_NODE_TYPES.EMPTY_COLUMN,
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
label: t("hideColumn"),
|
|
335
|
+
type: CONTEXTMENU_NODE_TYPES.HIDE_COLUMN,
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
label: t("leftFixedColumnTo"),
|
|
339
|
+
type: CONTEXTMENU_NODE_TYPES.LEFT_FIXED_COLUMN_TO,
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
label: t("cancelLeftFixedColumnTo"),
|
|
343
|
+
type: CONTEXTMENU_NODE_TYPES.CANCEL_LEFT_FIXED_COLUMN_TO,
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
label: t("rightFixedColumnTo"),
|
|
347
|
+
type: CONTEXTMENU_NODE_TYPES.RIGHT_FIXED_COLUMN_TO,
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
label: t("cancelRightFixedColumnTo"),
|
|
351
|
+
type: CONTEXTMENU_NODE_TYPES.CANCEL_RIGHT_FIXED_COLUMN_TO,
|
|
352
|
+
},
|
|
353
|
+
];
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// get body contextmenu option collection
|
|
357
|
+
export function getBodyContextmenuOptionCollection(t) {
|
|
358
|
+
return [
|
|
359
|
+
{
|
|
360
|
+
type: CONTEXTMENU_NODE_TYPES.SEPARATOR,
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
label: t("cut"),
|
|
364
|
+
type: CONTEXTMENU_NODE_TYPES.CUT,
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
label: t("copy"),
|
|
368
|
+
type: CONTEXTMENU_NODE_TYPES.COPY,
|
|
369
|
+
},
|
|
370
|
+
// {
|
|
371
|
+
// label: t("paste"),
|
|
372
|
+
// type: CONTEXTMENU_NODE_TYPES.PASTE,
|
|
373
|
+
// },
|
|
374
|
+
{
|
|
375
|
+
label: t("insertRowAbove"),
|
|
376
|
+
type: CONTEXTMENU_NODE_TYPES.INSERT_ROW_ABOVE,
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
label: t("insertRowBelow"),
|
|
380
|
+
type: CONTEXTMENU_NODE_TYPES.INSERT_ROW_BELOW,
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
label: t("removeRow"),
|
|
384
|
+
type: CONTEXTMENU_NODE_TYPES.REMOVE_ROW,
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
label: t("emptyRow"),
|
|
388
|
+
type: CONTEXTMENU_NODE_TYPES.EMPTY_ROW,
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
label: t("removeColumn"),
|
|
392
|
+
type: CONTEXTMENU_NODE_TYPES.REMOVE_COLUMN,
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
label: t("emptyCell"),
|
|
396
|
+
type: CONTEXTMENU_NODE_TYPES.EMPTY_CELL,
|
|
397
|
+
},
|
|
398
|
+
];
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/***
|
|
402
|
+
* @setHeaderContextmenuOptions
|
|
403
|
+
* @desc set header contextmenu options
|
|
404
|
+
* @param {array<object>} column
|
|
405
|
+
* @param {array<object>} contextmenuHeaderOption
|
|
406
|
+
* @param {object} cellSelectionRangeData
|
|
407
|
+
* @param {array<object>} colgroups
|
|
408
|
+
* @param {object} headerIndicatorColKeys
|
|
409
|
+
* @param {boolean} enableHeaderContextmenu
|
|
410
|
+
* @param {boolean} t locale
|
|
411
|
+
* @return headerContextmenuOptions
|
|
412
|
+
*/
|
|
413
|
+
export function setHeaderContextmenuOptions({
|
|
414
|
+
column,
|
|
415
|
+
contextmenuHeaderOption,
|
|
416
|
+
cellSelectionRangeData,
|
|
417
|
+
colgroups,
|
|
418
|
+
allRowKeys,
|
|
419
|
+
headerIndicatorColKeys,
|
|
420
|
+
enableHeaderContextmenu,
|
|
421
|
+
t,
|
|
422
|
+
}) {
|
|
423
|
+
let result = [];
|
|
424
|
+
|
|
425
|
+
if (enableHeaderContextmenu) {
|
|
426
|
+
let selectionRangeKeys = getSelectionRangeKeys({
|
|
427
|
+
cellSelectionRangeData,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
let selectionRangeIndexes = getSelectionRangeIndexes({
|
|
431
|
+
cellSelectionRangeData,
|
|
432
|
+
colgroups,
|
|
433
|
+
allRowKeys,
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
const isOperationCol = isOperationColumn(column.key, colgroups);
|
|
437
|
+
|
|
438
|
+
const colCount =
|
|
439
|
+
selectionRangeIndexes.endColIndex -
|
|
440
|
+
selectionRangeIndexes.startColIndex +
|
|
441
|
+
1;
|
|
442
|
+
|
|
443
|
+
const { contextmenus, beforeShow } = contextmenuHeaderOption;
|
|
444
|
+
|
|
445
|
+
const isWholeColSelection = !isEmptyValue(
|
|
446
|
+
headerIndicatorColKeys.startColKey,
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
const leftFixedColKeys = getColKeysByFixedType({
|
|
450
|
+
fixedType: COLUMN_FIXED_TYPE.LEFT,
|
|
451
|
+
colgroups,
|
|
452
|
+
isExcludeOperationColumn: true,
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const rightFixedColKeys = getColKeysByFixedType({
|
|
456
|
+
fixedType: COLUMN_FIXED_TYPE.RIGHT,
|
|
457
|
+
colgroups,
|
|
458
|
+
isExcludeOperationColumn: true,
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
if (isFunction(beforeShow)) {
|
|
462
|
+
beforeShow({
|
|
463
|
+
isWholeColSelection,
|
|
464
|
+
selectionRangeKeys,
|
|
465
|
+
selectionRangeIndexes,
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const headerContextmenuOptionCollection =
|
|
470
|
+
getHeaderContextmenuOptionCollection(t);
|
|
471
|
+
|
|
472
|
+
contextmenus.forEach((contextmenu) => {
|
|
473
|
+
const contentmenuCollectionItem =
|
|
474
|
+
headerContextmenuOptionCollection.find(
|
|
475
|
+
(x) => x.type === contextmenu.type,
|
|
476
|
+
);
|
|
477
|
+
if (contentmenuCollectionItem) {
|
|
478
|
+
let isContinue = true;
|
|
479
|
+
// empty column. 选中整列时支持
|
|
480
|
+
if (
|
|
481
|
+
contentmenuCollectionItem.type ===
|
|
482
|
+
CONTEXTMENU_NODE_TYPES.EMPTY_COLUMN
|
|
483
|
+
) {
|
|
484
|
+
if (isWholeColSelection) {
|
|
485
|
+
contentmenuCollectionItem.label =
|
|
486
|
+
contentmenuCollectionItem.label.replace(
|
|
487
|
+
"$1",
|
|
488
|
+
colCount,
|
|
489
|
+
);
|
|
490
|
+
} else {
|
|
491
|
+
isContinue = false;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
// left fixed column to
|
|
495
|
+
else if (
|
|
496
|
+
contentmenuCollectionItem.type ===
|
|
497
|
+
CONTEXTMENU_NODE_TYPES.LEFT_FIXED_COLUMN_TO
|
|
498
|
+
) {
|
|
499
|
+
//
|
|
500
|
+
if (isOperationCol) {
|
|
501
|
+
contentmenuCollectionItem.disabled = true;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
// calcel left fixed column to
|
|
505
|
+
else if (
|
|
506
|
+
contentmenuCollectionItem.type ===
|
|
507
|
+
CONTEXTMENU_NODE_TYPES.CANCEL_LEFT_FIXED_COLUMN_TO
|
|
508
|
+
) {
|
|
509
|
+
if (leftFixedColKeys.length < 1) {
|
|
510
|
+
contentmenuCollectionItem.disabled = true;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
// right fixed column to
|
|
514
|
+
else if (
|
|
515
|
+
contentmenuCollectionItem.type ===
|
|
516
|
+
CONTEXTMENU_NODE_TYPES.RIGHT_FIXED_COLUMN_TO
|
|
517
|
+
) {
|
|
518
|
+
//
|
|
519
|
+
if (isOperationCol) {
|
|
520
|
+
contentmenuCollectionItem.disabled = true;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
// calcel right fixed column to
|
|
524
|
+
else if (
|
|
525
|
+
contentmenuCollectionItem.type ===
|
|
526
|
+
CONTEXTMENU_NODE_TYPES.CANCEL_RIGHT_FIXED_COLUMN_TO
|
|
527
|
+
) {
|
|
528
|
+
if (rightFixedColKeys.length < 1) {
|
|
529
|
+
contentmenuCollectionItem.disabled = true;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (isContinue) {
|
|
534
|
+
result.push(contentmenuCollectionItem);
|
|
535
|
+
}
|
|
536
|
+
} else {
|
|
537
|
+
result.push(contextmenu);
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return result;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/***
|
|
546
|
+
* @setHeaderContextmenuOptions
|
|
547
|
+
* @desc set header contextmenu options
|
|
548
|
+
* @param {array<object>} column
|
|
549
|
+
* @param {array<object>} contextmenuBodyOption
|
|
550
|
+
* @param {object} cellSelectionRangeData
|
|
551
|
+
* @param {array<object>} colgroups
|
|
552
|
+
* @param {object} bodyIndicatorRowKeys
|
|
553
|
+
* @param {boolean} enableHeaderContextmenu
|
|
554
|
+
* @param {boolean} t locale
|
|
555
|
+
* @return headerContextmenuOptions
|
|
556
|
+
*/
|
|
557
|
+
export function setBodyContextmenuOptions({
|
|
558
|
+
enableBodyContextmenu,
|
|
559
|
+
contextmenuBodyOption,
|
|
560
|
+
cellSelectionRangeData,
|
|
561
|
+
colgroups,
|
|
562
|
+
allRowKeys,
|
|
563
|
+
bodyIndicatorRowKeys,
|
|
564
|
+
t,
|
|
565
|
+
}) {
|
|
566
|
+
let result = [];
|
|
567
|
+
if (enableBodyContextmenu) {
|
|
568
|
+
let selectionRangeKeys = getSelectionRangeKeys({
|
|
569
|
+
cellSelectionRangeData,
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
let selectionRangeIndexes = getSelectionRangeIndexes({
|
|
573
|
+
cellSelectionRangeData,
|
|
574
|
+
colgroups,
|
|
575
|
+
allRowKeys,
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
const rowCount =
|
|
579
|
+
selectionRangeIndexes.endRowIndex -
|
|
580
|
+
selectionRangeIndexes.startRowIndex +
|
|
581
|
+
1;
|
|
582
|
+
const colCount =
|
|
583
|
+
selectionRangeIndexes.endColIndex -
|
|
584
|
+
selectionRangeIndexes.startColIndex +
|
|
585
|
+
1;
|
|
586
|
+
|
|
587
|
+
const { contextmenus, beforeShow } = contextmenuBodyOption;
|
|
588
|
+
|
|
589
|
+
const isWholeRowSelection = !isEmptyValue(
|
|
590
|
+
bodyIndicatorRowKeys.startRowKey,
|
|
591
|
+
);
|
|
592
|
+
if (isFunction(beforeShow)) {
|
|
593
|
+
beforeShow({
|
|
594
|
+
isWholeRowSelection,
|
|
595
|
+
selectionRangeKeys,
|
|
596
|
+
selectionRangeIndexes,
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const bodyContextmenuOptionCollection =
|
|
601
|
+
getBodyContextmenuOptionCollection(t);
|
|
602
|
+
|
|
603
|
+
contextmenus.forEach((contextmenu) => {
|
|
604
|
+
const contentmenuCollectionItem =
|
|
605
|
+
bodyContextmenuOptionCollection.find(
|
|
606
|
+
(x) => x.type === contextmenu.type,
|
|
607
|
+
);
|
|
608
|
+
if (contentmenuCollectionItem) {
|
|
609
|
+
let isContinue = true;
|
|
610
|
+
|
|
611
|
+
// remove row
|
|
612
|
+
if (
|
|
613
|
+
contentmenuCollectionItem.type ===
|
|
614
|
+
CONTEXTMENU_NODE_TYPES.REMOVE_ROW
|
|
615
|
+
) {
|
|
616
|
+
contentmenuCollectionItem.label =
|
|
617
|
+
contentmenuCollectionItem.label.replace("$1", rowCount);
|
|
618
|
+
}
|
|
619
|
+
// empty row. 选中整行时支持
|
|
620
|
+
else if (
|
|
621
|
+
contentmenuCollectionItem.type ===
|
|
622
|
+
CONTEXTMENU_NODE_TYPES.EMPTY_ROW
|
|
623
|
+
) {
|
|
624
|
+
if (isWholeRowSelection) {
|
|
625
|
+
contentmenuCollectionItem.label =
|
|
626
|
+
contentmenuCollectionItem.label.replace(
|
|
627
|
+
"$1",
|
|
628
|
+
rowCount,
|
|
629
|
+
);
|
|
630
|
+
} else {
|
|
631
|
+
isContinue = false;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
// empty cell.没选中整行时支持
|
|
635
|
+
else if (
|
|
636
|
+
contentmenuCollectionItem.type ===
|
|
637
|
+
CONTEXTMENU_NODE_TYPES.EMPTY_CELL
|
|
638
|
+
) {
|
|
639
|
+
isContinue = !isWholeRowSelection;
|
|
640
|
+
}
|
|
641
|
+
// remove column.没选中整行时支持
|
|
642
|
+
else if (
|
|
643
|
+
contentmenuCollectionItem.type ===
|
|
644
|
+
CONTEXTMENU_NODE_TYPES.REMOVE_COLUMN
|
|
645
|
+
) {
|
|
646
|
+
if (isWholeRowSelection) {
|
|
647
|
+
isContinue = false;
|
|
648
|
+
} else {
|
|
649
|
+
contentmenuCollectionItem.label =
|
|
650
|
+
contentmenuCollectionItem.label.replace(
|
|
651
|
+
"$1",
|
|
652
|
+
colCount,
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (isContinue) {
|
|
658
|
+
result.push(contentmenuCollectionItem);
|
|
659
|
+
}
|
|
660
|
+
} else {
|
|
661
|
+
result.push(contextmenu);
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
return result;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// create empty row data
|
|
669
|
+
export function createEmptyRowData({ colgroups, rowKeyFieldName }) {
|
|
670
|
+
let rowData = {
|
|
671
|
+
[rowKeyFieldName]: getRandomId(),
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
colgroups.forEach((column) => {
|
|
675
|
+
if (column.field) {
|
|
676
|
+
rowData[column.field] = "";
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
return rowData;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// empty row data
|
|
684
|
+
// export function emptyRowData({ rowData, rowKeyFieldName }) {
|
|
685
|
+
// Object.keys(rowData).forEach((key) => {
|
|
686
|
+
// if (key !== rowKeyFieldName) {
|
|
687
|
+
// rowData[key] = "";
|
|
688
|
+
// }
|
|
689
|
+
// });
|
|
690
|
+
|
|
691
|
+
// return rowData;
|
|
692
|
+
// }
|
|
693
|
+
|
|
694
|
+
// is contextmenu panel clicked
|
|
695
|
+
export function isContextmenuPanelClicked(event) {
|
|
696
|
+
let result = false;
|
|
697
|
+
const contextmenuPanelEls = document.querySelectorAll(
|
|
698
|
+
".ve-contextmenu-popper",
|
|
699
|
+
);
|
|
700
|
+
[].forEach.call(contextmenuPanelEls, function (el) {
|
|
701
|
+
if (el.contains(event.target)) {
|
|
702
|
+
result = true;
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
return result;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* @getColKeysByHeaderColumn
|
|
711
|
+
* @desc
|
|
712
|
+
* @param {object} headerColumnItem
|
|
713
|
+
* @param {any} colKey2
|
|
714
|
+
* @return Array<colKeys>
|
|
715
|
+
*/
|
|
716
|
+
export function getColKeysByHeaderColumn({ headerColumnItem }) {
|
|
717
|
+
let result = null;
|
|
718
|
+
|
|
719
|
+
const { _keys } = headerColumnItem;
|
|
720
|
+
|
|
721
|
+
result = _keys.split("|");
|
|
722
|
+
if (result.length > 1) {
|
|
723
|
+
result = result.slice(0, result.length - 1);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
return result;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* @getColKeysByRangeColKeys
|
|
731
|
+
* @desc get col keys by range col keys
|
|
732
|
+
* @param {any} colKey1
|
|
733
|
+
* @param {any} colKey2
|
|
734
|
+
* @return Array<colKeys>
|
|
735
|
+
*/
|
|
736
|
+
export function getColKeysByRangeColKeys({ colKey1, colKey2, colgroups }) {
|
|
737
|
+
let result = null;
|
|
738
|
+
|
|
739
|
+
const index1 = colgroups.findIndex((x) => x.key === colKey1);
|
|
740
|
+
const index2 = colgroups.findIndex((x) => x.key === colKey2);
|
|
741
|
+
|
|
742
|
+
if (index1 !== -1 && index1 !== -1) {
|
|
743
|
+
const beginIndex = index1 < index2 ? index1 : index2;
|
|
744
|
+
const endIndex = index1 < index2 ? index2 : index1;
|
|
745
|
+
result = colgroups.slice(beginIndex, endIndex + 1).map((x) => x.key);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
return result;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* @getColKeysByFixedTypeWithinColKeys
|
|
753
|
+
* @desc get col keys by fixed type
|
|
754
|
+
* @param {array<T>} colKeys
|
|
755
|
+
* @param {string} fixedType - fixed type
|
|
756
|
+
* @param {array<object>} colgroups
|
|
757
|
+
* @return {array} colKeys
|
|
758
|
+
*/
|
|
759
|
+
export function getColKeysByFixedTypeWithinColKeys({
|
|
760
|
+
colKeys,
|
|
761
|
+
fixedType,
|
|
762
|
+
colgroups,
|
|
763
|
+
}) {
|
|
764
|
+
let result = null;
|
|
765
|
+
|
|
766
|
+
if (Array.isArray(colKeys)) {
|
|
767
|
+
result = colgroups
|
|
768
|
+
.filter((x) => colKeys.indexOf(x.key) > -1 && x.fixed === fixedType)
|
|
769
|
+
.map((x) => x.key);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
return result;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* @getColKeysByFixedType
|
|
777
|
+
* @desc get col keys by fixed type
|
|
778
|
+
* @param {string} fixedType - fixed type
|
|
779
|
+
* @param {array<object>} colgroups
|
|
780
|
+
* * @param {boolean} isExcludeOperationColumn
|
|
781
|
+
* @return colKey
|
|
782
|
+
*/
|
|
783
|
+
export function getColKeysByFixedType({
|
|
784
|
+
fixedType,
|
|
785
|
+
colgroups,
|
|
786
|
+
isExcludeOperationColumn,
|
|
787
|
+
}) {
|
|
788
|
+
let result = null;
|
|
789
|
+
|
|
790
|
+
result = colgroups
|
|
791
|
+
.filter((x) => {
|
|
792
|
+
const condition = x.fixed === fixedType;
|
|
793
|
+
|
|
794
|
+
// 排除操作列
|
|
795
|
+
if (isExcludeOperationColumn) {
|
|
796
|
+
return condition && !x.operationColumn;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
return condition;
|
|
800
|
+
})
|
|
801
|
+
.map((x) => x.key);
|
|
802
|
+
return result;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* @getRowKeysByRangeRowKeys
|
|
807
|
+
* @desc get row keys by range row keys
|
|
808
|
+
* @param {any} topRowKey - top row key
|
|
809
|
+
* @param {any} bottomRowKey - bottom row key
|
|
810
|
+
* @return Array<colKeys>
|
|
811
|
+
*/
|
|
812
|
+
export function getRowKeysByRangeRowKeys({
|
|
813
|
+
topRowKey,
|
|
814
|
+
bottomRowKey,
|
|
815
|
+
allRowKeys,
|
|
816
|
+
}) {
|
|
817
|
+
let result = null;
|
|
818
|
+
|
|
819
|
+
const beginIndex = allRowKeys.findIndex((x) => x === topRowKey);
|
|
820
|
+
const endIndex = allRowKeys.findIndex((x) => x === bottomRowKey);
|
|
821
|
+
|
|
822
|
+
if (beginIndex !== -1 && endIndex !== -1) {
|
|
823
|
+
result = allRowKeys.slice(beginIndex, endIndex + 1);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
return result;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* @isCellInSelectionRange
|
|
831
|
+
* @desc is cell in selection range
|
|
832
|
+
* @param {object} cellData - cell data
|
|
833
|
+
* @param {object} cellSelectionRangeData
|
|
834
|
+
* @param {array<object>} colgroups
|
|
835
|
+
* @param {array<object>} allRowKeys
|
|
836
|
+
* @return {Array<colKeys>}
|
|
837
|
+
*/
|
|
838
|
+
export function isCellInSelectionRange({
|
|
839
|
+
cellData,
|
|
840
|
+
cellSelectionRangeData,
|
|
841
|
+
colgroups,
|
|
842
|
+
allRowKeys,
|
|
843
|
+
}) {
|
|
844
|
+
const { leftColKey, rightColKey, topRowKey, bottomRowKey } =
|
|
845
|
+
cellSelectionRangeData;
|
|
846
|
+
|
|
847
|
+
const colKeys = getColKeysByRangeColKeys({
|
|
848
|
+
colKey1: leftColKey,
|
|
849
|
+
colKey2: rightColKey,
|
|
850
|
+
colgroups,
|
|
851
|
+
});
|
|
852
|
+
const rowKeys = getRowKeysByRangeRowKeys({
|
|
853
|
+
topRowKey,
|
|
854
|
+
bottomRowKey,
|
|
855
|
+
allRowKeys,
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
if (
|
|
859
|
+
colKeys.indexOf(cellData.colKey) > -1 &&
|
|
860
|
+
rowKeys.indexOf(cellData.rowKey) > -1
|
|
861
|
+
) {
|
|
862
|
+
return true;
|
|
863
|
+
}
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* @isClearSelectionByBodyCellRightClick
|
|
869
|
+
* @desc is clear selection by body cell click
|
|
870
|
+
* @param {number} mouseEventClickType
|
|
871
|
+
* @param {object} cellData - cell data
|
|
872
|
+
* @param {object} cellSelectionRangeData
|
|
873
|
+
* @param {array<object>} colgroups
|
|
874
|
+
* @param {array<object>} allRowKeys
|
|
875
|
+
* @return {bool}
|
|
876
|
+
*/
|
|
877
|
+
export function isClearSelectionByBodyCellRightClick({
|
|
878
|
+
mouseEventClickType,
|
|
879
|
+
cellData,
|
|
880
|
+
cellSelectionData,
|
|
881
|
+
cellSelectionRangeData,
|
|
882
|
+
colgroups,
|
|
883
|
+
allRowKeys,
|
|
884
|
+
}) {
|
|
885
|
+
let result = true;
|
|
886
|
+
if (mouseEventClickType === MOUSE_EVENT_CLICK_TYPE.RIGHT_MOUSE) {
|
|
887
|
+
const { normalEndCell } = cellSelectionData;
|
|
888
|
+
if (normalEndCell.rowIndex > -1) {
|
|
889
|
+
result = !isCellInSelectionRange({
|
|
890
|
+
cellData,
|
|
891
|
+
cellSelectionRangeData,
|
|
892
|
+
colgroups,
|
|
893
|
+
allRowKeys,
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return result;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* @getSelectionRangeKeys
|
|
902
|
+
* @desc get selection range keys
|
|
903
|
+
* @param {object} cellSelectionRangeData
|
|
904
|
+
* @return Array<colKeys>
|
|
905
|
+
*/
|
|
906
|
+
export function getSelectionRangeKeys({ cellSelectionRangeData }) {
|
|
907
|
+
const { leftColKey, rightColKey, topRowKey, bottomRowKey } =
|
|
908
|
+
cellSelectionRangeData;
|
|
909
|
+
return {
|
|
910
|
+
startColKey: leftColKey,
|
|
911
|
+
endColKey: rightColKey,
|
|
912
|
+
startRowKey: topRowKey,
|
|
913
|
+
endRowKey: bottomRowKey,
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* @getSelectionRangeIndexes
|
|
919
|
+
* @desc get selection range indexes
|
|
920
|
+
* @param {object} cellSelectionRangeData
|
|
921
|
+
* @param {array<object>} colgroups
|
|
922
|
+
* @param {array<object>} allRowKeys
|
|
923
|
+
* @return Array<colKeys>
|
|
924
|
+
*/
|
|
925
|
+
export function getSelectionRangeIndexes({
|
|
926
|
+
cellSelectionRangeData,
|
|
927
|
+
colgroups,
|
|
928
|
+
allRowKeys,
|
|
929
|
+
}) {
|
|
930
|
+
const { leftColKey, rightColKey, topRowKey, bottomRowKey } =
|
|
931
|
+
cellSelectionRangeData;
|
|
932
|
+
return {
|
|
933
|
+
startColIndex: colgroups.findIndex((x) => x.key === leftColKey),
|
|
934
|
+
endColIndex: colgroups.findIndex((x) => x.key === rightColKey),
|
|
935
|
+
startRowIndex: allRowKeys.indexOf(topRowKey),
|
|
936
|
+
endRowIndex: allRowKeys.indexOf(bottomRowKey),
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* @getSelectionRangeData
|
|
942
|
+
* @desc get selection range data
|
|
943
|
+
* @param {object} cellSelectionRangeData
|
|
944
|
+
* @param {string} resultType "normal": contains key/value ; "flat":only contains value
|
|
945
|
+
* @param {array<object>} tableData
|
|
946
|
+
* @param {array<object>} colgroups
|
|
947
|
+
* @param {array<object>} allRowKeys
|
|
948
|
+
* @return Array<colKeys>
|
|
949
|
+
*/
|
|
950
|
+
export function getSelectionRangeData({
|
|
951
|
+
cellSelectionRangeData,
|
|
952
|
+
resultType = "normal",
|
|
953
|
+
tableData,
|
|
954
|
+
colgroups,
|
|
955
|
+
allRowKeys,
|
|
956
|
+
}) {
|
|
957
|
+
let result = null;
|
|
958
|
+
|
|
959
|
+
const { leftColKey, rightColKey, topRowKey, bottomRowKey } =
|
|
960
|
+
cellSelectionRangeData;
|
|
961
|
+
|
|
962
|
+
const startColIndex = colgroups.findIndex((x) => x.key === leftColKey);
|
|
963
|
+
const endColIndex = colgroups.findIndex((x) => x.key === rightColKey);
|
|
964
|
+
const startRowIndex = allRowKeys.indexOf(topRowKey);
|
|
965
|
+
const endRowIndex = allRowKeys.indexOf(bottomRowKey);
|
|
966
|
+
|
|
967
|
+
const fieldNames = colgroups
|
|
968
|
+
.slice(startColIndex, endColIndex + 1)
|
|
969
|
+
.map((x) => x.field);
|
|
970
|
+
|
|
971
|
+
if (resultType === "normal") {
|
|
972
|
+
result = tableData
|
|
973
|
+
.slice(startRowIndex, endRowIndex + 1)
|
|
974
|
+
.map((rowData) => {
|
|
975
|
+
let newRow = {};
|
|
976
|
+
|
|
977
|
+
fieldNames.forEach((fieldName) => {
|
|
978
|
+
newRow[fieldName] = rowData[fieldName] ?? "";
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
return newRow;
|
|
982
|
+
});
|
|
983
|
+
} else {
|
|
984
|
+
result = tableData
|
|
985
|
+
.slice(startRowIndex, endRowIndex + 1)
|
|
986
|
+
.map((rowData) => {
|
|
987
|
+
let newRow = [];
|
|
988
|
+
|
|
989
|
+
fieldNames.forEach((fieldName) => {
|
|
990
|
+
newRow.push(rowData[fieldName] ?? "");
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
return newRow;
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
return result;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* @isExistFixedColKey
|
|
1002
|
+
* @desc is exist given fixed col key
|
|
1003
|
+
* @param {string} fixedType - fixed type
|
|
1004
|
+
* @param {array<T>} colKeys
|
|
1005
|
+
* @param {array<object>} colgroups
|
|
1006
|
+
* @return bool
|
|
1007
|
+
*/
|
|
1008
|
+
export function isExistGivenFixedColKey({ fixedType, colKeys, colgroups }) {
|
|
1009
|
+
let result = false;
|
|
1010
|
+
if (Array.isArray(colKeys)) {
|
|
1011
|
+
result = colgroups.some((x) => {
|
|
1012
|
+
return colKeys.indexOf(x.key) > -1 && x.fixed === fixedType;
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
return result;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* @isExistNotFixedColKey
|
|
1020
|
+
* @desc is exist not fixed col key
|
|
1021
|
+
* @param {array<T>} colKeys
|
|
1022
|
+
* @param {array<object>} colgroups
|
|
1023
|
+
* @return bool
|
|
1024
|
+
*/
|
|
1025
|
+
export function isExistNotFixedColKey({ colKeys, colgroups }) {
|
|
1026
|
+
let result = false;
|
|
1027
|
+
if (Array.isArray(colKeys)) {
|
|
1028
|
+
result = colgroups.filter(
|
|
1029
|
+
(x) => !x.fixed && colKeys.indexOf(x.key) > -1,
|
|
1030
|
+
).length;
|
|
1031
|
+
}
|
|
1032
|
+
return result;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* @getLeftmostOrRightmostColKey
|
|
1037
|
+
* @desc get leftmost or rightmost column key
|
|
1038
|
+
* @param {string} type
|
|
1039
|
+
* @param {array<object>} colgroups
|
|
1040
|
+
* @param {array<any>} colKeys
|
|
1041
|
+
* @return colKey
|
|
1042
|
+
*/
|
|
1043
|
+
function getLeftmostOrRightmostColKey({ type, colgroups, colKeys }) {
|
|
1044
|
+
let result = null;
|
|
1045
|
+
|
|
1046
|
+
if (Array.isArray(colKeys) && colKeys.length) {
|
|
1047
|
+
let mostObj = {
|
|
1048
|
+
colKey: null,
|
|
1049
|
+
colIndex: null,
|
|
1050
|
+
};
|
|
1051
|
+
colKeys.forEach((colKey) => {
|
|
1052
|
+
const colIndex = colgroups.findIndex((x) => x.key === colKey);
|
|
1053
|
+
|
|
1054
|
+
if (colIndex === -1) {
|
|
1055
|
+
console.warn(
|
|
1056
|
+
`getLeftmostOrRightmostColKey error:: can't find colKey:${colKey}`,
|
|
1057
|
+
);
|
|
1058
|
+
return false;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (isEmptyValue(mostObj.colKey)) {
|
|
1062
|
+
mostObj = {
|
|
1063
|
+
colKey,
|
|
1064
|
+
colIndex: colIndex,
|
|
1065
|
+
};
|
|
1066
|
+
} else {
|
|
1067
|
+
if (type === "leftmost") {
|
|
1068
|
+
if (colIndex < mostObj.colIndex) {
|
|
1069
|
+
mostObj = {
|
|
1070
|
+
colKey,
|
|
1071
|
+
colIndex: colIndex,
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
} else if (type === "rightmost") {
|
|
1075
|
+
if (colIndex > mostObj.colIndex) {
|
|
1076
|
+
mostObj = {
|
|
1077
|
+
colKey,
|
|
1078
|
+
colIndex: colIndex,
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
result = mostObj.colKey;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
return result;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/**
|
|
1092
|
+
* @getLeftmostColKey
|
|
1093
|
+
* @desc get leftmost column key
|
|
1094
|
+
* @param {array<object>} colgroups
|
|
1095
|
+
* @param {array<any>} colKeys
|
|
1096
|
+
* @return colKey
|
|
1097
|
+
*/
|
|
1098
|
+
export function getLeftmostColKey({ colgroups, colKeys }) {
|
|
1099
|
+
return getLeftmostOrRightmostColKey({
|
|
1100
|
+
type: "leftmost",
|
|
1101
|
+
colgroups,
|
|
1102
|
+
colKeys,
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* @getRightmostColKey
|
|
1108
|
+
* @desc get rightmost column key
|
|
1109
|
+
* @param {array<object>} colgroups
|
|
1110
|
+
* @param {array<any>} colKeys
|
|
1111
|
+
* @return colKey
|
|
1112
|
+
*/
|
|
1113
|
+
export function getRightmostColKey({ colgroups, colKeys }) {
|
|
1114
|
+
return getLeftmostOrRightmostColKey({
|
|
1115
|
+
type: "rightmost",
|
|
1116
|
+
colgroups,
|
|
1117
|
+
colKeys,
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* @getPreviewColKey
|
|
1123
|
+
* @desc get preview column key
|
|
1124
|
+
* @param {array<object>} colgroups
|
|
1125
|
+
* @param {any} currentColKey
|
|
1126
|
+
* @return colKey
|
|
1127
|
+
*/
|
|
1128
|
+
export function getPreviewColKey({ colgroups, currentColKey }) {
|
|
1129
|
+
let result = null;
|
|
1130
|
+
|
|
1131
|
+
if (!isEmptyValue(currentColKey)) {
|
|
1132
|
+
const index = colgroups.findIndex((x) => x.key === currentColKey);
|
|
1133
|
+
if (index === 0) {
|
|
1134
|
+
result = currentColKey;
|
|
1135
|
+
} else if (index > 0) {
|
|
1136
|
+
result = colgroups[index - 1].key;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return result;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* @getNextColKey
|
|
1144
|
+
* @desc get next column key
|
|
1145
|
+
* @param {array<object>} colgroups
|
|
1146
|
+
* @param {any} currentColKey
|
|
1147
|
+
* @return colKey
|
|
1148
|
+
*/
|
|
1149
|
+
export function getNextColKey({ colgroups, currentColKey }) {
|
|
1150
|
+
let result = null;
|
|
1151
|
+
|
|
1152
|
+
if (!isEmptyValue(currentColKey)) {
|
|
1153
|
+
const index = colgroups.findIndex((x) => x.key === currentColKey);
|
|
1154
|
+
if (index === colgroups.length - 1) {
|
|
1155
|
+
result = currentColKey;
|
|
1156
|
+
} else if (index < colgroups.length - 1) {
|
|
1157
|
+
result = colgroups[index + 1].key;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return result;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/***
|
|
1164
|
+
* @cellAutofill
|
|
1165
|
+
* @desc cell auto fill
|
|
1166
|
+
* @param {bool} isReplaceData
|
|
1167
|
+
* @param {array<object>} tableData
|
|
1168
|
+
* @param {array<any>} allRowKeys
|
|
1169
|
+
* @param {array<object>} colgroups
|
|
1170
|
+
* @param {string} direction
|
|
1171
|
+
* @param {string} rowKeyFieldName
|
|
1172
|
+
* @param {object} nextCurrentCell next current cell
|
|
1173
|
+
* @param {object} nextNormalEndCell next normal end cell
|
|
1174
|
+
* @return autofillChangeDatas
|
|
1175
|
+
*/
|
|
1176
|
+
export function cellAutofill({
|
|
1177
|
+
isReplaceData,
|
|
1178
|
+
tableData,
|
|
1179
|
+
allRowKeys,
|
|
1180
|
+
colgroups,
|
|
1181
|
+
direction,
|
|
1182
|
+
rowKeyFieldName,
|
|
1183
|
+
cellSelectionRangeData,
|
|
1184
|
+
nextCurrentCell,
|
|
1185
|
+
nextNormalEndCell,
|
|
1186
|
+
}) {
|
|
1187
|
+
let cellSelectionTableData = [];
|
|
1188
|
+
|
|
1189
|
+
const { leftColKey, rightColKey, topRowKey, bottomRowKey } =
|
|
1190
|
+
cellSelectionRangeData;
|
|
1191
|
+
|
|
1192
|
+
// source selection range
|
|
1193
|
+
let sourceSelectionRangeIndexes = {
|
|
1194
|
+
startRowIndex: -1,
|
|
1195
|
+
endRowIndex: -1,
|
|
1196
|
+
startColIndex: -1,
|
|
1197
|
+
endColIndex: -1,
|
|
1198
|
+
};
|
|
1199
|
+
// target selection range
|
|
1200
|
+
let targetSelectionRangeIndexes = {
|
|
1201
|
+
startRowIndex: -1,
|
|
1202
|
+
endRowIndex: -1,
|
|
1203
|
+
startColIndex: -1,
|
|
1204
|
+
endColIndex: -1,
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
sourceSelectionRangeIndexes.startRowIndex = allRowKeys.indexOf(topRowKey);
|
|
1208
|
+
sourceSelectionRangeIndexes.endRowIndex = allRowKeys.indexOf(bottomRowKey);
|
|
1209
|
+
sourceSelectionRangeIndexes.startColIndex = colgroups.findIndex(
|
|
1210
|
+
(x) => x.key === leftColKey,
|
|
1211
|
+
);
|
|
1212
|
+
sourceSelectionRangeIndexes.endColIndex = colgroups.findIndex(
|
|
1213
|
+
(x) => x.key === rightColKey,
|
|
1214
|
+
);
|
|
1215
|
+
|
|
1216
|
+
cellSelectionTableData = tableData.slice(
|
|
1217
|
+
sourceSelectionRangeIndexes.startRowIndex,
|
|
1218
|
+
sourceSelectionRangeIndexes.endRowIndex + 1,
|
|
1219
|
+
);
|
|
1220
|
+
|
|
1221
|
+
if (direction === AUTOFILLING_DIRECTION.UP) {
|
|
1222
|
+
//
|
|
1223
|
+
targetSelectionRangeIndexes.startRowIndex = allRowKeys.indexOf(
|
|
1224
|
+
nextCurrentCell.rowKey,
|
|
1225
|
+
);
|
|
1226
|
+
targetSelectionRangeIndexes.endRowIndex =
|
|
1227
|
+
sourceSelectionRangeIndexes.startRowIndex - 1;
|
|
1228
|
+
targetSelectionRangeIndexes.startColIndex =
|
|
1229
|
+
sourceSelectionRangeIndexes.startColIndex;
|
|
1230
|
+
targetSelectionRangeIndexes.endColIndex =
|
|
1231
|
+
sourceSelectionRangeIndexes.endColIndex;
|
|
1232
|
+
|
|
1233
|
+
if (isReplaceData) {
|
|
1234
|
+
let cellSelectionTableDataRowIndex =
|
|
1235
|
+
cellSelectionTableData.length - 1;
|
|
1236
|
+
for (
|
|
1237
|
+
let rowIndex = targetSelectionRangeIndexes.endRowIndex;
|
|
1238
|
+
rowIndex >= targetSelectionRangeIndexes.startRowIndex;
|
|
1239
|
+
rowIndex--
|
|
1240
|
+
) {
|
|
1241
|
+
for (
|
|
1242
|
+
let colIndex = targetSelectionRangeIndexes.startColIndex;
|
|
1243
|
+
colIndex <= targetSelectionRangeIndexes.endColIndex;
|
|
1244
|
+
colIndex++
|
|
1245
|
+
) {
|
|
1246
|
+
const fieldName = colgroups[colIndex].field;
|
|
1247
|
+
|
|
1248
|
+
// repeat autofill cell selection data
|
|
1249
|
+
if (cellSelectionTableDataRowIndex < 0) {
|
|
1250
|
+
cellSelectionTableDataRowIndex =
|
|
1251
|
+
cellSelectionTableData.length - 1;
|
|
1252
|
+
}
|
|
1253
|
+
tableData[rowIndex][fieldName] =
|
|
1254
|
+
cellSelectionTableData[cellSelectionTableDataRowIndex][
|
|
1255
|
+
fieldName
|
|
1256
|
+
];
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
--cellSelectionTableDataRowIndex;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
} else if (direction === AUTOFILLING_DIRECTION.DOWN) {
|
|
1263
|
+
//
|
|
1264
|
+
targetSelectionRangeIndexes.startRowIndex =
|
|
1265
|
+
sourceSelectionRangeIndexes.endRowIndex + 1;
|
|
1266
|
+
targetSelectionRangeIndexes.endRowIndex = allRowKeys.indexOf(
|
|
1267
|
+
nextNormalEndCell.rowKey,
|
|
1268
|
+
);
|
|
1269
|
+
targetSelectionRangeIndexes.startColIndex =
|
|
1270
|
+
sourceSelectionRangeIndexes.startColIndex;
|
|
1271
|
+
targetSelectionRangeIndexes.endColIndex =
|
|
1272
|
+
sourceSelectionRangeIndexes.endColIndex;
|
|
1273
|
+
|
|
1274
|
+
if (isReplaceData) {
|
|
1275
|
+
let cellSelectionTableDataRowIndex = 0;
|
|
1276
|
+
for (
|
|
1277
|
+
let rowIndex = targetSelectionRangeIndexes.startRowIndex;
|
|
1278
|
+
rowIndex <= targetSelectionRangeIndexes.endRowIndex;
|
|
1279
|
+
rowIndex++
|
|
1280
|
+
) {
|
|
1281
|
+
for (
|
|
1282
|
+
let colIndex = targetSelectionRangeIndexes.startColIndex;
|
|
1283
|
+
colIndex <= targetSelectionRangeIndexes.endColIndex;
|
|
1284
|
+
colIndex++
|
|
1285
|
+
) {
|
|
1286
|
+
const fieldName = colgroups[colIndex].field;
|
|
1287
|
+
|
|
1288
|
+
// repeat autofill cell selection data
|
|
1289
|
+
if (
|
|
1290
|
+
cellSelectionTableDataRowIndex >
|
|
1291
|
+
cellSelectionTableData.length - 1
|
|
1292
|
+
) {
|
|
1293
|
+
cellSelectionTableDataRowIndex = 0;
|
|
1294
|
+
}
|
|
1295
|
+
tableData[rowIndex][fieldName] =
|
|
1296
|
+
cellSelectionTableData[cellSelectionTableDataRowIndex][
|
|
1297
|
+
fieldName
|
|
1298
|
+
];
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
++cellSelectionTableDataRowIndex;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
} else if (direction === AUTOFILLING_DIRECTION.LEFT) {
|
|
1305
|
+
//
|
|
1306
|
+
targetSelectionRangeIndexes.startRowIndex =
|
|
1307
|
+
sourceSelectionRangeIndexes.startRowIndex;
|
|
1308
|
+
targetSelectionRangeIndexes.endRowIndex =
|
|
1309
|
+
sourceSelectionRangeIndexes.endRowIndex;
|
|
1310
|
+
targetSelectionRangeIndexes.startColIndex = colgroups.findIndex(
|
|
1311
|
+
(x) => x.key === nextCurrentCell.colKey,
|
|
1312
|
+
);
|
|
1313
|
+
targetSelectionRangeIndexes.endColIndex =
|
|
1314
|
+
sourceSelectionRangeIndexes.startColIndex - 1;
|
|
1315
|
+
|
|
1316
|
+
if (isReplaceData) {
|
|
1317
|
+
let cellSelectionTableDataRowIndex = 0;
|
|
1318
|
+
for (
|
|
1319
|
+
let rowIndex = targetSelectionRangeIndexes.startRowIndex;
|
|
1320
|
+
rowIndex <= targetSelectionRangeIndexes.endRowIndex;
|
|
1321
|
+
rowIndex++
|
|
1322
|
+
) {
|
|
1323
|
+
let cellSelectionTableDataColIndex =
|
|
1324
|
+
sourceSelectionRangeIndexes.endColIndex;
|
|
1325
|
+
|
|
1326
|
+
for (
|
|
1327
|
+
let colIndex = targetSelectionRangeIndexes.endColIndex;
|
|
1328
|
+
colIndex >= targetSelectionRangeIndexes.startColIndex;
|
|
1329
|
+
colIndex--
|
|
1330
|
+
) {
|
|
1331
|
+
const fieldName = colgroups[colIndex].field;
|
|
1332
|
+
|
|
1333
|
+
// repeat autofill cell selection data
|
|
1334
|
+
if (
|
|
1335
|
+
cellSelectionTableDataColIndex <
|
|
1336
|
+
sourceSelectionRangeIndexes.startColIndex
|
|
1337
|
+
) {
|
|
1338
|
+
cellSelectionTableDataColIndex =
|
|
1339
|
+
sourceSelectionRangeIndexes.endColIndex;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
tableData[rowIndex][fieldName] =
|
|
1343
|
+
cellSelectionTableData[cellSelectionTableDataRowIndex][
|
|
1344
|
+
colgroups[cellSelectionTableDataColIndex].field
|
|
1345
|
+
];
|
|
1346
|
+
--cellSelectionTableDataColIndex;
|
|
1347
|
+
}
|
|
1348
|
+
++cellSelectionTableDataRowIndex;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
} else if (direction === AUTOFILLING_DIRECTION.RIGHT) {
|
|
1352
|
+
//
|
|
1353
|
+
targetSelectionRangeIndexes.startRowIndex =
|
|
1354
|
+
sourceSelectionRangeIndexes.startRowIndex;
|
|
1355
|
+
targetSelectionRangeIndexes.endRowIndex =
|
|
1356
|
+
sourceSelectionRangeIndexes.endRowIndex;
|
|
1357
|
+
targetSelectionRangeIndexes.startColIndex =
|
|
1358
|
+
sourceSelectionRangeIndexes.endColIndex + 1;
|
|
1359
|
+
targetSelectionRangeIndexes.endColIndex = colgroups.findIndex(
|
|
1360
|
+
(x) => x.key === nextNormalEndCell.colKey,
|
|
1361
|
+
);
|
|
1362
|
+
|
|
1363
|
+
if (isReplaceData) {
|
|
1364
|
+
let cellSelectionTableDataRowIndex = 0;
|
|
1365
|
+
for (
|
|
1366
|
+
let rowIndex = targetSelectionRangeIndexes.startRowIndex;
|
|
1367
|
+
rowIndex <= targetSelectionRangeIndexes.endRowIndex;
|
|
1368
|
+
rowIndex++
|
|
1369
|
+
) {
|
|
1370
|
+
let cellSelectionTableDataColIndex =
|
|
1371
|
+
sourceSelectionRangeIndexes.startColIndex;
|
|
1372
|
+
|
|
1373
|
+
for (
|
|
1374
|
+
let colIndex = targetSelectionRangeIndexes.startColIndex;
|
|
1375
|
+
colIndex <= targetSelectionRangeIndexes.endColIndex;
|
|
1376
|
+
colIndex++
|
|
1377
|
+
) {
|
|
1378
|
+
const fieldName = colgroups[colIndex].field;
|
|
1379
|
+
|
|
1380
|
+
// repeat autofill cell selection data
|
|
1381
|
+
if (
|
|
1382
|
+
cellSelectionTableDataColIndex >
|
|
1383
|
+
sourceSelectionRangeIndexes.startColIndex +
|
|
1384
|
+
(sourceSelectionRangeIndexes.endColIndex -
|
|
1385
|
+
sourceSelectionRangeIndexes.startColIndex)
|
|
1386
|
+
) {
|
|
1387
|
+
cellSelectionTableDataColIndex =
|
|
1388
|
+
sourceSelectionRangeIndexes.startColIndex;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
tableData[rowIndex][fieldName] =
|
|
1392
|
+
cellSelectionTableData[cellSelectionTableDataRowIndex][
|
|
1393
|
+
colgroups[cellSelectionTableDataColIndex].field
|
|
1394
|
+
];
|
|
1395
|
+
++cellSelectionTableDataColIndex;
|
|
1396
|
+
}
|
|
1397
|
+
++cellSelectionTableDataRowIndex;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
let response = {
|
|
1403
|
+
direction,
|
|
1404
|
+
sourceSelectionRangeIndexes,
|
|
1405
|
+
targetSelectionRangeIndexes,
|
|
1406
|
+
sourceSelectionData: [],
|
|
1407
|
+
targetSelectionData: [],
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
const sourceFieldNames = colgroups
|
|
1411
|
+
.slice(
|
|
1412
|
+
sourceSelectionRangeIndexes.startColIndex,
|
|
1413
|
+
sourceSelectionRangeIndexes.endColIndex + 1,
|
|
1414
|
+
)
|
|
1415
|
+
.map((x) => x.field);
|
|
1416
|
+
response.sourceSelectionData = tableData
|
|
1417
|
+
.slice(
|
|
1418
|
+
sourceSelectionRangeIndexes.startRowIndex,
|
|
1419
|
+
sourceSelectionRangeIndexes.endRowIndex + 1,
|
|
1420
|
+
)
|
|
1421
|
+
.map((rowData) => {
|
|
1422
|
+
let newData = {
|
|
1423
|
+
[rowKeyFieldName]: rowData[rowKeyFieldName],
|
|
1424
|
+
};
|
|
1425
|
+
sourceFieldNames.forEach((fieldName) => {
|
|
1426
|
+
newData[fieldName] = rowData[fieldName];
|
|
1427
|
+
});
|
|
1428
|
+
return newData;
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
const targetFieldNames = colgroups
|
|
1432
|
+
.slice(
|
|
1433
|
+
targetSelectionRangeIndexes.startColIndex,
|
|
1434
|
+
targetSelectionRangeIndexes.endColIndex + 1,
|
|
1435
|
+
)
|
|
1436
|
+
.map((x) => x.field);
|
|
1437
|
+
response.targetSelectionData = tableData
|
|
1438
|
+
.slice(
|
|
1439
|
+
targetSelectionRangeIndexes.startRowIndex,
|
|
1440
|
+
targetSelectionRangeIndexes.endRowIndex + 1,
|
|
1441
|
+
)
|
|
1442
|
+
.map((rowData) => {
|
|
1443
|
+
let newData = {
|
|
1444
|
+
[rowKeyFieldName]: rowData[rowKeyFieldName],
|
|
1445
|
+
};
|
|
1446
|
+
targetFieldNames.forEach((fieldName) => {
|
|
1447
|
+
newData[fieldName] = rowData[fieldName];
|
|
1448
|
+
});
|
|
1449
|
+
return newData;
|
|
1450
|
+
});
|
|
1451
|
+
|
|
1452
|
+
return response;
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
/***
|
|
1456
|
+
* @setColumnFixed
|
|
1457
|
+
* @desc set column fixed
|
|
1458
|
+
* @param {array<object>} cloneColumns
|
|
1459
|
+
* @param {object} cellSelectionRangeData
|
|
1460
|
+
* @param {string} fixedType COLUMN_FIXED_TYPE
|
|
1461
|
+
* @param {array<object>} colgroups
|
|
1462
|
+
* @param {bool} enableColumnResize
|
|
1463
|
+
* @return cloneColumns
|
|
1464
|
+
*/
|
|
1465
|
+
export function setColumnFixed({
|
|
1466
|
+
cloneColumns,
|
|
1467
|
+
cellSelectionRangeData,
|
|
1468
|
+
fixedType,
|
|
1469
|
+
colgroups,
|
|
1470
|
+
enableColumnResize,
|
|
1471
|
+
}) {
|
|
1472
|
+
let result = cloneColumns;
|
|
1473
|
+
|
|
1474
|
+
const { leftColKey, rightColKey } = cellSelectionRangeData;
|
|
1475
|
+
|
|
1476
|
+
let colKey;
|
|
1477
|
+
|
|
1478
|
+
if (COLUMN_FIXED_TYPE.LEFT === fixedType) {
|
|
1479
|
+
colKey = rightColKey;
|
|
1480
|
+
} else if (COLUMN_FIXED_TYPE.RIGHT === fixedType) {
|
|
1481
|
+
colKey = leftColKey;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// find col index from cloneColumns
|
|
1485
|
+
const fixedColIndex = cloneColumns.findIndex((colItem) => {
|
|
1486
|
+
if (colItem._level === 1 && colItem.key === colKey) {
|
|
1487
|
+
return true;
|
|
1488
|
+
} else {
|
|
1489
|
+
const colKeys = getColKeysByHeaderColumn({
|
|
1490
|
+
headerColumnItem: colItem,
|
|
1491
|
+
});
|
|
1492
|
+
if (colKeys.indexOf(colKey) > -1) {
|
|
1493
|
+
return true;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
|
|
1498
|
+
if (fixedColIndex > -1) {
|
|
1499
|
+
// 不允许改变原有固定列方向
|
|
1500
|
+
const oldFixedType = cloneColumns[fixedColIndex].fixed;
|
|
1501
|
+
if (!isEmptyValue(oldFixedType) && oldFixedType !== fixedType) {
|
|
1502
|
+
return false;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
result = cloneColumns.map((colItem, index) => {
|
|
1506
|
+
// 清除所有固定
|
|
1507
|
+
if (colItem.fixed === fixedType) {
|
|
1508
|
+
colItem.fixed = "";
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
// 允许列自适应 && 不是多列表头
|
|
1512
|
+
if (
|
|
1513
|
+
enableColumnResize &&
|
|
1514
|
+
!(Array.isArray(colItem.children) && colItem.children.length)
|
|
1515
|
+
) {
|
|
1516
|
+
const _colItem = colgroups.find(
|
|
1517
|
+
(x) => x.key === colItem.key && !isEmptyValue(x.key),
|
|
1518
|
+
);
|
|
1519
|
+
if (_colItem) {
|
|
1520
|
+
colItem.width = _colItem._columnResizeWidth;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
if (COLUMN_FIXED_TYPE.LEFT === fixedType) {
|
|
1525
|
+
// 不允许左冻结最后一列
|
|
1526
|
+
if (index <= fixedColIndex && index < cloneColumns.length) {
|
|
1527
|
+
colItem.fixed = fixedType;
|
|
1528
|
+
}
|
|
1529
|
+
} else {
|
|
1530
|
+
// 不允许右冻结第一列
|
|
1531
|
+
if (index >= fixedColIndex && index > 0) {
|
|
1532
|
+
colItem.fixed = fixedType;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
return colItem;
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
return result;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
/***
|
|
1543
|
+
* @cancelColumnFixed
|
|
1544
|
+
* @desc cancel column fixed
|
|
1545
|
+
* @param {array<object>} cloneColumns
|
|
1546
|
+
* @param {array<object>} colgroups
|
|
1547
|
+
* @param {string} fixedType COLUMN_FIXED_TYPE
|
|
1548
|
+
* @param {bool} enableColumnResize
|
|
1549
|
+
* @return cloneColumns
|
|
1550
|
+
*/
|
|
1551
|
+
export function cancelColumnFixed({
|
|
1552
|
+
cloneColumns,
|
|
1553
|
+
colgroups,
|
|
1554
|
+
fixedType,
|
|
1555
|
+
enableColumnResize,
|
|
1556
|
+
}) {
|
|
1557
|
+
return cloneColumns.map((colItem) => {
|
|
1558
|
+
// 允许列自适应 && 不是多列表头
|
|
1559
|
+
if (
|
|
1560
|
+
enableColumnResize &&
|
|
1561
|
+
!(Array.isArray(colItem.children) && colItem.children.length)
|
|
1562
|
+
) {
|
|
1563
|
+
const _colItem = colgroups.find(
|
|
1564
|
+
(x) => x.key === colItem.key && !isEmptyValue(x.key),
|
|
1565
|
+
);
|
|
1566
|
+
if (_colItem) {
|
|
1567
|
+
colItem.width = _colItem._columnResizeWidth;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
if (COLUMN_FIXED_TYPE.LEFT === fixedType) {
|
|
1572
|
+
if (
|
|
1573
|
+
colItem.fixed === fixedType &&
|
|
1574
|
+
!isOperationColumn(colItem.key, colgroups)
|
|
1575
|
+
) {
|
|
1576
|
+
colItem.fixed = "";
|
|
1577
|
+
}
|
|
1578
|
+
} else {
|
|
1579
|
+
if (colItem.fixed === fixedType) {
|
|
1580
|
+
colItem.fixed = "";
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
return colItem;
|
|
1584
|
+
});
|
|
1585
|
+
}
|