Vanessa 2024-01-02 23:04:25 +08:00
parent d9bfc45592
commit 84f3da2ae8
2 changed files with 27 additions and 32 deletions

View file

@ -51,24 +51,9 @@ export const bindAssetEvent = (options: {
}); });
}; };
export const getAssetHTML = (data: IAVTable, cellElements: HTMLElement[]) => { export const getAssetHTML = (cellElements: HTMLElement[]) => {
const cellId = cellElements[0].dataset.id;
const rowId = (hasClosestByClassName(cellElements[0], "av__row") as HTMLElement).dataset.id;
let cellData: IAVCell;
data.rows.find(row => {
if (row.id === rowId) {
row.cells.find(cell => {
if (cell.id === cellId) {
cellData = cell;
return true;
}
});
return true;
}
});
let html = ""; let html = "";
if (cellData?.value?.mAsset) { genCellValueByElement(getTypeByCellElement(cellElements[0]), cellElements[0]).mAsset.forEach(item => {
cellData.value.mAsset.forEach(item => {
if (!item.content) { if (!item.content) {
return; return;
} }
@ -87,7 +72,6 @@ ${contentHTML}
<svg class="b3-menu__action" data-type="editAssetItem"><use xlink:href="#iconEdit"></use></svg> <svg class="b3-menu__action" data-type="editAssetItem"><use xlink:href="#iconEdit"></use></svg>
</button>`; </button>`;
}); });
}
return `<div class="b3-menu__items"> return `<div class="b3-menu__items">
${html} ${html}
<button data-type="addAssetExist" class="b3-menu__item"> <button data-type="addAssetExist" class="b3-menu__item">
@ -121,7 +105,18 @@ export const updateAssetCell = (options: {
const cellUndoOperations: IOperation[] = []; const cellUndoOperations: IOperation[] = [];
options.cellElements.forEach((item, elementIndex) => { options.cellElements.forEach((item, elementIndex) => {
if (!options.blockElement.contains(item)) { if (!options.blockElement.contains(item)) {
item = options.cellElements[elementIndex] = options.blockElement.querySelector(`.av__cell[data-id="${item.dataset.id}"]`) as HTMLElement; const rowElement = hasClosestByClassName(item, "av__row");
if (rowElement) {
let cellIndex: number;
rowElement.querySelectorAll(".av__cell").forEach((cellElement: HTMLElement, ghostIndex) => {
if (cellElement.dataset.id === item.dataset.id) {
cellIndex = ghostIndex
}
});
if (typeof cellIndex === "number") {
item = options.cellElements[elementIndex] = options.blockElement.querySelectorAll(`.av__row[data-id="${rowElement.dataset.id}"] .av__cell`)[cellIndex] as HTMLElement;
}
}
} }
const cellValue = genCellValueByElement(getTypeByCellElement(item) || item.dataset.type as TAVCol, item); const cellValue = genCellValueByElement(getTypeByCellElement(item) || item.dataset.type as TAVCol, item);
const rowID = (hasClosestByClassName(item, "av__row") as HTMLElement).dataset.id; const rowID = (hasClosestByClassName(item, "av__row") as HTMLElement).dataset.id;
@ -193,7 +188,7 @@ export const updateAssetCell = (options: {
transaction(options.protyle, cellDoOperations, cellUndoOperations); transaction(options.protyle, cellDoOperations, cellUndoOperations);
const menuElement = document.querySelector(".av__panel > .b3-menu") as HTMLElement; const menuElement = document.querySelector(".av__panel > .b3-menu") as HTMLElement;
if (menuElement) { if (menuElement) {
menuElement.innerHTML = getAssetHTML(options.data.view, options.cellElements); menuElement.innerHTML = getAssetHTML(options.cellElements);
bindAssetEvent({ bindAssetEvent({
protyle: options.protyle, protyle: options.protyle,
data: options.data, data: options.data,

View file

@ -65,7 +65,7 @@ export const openMenuPanel = (options: {
} else if (options.type === "select") { } else if (options.type === "select") {
html = getSelectHTML(data.view, options.cellElements); html = getSelectHTML(data.view, options.cellElements);
} else if (options.type === "asset") { } else if (options.type === "asset") {
html = getAssetHTML(data.view, options.cellElements); html = getAssetHTML(options.cellElements);
} else if (options.type === "edit") { } else if (options.type === "edit") {
html = getEditHTML({protyle: options.protyle, data, colId: options.colId}); html = getEditHTML({protyle: options.protyle, data, colId: options.colId});
} else if (options.type === "date") { } else if (options.type === "date") {