diff --git a/lib/page.common.js b/lib/page.common.js index 94da9971..125e7af1 100644 --- a/lib/page.common.js +++ b/lib/page.common.js @@ -190,6 +190,16 @@ function reRender(option, extra) { Object.assign(data, { oakLegalActions: oakLegalActions, }); + if (option.isList) { + var oakFilters = this.getFilters(); + var oakSorters = this.getSorters(); + var oakPagination = this.getPagination(); + Object.assign(data, { + oakFilters: oakFilters, + oakSorters: oakSorters, + oakPagination: oakPagination, + }); + } for (var k in data) { if (data[k] === undefined) { Object.assign(data, (_a = {}, diff --git a/lib/page.mp.js b/lib/page.mp.js index 4c583686..b5d27cbe 100644 --- a/lib/page.mp.js +++ b/lib/page.mp.js @@ -264,11 +264,13 @@ var oakBehavior = Behavior({ getId: function () { return this.features.runningTree.getId(this.state.oakFullpath); }, - setFilters: function (filters) { - this.features.runningTree.setNamedFilters(this.state.oakFullpath, filters); + setFilters: function (filters, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.setNamedFilters(path2, filters); }, - getFilters: function () { + getFilters: function (path) { if (this.state.oakFullpath) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; var namedFilters = this.features.runningTree.getNamedFilters(this.state.oakFullpath); return namedFilters.map(function (_a) { var filter = _a.filter; @@ -279,9 +281,10 @@ var oakBehavior = Behavior({ }); } }, - getFilterByName: function (name) { + getFilterByName: function (name, path) { if (this.state.oakFullpath) { - var filter = this.features.runningTree.getNamedFilterByName(this.state.oakFullpath, name); + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + var filter = this.features.runningTree.getNamedFilterByName(path2, name); if (filter === null || filter === void 0 ? void 0 : filter.filter) { if (typeof filter.filter === 'function') { return filter.filter(); @@ -290,21 +293,26 @@ var oakBehavior = Behavior({ } } }, - addNamedFilter: function (namedFilter, refresh) { - this.features.runningTree.addNamedFilter(this.state.oakFullpath, namedFilter, refresh); + addNamedFilter: function (namedFilter, refresh, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.addNamedFilter(path2, namedFilter, refresh); }, - removeNamedFilter: function (namedFilter, refresh) { - this.features.runningTree.removeNamedFilter(this.state.oakFullpath, namedFilter, refresh); + removeNamedFilter: function (namedFilter, refresh, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.removeNamedFilter(path2, namedFilter, refresh); }, - removeNamedFilterByName: function (name, refresh) { - this.features.runningTree.removeNamedFilterByName(this.state.oakFullpath, name, refresh); + removeNamedFilterByName: function (name, refresh, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.removeNamedFilterByName(path2, name, refresh); }, - setNamedSorters: function (namedSorters) { - this.features.runningTree.setNamedSorters(this.state.oakFullpath, namedSorters); + setNamedSorters: function (namedSorters, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.setNamedSorters(path2, namedSorters); }, - getSorters: function () { + getSorters: function (path) { if (this.state.oakFullpath) { - var namedSorters = this.features.runningTree.getNamedSorters(this.state.oakFullpath); + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + var namedSorters = this.features.runningTree.getNamedSorters(path2); var sorters = namedSorters .map(function (_a) { var sorter = _a.sorter; @@ -317,9 +325,10 @@ var oakBehavior = Behavior({ return sorters; } }, - getSorterByName: function (name) { + getSorterByName: function (name, path) { if (this.state.oakFullpath) { - var sorter = this.features.runningTree.getNamedSorterByName(this.state.oakFullpath, name); + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + var sorter = this.features.runningTree.getNamedSorterByName(path2, name); if (sorter === null || sorter === void 0 ? void 0 : sorter.sorter) { if (typeof sorter.sorter === 'function') { return sorter.sorter(); @@ -328,40 +337,50 @@ var oakBehavior = Behavior({ } } }, - addNamedSorter: function (namedSorter, refresh) { - this.features.runningTree.addNamedSorter(this.state.oakFullpath, namedSorter, refresh); + addNamedSorter: function (namedSorter, refresh, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.addNamedSorter(path2, namedSorter, refresh); }, - removeNamedSorter: function (namedSorter, refresh) { - this.features.runningTree.removeNamedSorter(this.state.oakFullpath, namedSorter, refresh); + removeNamedSorter: function (namedSorter, refresh, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.removeNamedSorter(path2, namedSorter, refresh); }, - removeNamedSorterByName: function (name, refresh) { - this.features.runningTree.removeNamedSorterByName(this.state.oakFullpath, name, refresh); + removeNamedSorterByName: function (name, refresh, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.removeNamedSorterByName(path2, name, refresh); }, - getPagination: function () { + getPagination: function (path) { if (this.state.oakFullpath) { - return this.features.runningTree.getPagination(this.state.oakFullpath); + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + return this.features.runningTree.getPagination(path2); } }, - setPageSize: function (pageSize) { - this.features.runningTree.setPageSize(this.state.oakFullpath, pageSize); + setPageSize: function (pageSize, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.setPageSize(path2, pageSize); }, - setCurrentPage: function (currentPage) { + setCurrentPage: function (currentPage, path) { (0, assert_1.default)(currentPage !== 0); if (this.state.oakEntity && this.state.oakFullpath) { - this.features.runningTree.setCurrentPage(this.state.oakFullpath, currentPage); + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + this.features.runningTree.setCurrentPage(path2, currentPage); } }, - addItem: function (data, beforeExecute, afterExecute) { - return this.features.runningTree.addItem(this.state.oakFullpath, data, beforeExecute, afterExecute); + addItem: function (data, beforeExecute, afterExecute, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + return this.features.runningTree.addItem(path2, data, beforeExecute, afterExecute); }, - updateItem: function (data, id, action, beforeExecute, afterExecute) { - return this.features.runningTree.updateItem(this.state.oakFullpath, data, id, action, beforeExecute, afterExecute); + updateItem: function (data, id, action, beforeExecute, afterExecute, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + return this.features.runningTree.updateItem(path2, data, id, action, beforeExecute, afterExecute); }, - removeItem: function (id, beforeExecute, afterExecute) { - return this.features.runningTree.removeItem(this.state.oakFullpath, id, beforeExecute, afterExecute); + removeItem: function (id, beforeExecute, afterExecute, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + return this.features.runningTree.removeItem(path2, id, beforeExecute, afterExecute); }, - recoverItem: function (id) { - return this.features.runningTree.recoverItem(this.state.oakFullpath, id); + recoverItem: function (id, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + return this.features.runningTree.recoverItem(path2, id); }, setId: function (id) { return this.features.runningTree.setId(this.state.oakFullpath, id); @@ -369,11 +388,13 @@ var oakBehavior = Behavior({ unsetId: function () { return this.features.runningTree.unsetId(this.state.oakFullpath); }, - update: function (data, action, beforeExecute, afterExecute) { - return this.features.runningTree.update(this.state.oakFullpath, data, action, beforeExecute, afterExecute); + update: function (data, action, beforeExecute, afterExecute, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + return this.features.runningTree.update(path2, data, action, beforeExecute, afterExecute); }, - remove: function (beforeExecute, afterExecute) { - return this.features.runningTree.remove(this.state.oakFullpath, beforeExecute, afterExecute); + remove: function (beforeExecute, afterExecute, path) { + var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath; + return this.features.runningTree.remove(path2, beforeExecute, afterExecute); }, aggregate: function (aggregation) { return tslib_1.__awaiter(this, void 0, void 0, function () { diff --git a/lib/page.web.js b/lib/page.web.js index 31e4d098..954e6dad 100644 --- a/lib/page.web.js +++ b/lib/page.web.js @@ -127,26 +127,44 @@ var OakComponentBase = /** @class */ (function (_super) { return this.props.navigate(url2, { replace: true }); } } */ - OakComponentBase.prototype.addItem = function (data, beforeExecute, afterExecute) { + OakComponentBase.prototype.addItem = function (data, beforeExecute, afterExecute, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; this.features.runningTree.addItem(this.state.oakFullpath, data, beforeExecute, afterExecute); }; - OakComponentBase.prototype.removeItem = function (id, beforeExecute, afterExecute) { - this.features.runningTree.removeItem(this.state.oakFullpath, id, beforeExecute, afterExecute); + OakComponentBase.prototype.removeItem = function (id, beforeExecute, afterExecute, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.removeItem(path2, id, beforeExecute, afterExecute); }; - OakComponentBase.prototype.updateItem = function (data, id, action, beforeExecute, afterExecute) { - this.features.runningTree.updateItem(this.state.oakFullpath, data, id, action, beforeExecute, afterExecute); + OakComponentBase.prototype.updateItem = function (data, id, action, beforeExecute, afterExecute, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.updateItem(path2, data, id, action, beforeExecute, afterExecute); }; - OakComponentBase.prototype.recoverItem = function (id) { - this.features.runningTree.recoverItem(this.state.oakFullpath, id); + OakComponentBase.prototype.recoverItem = function (id, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.recoverItem(path2, id); }; /* create(data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) { this.features.runningTree.create(this.state.oakFullpath, data, beforeExecute, afterExecute); } */ - OakComponentBase.prototype.update = function (data, action, beforeExecute, afterExecute) { - this.features.runningTree.update(this.state.oakFullpath, data, action, beforeExecute, afterExecute); + OakComponentBase.prototype.update = function (data, action, beforeExecute, afterExecute, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.update(path2, data, action, beforeExecute, afterExecute); }; - OakComponentBase.prototype.remove = function (beforeExecute, afterExecute) { - this.features.runningTree.remove(this.state.oakFullpath, beforeExecute, afterExecute); + OakComponentBase.prototype.remove = function (beforeExecute, afterExecute, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.remove(path2, beforeExecute, afterExecute); }; OakComponentBase.prototype.clean = function (path) { var path2 = path @@ -193,15 +211,24 @@ var OakComponentBase = /** @class */ (function (_super) { OakComponentBase.prototype.unsetId = function () { return this.features.runningTree.unsetId(this.state.oakFullpath); }; - OakComponentBase.prototype.getId = function () { - return this.features.runningTree.getId(this.state.oakFullpath); + OakComponentBase.prototype.getId = function (path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + return this.features.runningTree.getId(path2); }; - OakComponentBase.prototype.setFilters = function (filters) { - this.features.runningTree.setNamedFilters(this.state.oakFullpath, filters); + OakComponentBase.prototype.setFilters = function (filters, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.setNamedFilters(path2, filters); }; - OakComponentBase.prototype.getFilters = function () { + OakComponentBase.prototype.getFilters = function (path) { if (this.state.oakFullpath) { - var namedFilters = this.features.runningTree.getNamedFilters(this.state.oakFullpath); + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + var namedFilters = this.features.runningTree.getNamedFilters(path2); var filters = namedFilters.map(function (_a) { var filter = _a.filter; if (typeof filter === 'function') { @@ -212,9 +239,12 @@ var OakComponentBase = /** @class */ (function (_super) { return filters; } }; - OakComponentBase.prototype.getFilterByName = function (name) { + OakComponentBase.prototype.getFilterByName = function (name, path) { if (this.state.oakFullpath) { - var filter = this.features.runningTree.getNamedFilterByName(this.state.oakFullpath, name); + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + var filter = this.features.runningTree.getNamedFilterByName(path2, name); if (filter === null || filter === void 0 ? void 0 : filter.filter) { if (typeof filter.filter === 'function') { return filter.filter(); @@ -223,21 +253,36 @@ var OakComponentBase = /** @class */ (function (_super) { } } }; - OakComponentBase.prototype.addNamedFilter = function (namedFilter, refresh) { - this.features.runningTree.addNamedFilter(this.state.oakFullpath, namedFilter, refresh); + OakComponentBase.prototype.addNamedFilter = function (namedFilter, refresh, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.addNamedFilter(path2, namedFilter, refresh); }; - OakComponentBase.prototype.removeNamedFilter = function (namedFilter, refresh) { - this.features.runningTree.removeNamedFilter(this.state.oakFullpath, namedFilter, refresh); + OakComponentBase.prototype.removeNamedFilter = function (namedFilter, refresh, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.removeNamedFilter(path2, namedFilter, refresh); }; - OakComponentBase.prototype.removeNamedFilterByName = function (name, refresh) { - this.features.runningTree.removeNamedFilterByName(this.state.oakFullpath, name, refresh); + OakComponentBase.prototype.removeNamedFilterByName = function (name, refresh, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.removeNamedFilterByName(path2, name, refresh); }; - OakComponentBase.prototype.setNamedSorters = function (namedSorters) { - this.features.runningTree.setNamedSorters(this.state.oakFullpath, namedSorters); + OakComponentBase.prototype.setNamedSorters = function (namedSorters, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.setNamedSorters(path2, namedSorters); }; - OakComponentBase.prototype.getSorters = function () { + OakComponentBase.prototype.getSorters = function (path) { if (this.state.oakFullpath) { - var namedSorters = this.features.runningTree.getNamedSorters(this.state.oakFullpath); + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + var namedSorters = this.features.runningTree.getNamedSorters(path2); var sorters = namedSorters .map(function (_a) { var sorter = _a.sorter; @@ -250,9 +295,12 @@ var OakComponentBase = /** @class */ (function (_super) { return sorters; } }; - OakComponentBase.prototype.getSorterByName = function (name) { + OakComponentBase.prototype.getSorterByName = function (name, path) { if (this.state.oakFullpath) { - var sorter = this.features.runningTree.getNamedSorterByName(this.state.oakFullpath, name); + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + var sorter = this.features.runningTree.getNamedSorterByName(path2, name); if (sorter === null || sorter === void 0 ? void 0 : sorter.sorter) { if (typeof sorter.sorter === 'function') { return sorter.sorter(); @@ -261,27 +309,47 @@ var OakComponentBase = /** @class */ (function (_super) { } } }; - OakComponentBase.prototype.addNamedSorter = function (namedSorter, refresh) { - this.features.runningTree.addNamedSorter(this.state.oakFullpath, namedSorter, refresh); + OakComponentBase.prototype.addNamedSorter = function (namedSorter, refresh, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.addNamedSorter(path2, namedSorter, refresh); }; - OakComponentBase.prototype.removeNamedSorter = function (namedSorter, refresh) { - this.features.runningTree.removeNamedSorter(this.state.oakFullpath, namedSorter, refresh); + OakComponentBase.prototype.removeNamedSorter = function (namedSorter, refresh, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.removeNamedSorter(path2, namedSorter, refresh); }; - OakComponentBase.prototype.removeNamedSorterByName = function (name, refresh) { - this.features.runningTree.removeNamedSorterByName(this.state.oakFullpath, name, refresh); + OakComponentBase.prototype.removeNamedSorterByName = function (name, refresh, path) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.removeNamedSorterByName(path2, name, refresh); }; - OakComponentBase.prototype.getPagination = function () { + OakComponentBase.prototype.getPagination = function (path) { if (this.state.oakFullpath) { - return this.features.runningTree.getPagination(this.state.oakFullpath); + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + return this.features.runningTree.getPagination(path2); } }; - OakComponentBase.prototype.setPageSize = function (pageSize) { - this.features.runningTree.setPageSize(this.state.oakFullpath, pageSize); + OakComponentBase.prototype.setPageSize = function (pageSize, path) { + if (this.state.oakFullpath) { + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.setPageSize(path2, pageSize); + } }; - OakComponentBase.prototype.setCurrentPage = function (currentPage) { + OakComponentBase.prototype.setCurrentPage = function (currentPage, path) { (0, assert_1.default)(currentPage !== 0); if (this.state.oakEntity && this.state.oakFullpath) { - this.features.runningTree.setCurrentPage(this.state.oakFullpath, currentPage); + var path2 = path + ? "".concat(this.state.oakFullpath, ".").concat(path) + : this.state.oakFullpath; + this.features.runningTree.setCurrentPage(path2, currentPage); } }; return OakComponentBase; @@ -385,65 +453,61 @@ function createComponent(option, features) { return _this.clean(path); }, }; - if (option.isList) { - Object.assign(methodProps, { - addItem: function (data, beforeExecute, afterExecute) { - return _this.addItem(data, beforeExecute, afterExecute); - }, - removeItem: function (id, beforeExecute, afterExecute) { - return _this.removeItem(id, beforeExecute, afterExecute); - }, - updateItem: function (data, id, action, beforeExecute, afterExecute) { - return _this.updateItem(data, id, action, beforeExecute, afterExecute); - }, - setFilters: function (filters) { - return _this.setFilters(filters); - }, - addNamedFilter: function (filter, refresh) { - return _this.addNamedFilter(filter, refresh); - }, - removeNamedFilter: function (filter, refresh) { - return _this.removeNamedFilter(filter, refresh); - }, - removeNamedFilterByName: function (name, refresh) { - return _this.removeNamedFilterByName(name, refresh); - }, - setNamedSorters: function (sorters) { - return _this.setNamedSorters(sorters); - }, - addNamedSorter: function (sorter, refresh) { - return _this.addNamedSorter(sorter, refresh); - }, - removeNamedSorter: function (sorter, refresh) { - return _this.removeNamedSorter(sorter, refresh); - }, - removeNamedSorterByName: function (name, refresh) { - return _this.removeNamedSorterByName(name, refresh); - }, - setPageSize: function (pageSize) { - return _this.setPageSize(pageSize); - }, - setCurrentPage: function (current) { - return _this.setCurrentPage(current); - }, - loadMore: function () { - return _this.loadMore(); - } - }); - } - else { - Object.assign(methodProps, { - /* create: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => { - return this.create(data, beforeExecute, afterExecute); - }, */ - update: function (data, action, beforeExecute, afterExecute) { - return _this.update(data, action, beforeExecute, afterExecute); - }, - remove: function (beforeExecute, afterExecute) { - return _this.remove(beforeExecute, afterExecute); - }, - }); - } + Object.assign(methodProps, { + addItem: function (data, beforeExecute, afterExecute, path) { + return _this.addItem(data, beforeExecute, afterExecute, path); + }, + removeItem: function (id, beforeExecute, afterExecute, path) { + return _this.removeItem(id, beforeExecute, afterExecute, path); + }, + updateItem: function (data, id, action, beforeExecute, afterExecute, path) { + return _this.updateItem(data, id, action, beforeExecute, afterExecute, path); + }, + setFilters: function (filters, path) { + return _this.setFilters(filters, path); + }, + addNamedFilter: function (filter, refresh, path) { + return _this.addNamedFilter(filter, refresh, path); + }, + removeNamedFilter: function (filter, refresh, path) { + return _this.removeNamedFilter(filter, refresh, path); + }, + removeNamedFilterByName: function (name, refresh, path) { + return _this.removeNamedFilterByName(name, refresh, path); + }, + setNamedSorters: function (sorters, path) { + return _this.setNamedSorters(sorters, path); + }, + addNamedSorter: function (sorter, refresh, path) { + return _this.addNamedSorter(sorter, refresh, path); + }, + removeNamedSorter: function (sorter, refresh, path) { + return _this.removeNamedSorter(sorter, refresh, path); + }, + removeNamedSorterByName: function (name, refresh, path) { + return _this.removeNamedSorterByName(name, refresh, path); + }, + setPageSize: function (pageSize, path) { + return _this.setPageSize(pageSize, path); + }, + setCurrentPage: function (current, path) { + return _this.setCurrentPage(current, path); + }, + loadMore: function () { + return _this.loadMore(); + } + }); + Object.assign(methodProps, { + /* create: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => { + return this.create(data, beforeExecute, afterExecute); + }, */ + update: function (data, action, beforeExecute, afterExecute, path) { + return _this.update(data, action, beforeExecute, afterExecute, path); + }, + remove: function (beforeExecute, afterExecute, path) { + return _this.remove(beforeExecute, afterExecute, path); + }, + }); if (methods) { var _loop_1 = function (m) { var _a, _b; diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index a97d8d05..9d0f9201 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -60,7 +60,7 @@ export declare type ComponentPublicThisType; setState: (data: Partial>, callback?: () => void) => void; triggerEvent: (name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void; -} & TMethod & OakCommonComponentMethods & (IsList extends true ? OakListComponentMethods : OakSingleComponentMethods); +} & TMethod & OakCommonComponentMethods & OakListComponentMethods & OakSingleComponentMethods; export declare type ComponentFullThisType, FrontCxt extends SyncContext> = { subscribed: Array<() => void>; features: BasicFeatures>; @@ -68,7 +68,7 @@ export declare type ComponentFullThisType; setState: (data: Partial>, callback?: () => void) => void; triggerEvent: (name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void; -} & OakCommonComponentMethods & (IsList extends true ? OakListComponentMethods : OakSingleComponentMethods); +} & OakCommonComponentMethods & OakListComponentMethods & OakSingleComponentMethods; export declare type OakComponentOption, FrontCxt extends SyncContext, AD extends Record>, FD extends Record, FormedData extends Record, IsList extends boolean, TData extends Record, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends Record> = ComponentOption & Partial<{ data?: ((option: { features: BasicFeatures> & FD; @@ -108,6 +108,7 @@ export declare type OakListComponentProperties = { oakFilters: ObjectConstructor; oakSorters: ObjectConstructor; oakIsPicker: BooleanConstructor; + oakPagination: ObjectConstructor; }; export declare type OakNavigateToParameters = { oakId?: string; @@ -162,30 +163,30 @@ export declare type OakSingleComponentMethods void; unsetId: () => void; getId: () => string | undefined; - update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - remove: (beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; + update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; + remove: (beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; }; export declare type OakListComponentMethods = { loadMore: () => Promise; - setFilters: (filters: NamedFilterItem[]) => void; - getFilters: () => ED[T]['Selection']['filter'][] | undefined; - getFilterByName: (name: string) => ED[T]['Selection']['filter'] | undefined; - addNamedFilter: (filter: NamedFilterItem, refresh?: boolean) => void; - removeNamedFilter: (filter: NamedFilterItem, refresh?: boolean) => void; - removeNamedFilterByName: (name: string, refresh?: boolean) => void; - setNamedSorters: (sorters: NamedSorterItem[]) => void; - getSorters: () => ED[T]['Selection']['sorter'] | undefined; - getSorterByName: (name: string) => NonNullable[number] | undefined; - addNamedSorter: (filter: NamedSorterItem, refresh?: boolean) => void; - removeNamedSorter: (filter: NamedSorterItem, refresh?: boolean) => void; - removeNamedSorterByName: (name: string, refresh?: boolean) => void; - getPagination: () => Pagination | undefined; - setPageSize: (pageSize: number) => void; - setCurrentPage: (current: number) => void; - addItem: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - removeItem: (id: string, beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - recoverItem: (id: string) => void; + setFilters: (filters: NamedFilterItem[], path?: string) => void; + getFilters: (path?: string) => ED[T]['Selection']['filter'][] | undefined; + getFilterByName: (name: string, path?: string) => ED[T]['Selection']['filter'] | undefined; + addNamedFilter: (filter: NamedFilterItem, refresh?: boolean, path?: string) => void; + removeNamedFilter: (filter: NamedFilterItem, refresh?: boolean, path?: string) => void; + removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => void; + setNamedSorters: (sorters: NamedSorterItem[], path?: string) => void; + getSorters: (path?: string) => ED[T]['Selection']['sorter'] | undefined; + getSorterByName: (name: string, path?: string) => NonNullable[number] | undefined; + addNamedSorter: (filter: NamedSorterItem, refresh?: boolean, path?: string) => void; + removeNamedSorter: (filter: NamedSorterItem, refresh?: boolean, path?: string) => void; + removeNamedSorterByName: (name: string, refresh?: boolean, path?: string) => void; + getPagination: (path?: string) => Pagination | undefined; + setPageSize: (pageSize: number, path?: string) => void; + setCurrentPage: (current: number, path?: string) => void; + addItem: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; + removeItem: (id: string, beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; + updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; + recoverItem: (id: string, path?: string) => void; }; declare type ComponentOnPropsChangeOption = { path?: string; @@ -212,12 +213,17 @@ export declare type OakComponentData = { + oakFilters?: NonNullable[]; + oakSorters?: NonNullable[]; + oakPagination?: Pagination; +}; export declare type MakeOakComponent, FrontCxt extends SyncContext, AD extends Record>, FD extends Record> = (options: OakComponentOption) => React.ComponentType; export declare type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'setDisablePulldownRefresh' | 'aggregate'; export declare type WebComponentListMethodNames = 'loadMore' | 'setFilters' | 'addNamedFilter' | 'removeNamedFilter' | 'removeNamedFilterByName' | 'setNamedSorters' | 'addNamedSorter' | 'removeNamedSorter' | 'removeNamedSorterByName' | 'setPageSize' | 'setCurrentPage' | 'addItem' | 'removeItem' | 'updateItem'; export declare type WebComponentSingleMethodNames = 'update' | 'remove'; export declare type WebComponentProps = { - methods: TMethod & Pick, WebComponentCommonMethodNames> & (IsList extends true ? Pick, WebComponentListMethodNames> : Pick, WebComponentSingleMethodNames>); - data: TData & OakComponentData & (IsList extends true ? OakListComponentProperties : {}); + methods: TMethod & OakCommonComponentMethods & OakListComponentMethods & OakSingleComponentMethods; + data: TData & OakComponentData & (IsList extends true ? OakListComoponetData : {}); }; export {}; diff --git a/src/page.common.ts b/src/page.common.ts index 58caecda..ee5de6cf 100644 --- a/src/page.common.ts +++ b/src/page.common.ts @@ -197,6 +197,18 @@ export function reRender< Object.assign(data, { oakLegalActions, }); + + if (option.isList) { + const oakFilters = (this as ComponentFullThisType).getFilters(); + const oakSorters = (this as ComponentFullThisType).getSorters(); + const oakPagination = (this as ComponentFullThisType).getPagination(); + Object.assign(data, { + oakFilters, + oakSorters, + oakPagination, + }); + } + for (const k in data) { if (data[k] === undefined) { Object.assign(data, { diff --git a/src/page.mp.ts b/src/page.mp.ts index 9b81562b..014f3cb9 100644 --- a/src/page.mp.ts +++ b/src/page.mp.ts @@ -360,15 +360,17 @@ const oakBehavior = Behavior< return this.features.runningTree.getId(this.state.oakFullpath); }, - setFilters(filters) { + setFilters(filters, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; this.features.runningTree.setNamedFilters( - this.state.oakFullpath, + path2, filters ); }, - getFilters() { + getFilters(path) { if (this.state.oakFullpath) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; const namedFilters = this.features.runningTree.getNamedFilters( this.state.oakFullpath ); @@ -381,10 +383,11 @@ const oakBehavior = Behavior< } }, - getFilterByName(name: string) { + getFilterByName(name, path) { if (this.state.oakFullpath) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; const filter = this.features.runningTree.getNamedFilterByName( - this.state.oakFullpath, + path2, name ); if (filter?.filter) { @@ -396,42 +399,45 @@ const oakBehavior = Behavior< } }, - addNamedFilter(namedFilter, refresh) { + addNamedFilter(namedFilter, refresh, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; this.features.runningTree.addNamedFilter( - this.state.oakFullpath, + path2, namedFilter, refresh ); }, - removeNamedFilter(namedFilter, refresh) { + removeNamedFilter(namedFilter, refresh, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; this.features.runningTree.removeNamedFilter( - this.state.oakFullpath, + path2, namedFilter, refresh ); }, - removeNamedFilterByName(name, refresh) { + removeNamedFilterByName(name, refresh, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; this.features.runningTree.removeNamedFilterByName( - this.state.oakFullpath, + path2, name, refresh ); }, - setNamedSorters(namedSorters) { + setNamedSorters(namedSorters, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; this.features.runningTree.setNamedSorters( - this.state.oakFullpath, + path2, namedSorters ); }, - getSorters() { + getSorters(path) { if (this.state.oakFullpath) { - const namedSorters = this.features.runningTree.getNamedSorters( - this.state.oakFullpath - ); + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; + const namedSorters = this.features.runningTree.getNamedSorters(path2); const sorters = namedSorters .map(({ sorter }) => { if (typeof sorter === 'function') { @@ -444,10 +450,11 @@ const oakBehavior = Behavior< } }, - getSorterByName(name) { + getSorterByName(name, path) { if (this.state.oakFullpath) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; const sorter = this.features.runningTree.getNamedSorterByName( - this.state.oakFullpath, + path2, name ); if (sorter?.sorter) { @@ -459,66 +466,64 @@ const oakBehavior = Behavior< } }, - addNamedSorter(namedSorter, refresh) { - this.features.runningTree.addNamedSorter( - this.state.oakFullpath, - namedSorter, - refresh - ); + addNamedSorter(namedSorter, refresh, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; + this.features.runningTree.addNamedSorter(path2, namedSorter, refresh); }, - removeNamedSorter(namedSorter, refresh) { + removeNamedSorter(namedSorter, refresh, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; this.features.runningTree.removeNamedSorter( - this.state.oakFullpath, + path2, namedSorter, refresh ); }, - removeNamedSorterByName(name, refresh) { - this.features.runningTree.removeNamedSorterByName( - this.state.oakFullpath, - name, - refresh - ); + removeNamedSorterByName(name, refresh, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; + this.features.runningTree.removeNamedSorterByName(path2, name, refresh); }, - getPagination() { + getPagination(path) { if (this.state.oakFullpath) { - return this.features.runningTree.getPagination( - this.state.oakFullpath - ); + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; + return this.features.runningTree.getPagination(path2); } }, - setPageSize(pageSize) { + setPageSize(pageSize, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; this.features.runningTree.setPageSize( - this.state.oakFullpath, + path2, pageSize ); }, - setCurrentPage(currentPage) { + setCurrentPage(currentPage, path) { assert(currentPage !== 0); if (this.state.oakEntity && this.state.oakFullpath) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; this.features.runningTree.setCurrentPage( - this.state.oakFullpath, + path2, currentPage ); } }, - addItem(data, beforeExecute, afterExecute) { + addItem(data, beforeExecute, afterExecute, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; return this.features.runningTree.addItem( - this.state.oakFullpath, + path2, data, beforeExecute, afterExecute ); }, - updateItem(data, id, action, beforeExecute, afterExecute) { + updateItem(data, id, action, beforeExecute, afterExecute, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; return this.features.runningTree.updateItem( - this.state.oakFullpath, + path2, data, id, action, @@ -526,17 +531,19 @@ const oakBehavior = Behavior< afterExecute ); }, - removeItem(id, beforeExecute, afterExecute) { + removeItem(id, beforeExecute, afterExecute, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; return this.features.runningTree.removeItem( - this.state.oakFullpath, + path2, id, beforeExecute, afterExecute ); }, - recoverItem(id) { + recoverItem(id, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; return this.features.runningTree.recoverItem( - this.state.oakFullpath, + path2, id ); }, @@ -546,18 +553,20 @@ const oakBehavior = Behavior< unsetId() { return this.features.runningTree.unsetId(this.state.oakFullpath); }, - update(data, action, beforeExecute, afterExecute) { + update(data, action, beforeExecute, afterExecute, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; return this.features.runningTree.update( - this.state.oakFullpath, + path2, data, action, beforeExecute, afterExecute ); }, - remove(beforeExecute, afterExecute) { + remove(beforeExecute, afterExecute, path) { + const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath; return this.features.runningTree.remove( - this.state.oakFullpath, + path2, beforeExecute, afterExecute ); diff --git a/src/page.web.tsx b/src/page.web.tsx index f6392515..a7f00bb7 100644 --- a/src/page.web.tsx +++ b/src/page.web.tsx @@ -41,10 +41,10 @@ abstract class OakComponentBase< TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption -> extends React.PureComponent< + > extends React.PureComponent< ComponentProps, ComponentData -> { + > { abstract features: FD & BasicFeatures>; abstract oakOption: OakComponentOption< @@ -75,7 +75,7 @@ abstract class OakComponentBase< name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption - ) {} + ) { } sub(type: string, callback: Function) { this.features.eventBus.sub(type, callback); @@ -216,8 +216,12 @@ abstract class OakComponentBase< addItem( data: Omit, beforeExecute?: () => Promise, - afterExecute?: () => Promise + afterExecute?: () => Promise, + path?: string ) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.addItem( this.state.oakFullpath, data, @@ -229,10 +233,14 @@ abstract class OakComponentBase< removeItem( id: string, beforeExecute?: () => Promise, - afterExecute?: () => Promise + afterExecute?: () => Promise, + path?: string ) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.removeItem( - this.state.oakFullpath, + path2, id, beforeExecute, afterExecute @@ -244,10 +252,14 @@ abstract class OakComponentBase< id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise, - afterExecute?: () => Promise + afterExecute?: () => Promise, + path?: string ) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.updateItem( - this.state.oakFullpath, + path2, data, id, action, @@ -256,8 +268,11 @@ abstract class OakComponentBase< ); } - recoverItem(id: string) { - this.features.runningTree.recoverItem(this.state.oakFullpath, id); + recoverItem(id: string, path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; + this.features.runningTree.recoverItem(path2, id); } /* create(data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) { @@ -268,10 +283,14 @@ abstract class OakComponentBase< data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise, - afterExecute?: () => Promise + afterExecute?: () => Promise, + path?: string ) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.update( - this.state.oakFullpath, + path2, data, action, beforeExecute, @@ -281,10 +300,14 @@ abstract class OakComponentBase< remove( beforeExecute?: () => Promise, - afterExecute?: () => Promise + afterExecute?: () => Promise, + path?: string ) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.remove( - this.state.oakFullpath, + path2, beforeExecute, afterExecute ); @@ -356,22 +379,29 @@ abstract class OakComponentBase< return this.features.runningTree.unsetId(this.state.oakFullpath); } - getId() { - return this.features.runningTree.getId(this.state.oakFullpath); + getId(path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; + return this.features.runningTree.getId(path2); } - setFilters(filters: NamedFilterItem[]) { + setFilters(filters: NamedFilterItem[], path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.setNamedFilters( - this.state.oakFullpath, + path2, filters ); } - getFilters() { + getFilters(path?: string) { if (this.state.oakFullpath) { - const namedFilters = this.features.runningTree.getNamedFilters( - this.state.oakFullpath - ); + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; + const namedFilters = this.features.runningTree.getNamedFilters(path2); const filters = namedFilters.map(({ filter }) => { if (typeof filter === 'function') { return (filter as Function)(); @@ -382,12 +412,12 @@ abstract class OakComponentBase< } } - getFilterByName(name: string) { + getFilterByName(name: string, path?: string) { if (this.state.oakFullpath) { - const filter = this.features.runningTree.getNamedFilterByName( - this.state.oakFullpath, - name - ); + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; + const filter = this.features.runningTree.getNamedFilterByName(path2, name); if (filter?.filter) { if (typeof filter.filter === 'function') { return (filter.filter as Function)(); @@ -397,42 +427,55 @@ abstract class OakComponentBase< } } - addNamedFilter(namedFilter: NamedFilterItem, refresh?: boolean) { + addNamedFilter(namedFilter: NamedFilterItem, refresh?: boolean, path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.addNamedFilter( - this.state.oakFullpath, + path2, namedFilter, refresh ); } - removeNamedFilter(namedFilter: NamedFilterItem, refresh?: boolean) { + removeNamedFilter(namedFilter: NamedFilterItem, refresh?: boolean, path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.removeNamedFilter( - this.state.oakFullpath, + path2, namedFilter, refresh ); } - removeNamedFilterByName(name: string, refresh?: boolean) { + removeNamedFilterByName(name: string, refresh?: boolean, path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.removeNamedFilterByName( - this.state.oakFullpath, + path2, name, refresh ); } - setNamedSorters(namedSorters: NamedSorterItem[]) { + setNamedSorters(namedSorters: NamedSorterItem[], path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.setNamedSorters( - this.state.oakFullpath, + path2, namedSorters ); } - getSorters() { + getSorters(path?: string) { if (this.state.oakFullpath) { - const namedSorters = this.features.runningTree.getNamedSorters( - this.state.oakFullpath - ); + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; + const namedSorters = this.features.runningTree.getNamedSorters(path2); const sorters = namedSorters .map(({ sorter }) => { if (typeof sorter === 'function') { @@ -445,12 +488,12 @@ abstract class OakComponentBase< } } - getSorterByName(name: string) { + getSorterByName(name: string, path?: string) { if (this.state.oakFullpath) { - const sorter = this.features.runningTree.getNamedSorterByName( - this.state.oakFullpath, - name - ); + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; + const sorter = this.features.runningTree.getNamedSorterByName(path2, name); if (sorter?.sorter) { if (typeof sorter.sorter === 'function') { return (sorter.sorter as Function)(); @@ -460,48 +503,66 @@ abstract class OakComponentBase< } } - addNamedSorter(namedSorter: NamedSorterItem, refresh?: boolean) { + addNamedSorter(namedSorter: NamedSorterItem, refresh?: boolean, path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.addNamedSorter( - this.state.oakFullpath, + path2, namedSorter, refresh ); } - removeNamedSorter(namedSorter: NamedSorterItem, refresh?: boolean) { + removeNamedSorter(namedSorter: NamedSorterItem, refresh?: boolean, path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.removeNamedSorter( - this.state.oakFullpath, + path2, namedSorter, refresh ); } - removeNamedSorterByName(name: string, refresh?: boolean) { + removeNamedSorterByName(name: string, refresh?: boolean, path?: string) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.removeNamedSorterByName( - this.state.oakFullpath, + path2, name, refresh ); } - getPagination() { + getPagination(path?: string) { if (this.state.oakFullpath) { - return this.features.runningTree.getPagination( - this.state.oakFullpath - ); + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; + return this.features.runningTree.getPagination(path2); } } - setPageSize(pageSize: number) { - this.features.runningTree.setPageSize(this.state.oakFullpath, pageSize); + setPageSize(pageSize: number, path?: string) { + if (this.state.oakFullpath) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; + this.features.runningTree.setPageSize(path2, pageSize); + } } - setCurrentPage(currentPage: number) { + setCurrentPage(currentPage: number, path?: string) { assert(currentPage !== 0); if (this.state.oakEntity && this.state.oakFullpath) { + const path2 = path + ? `${this.state.oakFullpath}.${path}` + : this.state.oakFullpath; this.features.runningTree.setCurrentPage( - this.state.oakFullpath, + path2, currentPage ); } @@ -605,126 +666,117 @@ export function createComponent< constructor(props: ComponentProps) { super(props); const methodProps: Record = - { - setDisablePulldownRefresh: (able: boolean) => - this.setDisablePulldownRefresh(able), - t: (key: string, params?: object) => this.t(key, params), - execute: ( - action?: ED[T]['Action'], - messageProps?: boolean | MessageProps - ) => { - return this.execute(action, messageProps); - }, - aggregate: (aggregation: ED[T]['Aggregation']) => { - return this.features.cache.aggregate(this.state.oakEntity, aggregation); - }, - refresh: () => { - return this.refresh(); - }, - setNotification: (data: NotificationProps) => { - return this.setNotification(data); - }, - setMessage: (data: MessageProps) => { - return this.setMessage(data); - }, - navigateTo: ( - options: { url: string } & OakNavigateToParameters< - ED, - T2 - >, - state?: Record, - disableNamespace?: boolean - ) => { - return this.navigateTo( - options, - state, - disableNamespace - ); - }, - navigateBack: (delta?: number) => { - return this.navigateBack(delta); - }, - redirectTo: ( - options: Parameters[0] & - OakNavigateToParameters, - state?: Record, - disableNamespace?: boolean - ) => { - return this.redirectTo( - options, - state, - disableNamespace - ); - }, - clean: (path?: string) => { - return this.clean(path); - }, - }; - if (option.isList) { - Object.assign(methodProps, { - addItem: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => { - return this.addItem(data, beforeExecute, afterExecute); - }, - removeItem: (id: string, beforeExecute?: () => Promise, afterExecute?: () => Promise) => { - return this.removeItem(id, beforeExecute, afterExecute); - }, - updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise) => { - return this.updateItem(data, id, action, beforeExecute, afterExecute); - }, - setFilters: (filters: NamedFilterItem[]) => { - return this.setFilters(filters); - }, - addNamedFilter: (filter: NamedFilterItem, refresh?: boolean) => { - return this.addNamedFilter(filter, refresh); - }, - removeNamedFilter: ( - filter: NamedFilterItem, - refresh?: boolean - ) => { - return this.removeNamedFilter(filter, refresh); - }, - removeNamedFilterByName: (name: string, refresh?: boolean) => { - return this.removeNamedFilterByName(name, refresh); - }, - setNamedSorters: (sorters: NamedSorterItem[]) => { - return this.setNamedSorters(sorters); - }, - addNamedSorter: (sorter: NamedSorterItem, refresh?: boolean) => { - return this.addNamedSorter(sorter, refresh); - }, - removeNamedSorter: ( - sorter: NamedSorterItem, - refresh?: boolean - ) => { - return this.removeNamedSorter(sorter, refresh); - }, - removeNamedSorterByName: (name: string, refresh?: boolean) => { - return this.removeNamedSorterByName(name, refresh); - }, - setPageSize: (pageSize: number) => { - return this.setPageSize(pageSize); - }, - setCurrentPage: (current: number) => { - return this.setCurrentPage(current); - }, - loadMore: () => { - return this.loadMore(); - } - } as Record); - } - else { - Object.assign(methodProps, { - /* create: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => { - return this.create(data, beforeExecute, afterExecute); - }, */ - update: (data: ED[T]['Update']['data'], action: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise) => { - return this.update(data, action, beforeExecute, afterExecute); - }, - remove: (beforeExecute?: () => Promise, afterExecute?: () => Promise) => { - return this.remove(beforeExecute, afterExecute); - }, - } as Record); - } + { + setDisablePulldownRefresh: (able: boolean) => + this.setDisablePulldownRefresh(able), + t: (key: string, params?: object) => this.t(key, params), + execute: ( + action?: ED[T]['Action'], + messageProps?: boolean | MessageProps + ) => { + return this.execute(action, messageProps); + }, + aggregate: (aggregation: ED[T]['Aggregation']) => { + return this.features.cache.aggregate(this.state.oakEntity, aggregation); + }, + refresh: () => { + return this.refresh(); + }, + setNotification: (data: NotificationProps) => { + return this.setNotification(data); + }, + setMessage: (data: MessageProps) => { + return this.setMessage(data); + }, + navigateTo: ( + options: { url: string } & OakNavigateToParameters< + ED, + T2 + >, + state?: Record, + disableNamespace?: boolean + ) => { + return this.navigateTo( + options, + state, + disableNamespace + ); + }, + navigateBack: (delta?: number) => { + return this.navigateBack(delta); + }, + redirectTo: ( + options: Parameters[0] & + OakNavigateToParameters, + state?: Record, + disableNamespace?: boolean + ) => { + return this.redirectTo( + options, + state, + disableNamespace + ); + }, + clean: (path?: string) => { + return this.clean(path); + }, + }; + Object.assign(methodProps, { + addItem: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => { + return this.addItem(data, beforeExecute, afterExecute, path); + }, + removeItem: (id: string, beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => { + return this.removeItem(id, beforeExecute, afterExecute, path); + }, + updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => { + return this.updateItem(data, id, action, beforeExecute, afterExecute, path); + }, + setFilters: (filters: NamedFilterItem[], path?: string) => { + return this.setFilters(filters, path); + }, + addNamedFilter: (filter: NamedFilterItem, refresh?: boolean, path?: string) => { + return this.addNamedFilter(filter, refresh, path); + }, + removeNamedFilter: (filter: NamedFilterItem, refresh?: boolean, path?: string) => { + return this.removeNamedFilter(filter, refresh, path); + }, + removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => { + return this.removeNamedFilterByName(name, refresh, path); + }, + setNamedSorters: (sorters: NamedSorterItem[], path?: string) => { + return this.setNamedSorters(sorters, path); + }, + addNamedSorter: (sorter: NamedSorterItem, refresh?: boolean, path?: string) => { + return this.addNamedSorter(sorter, refresh, path); + }, + removeNamedSorter: (sorter: NamedSorterItem, refresh?: boolean, path?: string) => { + return this.removeNamedSorter(sorter, refresh, path); + }, + removeNamedSorterByName: (name: string, refresh?: boolean, path?: string) => { + return this.removeNamedSorterByName(name, refresh, path); + }, + setPageSize: (pageSize: number, path?: string) => { + return this.setPageSize(pageSize, path); + }, + setCurrentPage: (current: number, path?: string) => { + return this.setCurrentPage(current, path); + }, + loadMore: () => { + return this.loadMore(); + } + } as Record); + + Object.assign(methodProps, { + /* create: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => { + return this.create(data, beforeExecute, afterExecute); + }, */ + update: (data: ED[T]['Update']['data'], action: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => { + return this.update(data, action, beforeExecute, afterExecute, path); + }, + remove: (beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => { + return this.remove(beforeExecute, afterExecute, path); + }, + } as Record); if (methods) { for (const m in methods) { @@ -738,7 +790,7 @@ export function createComponent< } // ts似乎有个BUG,这里不硬写as会有编译错误 - const data2 = typeof data === 'function' ? (data as ((option: { features: BasicFeatures> & FD, props: ComponentProps}) => TData))({ features, props }) : data; + const data2 = typeof data === 'function' ? (data as ((option: { features: BasicFeatures> & FD, props: ComponentProps }) => TData))({ features, props }) : data; this.state = Object.assign({}, data2, { oakLoading: false, oakLoadingMore: false, @@ -747,7 +799,7 @@ export function createComponent< oakDirty: false, }) as any; this.methodProps = methodProps; - + // 处理默认的properties this.defaultProperties = {}; const { properties } = option; diff --git a/src/types/Page.ts b/src/types/Page.ts index 76965b3e..35c06443 100644 --- a/src/types/Page.ts +++ b/src/types/Page.ts @@ -113,7 +113,7 @@ export type ComponentPublicThisType< detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption ) => void; - } & TMethod & OakCommonComponentMethods & (IsList extends true ? OakListComponentMethods : OakSingleComponentMethods); + } & TMethod & OakCommonComponentMethods & OakListComponentMethods & OakSingleComponentMethods; export type ComponentFullThisType< ED extends EntityDict & BaseEntityDict, @@ -135,7 +135,7 @@ export type ComponentFullThisType< detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption ) => void; - } & OakCommonComponentMethods & (IsList extends true ? OakListComponentMethods : OakSingleComponentMethods); + } & OakCommonComponentMethods & OakListComponentMethods & OakSingleComponentMethods; export type OakComponentOption< ED extends EntityDict & BaseEntityDict, @@ -151,7 +151,7 @@ export type OakComponentOption< TMethod extends Record, > = ComponentOption & Partial<{ - data?: ((option: { features: BasicFeatures> & FD, props: ComponentProps}) => TData) | TData; + data?: ((option: { features: BasicFeatures> & FD, props: ComponentProps }) => TData) | TData; properties: Record; methods: TMethod; lifetimes: { @@ -166,7 +166,7 @@ export type OakComponentOption< }; actions?: ED[T]['Action'][] | ((this: ComponentPublicThisType< ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod - >) => ED[T]['Action'][]); + >) => ED[T]['Action'][]); observers: Record any>; }> & Partial<{ @@ -193,6 +193,7 @@ export type OakListComponentProperties = { oakFilters: ObjectConstructor; oakSorters: ObjectConstructor; oakIsPicker: BooleanConstructor; + oakPagination: ObjectConstructor; } export type OakNavigateToParameters = { @@ -210,104 +211,92 @@ export type OakNavigateToParameters = { - setDisablePulldownRefresh: (able: boolean) => void; - sub: (type: string, callback: Function) => void; - unsub: (type: string, callback: Function) => void; - pub: (type: string, options?: any) => void; - unsubAll: (type: string) => void; - save: (key: string, item: any) => void; - load: (key: string) => any; - clear: () => void; - resolveInput: ( - input: any, - keys?: K[] - ) => { dataset?: Record; value?: string } & { - [k in K]?: any; - }; - setNotification: (data: NotificationProps) => void; - consumeNotification: () => NotificationProps | undefined; - setMessage: (data: MessageProps) => void; - consumeMessage: () => MessageProps | undefined; - reRender: (extra?: Record) => void; - getFreshValue: ( - path?: string - ) => - | Partial[] - | Partial - | undefined; - navigateTo: ( - options: { url: string } & OakNavigateToParameters, - state?: Record, - disableNamespace?: boolean - ) => Promise; - navigateBack: (delta?: number) => Promise; - redirectTo: ( - options: Parameters[0] & - OakNavigateToParameters, - state?: Record, - disableNamespace?: boolean - ) => Promise; - // setProps: (props: Record, usingState?: true) => void; - clean: (path?: string) => void; + > = { + setDisablePulldownRefresh: (able: boolean) => void; + sub: (type: string, callback: Function) => void; + unsub: (type: string, callback: Function) => void; + pub: (type: string, options?: any) => void; + unsubAll: (type: string) => void; + save: (key: string, item: any) => void; + load: (key: string) => any; + clear: () => void; + resolveInput: ( + input: any, + keys?: K[] + ) => { dataset?: Record; value?: string } & { + [k in K]?: any; + }; + setNotification: (data: NotificationProps) => void; + consumeNotification: () => NotificationProps | undefined; + setMessage: (data: MessageProps) => void; + consumeMessage: () => MessageProps | undefined; + reRender: (extra?: Record) => void; + getFreshValue: (path?: string) => + | Partial[] + | Partial + | undefined; + navigateTo: ( + options: { url: string } & OakNavigateToParameters, + state?: Record, + disableNamespace?: boolean + ) => Promise; + navigateBack: (delta?: number) => Promise; + redirectTo: ( + options: Parameters[0] & + OakNavigateToParameters, + state?: Record, + disableNamespace?: boolean + ) => Promise; + // setProps: (props: Record, usingState?: true) => void; + clean: (path?: string) => void; - t(key: string, params?: object): string; - execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps) => Promise; - checkOperation: ( - ntity: T, - action: ED[T]['Action'], - filter?: ED[T]['Update']['filter'], - checkerTypes?: CheckerType[] - ) => boolean; - tryExecute: (path?: string) => boolean | Error; - getOperations: ( - path?: string - ) => { operation: ED[T]['Operation']; entity: T }[] | undefined; - refresh: () => Promise; - aggregate: (aggregation: ED[T]['Aggregation']) => Promise>; -}; + t(key: string, params?: object): string; + execute: (action?: ED[T]['Action'], messageProps?: boolean | MessageProps) => Promise; + checkOperation: ( + ntity: T, + action: ED[T]['Action'], + filter?: ED[T]['Update']['filter'], + checkerTypes?: CheckerType[] + ) => boolean; + tryExecute: (path?: string) => boolean | Error; + getOperations: ( + path?: string + ) => { operation: ED[T]['Operation']; entity: T }[] | undefined; + refresh: () => Promise; + aggregate: (aggregation: ED[T]['Aggregation']) => Promise>; + }; export type OakSingleComponentMethods = { setId: (id: string) => void; unsetId: () => void; getId: () => string | undefined; // create: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - remove: (beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; + update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; + remove: (beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; } export type OakListComponentMethods = { loadMore: () => Promise; - setFilters: (filters: NamedFilterItem[]) => void; - getFilters: () => ED[T]['Selection']['filter'][] | undefined; - getFilterByName: ( - name: string - ) => ED[T]['Selection']['filter'] | undefined; - addNamedFilter: (filter: NamedFilterItem, refresh?: boolean) => void; - removeNamedFilter: ( - filter: NamedFilterItem, - refresh?: boolean - ) => void; - removeNamedFilterByName: (name: string, refresh?: boolean) => void; - setNamedSorters: (sorters: NamedSorterItem[]) => void; - getSorters: () => ED[T]['Selection']['sorter'] | undefined; - getSorterByName: ( - name: string - ) => NonNullable[number] | undefined; - addNamedSorter: (filter: NamedSorterItem, refresh?: boolean) => void; - removeNamedSorter: ( - filter: NamedSorterItem, - refresh?: boolean - ) => void; - removeNamedSorterByName: (name: string, refresh?: boolean) => void; - getPagination: () => Pagination | undefined; - setPageSize: (pageSize: number) => void; - setCurrentPage: (current: number) => void; + setFilters: (filters: NamedFilterItem[], path?: string) => void; + getFilters: (path?: string) => ED[T]['Selection']['filter'][] | undefined; + getFilterByName: (name: string, path?: string) => ED[T]['Selection']['filter'] | undefined; + addNamedFilter: (filter: NamedFilterItem, refresh?: boolean, path?: string) => void; + removeNamedFilter: (filter: NamedFilterItem, refresh?: boolean, path?: string) => void; + removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => void; + setNamedSorters: (sorters: NamedSorterItem[], path?: string) => void; + getSorters: (path?: string) => ED[T]['Selection']['sorter'] | undefined; + getSorterByName: (name: string, path?: string) => NonNullable[number] | undefined; + addNamedSorter: (filter: NamedSorterItem, refresh?: boolean, path?: string) => void; + removeNamedSorter: (filter: NamedSorterItem, refresh?: boolean, path?: string) => void; + removeNamedSorterByName: (name: string, refresh?: boolean, path?: string) => void; + getPagination: (path?: string) => Pagination | undefined; + setPageSize: (pageSize: number, path?: string) => void; + setCurrentPage: (current: number, path?: string) => void; - addItem: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - removeItem: (id: string, beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise) => void; - recoverItem: (id: string) => void; + addItem: (data: Omit, beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; + removeItem: (id: string, beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; + updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise, afterExecute?: () => Promise, path?: string) => void; + recoverItem: (id: string, path?: string) => void; }; type ComponentOnPropsChangeOption = { @@ -341,6 +330,15 @@ export type OakComponentData< oakDisablePulldownRefresh: boolean; }; +export type OakListComoponetData< + ED extends EntityDict & BaseEntityDict, + T extends keyof ED + > = { + oakFilters?: NonNullable[]; + oakSorters?: NonNullable[]; + oakPagination?: Pagination; + } + export type MakeOakComponent< ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext, @@ -386,7 +384,7 @@ export type WebComponentProps< IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}> = { - methods: TMethod & Pick, WebComponentCommonMethodNames> - & (IsList extends true ? Pick, WebComponentListMethodNames> : Pick, WebComponentSingleMethodNames>); - data: TData & OakComponentData & (IsList extends true ? OakListComponentProperties : {}); + methods: TMethod & OakCommonComponentMethods + & OakListComponentMethods & OakSingleComponentMethods; + data: TData & OakComponentData & (IsList extends true ? OakListComoponetData : {}); }