From e6363b141811b6689f7f5ada855310920bb004e1 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Thu, 4 Aug 2022 18:12:41 +0800 Subject: [PATCH] setpagesize --- lib/features/runningTree.d.ts | 10 +++++++--- lib/features/runningTree.js | 27 +++++++++++++++++++++++---- lib/page.common.js | 10 ++++++++++ lib/types/Page.d.ts | 2 ++ src/features/runningTree.ts | 33 ++++++++++++++++++++++++++++----- src/page.common.ts | 14 ++++++++++++++ src/types/Page.ts | 28 +++++++++++++++++++++++----- 7 files changed, 107 insertions(+), 17 deletions(-) diff --git a/lib/features/runningTree.d.ts b/lib/features/runningTree.d.ts index be7f8310..40ea60c1 100644 --- a/lib/features/runningTree.d.ts +++ b/lib/features/runningTree.d.ts @@ -16,7 +16,7 @@ declare abstract class Node[]): Promise; + abstract onCacheSync(opRecords: OpRecord[]): Promise; abstract refreshValue(): void; constructor(entity: T, schema: StorageSchema, cache: Cache, projection: ED[T]['Selection']['data'] | (() => Promise), parent?: Node, action?: ED[T]['Action'], updateData?: DeduceUpdateOperation['data']); getEntity(): T; @@ -46,10 +46,12 @@ declare class ListNode[]): Promise; + onCacheSync(records: OpRecord[]): Promise; setForeignKey(attr: string, entity: keyof ED, id: string | undefined): Promise; refreshValue(): void; constructor(entity: T, schema: StorageSchema, cache: Cache, projection: ED[T]['Selection']['data'] | (() => Promise), projectionShape: ED[T]['Selection']['data'], parent?: Node, action?: ED[T]['Action'], updateData?: DeduceUpdateOperation['data'], filters?: NamedFilterItem[], sorters?: NamedSorterItem[], pagination?: Pagination); + getPagination(): Pagination; + setPageSize(pageSize: number): void; getChild(path: string, newBorn?: true): SingleNode | undefined; getChildren(): SingleNode[]; getNewBorn(): SingleNode[]; @@ -91,7 +93,7 @@ declare class SingleNode[]): Promise; + onCacheSync(records: OpRecord[]): Promise; constructor(entity: T, schema: StorageSchema, cache: Cache, projection: ED[T]['Selection']['data'] | (() => Promise), projectionShape: ED[T]['Selection']['data'], parent?: Node, action?: ED[T]['Action'], updateData?: DeduceUpdateOperation['data']); getChild(path: string): SingleNode | ListNode; getChildren(): { @@ -147,6 +149,8 @@ export declare class RunningTree, setUniqueForeignKeys(parent: string, attr: string, ids: string[]): void; refresh(path: string): Promise; loadMore(path: string): Promise; + getPagination(path: string): Pagination; + setPageSize(path: string, pageSize: number): void; getNamedFilters(path: string): NamedFilterItem[]; getNamedFilterByName(path: string, name: string): NamedFilterItem | undefined; setNamedFilters(path: string, filters: NamedFilterItem[], refresh?: boolean): Promise; diff --git a/lib/features/runningTree.js b/lib/features/runningTree.js index 5ac1b360..0b2befc0 100644 --- a/lib/features/runningTree.js +++ b/lib/features/runningTree.js @@ -112,7 +112,7 @@ var Node = /** @class */ (function () { this.dirty = false; this.refreshing = false; this.updateData = updateData || {}; - this.cache.bindOnSync(function (records) { return _this.onCachSync(records); }); + this.cache.bindOnSync(function (records) { return _this.onCacheSync(records); }); } Node.prototype.getEntity = function () { return this.entity; @@ -226,7 +226,7 @@ var Node = /** @class */ (function () { return this.afterExecute; }; Node.prototype.destroy = function () { - this.cache.unbindOnSync(this.onCachSync); + this.cache.unbindOnSync(this.onCacheSync); }; Node.prototype.judgeRelation = function (attr) { return (0, relation_1.judgeRelation)(this.schema, this.entity, attr); @@ -257,7 +257,7 @@ var ListNode = /** @class */ (function (_super) { _this.pagination = pagination || DEFAULT_PAGINATION; return _this; } - ListNode.prototype.onCachSync = function (records) { + ListNode.prototype.onCacheSync = function (records) { return __awaiter(this, void 0, void 0, function () { var createdIds, removeIds, records_1, records_1_1, record, a, _a, e, d, id, _b, e, f, currentIds, filter, sorterss, projection, _c, value; var e_1, _d; @@ -367,6 +367,15 @@ var ListNode = /** @class */ (function (_super) { }; ListNode.prototype.refreshValue = function () { }; + ListNode.prototype.getPagination = function () { + return this.pagination; + }; + ListNode.prototype.setPageSize = function (pageSize) { + // 切换分页count就重新设置 + this.pagination.step = pageSize; + this.pagination.indexFrom = 0; + this.pagination.more = true; + }; ListNode.prototype.getChild = function (path, newBorn) { var idx = parseInt(path, 10); (0, assert_1.assert)(typeof idx === 'number'); @@ -1075,7 +1084,7 @@ var SingleNode = /** @class */ (function (_super) { }); return _this; } - SingleNode.prototype.onCachSync = function (records) { + SingleNode.prototype.onCacheSync = function (records) { return __awaiter(this, void 0, void 0, function () { var needReGetValue, records_2, records_2_1, record, a, _a, e, d, _b, e, f, d, e, id, projection, _c, _d, value; var e_14, _e; @@ -1892,6 +1901,16 @@ var RunningTree = /** @class */ (function (_super) { }); }); }; + RunningTree.prototype.getPagination = function (path) { + var node = this.findNode(path); + (0, assert_1.assert)(node instanceof ListNode); + return node.getPagination(); + }; + RunningTree.prototype.setPageSize = function (path, pageSize) { + var node = this.findNode(path); + (0, assert_1.assert)(node instanceof ListNode); + return node.setPageSize(pageSize); + }; RunningTree.prototype.getNamedFilters = function (path) { var node = this.findNode(path); (0, assert_1.assert)(node instanceof ListNode); diff --git a/lib/page.common.js b/lib/page.common.js index 5a80b127..7d0aed1f 100644 --- a/lib/page.common.js +++ b/lib/page.common.js @@ -557,6 +557,16 @@ function makeListComponentMethods(features) { setFilters: function (filters) { return features.runningTree.setNamedFilters(this.state.oakFullpath, filters); }, + getPagination: function () { + return features.runningTree.getPagination(this.state.oakFullpath); + }, + setPageSize: function (pageSize, refresh) { + if (refresh === void 0) { refresh = true; } + features.runningTree.setPageSize(this.state.oakFullpath, pageSize); + if (refresh) { + this.refresh(); + } + } }; } exports.makeListComponentMethods = makeListComponentMethods; diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index 7040853f..34b69c36 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -173,6 +173,8 @@ export declare type OakListComponentMethods, refresh?: boolean) => void; removeNamedSorter: (filter: NamedSorterItem, refresh?: boolean) => void; removeNamedSorterByName: (name: string, refresh?: boolean) => void; + getPagination: () => void; + setPageSize: (pageSize: number) => void; }; declare type ComponentOnPropsChangeOption = { path?: string; diff --git a/src/features/runningTree.ts b/src/features/runningTree.ts index b81c9bd0..57109d3c 100644 --- a/src/features/runningTree.ts +++ b/src/features/runningTree.ts @@ -25,7 +25,7 @@ abstract class Node['data'], action: ED[T]['Action']) => Promise; private afterExecute?: (updateData: DeduceUpdateOperation['data'], action: ED[T]['Action']) => Promise; - abstract onCachSync(opRecords: OpRecord[]): Promise; + abstract onCacheSync(opRecords: OpRecord[]): Promise; abstract refreshValue(): void; @@ -42,7 +42,7 @@ abstract class Node this.onCachSync(records)); + this.cache.bindOnSync((records) => this.onCacheSync(records)); } getEntity() { @@ -157,7 +157,7 @@ abstract class Node[]): Promise { + async onCacheSync(records: OpRecord[]): Promise { if (this.refreshing) { return; } @@ -290,6 +290,17 @@ class ListNode | undefined { const idx = parseInt(path, 10); assert(typeof idx === 'number'); @@ -763,7 +774,7 @@ class SingleNode | ListNode; }; - async onCachSync(records: OpRecord[]): Promise { + async onCacheSync(records: OpRecord[]): Promise { let needReGetValue = false; if (this.refreshing || !this.id) { return; @@ -1444,6 +1455,18 @@ export class RunningTree, AD exte await node.loadMore(); } + getPagination(path: string) { + const node = this.findNode(path); + assert(node instanceof ListNode); + return node.getPagination(); + } + + setPageSize(path: string, pageSize: number) { + const node = this.findNode(path); + assert(node instanceof ListNode); + return node.setPageSize(pageSize); + } + getNamedFilters(path: string) { const node = this.findNode(path); assert(node instanceof ListNode); diff --git a/src/page.common.ts b/src/page.common.ts index 4ea8184c..ff3917cb 100644 --- a/src/page.common.ts +++ b/src/page.common.ts @@ -590,6 +590,20 @@ export function makeListComponentMethods< filters ); }, + + getPagination() { + return features.runningTree.getPagination(this.state.oakFullpath); + }, + + setPageSize(pageSize: number, refresh = true) { + features.runningTree.setPageSize( + this.state.oakFullpath, + pageSize + ); + if (refresh) { + this.refresh(); + } + } }; } diff --git a/src/types/Page.ts b/src/types/Page.ts index c061eadf..8ae5b0a9 100644 --- a/src/types/Page.ts +++ b/src/types/Page.ts @@ -277,20 +277,38 @@ export type OakCommonComponentMethods }; export type OakListComponentMethods = { - pushNode: (path?: string, options?: Pick, 'updateData' | 'beforeExecute' | 'afterExecute'>) => void; + pushNode: ( + path?: string, + options?: Pick< + CreateNodeOptions, + 'updateData' | 'beforeExecute' | 'afterExecute' + > + ) => void; removeNode: (parent: string, path: string) => void; setFilters: (filters: NamedFilterItem[]) => void; getFilters: () => Promise; - getFilterByName: (name: string) => Promise | undefined; + getFilterByName: ( + name: string + ) => Promise | undefined; addNamedFilter: (filter: NamedFilterItem, refresh?: boolean) => void; - removeNamedFilter: (filter: NamedFilterItem, refresh?: boolean) => void; + removeNamedFilter: ( + filter: NamedFilterItem, + refresh?: boolean + ) => void; removeNamedFilterByName: (name: string, refresh?: boolean) => void; setNamedSorters: (sorters: NamedSorterItem[]) => void; getSorters: () => Promise; - getSorterByName: (name: string) => Promise | undefined>; + getSorterByName: ( + name: string + ) => Promise | undefined>; addNamedSorter: (filter: NamedSorterItem, refresh?: boolean) => void; - removeNamedSorter: (filter: NamedSorterItem, refresh?: boolean) => void; + removeNamedSorter: ( + filter: NamedSorterItem, + refresh?: boolean + ) => void; removeNamedSorterByName: (name: string, refresh?: boolean) => void; + getPagination: () => void; + setPageSize: (pageSize: number) => void; }; type ComponentOnPropsChangeOption = {