Vanessa 2024-05-17 17:49:59 +08:00
parent ca6833bb02
commit 08da8f15a4
3 changed files with 178 additions and 127 deletions

View file

@ -514,7 +514,8 @@ const updateCellValueByInput = (protyle: IProtyle, type: TAVCol, blockElement: H
});
};
export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, value?: any, cElements?: HTMLElement[]) => {
export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, value?: any, cElements?: HTMLElement[],
columns?: IAVColumn[]) => {
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
@ -535,7 +536,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
});
}
}
const isCustomAttr = !hasClosestByClassName(cellElements[0], "custom-attr");
cellElements.forEach((item: HTMLElement, elementIndex) => {
const rowElement = hasClosestByClassName(item, "av__row");
if (!rowElement) {
@ -617,7 +618,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
rowID,
data: oldValue
});
if (!hasClosestByClassName(cellElements[0], "custom-attr")) {
if (!isCustomAttr) {
updateAttrViewCellAnimation(item, cellValue);
} else {
item.innerHTML = genAVValueHTML(cellValue);

View file

@ -63,7 +63,7 @@ export const removeCellOption = (protyle: IProtyle, cellElements: HTMLElement[],
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
let mSelectValue: IAVCellSelectValue[];
const avID = blockElement.getAttribute("data-av-id");
const avID = blockElement.getAttribute("data-av-id");
cellElements.forEach((item, elementIndex) => {
if (!blockElement.contains(item)) {
const rowElement = hasClosestByClassName(item, "av__row");
@ -565,3 +565,41 @@ export const getSelectHTML = (data: IAVTable, cellElements: HTMLElement[], init
<div>${filterSelectHTML("", colData.options, selected)}</div>
</div>`;
};
export const mergeAddOption = (column: IAVColumn, cellValue: IAVCellValue, avID:string) => {
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
cellValue.mSelect.forEach((item: IAVCellSelectValue) => {
const needAdd = column.options.find((option: {
name: string,
color: string,
}) => {
if (option.name === item.content) {
item.color = option.color;
return true;
}
});
if (!needAdd) {
column.options.push({
name: item.content,
color:(column.options?.length || 0) % 13 + 1
});
doOperations.push({
action: "updateAttrViewColOptions",
id: column.id,
avID,
data: column.options
})
undoOperations.push({
action: "removeAttrViewColOption",
id: column.id,
avID,
data: item.content,
});
}
});
return {
doOperations,
undoOperations
};
}