ocpview-plus 1.0.3 → 1.0.5

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.
@@ -0,0 +1,251 @@
1
+ export default {
2
+ name: "useVxeGridEditTypeKeydownEventHook",
3
+ data() {
4
+ return {
5
+ VG_currentEditRecord: {},
6
+ };
7
+ },
8
+ computed: {
9
+ /**
10
+ * 按键配置项
11
+ */
12
+ VG_keyboardConfig() {
13
+ const onOff = true;
14
+ return {
15
+ isArrow: onOff,
16
+ isEdit: onOff,
17
+ isEsc: onOff,
18
+ isEnter: onOff,
19
+ enterToTab: onOff,
20
+ isChecked: onOff,
21
+ };
22
+ },
23
+ VG_mouseConfig() {
24
+ const onOff = true;
25
+ return {
26
+ selected: onOff,
27
+ };
28
+ },
29
+ },
30
+ methods: {
31
+ /**
32
+ * 当表格被激活且键盘被按下时会触发的事件
33
+ * @param {*} $event
34
+ */
35
+ VG_keydown({ $event, $table }) {
36
+ // 按键码
37
+ const keyCode = $event.keyCode;
38
+ // console.log("🚀 ~ VG_keydown ~ keyCode:", keyCode);
39
+ // 按键分支
40
+ switch (keyCode) {
41
+ case 13:
42
+ // 回车事件
43
+ window.event.returnValue = false;
44
+ $event.preventDefault();
45
+ this.VG_keyCode13Event($table);
46
+ break;
47
+
48
+ case 38:
49
+ // 上键事件
50
+ window.event.returnValue = false;
51
+ $event.preventDefault();
52
+ this.VG_keyCodeUpAndDownEvent($table, "up");
53
+ break;
54
+
55
+ case 40:
56
+ // 下键事件
57
+ window.event.returnValue = false;
58
+ $event.preventDefault();
59
+ this.VG_keyCodeUpAndDownEvent($table, "down");
60
+ break;
61
+
62
+ default:
63
+ break;
64
+ }
65
+ },
66
+
67
+ /**
68
+ * 回车键盘事件
69
+ *
70
+ * keydown-start 当表格被激活且键盘被按下开始时会触发的事件
71
+ * keydown-end 当表格被激活且键盘被按下结束时会触发的事件
72
+ * @param {*} $table
73
+ */
74
+ VG_keyCode13Event($table) {
75
+ // 获取方法的返回值用来决定该单元格是否允许编辑
76
+ const activeMethod = this.$utils.get(
77
+ $table,
78
+ "editConfig.beforeEditMethod",
79
+ function () {
80
+ return true;
81
+ }
82
+ );
83
+ // 获取编辑状态、选择装填相关数据 getEditRecord
84
+ const editRecord = $table.getEditRecord();
85
+ const selectedCell = $table.getSelectedCell();
86
+ // 完整列信息查询
87
+ const { tableColumn } = $table.getTableColumn();
88
+ const fullData = $table.getTableData().fullData;
89
+ // 编辑状态,关闭当前编辑状态
90
+ if (editRecord) {
91
+ const { row, column } = editRecord;
92
+ const rowIndex = $table.getVTRowIndex(row);
93
+ const columnIndex = $table.getVTColumnIndex(column);
94
+ $table.scrollToRow(row, column).then(() => {
95
+ $table.clearEdit();
96
+ const isLastEditCell = this.VG_setRowIsEditCell(
97
+ row,
98
+ columnIndex,
99
+ tableColumn,
100
+ activeMethod,
101
+ $table
102
+ );
103
+ if (isLastEditCell) {
104
+ const nextRowSub = rowIndex + 1;
105
+ if (fullData[nextRowSub]) {
106
+ const { scrollTop } = $table.getScroll();
107
+ $table.scrollTo(0, scrollTop).then(() => {
108
+ // 存在下一行数据
109
+ // $table.setEditRow(fullData[nextRowSub]);
110
+ this.VG_setRowIsEditCell(
111
+ fullData[nextRowSub],
112
+ 0,
113
+ tableColumn,
114
+ activeMethod,
115
+ $table
116
+ );
117
+ });
118
+ } else {
119
+ $table.setEditRow(fullData[rowIndex], column);
120
+ }
121
+ }
122
+ });
123
+ }
124
+
125
+ // 单元格选中状态
126
+ if (selectedCell) {
127
+ const { row, column } = selectedCell;
128
+ const rowIndex = $table.getVTRowIndex(row);
129
+ const columnIndex = $table.getVTColumnIndex(column);
130
+ $table.scrollToRow(row, column).then(() => {
131
+ const succ = activeMethod(selectedCell);
132
+ if (column.editRender && succ) {
133
+ $table.setEditCell(row, column.property);
134
+ } else {
135
+ const isLastEditCell = this.VG_setRowIsEditCell(
136
+ row,
137
+ columnIndex,
138
+ tableColumn,
139
+ activeMethod,
140
+ $table
141
+ );
142
+ // 当前行到达最后一个可编辑项
143
+ if (isLastEditCell) {
144
+ const nextRowSub = rowIndex + 1;
145
+ if (fullData[nextRowSub]) {
146
+ const { scrollTop } = $table.getScroll();
147
+ $table.scrollTo(0, scrollTop).then(() => {
148
+ // 存在下一行数据
149
+ this.VG_setRowIsEditCell(
150
+ fullData[nextRowSub],
151
+ 0,
152
+ tableColumn,
153
+ activeMethod,
154
+ $table
155
+ );
156
+ });
157
+ } else {
158
+ // 已经到底,可以走新增逻辑
159
+ // console.log("已经到底,可以走新增逻辑111111");
160
+ // if (lastEditCellKeyCode13Method)
161
+ // lastEditCellKeyCode13Method();
162
+ }
163
+ }
164
+ }
165
+ });
166
+ }
167
+ },
168
+
169
+ /**
170
+ * 下键事件
171
+ * @param {*} $table
172
+ */
173
+ VG_keyCodeUpAndDownEvent($table, type = "down") {
174
+ // 暂存当前编辑行资源
175
+ this.VG_currentEditRecord = $table.getEditRecord();
176
+ // 获取方法的返回值用来决定该单元格是否允许编辑
177
+ const activeMethod = this.$utils.get(
178
+ $table,
179
+ "editConfig.beforeEditMethod",
180
+ function () {
181
+ return true;
182
+ }
183
+ );
184
+ // 获取编辑状态、选择装填相关数据 getEditRecord
185
+ const editRecord = $table.getEditRecord();
186
+ const fullData = $table.getTableData().fullData;
187
+ // 编辑状态,关闭当前编辑状态
188
+ if (editRecord) {
189
+ const { row, column } = editRecord;
190
+ const rowIndex = $table.getVTRowIndex(row);
191
+ $table.scrollToRow(row, column).then(() => {
192
+ $table.clearEdit();
193
+ const succ = activeMethod({ row, column });
194
+ if (column.editRender && succ) {
195
+ const nextRowSub =
196
+ type === "down" ? rowIndex + 1 : rowIndex - 1;
197
+ if (fullData[nextRowSub]) {
198
+ const { scrollTop } = $table.getScroll();
199
+ $table.scrollTo(0, scrollTop).then(() => {
200
+ // 存在下一行\上一行数据
201
+ $table.setEditRow(fullData[nextRowSub], column);
202
+ });
203
+ } else {
204
+ $table.setEditRow(fullData[rowIndex], column);
205
+ }
206
+ }
207
+ });
208
+ }
209
+ },
210
+
211
+ /**
212
+ * 行内可编辑项跳转
213
+ * @param {*} row
214
+ * @param {*} columnIndex
215
+ * @param {*} fullColumn
216
+ * @param {*} activeMethod
217
+ * @param {*} $table
218
+ * @returns
219
+ */
220
+ VG_setRowIsEditCell(
221
+ row,
222
+ columnIndex,
223
+ fullColumn,
224
+ activeMethod,
225
+ $table
226
+ ) {
227
+ let isLastEditCell = true;
228
+ for (
229
+ let i = columnIndex + 1, len = fullColumn.length;
230
+ i < len;
231
+ i++
232
+ ) {
233
+ const column = fullColumn[i];
234
+ const succ = activeMethod({ row, column });
235
+
236
+ if (column.editRender && column.editRender.enabled && succ) {
237
+ $table.scrollToRow(row, column).then(() => {
238
+ $table.setEditCell(row, column.property);
239
+ });
240
+ isLastEditCell = false;
241
+ break;
242
+ }
243
+ }
244
+ return isLastEditCell;
245
+ },
246
+
247
+ VG_editActivated(params) {
248
+ this.VG_currentEditRecord = params;
249
+ },
250
+ },
251
+ };