Files
workspace/code/g3hd/frontend/src/utils/g3Funlibgrid.js
T
2026-08-08 17:29:51 +08:00

65 lines
2.0 KiB
JavaScript

export function processGridKeydown(event, $table) {
if (!$table) {
return;
}
const currentRow = $table.getCurrentRecord();
const currentRowIndex = $table.getRowIndex(currentRow);
const currentColumn = $table.getCurrentColumn();
const { key } = event;
// 获取表格的所有数据和列配置
const fullData = $table.getFullData();
const columns = $table.getColumns();
const currentColumnIndex = $table.getColumnIndex(currentColumn);
// ArrowUp - 向上移动一行
if (key === "ArrowUp" && currentRowIndex > 0) {
const toIndex = currentRowIndex - 1;
$table.setEditRow(fullData[toIndex], currentColumn.property);
$table.setCurrentRow(fullData[toIndex]);
}
// ArrowDown - 向下移动一行
else if (key === "ArrowDown" && currentRowIndex < fullData.length - 1) {
const toIndex = currentRowIndex + 1;
$table.setEditRow(fullData[toIndex], currentColumn.property);
$table.setCurrentRow(fullData[toIndex]);
}
// ArrowLeft - 向左移动一列
else if (key === "ArrowLeft" && currentColumnIndex > 0) {
const toIndex = currentColumnIndex - 1;
$table.setEditCell(currentRow, columns[toIndex]);
$table.setCurrentColumn(columns[toIndex]);
}
// ArrowRight || Enter - 向右移动一列
else if ((key === "ArrowRight" || key === "Enter") && currentColumnIndex < columns.length - 1) {
event.preventDefault();
const toIndex = currentColumnIndex + 1;
$table.setEditCell(currentRow, columns[toIndex]);
$table.setCurrentColumn(columns[toIndex]);
}
}
export function processRowDrag(list, event, sortField = "mx_xh") {
const { oldRow, newRow } = event;
console.log("1111111111");
const oldIndex = list.indexOf(oldRow);
const newIndex = list.indexOf(newRow);
console.log(oldIndex);
console.log(newIndex);
if (oldIndex < 0 || newIndex < 0 || oldIndex === newIndex) {
return;
}
const [row] = list.splice(oldIndex, 1);
list.splice(newIndex, 0, row);
list.forEach((item, index) => {
item[sortField] = index + 1;
});
}