Vanessa 2024-01-18 22:14:08 +08:00
parent e51fb3cde7
commit a5d6d4e848
3 changed files with 52 additions and 41 deletions

View File

@ -53,7 +53,7 @@ export const bindAssetEvent = (options: {
export const getAssetHTML = (cellElements: HTMLElement[]) => { export const getAssetHTML = (cellElements: HTMLElement[]) => {
let html = ""; let html = "";
genCellValueByElement(getTypeByCellElement(cellElements[0]), cellElements[0]).mAsset.forEach(item => { genCellValueByElement("mAsset", cellElements[0]).mAsset.forEach(item => {
if (!item.content) { if (!item.content) {
return; return;
} }

View File

@ -106,24 +106,25 @@ export const genAVValueHTML = (value: IAVCellValue) => {
break; break;
case "relation": case "relation":
value.relation?.blockIDs?.forEach((item, index) => { value.relation?.blockIDs?.forEach((item, index) => {
html += `<span class="av__celltext--url" style="margin-right: 8px" data-id="${item}">${value.relation?.contents[index]}</span>`; html += `<span class="av__celltext--url" style="margin-right: 8px" data-id="${item}">${value.relation?.contents[index] || "Untitled"}</span>`;
}); });
break; break;
case "rollup": case "rollup":
value?.rollup?.contents?.forEach((item, index) => { value?.rollup?.contents?.forEach((item) => {
const rollupText = ["select", "mSelect", "mAsset", "checkbox", "relation"].includes(item.type) ? genAVValueHTML(item) : genAVRollupHTML(item); const rollupText = ["select", "mSelect", "mAsset", "checkbox", "relation"].includes(item.type) ? genAVValueHTML(item) : genAVRollupHTML(item);
if (!rollupText && html) { if (rollupText) {
html = html.substring(0, html.length - 2); html += rollupText + ", ";
} else {
html += rollupText + ((index === value.rollup.contents.length - 1 || !rollupText) ? "" : ",&nbsp;");
} }
}); });
if (html && html.endsWith(", ")) {
html = html.substring(0, html.length - 2);
}
break; break;
} }
return html; return html;
}; };
export const renderAVAttribute = (element: HTMLElement, id: string, protyle?: IProtyle) => { export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IProtyle) => {
fetchPost("/api/av/getAttributeViewKeys", {id}, (response) => { fetchPost("/api/av/getAttributeViewKeys", {id}, (response) => {
let html = ""; let html = "";
response.data.forEach((table: { response.data.forEach((table: {
@ -167,40 +168,42 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone"].includes
}); });
html += "</div>"; html += "</div>";
}); });
element.innerHTML = html; if (element.innerHTML === "") {
element.addEventListener("click", (event) => { element.addEventListener("click", (event) => {
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
while (target && !element.isSameNode(target)) { while (target && !element.isSameNode(target)) {
const type = target.getAttribute("data-type"); const type = target.getAttribute("data-type");
if (type === "date") { if (type === "date") {
popTextCell(protyle, [target], "date"); popTextCell(protyle, [target], "date");
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "select" || type === "mSelect") { } else if (type === "select" || type === "mSelect") {
popTextCell(protyle, [target], target.getAttribute("data-type") as TAVCol); popTextCell(protyle, [target], target.getAttribute("data-type") as TAVCol);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "mAsset") { } else if (type === "mAsset") {
popTextCell(protyle, [target], "mAsset"); popTextCell(protyle, [target], "mAsset");
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "checkbox") { } else if (type === "checkbox") {
popTextCell(protyle, [target], "checkbox"); popTextCell(protyle, [target], "checkbox");
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "relation") { } else if (type === "relation") {
popTextCell(protyle, [target], "relation"); popTextCell(protyle, [target], "relation");
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
}
target = target.parentElement;
} }
target = target.parentElement; });
} }
}); element.innerHTML = html;
element.querySelectorAll(".b3-text-field--text").forEach((item: HTMLInputElement) => { element.querySelectorAll(".b3-text-field--text").forEach((item: HTMLInputElement) => {
item.addEventListener("change", () => { item.addEventListener("change", () => {
let value; let value;

View File

@ -8,6 +8,7 @@ import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest";
import {stickyRow} from "./row"; import {stickyRow} from "./row";
import {getCalcValue} from "./calc"; import {getCalcValue} from "./calc";
import {openMenuPanel} from "./openMenuPanel"; import {openMenuPanel} from "./openMenuPanel";
import {renderAVAttribute} from "./blockAttr";
export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, viewID?: string) => { export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, viewID?: string) => {
let avElements: Element[] = []; let avElements: Element[] = [];
@ -295,6 +296,13 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
if (operation.action === "addAttrViewCol" && isPulse) { if (operation.action === "addAttrViewCol" && isPulse) {
openMenuPanel({protyle, blockElement: item, type: "edit", colId: operation.id}); openMenuPanel({protyle, blockElement: item, type: "edit", colId: operation.id});
} }
if (operation.action === "updateAttrViewCell") {
const attrElement = document.querySelector(`.b3-dialog--open[data-key="${Constants.DIALOG_ATTR}"] div[data-av-id="${operation.avID}"]`) as HTMLElement
if (attrElement) {
// 更新属性面板
renderAVAttribute(attrElement.parentElement, attrElement.dataset.nodeId, protyle);
}
}
}, ["addAttrViewView", "duplicateAttrViewView"].includes(operation.action) ? operation.id : }, ["addAttrViewView", "duplicateAttrViewView"].includes(operation.action) ? operation.id :
(operation.action === "removeAttrViewView" ? null : undefined)); (operation.action === "removeAttrViewView" ? null : undefined));
}); });