setpagesize

This commit is contained in:
Wang Kejun 2022-08-04 18:12:41 +08:00
parent f273c92e32
commit e6363b1418
7 changed files with 107 additions and 17 deletions

View File

@ -16,7 +16,7 @@ declare abstract class Node<ED extends EntityDict, T extends keyof ED, Cxt exten
protected refreshing: boolean;
private beforeExecute?;
private afterExecute?;
abstract onCachSync(opRecords: OpRecord<ED>[]): Promise<void>;
abstract onCacheSync(opRecords: OpRecord<ED>[]): Promise<void>;
abstract refreshValue(): void;
constructor(entity: T, schema: StorageSchema<ED>, cache: Cache<ED, Cxt, AD>, projection: ED[T]['Selection']['data'] | (() => Promise<ED[T]['Selection']['data']>), parent?: Node<ED, keyof ED, Cxt, AD>, action?: ED[T]['Action'], updateData?: DeduceUpdateOperation<ED[T]['OpSchema']>['data']);
getEntity(): T;
@ -46,10 +46,12 @@ declare class ListNode<ED extends EntityDict, T extends keyof ED, Cxt extends Co
private sorters;
private pagination;
private projectionShape;
onCachSync(records: OpRecord<ED>[]): Promise<void>;
onCacheSync(records: OpRecord<ED>[]): Promise<void>;
setForeignKey(attr: string, entity: keyof ED, id: string | undefined): Promise<void>;
refreshValue(): void;
constructor(entity: T, schema: StorageSchema<ED>, cache: Cache<ED, Cxt, AD>, projection: ED[T]['Selection']['data'] | (() => Promise<ED[T]['Selection']['data']>), projectionShape: ED[T]['Selection']['data'], parent?: Node<ED, keyof ED, Cxt, AD>, action?: ED[T]['Action'], updateData?: DeduceUpdateOperation<ED[T]['OpSchema']>['data'], filters?: NamedFilterItem<ED, T>[], sorters?: NamedSorterItem<ED, T>[], pagination?: Pagination);
getPagination(): Pagination;
setPageSize(pageSize: number): void;
getChild(path: string, newBorn?: true): SingleNode<ED, T, Cxt, AD> | undefined;
getChildren(): SingleNode<ED, T, Cxt, AD>[];
getNewBorn(): SingleNode<ED, T, Cxt, AD>[];
@ -91,7 +93,7 @@ declare class SingleNode<ED extends EntityDict, T extends keyof ED, Cxt extends
private value?;
private freshValue?;
private children;
onCachSync(records: OpRecord<ED>[]): Promise<void>;
onCacheSync(records: OpRecord<ED>[]): Promise<void>;
constructor(entity: T, schema: StorageSchema<ED>, cache: Cache<ED, Cxt, AD>, projection: ED[T]['Selection']['data'] | (() => Promise<ED[T]['Selection']['data']>), projectionShape: ED[T]['Selection']['data'], parent?: Node<ED, keyof ED, Cxt, AD>, action?: ED[T]['Action'], updateData?: DeduceUpdateOperation<ED[T]['OpSchema']>['data']);
getChild(path: string): SingleNode<ED, keyof ED, Cxt, AD> | ListNode<ED, keyof ED, Cxt, AD>;
getChildren(): {
@ -147,6 +149,8 @@ export declare class RunningTree<ED extends EntityDict, Cxt extends Context<ED>,
setUniqueForeignKeys(parent: string, attr: string, ids: string[]): void;
refresh(path: string): Promise<void>;
loadMore(path: string): Promise<void>;
getPagination<T extends keyof ED>(path: string): Pagination;
setPageSize<T extends keyof ED>(path: string, pageSize: number): void;
getNamedFilters<T extends keyof ED>(path: string): NamedFilterItem<ED, keyof ED>[];
getNamedFilterByName<T extends keyof ED>(path: string, name: string): NamedFilterItem<ED, keyof ED> | undefined;
setNamedFilters<T extends keyof ED>(path: string, filters: NamedFilterItem<ED, T>[], refresh?: boolean): Promise<void>;

View File

@ -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);

View File

@ -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;

2
lib/types/Page.d.ts vendored
View File

@ -173,6 +173,8 @@ export declare type OakListComponentMethods<ED extends EntityDict, T extends key
addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void;
removeNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void;
removeNamedSorterByName: (name: string, refresh?: boolean) => void;
getPagination: () => void;
setPageSize: (pageSize: number) => void;
};
declare type ComponentOnPropsChangeOption = {
path?: string;

View File

@ -25,7 +25,7 @@ abstract class Node<ED extends EntityDict, T extends keyof ED, Cxt extends Conte
private beforeExecute?: (updateData: DeduceUpdateOperation<ED[T]['OpSchema']>['data'], action: ED[T]['Action']) => Promise<void>;
private afterExecute?: (updateData: DeduceUpdateOperation<ED[T]['OpSchema']>['data'], action: ED[T]['Action']) => Promise<void>;
abstract onCachSync(opRecords: OpRecord<ED>[]): Promise<void>;
abstract onCacheSync(opRecords: OpRecord<ED>[]): Promise<void>;
abstract refreshValue(): void;
@ -42,7 +42,7 @@ abstract class Node<ED extends EntityDict, T extends keyof ED, Cxt extends Conte
this.dirty = false;
this.refreshing = false;
this.updateData = updateData || {};
this.cache.bindOnSync((records) => this.onCachSync(records));
this.cache.bindOnSync((records) => this.onCacheSync(records));
}
getEntity() {
@ -157,7 +157,7 @@ abstract class Node<ED extends EntityDict, T extends keyof ED, Cxt extends Conte
}
destroy() {
this.cache.unbindOnSync(this.onCachSync);
this.cache.unbindOnSync(this.onCacheSync);
}
protected judgeRelation(attr: string) {
@ -192,7 +192,7 @@ class ListNode<ED extends EntityDict,
private pagination: Pagination;
private projectionShape: ED[T]['Selection']['data'];
async onCachSync(records: OpRecord<ED>[]): Promise<void> {
async onCacheSync(records: OpRecord<ED>[]): Promise<void> {
if (this.refreshing) {
return;
}
@ -290,6 +290,17 @@ class ListNode<ED extends EntityDict,
this.pagination = pagination || DEFAULT_PAGINATION;
}
getPagination() {
return this.pagination;
}
setPageSize(pageSize: number) {
// 切换分页count就重新设置
this.pagination.step = pageSize;
this.pagination.indexFrom = 0;
this.pagination.more = true;
}
getChild(path: string, newBorn?: true): SingleNode<ED, T, Cxt, AD> | undefined {
const idx = parseInt(path, 10);
assert(typeof idx === 'number');
@ -763,7 +774,7 @@ class SingleNode<ED extends EntityDict,
[K: string]: SingleNode<ED, keyof ED, Cxt, AD> | ListNode<ED, keyof ED, Cxt, AD>;
};
async onCachSync(records: OpRecord<ED>[]): Promise<void> {
async onCacheSync(records: OpRecord<ED>[]): Promise<void> {
let needReGetValue = false;
if (this.refreshing || !this.id) {
return;
@ -1444,6 +1455,18 @@ export class RunningTree<ED extends EntityDict, Cxt extends Context<ED>, AD exte
await node.loadMore();
}
getPagination<T extends keyof ED>(path: string) {
const node = this.findNode(path);
assert(node instanceof ListNode);
return node.getPagination();
}
setPageSize<T extends keyof ED>(path: string, pageSize: number) {
const node = this.findNode(path);
assert(node instanceof ListNode);
return node.setPageSize(pageSize);
}
getNamedFilters<T extends keyof ED>(path: string) {
const node = this.findNode(path);
assert(node instanceof ListNode);

View File

@ -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();
}
}
};
}

View File

@ -277,20 +277,38 @@ export type OakCommonComponentMethods<ED extends EntityDict, T extends keyof ED>
};
export type OakListComponentMethods<ED extends EntityDict, T extends keyof ED> = {
pushNode: (path?: string, options?: Pick<CreateNodeOptions<ED, keyof ED>, 'updateData' | 'beforeExecute' | 'afterExecute'>) => void;
pushNode: (
path?: string,
options?: Pick<
CreateNodeOptions<ED, keyof ED>,
'updateData' | 'beforeExecute' | 'afterExecute'
>
) => void;
removeNode: (parent: string, path: string) => void;
setFilters: (filters: NamedFilterItem<ED, T>[]) => void;
getFilters: () => Promise<ED[T]['Selection']['filter'][]>;
getFilterByName: (name: string) => Promise<ED[T]['Selection']['filter']> | undefined;
getFilterByName: (
name: string
) => Promise<ED[T]['Selection']['filter']> | undefined;
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => void;
removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => void;
removeNamedFilter: (
filter: NamedFilterItem<ED, T>,
refresh?: boolean
) => void;
removeNamedFilterByName: (name: string, refresh?: boolean) => void;
setNamedSorters: (sorters: NamedSorterItem<ED, T>[]) => void;
getSorters: () => Promise<ED[T]['Selection']['sorter']>;
getSorterByName: (name: string) => Promise<DeduceSorterItem<ED[T]['Schema']> | undefined>;
getSorterByName: (
name: string
) => Promise<DeduceSorterItem<ED[T]['Schema']> | undefined>;
addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void;
removeNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void;
removeNamedSorter: (
filter: NamedSorterItem<ED, T>,
refresh?: boolean
) => void;
removeNamedSorterByName: (name: string, refresh?: boolean) => void;
getPagination: () => void;
setPageSize: (pageSize: number) => void;
};
type ComponentOnPropsChangeOption = {