Vanessa 2025-08-02 11:29:02 +08:00
parent 141c139782
commit deb781023a
6 changed files with 61 additions and 27 deletions

View file

@ -54,7 +54,8 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
rowFooterElement.style.transform = ""; rowFooterElement.style.transform = "";
} }
blockElement.removeAttribute("data-render"); blockElement.removeAttribute("data-render");
blockElement.dataset.pageSize = (parseInt(blockElement.dataset.pageSize) + parseInt(blockElement.querySelector('[data-type="set-page-size"]').getAttribute("data-size"))).toString(); const bodyElement = hasClosestByClassName(event.target, "av__body") as HTMLElement;
bodyElement.dataset.pageSize = (parseInt(bodyElement.dataset.pageSize) + parseInt(bodyElement.querySelector('[data-type="set-page-size"]').getAttribute("data-size"))).toString();
avRender(blockElement, protyle); avRender(blockElement, protyle);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();

View file

@ -11,6 +11,7 @@ import {avRender, genTabHeaderHTML, getGroupTitleHTML, updateSearch} from "../re
import {processRender} from "../../../util/processCode"; import {processRender} from "../../../util/processCode";
import {getColIconByType, getColNameByType} from "../col"; import {getColIconByType, getColNameByType} from "../col";
import {getCompressURL} from "../../../../util/image"; import {getCompressURL} from "../../../../util/image";
import {getPageSize} from "../groups";
interface ITableOptions { interface ITableOptions {
protyle: IProtyle, protyle: IProtyle,
@ -63,7 +64,7 @@ const getGalleryHTML = (data: IAVGallery, selectItemIds: string[], editIds: stri
ariaLabel += escapeAttr(`<div class="ft__on-surface">${data.fields[fieldsIndex].desc}</div>`); ariaLabel += escapeAttr(`<div class="ft__on-surface">${data.fields[fieldsIndex].desc}</div>`);
} }
if (cell.valueType === "checkbox") { if (cell.valueType === "checkbox") {
cell.value["checkbox"].content = data.fields[fieldsIndex].name||getColNameByType(data.fields[fieldsIndex].type) cell.value["checkbox"].content = data.fields[fieldsIndex].name || getColNameByType(data.fields[fieldsIndex].type);
} }
galleryHTML += `<div class="av__cell${checkClass} ariaLabel" data-wrap="${data.fields[fieldsIndex].wrap}" galleryHTML += `<div class="av__cell${checkClass} ariaLabel" data-wrap="${data.fields[fieldsIndex].wrap}"
data-empty="${isEmpty}" data-empty="${isEmpty}"
@ -107,7 +108,7 @@ const renderGroupGallery = (options: ITableOptions) => {
if (group.groupHidden === 0) { if (group.groupHidden === 0) {
group.fields = (options.data.view as IAVGallery).fields; group.fields = (options.data.view as IAVGallery).fields;
avBodyHTML += `${getGroupTitleHTML(group, group.fields.length)} avBodyHTML += `${getGroupTitleHTML(group, group.fields.length)}
<div data-group-id="${group.id}" class="av__body${group.groupFolded ? " fn__none" : ""}">${getGalleryHTML(group, options.resetData.selectItemIds, options.resetData.editIds)}</div>`; <div data-group-id="${group.id}" data-page-size="${group.pageSize}" class="av__body${group.groupFolded ? " fn__none" : ""}">${getGalleryHTML(group, options.resetData.selectItemIds, options.resetData.editIds)}</div>`;
} }
}); });
if (options.renderAll) { if (options.renderAll) {
@ -253,11 +254,13 @@ export const renderGallery = async (options: {
let data: IAV = options.data; let data: IAV = options.data;
if (!data) { if (!data) {
const avPageSize = getPageSize(options.blockElement);
const response = await fetchSyncPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), { const response = await fetchSyncPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), {
id: options.blockElement.getAttribute("data-av-id"), id: options.blockElement.getAttribute("data-av-id"),
created, created,
snapshot, snapshot,
pageSize: parseInt(options.blockElement.dataset.pageSize) || undefined, pageSize: avPageSize.unGroupPageSize,
groupPaging: avPageSize.groupPageSize,
viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "", viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "",
query: resetData.query.trim() query: resetData.query.trim()
}); });
@ -280,22 +283,21 @@ export const renderGallery = async (options: {
}); });
return; return;
} }
if (!options.blockElement.dataset.pageSize) {
options.blockElement.dataset.pageSize = view.pageSize.toString();
}
const bodyHTML = getGalleryHTML(view, selectItemIds, editIds); const bodyHTML = getGalleryHTML(view, selectItemIds, editIds);
if (options.renderAll) { if (options.renderAll) {
options.blockElement.firstElementChild.outerHTML = `<div class="av__container fn__block"> options.blockElement.firstElementChild.outerHTML = `<div class="av__container fn__block">
${genTabHeaderHTML(data, resetData.isSearching || !!resetData.query, options.protyle.disabled || !!hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed"))} ${genTabHeaderHTML(data, resetData.isSearching || !!resetData.query, options.protyle.disabled || !!hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed"))}
<div> <div>
<div class="av__body"> <div class="av__body" data-page-size="${view.pageSize}">
${bodyHTML} ${bodyHTML}
</div> </div>
</div> </div>
<div class="av__cursor" contenteditable="true">${Constants.ZWSP}</div> <div class="av__cursor" contenteditable="true">${Constants.ZWSP}</div>
</div>`; </div>`;
} else { } else {
options.blockElement.querySelector(".av__body").innerHTML = bodyHTML; const bodyElement = options.blockElement.querySelector(".av__body") as HTMLElement;
bodyElement.innerHTML = bodyHTML;
bodyElement.dataset.pageSize = view.pageSize.toString();
} }
afterRenderGallery({ afterRenderGallery({
resetData, resetData,

View file

@ -7,6 +7,25 @@ import {fetchSyncPost} from "../../../util/fetch";
import {Menu} from "../../../plugin/Menu"; import {Menu} from "../../../plugin/Menu";
import {objEquals} from "../../../util/functions"; import {objEquals} from "../../../util/functions";
export const getPageSize = (blockElement: Element) => {
const groupPageSize: {
[key: string]: {
pageSize: string
}
}[] = [];
let unGroupPageSize: string;
blockElement.querySelectorAll(".av__body").forEach((item:HTMLElement) => {
const id = item.dataset.groupId;
const pageSize = item.dataset.pageSize;
if (id) {
groupPageSize.push({[id]: {pageSize}});
} else if (!unGroupPageSize) {
unGroupPageSize = pageSize;
}
});
return {groupPageSize, unGroupPageSize};
};
export const setGroupMethod = async (options: { export const setGroupMethod = async (options: {
protyle: IProtyle; protyle: IProtyle;
fieldId: string; fieldId: string;

View file

@ -51,7 +51,7 @@ import {setGalleryCover, setGalleryRatio, setGallerySize} from "./gallery/util";
import { import {
bindGroupsEvent, bindGroupsNumber, bindGroupsEvent, bindGroupsNumber,
getGroupsHTML, getGroupsHTML,
getGroupsMethodHTML, getGroupsNumberHTML, getLanguageByIndex, getGroupsMethodHTML, getGroupsNumberHTML, getLanguageByIndex, getPageSize,
goGroupsDate, goGroupsDate,
goGroupsSort, goGroupsSort,
setGroupMethod setGroupMethod
@ -76,10 +76,12 @@ export const openMenuPanel = (options: {
return; return;
} }
const avID = options.blockElement.getAttribute("data-av-id"); const avID = options.blockElement.getAttribute("data-av-id");
const avPageSize = getPageSize(options.blockElement);
fetchPost("/api/av/renderAttributeView", { fetchPost("/api/av/renderAttributeView", {
id: avID, id: avID,
query: (options.blockElement.querySelector('[data-type="av-search"]') as HTMLInputElement)?.value.trim() || "", query: (options.blockElement.querySelector('[data-type="av-search"]') as HTMLInputElement)?.value.trim() || "",
pageSize: parseInt(options.blockElement.getAttribute("data-page-size")) || undefined, pageSize: avPageSize.unGroupPageSize,
groupPaging: avPageSize.groupPageSize,
viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW) viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW)
}, (response) => { }, (response) => {
avPanelElement = document.querySelector(".av__panel"); avPanelElement = document.querySelector(".av__panel");

View file

@ -17,6 +17,7 @@ import {isMobile} from "../../../util/functions";
import {renderGallery} from "./gallery/render"; import {renderGallery} from "./gallery/render";
import {getFieldsByData, getViewIcon} from "./view"; import {getFieldsByData, getViewIcon} from "./view";
import {openMenuPanel} from "./openMenuPanel"; import {openMenuPanel} from "./openMenuPanel";
import {getPageSize} from "./groups";
interface ITableOptions { interface ITableOptions {
protyle: IProtyle, protyle: IProtyle,
@ -470,11 +471,13 @@ export const avRender = (element: Element, protyle: IProtyle, cb?: (data: IAV) =
} }
const created = protyle.options.history?.created; const created = protyle.options.history?.created;
const snapshot = protyle.options.history?.snapshot; const snapshot = protyle.options.history?.snapshot;
const avPageSize = getPageSize(e);
fetchPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), { fetchPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), {
id: e.getAttribute("data-av-id"), id: e.getAttribute("data-av-id"),
created, created,
snapshot, snapshot,
pageSize: parseInt(e.dataset.pageSize) || undefined, pageSize: avPageSize.unGroupPageSize,
groupPaging: avPageSize.groupPageSize,
viewID: e.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "", viewID: e.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "",
query: resetData.query.trim(), query: resetData.query.trim(),
blockID: e.getAttribute("data-node-id"), blockID: e.getAttribute("data-node-id"),
@ -489,10 +492,7 @@ export const avRender = (element: Element, protyle: IProtyle, cb?: (data: IAV) =
renderGroupTable({blockElement: e, protyle, cb, renderAll, data: response.data, resetData}); renderGroupTable({blockElement: e, protyle, cb, renderAll, data: response.data, resetData});
return; return;
} }
if (!e.dataset.pageSize) { const avBodyHTML = `<div class="av__body" data-page-size="${data.pageSize}" style="float: left">
e.dataset.pageSize = data.pageSize.toString();
}
const avBodyHTML = `<div class="av__body" style="float: left">
${getTableHTMLs(data, e)} ${getTableHTMLs(data, e)}
</div>`; </div>`;
if (renderAll) { if (renderAll) {
@ -662,12 +662,18 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
} else if (operation.action === "setAttrViewBlockView") { } else if (operation.action === "setAttrViewBlockView") {
const viewTabElement = item.querySelector(`.av__views > .layout-tab-bar > .item[data-id="${operation.id}"]`) as HTMLElement; const viewTabElement = item.querySelector(`.av__views > .layout-tab-bar > .item[data-id="${operation.id}"]`) as HTMLElement;
if (viewTabElement) { if (viewTabElement) {
item.dataset.pageSize = viewTabElement.dataset.page; item.querySelectorAll(".av__body").forEach((bodyItem: HTMLElement) => {
bodyItem.dataset.pageSize = viewTabElement.dataset.page;
});
} }
} else if (operation.action === "addAttrViewView") { } else if (operation.action === "addAttrViewView") {
item.dataset.pageSize = "50"; item.querySelectorAll(".av__body").forEach((bodyItem: HTMLElement) => {
bodyItem.dataset.pageSize = "50";
});
} else if (operation.action === "removeAttrViewView") { } else if (operation.action === "removeAttrViewView") {
item.dataset.pageSize = item.querySelector(`.av__views > .layout-tab-bar .item[data-id="${item.getAttribute(Constants.CUSTOM_SY_AV_VIEW)}"]`)?.getAttribute("data-page"); item.querySelectorAll(".av__body").forEach((bodyItem: HTMLElement) => {
bodyItem.dataset.pageSize = item.querySelector(`.av__views > .layout-tab-bar .item[data-id="${item.getAttribute(Constants.CUSTOM_SY_AV_VIEW)}"]`)?.getAttribute("data-page");
});
} else if (operation.action === "sortAttrViewView" && operation.data === "unRefresh") { } else if (operation.action === "sortAttrViewView" && operation.data === "unRefresh") {
const viewTabElement = item.querySelector(`.av__views > .layout-tab-bar > .item[data-id="${operation.id}"]`) as HTMLElement; const viewTabElement = item.querySelector(`.av__views > .layout-tab-bar > .item[data-id="${operation.id}"]`) as HTMLElement;
if (viewTabElement && !operation.previousID && !viewTabElement.previousElementSibling) { if (viewTabElement && !operation.previousID && !viewTabElement.previousElementSibling) {

View file

@ -94,14 +94,16 @@ export const updateHeader = (rowElement: HTMLElement) => {
}; };
export const setPage = (blockElement: Element) => { export const setPage = (blockElement: Element) => {
const pageSize = parseInt(blockElement.getAttribute("data-page-size")); const avType = blockElement.getAttribute("data-av-type") as TAVView;
if (pageSize) { blockElement.querySelectorAll(".av__body").forEach((item: HTMLElement) => {
const avType = blockElement.getAttribute("data-av-type") as TAVView; const pageSize = item.dataset.pageSize;
const currentCount = blockElement.querySelectorAll(avType === "table" ? ".av__row:not(.av__row--header)" : ".av__gallery-item").length; if (pageSize) {
if (pageSize < currentCount) { const currentCount = item.querySelectorAll(avType === "table" ? ".av__row:not(.av__row--header)" : ".av__gallery-item").length;
blockElement.setAttribute("data-page-size", currentCount.toString()); if (parseInt(pageSize) < currentCount) {
item.dataset.pageSize = currentCount.toString();
}
} }
} });
}; };
/** /**
@ -316,7 +318,9 @@ const updatePageSize = (options: {
if (options.currentPageSize === options.newPageSize) { if (options.currentPageSize === options.newPageSize) {
return; return;
} }
options.nodeElement.setAttribute("data-page-size", options.newPageSize); options.nodeElement.querySelectorAll(".av__body").forEach((item: HTMLElement) => {
item.dataset.pageSize = options.newPageSize;
});
const blockID = options.nodeElement.getAttribute("data-node-id"); const blockID = options.nodeElement.getAttribute("data-node-id");
transaction(options.protyle, [{ transaction(options.protyle, [{
action: "setAttrViewPageSize", action: "setAttrViewPageSize",