Vanessa 2023-07-14 00:41:49 +08:00
parent 7f097f3b99
commit 5546bb75b8

View File

@ -355,7 +355,13 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: {
}, currentElement: HTMLElement, menuElement: HTMLElement) => { }, currentElement: HTMLElement, menuElement: HTMLElement) => {
const rowID = options.cellElement.parentElement.dataset.id; const rowID = options.cellElement.parentElement.dataset.id;
const colId = options.cellElement.dataset.colId; const colId = options.cellElement.dataset.colId;
const cellId = options.cellElement.dataset.id; let cellIndex = 0;
Array.from(options.cellElement.parentElement.querySelectorAll(".av__cell")).find((item: HTMLElement, index) => {
if (item.dataset.id === options.cellElement.dataset.id) {
cellIndex = index;
return true;
}
})
let colData: IAVColumn; let colData: IAVColumn;
data.view.columns.find((item: IAVColumn) => { data.view.columns.find((item: IAVColumn) => {
if (item.id === colId) { if (item.id === colId) {
@ -369,38 +375,26 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: {
let cellData: IAVCell; let cellData: IAVCell;
data.view.rows.find(row => { data.view.rows.find(row => {
if (row.id === rowID) { if (row.id === rowID) {
row.cells.find(cell => { cellData = row.cells[cellIndex];
if (cell.id === cellId) { // 为空时 cellId 每次请求都不一致
cellData = cell; cellData.id = options.cellElement.dataset.id;
if (!cellData.value.mSelect) { if (!cellData.value) {
cellData.value.mSelect = []; cellData.value = {mSelect:[]} as IAVCellValue;
} }
return true;
}
});
return true; return true;
} }
}); });
if (!cellData) {
cellData = { let hasSelected = false;
color: "", cellData.value.mSelect.find((item) => {
bgColor: "", if (item.content === currentElement.dataset.name) {
id: Lute.NewNodeID(), hasSelected = true;
value: genCellValue(colData.type, ""), return true;
valueType: colData.type
};
} else {
let hasSelected = false;
cellData.value.mSelect.find((item) => {
if (item.content === currentElement.dataset.name) {
hasSelected = true;
return true;
}
});
if (hasSelected) {
menuElement.querySelector("input").focus();
return;
} }
});
if (hasSelected) {
menuElement.querySelector("input").focus();
return;
} }
const oldValue = Object.assign([], cellData.value.mSelect); const oldValue = Object.assign([], cellData.value.mSelect);
@ -428,7 +422,7 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: {
data: colData.options data: colData.options
}, { }, {
action: "updateAttrViewCell", action: "updateAttrViewCell",
id: cellId, id: cellData.id,
keyID: colId, keyID: colId,
rowID, rowID,
avID: data.id, avID: data.id,
@ -442,14 +436,14 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: {
} else { } else {
transaction(protyle, [{ transaction(protyle, [{
action: "updateAttrViewCell", action: "updateAttrViewCell",
id: cellId, id: cellData.id,
keyID: colId, keyID: colId,
rowID, rowID,
avID: data.id, avID: data.id,
data: cellData.value data: cellData.value
}], [{ }], [{
action: "updateAttrViewCell", action: "updateAttrViewCell",
id: cellId, id: cellData.id,
keyID: colId, keyID: colId,
rowID, rowID,
avID: data.id, avID: data.id,