将很多runningTree上的方法修改为支持带path路径的调用

This commit is contained in:
Xu Chang 2023-01-31 19:33:11 +08:00
parent 89aeeec406
commit 414d7a52bc
8 changed files with 666 additions and 494 deletions

View File

@ -190,6 +190,16 @@ function reRender(option, extra) {
Object.assign(data, { Object.assign(data, {
oakLegalActions: oakLegalActions, 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) { for (var k in data) {
if (data[k] === undefined) { if (data[k] === undefined) {
Object.assign(data, (_a = {}, Object.assign(data, (_a = {},

View File

@ -264,11 +264,13 @@ var oakBehavior = Behavior({
getId: function () { getId: function () {
return this.features.runningTree.getId(this.state.oakFullpath); return this.features.runningTree.getId(this.state.oakFullpath);
}, },
setFilters: function (filters) { setFilters: function (filters, path) {
this.features.runningTree.setNamedFilters(this.state.oakFullpath, filters); 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) { 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); var namedFilters = this.features.runningTree.getNamedFilters(this.state.oakFullpath);
return namedFilters.map(function (_a) { return namedFilters.map(function (_a) {
var filter = _a.filter; var filter = _a.filter;
@ -279,9 +281,10 @@ var oakBehavior = Behavior({
}); });
} }
}, },
getFilterByName: function (name) { getFilterByName: function (name, path) {
if (this.state.oakFullpath) { 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 (filter === null || filter === void 0 ? void 0 : filter.filter) {
if (typeof filter.filter === 'function') { if (typeof filter.filter === 'function') {
return filter.filter(); return filter.filter();
@ -290,21 +293,26 @@ var oakBehavior = Behavior({
} }
} }
}, },
addNamedFilter: function (namedFilter, refresh) { addNamedFilter: function (namedFilter, refresh, path) {
this.features.runningTree.addNamedFilter(this.state.oakFullpath, namedFilter, refresh); var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath;
this.features.runningTree.addNamedFilter(path2, namedFilter, refresh);
}, },
removeNamedFilter: function (namedFilter, refresh) { removeNamedFilter: function (namedFilter, refresh, path) {
this.features.runningTree.removeNamedFilter(this.state.oakFullpath, namedFilter, refresh); var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath;
this.features.runningTree.removeNamedFilter(path2, namedFilter, refresh);
}, },
removeNamedFilterByName: function (name, refresh) { removeNamedFilterByName: function (name, refresh, path) {
this.features.runningTree.removeNamedFilterByName(this.state.oakFullpath, name, refresh); var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath;
this.features.runningTree.removeNamedFilterByName(path2, name, refresh);
}, },
setNamedSorters: function (namedSorters) { setNamedSorters: function (namedSorters, path) {
this.features.runningTree.setNamedSorters(this.state.oakFullpath, namedSorters); 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) { 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 var sorters = namedSorters
.map(function (_a) { .map(function (_a) {
var sorter = _a.sorter; var sorter = _a.sorter;
@ -317,9 +325,10 @@ var oakBehavior = Behavior({
return sorters; return sorters;
} }
}, },
getSorterByName: function (name) { getSorterByName: function (name, path) {
if (this.state.oakFullpath) { 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 (sorter === null || sorter === void 0 ? void 0 : sorter.sorter) {
if (typeof sorter.sorter === 'function') { if (typeof sorter.sorter === 'function') {
return sorter.sorter(); return sorter.sorter();
@ -328,40 +337,50 @@ var oakBehavior = Behavior({
} }
} }
}, },
addNamedSorter: function (namedSorter, refresh) { addNamedSorter: function (namedSorter, refresh, path) {
this.features.runningTree.addNamedSorter(this.state.oakFullpath, namedSorter, refresh); var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath;
this.features.runningTree.addNamedSorter(path2, namedSorter, refresh);
}, },
removeNamedSorter: function (namedSorter, refresh) { removeNamedSorter: function (namedSorter, refresh, path) {
this.features.runningTree.removeNamedSorter(this.state.oakFullpath, namedSorter, refresh); var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath;
this.features.runningTree.removeNamedSorter(path2, namedSorter, refresh);
}, },
removeNamedSorterByName: function (name, refresh) { removeNamedSorterByName: function (name, refresh, path) {
this.features.runningTree.removeNamedSorterByName(this.state.oakFullpath, name, refresh); 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) { 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) { setPageSize: function (pageSize, path) {
this.features.runningTree.setPageSize(this.state.oakFullpath, pageSize); 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); (0, assert_1.default)(currentPage !== 0);
if (this.state.oakEntity && this.state.oakFullpath) { 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) { addItem: function (data, beforeExecute, afterExecute, path) {
return this.features.runningTree.addItem(this.state.oakFullpath, data, beforeExecute, afterExecute); 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) { updateItem: function (data, id, action, beforeExecute, afterExecute, path) {
return this.features.runningTree.updateItem(this.state.oakFullpath, data, id, action, beforeExecute, afterExecute); 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) { removeItem: function (id, beforeExecute, afterExecute, path) {
return this.features.runningTree.removeItem(this.state.oakFullpath, id, beforeExecute, afterExecute); var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath;
return this.features.runningTree.removeItem(path2, id, beforeExecute, afterExecute);
}, },
recoverItem: function (id) { recoverItem: function (id, path) {
return this.features.runningTree.recoverItem(this.state.oakFullpath, id); var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath;
return this.features.runningTree.recoverItem(path2, id);
}, },
setId: function (id) { setId: function (id) {
return this.features.runningTree.setId(this.state.oakFullpath, id); return this.features.runningTree.setId(this.state.oakFullpath, id);
@ -369,11 +388,13 @@ var oakBehavior = Behavior({
unsetId: function () { unsetId: function () {
return this.features.runningTree.unsetId(this.state.oakFullpath); return this.features.runningTree.unsetId(this.state.oakFullpath);
}, },
update: function (data, action, beforeExecute, afterExecute) { update: function (data, action, beforeExecute, afterExecute, path) {
return this.features.runningTree.update(this.state.oakFullpath, data, action, beforeExecute, afterExecute); 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) { remove: function (beforeExecute, afterExecute, path) {
return this.features.runningTree.remove(this.state.oakFullpath, beforeExecute, afterExecute); var path2 = path ? "".concat(this.state.oakFullpath, ".").concat(path) : this.state.oakFullpath;
return this.features.runningTree.remove(path2, beforeExecute, afterExecute);
}, },
aggregate: function (aggregation) { aggregate: function (aggregation) {
return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__awaiter(this, void 0, void 0, function () {

View File

@ -127,26 +127,44 @@ var OakComponentBase = /** @class */ (function (_super) {
return this.props.navigate(url2, { replace: true }); 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); this.features.runningTree.addItem(this.state.oakFullpath, data, beforeExecute, afterExecute);
}; };
OakComponentBase.prototype.removeItem = function (id, beforeExecute, afterExecute) { OakComponentBase.prototype.removeItem = function (id, beforeExecute, afterExecute, path) {
this.features.runningTree.removeItem(this.state.oakFullpath, id, beforeExecute, afterExecute); 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) { OakComponentBase.prototype.updateItem = function (data, id, action, beforeExecute, afterExecute, path) {
this.features.runningTree.updateItem(this.state.oakFullpath, data, id, action, beforeExecute, afterExecute); 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) { OakComponentBase.prototype.recoverItem = function (id, path) {
this.features.runningTree.recoverItem(this.state.oakFullpath, id); var path2 = path
? "".concat(this.state.oakFullpath, ".").concat(path)
: this.state.oakFullpath;
this.features.runningTree.recoverItem(path2, id);
}; };
/* create<T extends keyof ED>(data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) { /* create<T extends keyof ED>(data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) {
this.features.runningTree.create(this.state.oakFullpath, data, beforeExecute, afterExecute); this.features.runningTree.create(this.state.oakFullpath, data, beforeExecute, afterExecute);
} */ } */
OakComponentBase.prototype.update = function (data, action, beforeExecute, afterExecute) { OakComponentBase.prototype.update = function (data, action, beforeExecute, afterExecute, path) {
this.features.runningTree.update(this.state.oakFullpath, data, action, beforeExecute, afterExecute); 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) { OakComponentBase.prototype.remove = function (beforeExecute, afterExecute, path) {
this.features.runningTree.remove(this.state.oakFullpath, beforeExecute, afterExecute); var path2 = path
? "".concat(this.state.oakFullpath, ".").concat(path)
: this.state.oakFullpath;
this.features.runningTree.remove(path2, beforeExecute, afterExecute);
}; };
OakComponentBase.prototype.clean = function (path) { OakComponentBase.prototype.clean = function (path) {
var path2 = path var path2 = path
@ -193,15 +211,24 @@ var OakComponentBase = /** @class */ (function (_super) {
OakComponentBase.prototype.unsetId = function () { OakComponentBase.prototype.unsetId = function () {
return this.features.runningTree.unsetId(this.state.oakFullpath); return this.features.runningTree.unsetId(this.state.oakFullpath);
}; };
OakComponentBase.prototype.getId = function () { OakComponentBase.prototype.getId = function (path) {
return this.features.runningTree.getId(this.state.oakFullpath); var path2 = path
? "".concat(this.state.oakFullpath, ".").concat(path)
: this.state.oakFullpath;
return this.features.runningTree.getId(path2);
}; };
OakComponentBase.prototype.setFilters = function (filters) { OakComponentBase.prototype.setFilters = function (filters, path) {
this.features.runningTree.setNamedFilters(this.state.oakFullpath, filters); 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) { 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 filters = namedFilters.map(function (_a) {
var filter = _a.filter; var filter = _a.filter;
if (typeof filter === 'function') { if (typeof filter === 'function') {
@ -212,9 +239,12 @@ var OakComponentBase = /** @class */ (function (_super) {
return filters; return filters;
} }
}; };
OakComponentBase.prototype.getFilterByName = function (name) { OakComponentBase.prototype.getFilterByName = function (name, path) {
if (this.state.oakFullpath) { 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 (filter === null || filter === void 0 ? void 0 : filter.filter) {
if (typeof filter.filter === 'function') { if (typeof filter.filter === 'function') {
return filter.filter(); return filter.filter();
@ -223,21 +253,36 @@ var OakComponentBase = /** @class */ (function (_super) {
} }
} }
}; };
OakComponentBase.prototype.addNamedFilter = function (namedFilter, refresh) { OakComponentBase.prototype.addNamedFilter = function (namedFilter, refresh, path) {
this.features.runningTree.addNamedFilter(this.state.oakFullpath, namedFilter, refresh); 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) { OakComponentBase.prototype.removeNamedFilter = function (namedFilter, refresh, path) {
this.features.runningTree.removeNamedFilter(this.state.oakFullpath, namedFilter, refresh); 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) { OakComponentBase.prototype.removeNamedFilterByName = function (name, refresh, path) {
this.features.runningTree.removeNamedFilterByName(this.state.oakFullpath, name, refresh); var path2 = path
? "".concat(this.state.oakFullpath, ".").concat(path)
: this.state.oakFullpath;
this.features.runningTree.removeNamedFilterByName(path2, name, refresh);
}; };
OakComponentBase.prototype.setNamedSorters = function (namedSorters) { OakComponentBase.prototype.setNamedSorters = function (namedSorters, path) {
this.features.runningTree.setNamedSorters(this.state.oakFullpath, namedSorters); 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) { 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 var sorters = namedSorters
.map(function (_a) { .map(function (_a) {
var sorter = _a.sorter; var sorter = _a.sorter;
@ -250,9 +295,12 @@ var OakComponentBase = /** @class */ (function (_super) {
return sorters; return sorters;
} }
}; };
OakComponentBase.prototype.getSorterByName = function (name) { OakComponentBase.prototype.getSorterByName = function (name, path) {
if (this.state.oakFullpath) { 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 (sorter === null || sorter === void 0 ? void 0 : sorter.sorter) {
if (typeof sorter.sorter === 'function') { if (typeof sorter.sorter === 'function') {
return sorter.sorter(); return sorter.sorter();
@ -261,27 +309,47 @@ var OakComponentBase = /** @class */ (function (_super) {
} }
} }
}; };
OakComponentBase.prototype.addNamedSorter = function (namedSorter, refresh) { OakComponentBase.prototype.addNamedSorter = function (namedSorter, refresh, path) {
this.features.runningTree.addNamedSorter(this.state.oakFullpath, namedSorter, refresh); 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) { OakComponentBase.prototype.removeNamedSorter = function (namedSorter, refresh, path) {
this.features.runningTree.removeNamedSorter(this.state.oakFullpath, namedSorter, refresh); 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) { OakComponentBase.prototype.removeNamedSorterByName = function (name, refresh, path) {
this.features.runningTree.removeNamedSorterByName(this.state.oakFullpath, name, refresh); 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) { 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) { OakComponentBase.prototype.setPageSize = function (pageSize, path) {
this.features.runningTree.setPageSize(this.state.oakFullpath, pageSize); 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); (0, assert_1.default)(currentPage !== 0);
if (this.state.oakEntity && this.state.oakFullpath) { 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; return OakComponentBase;
@ -385,65 +453,61 @@ function createComponent(option, features) {
return _this.clean(path); return _this.clean(path);
}, },
}; };
if (option.isList) {
Object.assign(methodProps, { Object.assign(methodProps, {
addItem: function (data, beforeExecute, afterExecute) { addItem: function (data, beforeExecute, afterExecute, path) {
return _this.addItem(data, beforeExecute, afterExecute); return _this.addItem(data, beforeExecute, afterExecute, path);
}, },
removeItem: function (id, beforeExecute, afterExecute) { removeItem: function (id, beforeExecute, afterExecute, path) {
return _this.removeItem(id, beforeExecute, afterExecute); return _this.removeItem(id, beforeExecute, afterExecute, path);
}, },
updateItem: function (data, id, action, beforeExecute, afterExecute) { updateItem: function (data, id, action, beforeExecute, afterExecute, path) {
return _this.updateItem(data, id, action, beforeExecute, afterExecute); return _this.updateItem(data, id, action, beforeExecute, afterExecute, path);
}, },
setFilters: function (filters) { setFilters: function (filters, path) {
return _this.setFilters(filters); return _this.setFilters(filters, path);
}, },
addNamedFilter: function (filter, refresh) { addNamedFilter: function (filter, refresh, path) {
return _this.addNamedFilter(filter, refresh); return _this.addNamedFilter(filter, refresh, path);
}, },
removeNamedFilter: function (filter, refresh) { removeNamedFilter: function (filter, refresh, path) {
return _this.removeNamedFilter(filter, refresh); return _this.removeNamedFilter(filter, refresh, path);
}, },
removeNamedFilterByName: function (name, refresh) { removeNamedFilterByName: function (name, refresh, path) {
return _this.removeNamedFilterByName(name, refresh); return _this.removeNamedFilterByName(name, refresh, path);
}, },
setNamedSorters: function (sorters) { setNamedSorters: function (sorters, path) {
return _this.setNamedSorters(sorters); return _this.setNamedSorters(sorters, path);
}, },
addNamedSorter: function (sorter, refresh) { addNamedSorter: function (sorter, refresh, path) {
return _this.addNamedSorter(sorter, refresh); return _this.addNamedSorter(sorter, refresh, path);
}, },
removeNamedSorter: function (sorter, refresh) { removeNamedSorter: function (sorter, refresh, path) {
return _this.removeNamedSorter(sorter, refresh); return _this.removeNamedSorter(sorter, refresh, path);
}, },
removeNamedSorterByName: function (name, refresh) { removeNamedSorterByName: function (name, refresh, path) {
return _this.removeNamedSorterByName(name, refresh); return _this.removeNamedSorterByName(name, refresh, path);
}, },
setPageSize: function (pageSize) { setPageSize: function (pageSize, path) {
return _this.setPageSize(pageSize); return _this.setPageSize(pageSize, path);
}, },
setCurrentPage: function (current) { setCurrentPage: function (current, path) {
return _this.setCurrentPage(current); return _this.setCurrentPage(current, path);
}, },
loadMore: function () { loadMore: function () {
return _this.loadMore(); return _this.loadMore();
} }
}); });
}
else {
Object.assign(methodProps, { Object.assign(methodProps, {
/* create: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => { /* create: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
return this.create(data, beforeExecute, afterExecute); return this.create(data, beforeExecute, afterExecute);
}, */ }, */
update: function (data, action, beforeExecute, afterExecute) { update: function (data, action, beforeExecute, afterExecute, path) {
return _this.update(data, action, beforeExecute, afterExecute); return _this.update(data, action, beforeExecute, afterExecute, path);
}, },
remove: function (beforeExecute, afterExecute) { remove: function (beforeExecute, afterExecute, path) {
return _this.remove(beforeExecute, afterExecute); return _this.remove(beforeExecute, afterExecute, path);
}, },
}); });
}
if (methods) { if (methods) {
var _loop_1 = function (m) { var _loop_1 = function (m) {
var _a, _b; var _a, _b;

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

@ -60,7 +60,7 @@ export declare type ComponentPublicThisType<ED extends EntityDict & BaseEntityDi
props: ComponentProps<IsList, TProperty>; props: ComponentProps<IsList, TProperty>;
setState: (data: Partial<ComponentData<ED, T, FormedData, TData>>, callback?: () => void) => void; setState: (data: Partial<ComponentData<ED, T, FormedData, TData>>, callback?: () => void) => void;
triggerEvent: <DetailType = any>(name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void; triggerEvent: <DetailType = any>(name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void;
} & TMethod & OakCommonComponentMethods<ED, T> & (IsList extends true ? OakListComponentMethods<ED, T> : OakSingleComponentMethods<ED, T>); } & TMethod & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
export declare type ComponentFullThisType<ED extends EntityDict & BaseEntityDict, T extends keyof ED, IsList extends boolean, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>> = { export declare type ComponentFullThisType<ED extends EntityDict & BaseEntityDict, T extends keyof ED, IsList extends boolean, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>> = {
subscribed: Array<() => void>; subscribed: Array<() => void>;
features: BasicFeatures<ED, Cxt, FrontCxt, CommonAspectDict<ED, Cxt>>; features: BasicFeatures<ED, Cxt, FrontCxt, CommonAspectDict<ED, Cxt>>;
@ -68,7 +68,7 @@ export declare type ComponentFullThisType<ED extends EntityDict & BaseEntityDict
props: ComponentProps<true, {}>; props: ComponentProps<true, {}>;
setState: (data: Partial<OakComponentData<ED, T>>, callback?: () => void) => void; setState: (data: Partial<OakComponentData<ED, T>>, callback?: () => void) => void;
triggerEvent: <DetailType = any>(name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void; triggerEvent: <DetailType = any>(name: string, detail?: DetailType, options?: WechatMiniprogram.Component.TriggerEventOption) => void;
} & OakCommonComponentMethods<ED, T> & (IsList extends true ? OakListComponentMethods<ED, T> : OakSingleComponentMethods<ED, T>); } & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
export declare type OakComponentOption<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, IsList extends boolean, TData extends Record<string, any>, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends Record<string, Function>> = ComponentOption<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TProperty> & Partial<{ export declare type OakComponentOption<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature>, FormedData extends Record<string, any>, IsList extends boolean, TData extends Record<string, any>, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends Record<string, Function>> = ComponentOption<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TProperty> & Partial<{
data?: ((option: { data?: ((option: {
features: BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>> & FD; features: BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>> & FD;
@ -108,6 +108,7 @@ export declare type OakListComponentProperties = {
oakFilters: ObjectConstructor; oakFilters: ObjectConstructor;
oakSorters: ObjectConstructor; oakSorters: ObjectConstructor;
oakIsPicker: BooleanConstructor; oakIsPicker: BooleanConstructor;
oakPagination: ObjectConstructor;
}; };
export declare type OakNavigateToParameters<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = { export declare type OakNavigateToParameters<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
oakId?: string; oakId?: string;
@ -162,30 +163,30 @@ export declare type OakSingleComponentMethods<ED extends EntityDict & BaseEntity
setId: (id: string) => void; setId: (id: string) => void;
unsetId: () => void; unsetId: () => void;
getId: () => string | undefined; getId: () => string | undefined;
update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
remove: (beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; remove: (beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
}; };
export declare type OakListComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = { export declare type OakListComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
loadMore: () => Promise<void>; loadMore: () => Promise<void>;
setFilters: (filters: NamedFilterItem<ED, T>[]) => void; setFilters: (filters: NamedFilterItem<ED, T>[], path?: string) => void;
getFilters: () => ED[T]['Selection']['filter'][] | undefined; getFilters: (path?: string) => ED[T]['Selection']['filter'][] | undefined;
getFilterByName: (name: string) => ED[T]['Selection']['filter'] | undefined; getFilterByName: (name: string, path?: string) => ED[T]['Selection']['filter'] | undefined;
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => void; addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => void; removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedFilterByName: (name: string, refresh?: boolean) => void; removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => void;
setNamedSorters: (sorters: NamedSorterItem<ED, T>[]) => void; setNamedSorters: (sorters: NamedSorterItem<ED, T>[], path?: string) => void;
getSorters: () => ED[T]['Selection']['sorter'] | undefined; getSorters: (path?: string) => ED[T]['Selection']['sorter'] | undefined;
getSorterByName: (name: string) => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined; getSorterByName: (name: string, path?: string) => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined;
addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void; addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void; removeNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedSorterByName: (name: string, refresh?: boolean) => void; removeNamedSorterByName: (name: string, refresh?: boolean, path?: string) => void;
getPagination: () => Pagination | undefined; getPagination: (path?: string) => Pagination | undefined;
setPageSize: (pageSize: number) => void; setPageSize: (pageSize: number, path?: string) => void;
setCurrentPage: (current: number) => void; setCurrentPage: (current: number, path?: string) => void;
addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
removeItem: (id: string, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; removeItem: (id: string, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
recoverItem: (id: string) => void; recoverItem: (id: string, path?: string) => void;
}; };
declare type ComponentOnPropsChangeOption = { declare type ComponentOnPropsChangeOption = {
path?: string; path?: string;
@ -212,12 +213,17 @@ export declare type OakComponentData<ED extends EntityDict & BaseEntityDict, T e
oakLegalActions?: ED[T]['Action'][]; oakLegalActions?: ED[T]['Action'][];
oakDisablePulldownRefresh: boolean; oakDisablePulldownRefresh: boolean;
}; };
export declare type OakListComoponetData<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
oakFilters?: NonNullable<ED[T]['Selection']['filter']>[];
oakSorters?: NonNullable<ED[T]['Selection']['sorter']>[];
oakPagination?: Pagination;
};
export declare type MakeOakComponent<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature>> = <T extends keyof ED, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption>(options: OakComponentOption<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod>) => React.ComponentType<any>; export declare type MakeOakComponent<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature>> = <T extends keyof ED, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption>(options: OakComponentOption<ED, T, Cxt, FrontCxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod>) => React.ComponentType<any>;
export declare type WebComponentCommonMethodNames = 'setNotification' | 'setMessage' | 'navigateTo' | 'navigateBack' | 'redirectTo' | 'clean' | 't' | 'execute' | 'refresh' | 'setDisablePulldownRefresh' | 'aggregate'; 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 WebComponentListMethodNames = 'loadMore' | 'setFilters' | 'addNamedFilter' | 'removeNamedFilter' | 'removeNamedFilterByName' | 'setNamedSorters' | 'addNamedSorter' | 'removeNamedSorter' | 'removeNamedSorterByName' | 'setPageSize' | 'setCurrentPage' | 'addItem' | 'removeItem' | 'updateItem';
export declare type WebComponentSingleMethodNames = 'update' | 'remove'; export declare type WebComponentSingleMethodNames = 'update' | 'remove';
export declare type WebComponentProps<ED extends EntityDict & BaseEntityDict, T extends keyof ED, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}> = { export declare type WebComponentProps<ED extends EntityDict & BaseEntityDict, T extends keyof ED, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}> = {
methods: TMethod & Pick<OakCommonComponentMethods<ED, T>, WebComponentCommonMethodNames> & (IsList extends true ? Pick<OakListComponentMethods<ED, T>, WebComponentListMethodNames> : Pick<OakSingleComponentMethods<ED, T>, WebComponentSingleMethodNames>); methods: TMethod & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
data: TData & OakComponentData<ED, T> & (IsList extends true ? OakListComponentProperties : {}); data: TData & OakComponentData<ED, T> & (IsList extends true ? OakListComoponetData<ED, T> : {});
}; };
export {}; export {};

View File

@ -197,6 +197,18 @@ export function reRender<
Object.assign(data, { Object.assign(data, {
oakLegalActions, oakLegalActions,
}); });
if (option.isList) {
const oakFilters = (this as ComponentFullThisType<ED, T, true, Cxt, FrontCxt>).getFilters();
const oakSorters = (this as ComponentFullThisType<ED, T, true, Cxt, FrontCxt>).getSorters();
const oakPagination = (this as ComponentFullThisType<ED, T, true, Cxt, FrontCxt>).getPagination();
Object.assign(data, {
oakFilters,
oakSorters,
oakPagination,
});
}
for (const k in data) { for (const k in data) {
if (data[k] === undefined) { if (data[k] === undefined) {
Object.assign(data, { Object.assign(data, {

View File

@ -360,15 +360,17 @@ const oakBehavior = Behavior<
return this.features.runningTree.getId(this.state.oakFullpath); 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.features.runningTree.setNamedFilters(
this.state.oakFullpath, path2,
filters filters
); );
}, },
getFilters() { getFilters(path) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
const namedFilters = this.features.runningTree.getNamedFilters( const namedFilters = this.features.runningTree.getNamedFilters(
this.state.oakFullpath this.state.oakFullpath
); );
@ -381,10 +383,11 @@ const oakBehavior = Behavior<
} }
}, },
getFilterByName(name: string) { getFilterByName(name, path) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
const filter = this.features.runningTree.getNamedFilterByName( const filter = this.features.runningTree.getNamedFilterByName(
this.state.oakFullpath, path2,
name name
); );
if (filter?.filter) { 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.features.runningTree.addNamedFilter(
this.state.oakFullpath, path2,
namedFilter, namedFilter,
refresh refresh
); );
}, },
removeNamedFilter(namedFilter, refresh) { removeNamedFilter(namedFilter, refresh, path) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
this.features.runningTree.removeNamedFilter( this.features.runningTree.removeNamedFilter(
this.state.oakFullpath, path2,
namedFilter, namedFilter,
refresh refresh
); );
}, },
removeNamedFilterByName(name, refresh) { removeNamedFilterByName(name, refresh, path) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
this.features.runningTree.removeNamedFilterByName( this.features.runningTree.removeNamedFilterByName(
this.state.oakFullpath, path2,
name, name,
refresh refresh
); );
}, },
setNamedSorters(namedSorters) { setNamedSorters(namedSorters, path) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
this.features.runningTree.setNamedSorters( this.features.runningTree.setNamedSorters(
this.state.oakFullpath, path2,
namedSorters namedSorters
); );
}, },
getSorters() { getSorters(path) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
const namedSorters = this.features.runningTree.getNamedSorters( const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
this.state.oakFullpath const namedSorters = this.features.runningTree.getNamedSorters(path2);
);
const sorters = namedSorters const sorters = namedSorters
.map(({ sorter }) => { .map(({ sorter }) => {
if (typeof sorter === 'function') { if (typeof sorter === 'function') {
@ -444,10 +450,11 @@ const oakBehavior = Behavior<
} }
}, },
getSorterByName(name) { getSorterByName(name, path) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
const sorter = this.features.runningTree.getNamedSorterByName( const sorter = this.features.runningTree.getNamedSorterByName(
this.state.oakFullpath, path2,
name name
); );
if (sorter?.sorter) { if (sorter?.sorter) {
@ -459,66 +466,64 @@ const oakBehavior = Behavior<
} }
}, },
addNamedSorter(namedSorter, refresh) { addNamedSorter(namedSorter, refresh, path) {
this.features.runningTree.addNamedSorter( const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
this.state.oakFullpath, this.features.runningTree.addNamedSorter(path2, namedSorter, refresh);
namedSorter,
refresh
);
}, },
removeNamedSorter(namedSorter, refresh) { removeNamedSorter(namedSorter, refresh, path) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
this.features.runningTree.removeNamedSorter( this.features.runningTree.removeNamedSorter(
this.state.oakFullpath, path2,
namedSorter, namedSorter,
refresh refresh
); );
}, },
removeNamedSorterByName(name, refresh) { removeNamedSorterByName(name, refresh, path) {
this.features.runningTree.removeNamedSorterByName( const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
this.state.oakFullpath, this.features.runningTree.removeNamedSorterByName(path2, name, refresh);
name,
refresh
);
}, },
getPagination() { getPagination(path) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
return this.features.runningTree.getPagination( const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
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.features.runningTree.setPageSize(
this.state.oakFullpath, path2,
pageSize pageSize
); );
}, },
setCurrentPage(currentPage) { setCurrentPage(currentPage, path) {
assert(currentPage !== 0); assert(currentPage !== 0);
if (this.state.oakEntity && this.state.oakFullpath) { if (this.state.oakEntity && this.state.oakFullpath) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
this.features.runningTree.setCurrentPage( this.features.runningTree.setCurrentPage(
this.state.oakFullpath, path2,
currentPage 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( return this.features.runningTree.addItem(
this.state.oakFullpath, path2,
data, data,
beforeExecute, beforeExecute,
afterExecute 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( return this.features.runningTree.updateItem(
this.state.oakFullpath, path2,
data, data,
id, id,
action, action,
@ -526,17 +531,19 @@ const oakBehavior = Behavior<
afterExecute 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( return this.features.runningTree.removeItem(
this.state.oakFullpath, path2,
id, id,
beforeExecute, beforeExecute,
afterExecute afterExecute
); );
}, },
recoverItem(id) { recoverItem(id, path) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
return this.features.runningTree.recoverItem( return this.features.runningTree.recoverItem(
this.state.oakFullpath, path2,
id id
); );
}, },
@ -546,18 +553,20 @@ const oakBehavior = Behavior<
unsetId() { unsetId() {
return this.features.runningTree.unsetId(this.state.oakFullpath); 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( return this.features.runningTree.update(
this.state.oakFullpath, path2,
data, data,
action, action,
beforeExecute, beforeExecute,
afterExecute afterExecute
); );
}, },
remove(beforeExecute, afterExecute) { remove(beforeExecute, afterExecute, path) {
const path2 = path? `${this.state.oakFullpath}.${path}` : this.state.oakFullpath;
return this.features.runningTree.remove( return this.features.runningTree.remove(
this.state.oakFullpath, path2,
beforeExecute, beforeExecute,
afterExecute afterExecute
); );

View File

@ -216,8 +216,12 @@ abstract class OakComponentBase<
addItem<T extends keyof ED>( addItem<T extends keyof ED>(
data: Omit<ED[T]['CreateSingle']['data'], 'id'>, data: Omit<ED[T]['CreateSingle']['data'], 'id'>,
beforeExecute?: () => Promise<void>, beforeExecute?: () => Promise<void>,
afterExecute?: () => Promise<void> afterExecute?: () => Promise<void>,
path?: string
) { ) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.addItem( this.features.runningTree.addItem(
this.state.oakFullpath, this.state.oakFullpath,
data, data,
@ -229,10 +233,14 @@ abstract class OakComponentBase<
removeItem( removeItem(
id: string, id: string,
beforeExecute?: () => Promise<void>, beforeExecute?: () => Promise<void>,
afterExecute?: () => Promise<void> afterExecute?: () => Promise<void>,
path?: string
) { ) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.removeItem( this.features.runningTree.removeItem(
this.state.oakFullpath, path2,
id, id,
beforeExecute, beforeExecute,
afterExecute afterExecute
@ -244,10 +252,14 @@ abstract class OakComponentBase<
id: string, id: string,
action?: ED[T]['Action'], action?: ED[T]['Action'],
beforeExecute?: () => Promise<void>, beforeExecute?: () => Promise<void>,
afterExecute?: () => Promise<void> afterExecute?: () => Promise<void>,
path?: string
) { ) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.updateItem( this.features.runningTree.updateItem(
this.state.oakFullpath, path2,
data, data,
id, id,
action, action,
@ -256,8 +268,11 @@ abstract class OakComponentBase<
); );
} }
recoverItem(id: string) { recoverItem(id: string, path?: string) {
this.features.runningTree.recoverItem(this.state.oakFullpath, id); const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.recoverItem(path2, id);
} }
/* create<T extends keyof ED>(data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) { /* create<T extends keyof ED>(data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) {
@ -268,10 +283,14 @@ abstract class OakComponentBase<
data: ED[T]['Update']['data'], data: ED[T]['Update']['data'],
action?: ED[T]['Action'], action?: ED[T]['Action'],
beforeExecute?: () => Promise<void>, beforeExecute?: () => Promise<void>,
afterExecute?: () => Promise<void> afterExecute?: () => Promise<void>,
path?: string
) { ) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.update( this.features.runningTree.update(
this.state.oakFullpath, path2,
data, data,
action, action,
beforeExecute, beforeExecute,
@ -281,10 +300,14 @@ abstract class OakComponentBase<
remove( remove(
beforeExecute?: () => Promise<void>, beforeExecute?: () => Promise<void>,
afterExecute?: () => Promise<void> afterExecute?: () => Promise<void>,
path?: string
) { ) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.remove( this.features.runningTree.remove(
this.state.oakFullpath, path2,
beforeExecute, beforeExecute,
afterExecute afterExecute
); );
@ -356,22 +379,29 @@ abstract class OakComponentBase<
return this.features.runningTree.unsetId(this.state.oakFullpath); return this.features.runningTree.unsetId(this.state.oakFullpath);
} }
getId() { getId(path?: string) {
return this.features.runningTree.getId(this.state.oakFullpath); const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
return this.features.runningTree.getId(path2);
} }
setFilters(filters: NamedFilterItem<ED, T>[]) { setFilters(filters: NamedFilterItem<ED, T>[], path?: string) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.setNamedFilters( this.features.runningTree.setNamedFilters(
this.state.oakFullpath, path2,
filters filters
); );
} }
getFilters() { getFilters(path?: string) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
const namedFilters = this.features.runningTree.getNamedFilters( const path2 = path
this.state.oakFullpath ? `${this.state.oakFullpath}.${path}`
); : this.state.oakFullpath;
const namedFilters = this.features.runningTree.getNamedFilters(path2);
const filters = namedFilters.map(({ filter }) => { const filters = namedFilters.map(({ filter }) => {
if (typeof filter === 'function') { if (typeof filter === 'function') {
return (filter as Function)(); return (filter as Function)();
@ -382,12 +412,12 @@ abstract class OakComponentBase<
} }
} }
getFilterByName(name: string) { getFilterByName(name: string, path?: string) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
const filter = this.features.runningTree.getNamedFilterByName( const path2 = path
this.state.oakFullpath, ? `${this.state.oakFullpath}.${path}`
name : this.state.oakFullpath;
); const filter = this.features.runningTree.getNamedFilterByName(path2, name);
if (filter?.filter) { if (filter?.filter) {
if (typeof filter.filter === 'function') { if (typeof filter.filter === 'function') {
return (filter.filter as Function)(); return (filter.filter as Function)();
@ -397,42 +427,55 @@ abstract class OakComponentBase<
} }
} }
addNamedFilter(namedFilter: NamedFilterItem<ED, T>, refresh?: boolean) { addNamedFilter(namedFilter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.addNamedFilter( this.features.runningTree.addNamedFilter(
this.state.oakFullpath, path2,
namedFilter, namedFilter,
refresh refresh
); );
} }
removeNamedFilter(namedFilter: NamedFilterItem<ED, T>, refresh?: boolean) { removeNamedFilter(namedFilter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.removeNamedFilter( this.features.runningTree.removeNamedFilter(
this.state.oakFullpath, path2,
namedFilter, namedFilter,
refresh 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.features.runningTree.removeNamedFilterByName(
this.state.oakFullpath, path2,
name, name,
refresh refresh
); );
} }
setNamedSorters(namedSorters: NamedSorterItem<ED, T>[]) { setNamedSorters(namedSorters: NamedSorterItem<ED, T>[], path?: string) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.setNamedSorters( this.features.runningTree.setNamedSorters(
this.state.oakFullpath, path2,
namedSorters namedSorters
); );
} }
getSorters() { getSorters(path?: string) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
const namedSorters = this.features.runningTree.getNamedSorters( const path2 = path
this.state.oakFullpath ? `${this.state.oakFullpath}.${path}`
); : this.state.oakFullpath;
const namedSorters = this.features.runningTree.getNamedSorters(path2);
const sorters = namedSorters const sorters = namedSorters
.map(({ sorter }) => { .map(({ sorter }) => {
if (typeof sorter === 'function') { if (typeof sorter === 'function') {
@ -445,12 +488,12 @@ abstract class OakComponentBase<
} }
} }
getSorterByName(name: string) { getSorterByName(name: string, path?: string) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
const sorter = this.features.runningTree.getNamedSorterByName( const path2 = path
this.state.oakFullpath, ? `${this.state.oakFullpath}.${path}`
name : this.state.oakFullpath;
); const sorter = this.features.runningTree.getNamedSorterByName(path2, name);
if (sorter?.sorter) { if (sorter?.sorter) {
if (typeof sorter.sorter === 'function') { if (typeof sorter.sorter === 'function') {
return (sorter.sorter as Function)(); return (sorter.sorter as Function)();
@ -460,48 +503,66 @@ abstract class OakComponentBase<
} }
} }
addNamedSorter(namedSorter: NamedSorterItem<ED, T>, refresh?: boolean) { addNamedSorter(namedSorter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.addNamedSorter( this.features.runningTree.addNamedSorter(
this.state.oakFullpath, path2,
namedSorter, namedSorter,
refresh refresh
); );
} }
removeNamedSorter(namedSorter: NamedSorterItem<ED, T>, refresh?: boolean) { removeNamedSorter(namedSorter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.removeNamedSorter( this.features.runningTree.removeNamedSorter(
this.state.oakFullpath, path2,
namedSorter, namedSorter,
refresh 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.features.runningTree.removeNamedSorterByName(
this.state.oakFullpath, path2,
name, name,
refresh refresh
); );
} }
getPagination() { getPagination(path?: string) {
if (this.state.oakFullpath) { if (this.state.oakFullpath) {
return this.features.runningTree.getPagination( const path2 = path
this.state.oakFullpath ? `${this.state.oakFullpath}.${path}`
); : this.state.oakFullpath;
return this.features.runningTree.getPagination(path2);
} }
} }
setPageSize(pageSize: number) { setPageSize(pageSize: number, path?: string) {
this.features.runningTree.setPageSize(this.state.oakFullpath, pageSize); 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); assert(currentPage !== 0);
if (this.state.oakEntity && this.state.oakFullpath) { if (this.state.oakEntity && this.state.oakFullpath) {
const path2 = path
? `${this.state.oakFullpath}.${path}`
: this.state.oakFullpath;
this.features.runningTree.setCurrentPage( this.features.runningTree.setCurrentPage(
this.state.oakFullpath, path2,
currentPage currentPage
); );
} }
@ -660,71 +721,62 @@ export function createComponent<
return this.clean(path); return this.clean(path);
}, },
}; };
if (option.isList) {
Object.assign(methodProps, { Object.assign(methodProps, {
addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => { addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => {
return this.addItem(data, beforeExecute, afterExecute); return this.addItem(data, beforeExecute, afterExecute, path);
}, },
removeItem: (id: string, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => { removeItem: (id: string, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => {
return this.removeItem(id, beforeExecute, afterExecute); return this.removeItem(id, beforeExecute, afterExecute, path);
}, },
updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => { updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => {
return this.updateItem(data, id, action, beforeExecute, afterExecute); return this.updateItem(data, id, action, beforeExecute, afterExecute, path);
}, },
setFilters: (filters: NamedFilterItem<ED, T>[]) => { setFilters: (filters: NamedFilterItem<ED, T>[], path?: string) => {
return this.setFilters(filters); return this.setFilters(filters, path);
}, },
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => { addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => {
return this.addNamedFilter(filter, refresh); return this.addNamedFilter(filter, refresh, path);
}, },
removeNamedFilter: ( removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => {
filter: NamedFilterItem<ED, T>, return this.removeNamedFilter(filter, refresh, path);
refresh?: boolean
) => {
return this.removeNamedFilter(filter, refresh);
}, },
removeNamedFilterByName: (name: string, refresh?: boolean) => { removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => {
return this.removeNamedFilterByName(name, refresh); return this.removeNamedFilterByName(name, refresh, path);
}, },
setNamedSorters: (sorters: NamedSorterItem<ED, T>[]) => { setNamedSorters: (sorters: NamedSorterItem<ED, T>[], path?: string) => {
return this.setNamedSorters(sorters); return this.setNamedSorters(sorters, path);
}, },
addNamedSorter: (sorter: NamedSorterItem<ED, T>, refresh?: boolean) => { addNamedSorter: (sorter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => {
return this.addNamedSorter(sorter, refresh); return this.addNamedSorter(sorter, refresh, path);
}, },
removeNamedSorter: ( removeNamedSorter: (sorter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => {
sorter: NamedSorterItem<ED, T>, return this.removeNamedSorter(sorter, refresh, path);
refresh?: boolean
) => {
return this.removeNamedSorter(sorter, refresh);
}, },
removeNamedSorterByName: (name: string, refresh?: boolean) => { removeNamedSorterByName: (name: string, refresh?: boolean, path?: string) => {
return this.removeNamedSorterByName(name, refresh); return this.removeNamedSorterByName(name, refresh, path);
}, },
setPageSize: (pageSize: number) => { setPageSize: (pageSize: number, path?: string) => {
return this.setPageSize(pageSize); return this.setPageSize(pageSize, path);
}, },
setCurrentPage: (current: number) => { setCurrentPage: (current: number, path?: string) => {
return this.setCurrentPage(current); return this.setCurrentPage(current, path);
}, },
loadMore: () => { loadMore: () => {
return this.loadMore(); return this.loadMore();
} }
} as Record<WebComponentListMethodNames, Function>); } as Record<WebComponentListMethodNames, Function>);
}
else {
Object.assign(methodProps, { Object.assign(methodProps, {
/* create: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => { /* create: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
return this.create(data, beforeExecute, afterExecute); return this.create(data, beforeExecute, afterExecute);
}, */ }, */
update: (data: ED[T]['Update']['data'], action: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => { update: (data: ED[T]['Update']['data'], action: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => {
return this.update(data, action, beforeExecute, afterExecute); return this.update(data, action, beforeExecute, afterExecute, path);
}, },
remove: (beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => { remove: (beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => {
return this.remove(beforeExecute, afterExecute); return this.remove(beforeExecute, afterExecute, path);
}, },
} as Record<WebComponentSingleMethodNames, Function>); } as Record<WebComponentSingleMethodNames, Function>);
}
if (methods) { if (methods) {
for (const m in methods) { for (const m in methods) {

View File

@ -113,7 +113,7 @@ export type ComponentPublicThisType<
detail?: DetailType, detail?: DetailType,
options?: WechatMiniprogram.Component.TriggerEventOption options?: WechatMiniprogram.Component.TriggerEventOption
) => void; ) => void;
} & TMethod & OakCommonComponentMethods<ED, T> & (IsList extends true ? OakListComponentMethods<ED, T> : OakSingleComponentMethods<ED, T>); } & TMethod & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
export type ComponentFullThisType< export type ComponentFullThisType<
ED extends EntityDict & BaseEntityDict, ED extends EntityDict & BaseEntityDict,
@ -135,7 +135,7 @@ export type ComponentFullThisType<
detail?: DetailType, detail?: DetailType,
options?: WechatMiniprogram.Component.TriggerEventOption options?: WechatMiniprogram.Component.TriggerEventOption
) => void; ) => void;
} & OakCommonComponentMethods<ED, T> & (IsList extends true ? OakListComponentMethods<ED, T> : OakSingleComponentMethods<ED, T>); } & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
export type OakComponentOption< export type OakComponentOption<
ED extends EntityDict & BaseEntityDict, ED extends EntityDict & BaseEntityDict,
@ -193,6 +193,7 @@ export type OakListComponentProperties = {
oakFilters: ObjectConstructor; oakFilters: ObjectConstructor;
oakSorters: ObjectConstructor; oakSorters: ObjectConstructor;
oakIsPicker: BooleanConstructor; oakIsPicker: BooleanConstructor;
oakPagination: ObjectConstructor;
} }
export type OakNavigateToParameters<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = { export type OakNavigateToParameters<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
@ -230,9 +231,7 @@ export type OakCommonComponentMethods<
setMessage: (data: MessageProps) => void; setMessage: (data: MessageProps) => void;
consumeMessage: () => MessageProps | undefined; consumeMessage: () => MessageProps | undefined;
reRender: (extra?: Record<string, any>) => void; reRender: (extra?: Record<string, any>) => void;
getFreshValue: ( getFreshValue: (path?: string) =>
path?: string
) =>
| Partial<ED[keyof ED]['Schema']>[] | Partial<ED[keyof ED]['Schema']>[]
| Partial<ED[keyof ED]['Schema']> | Partial<ED[keyof ED]['Schema']>
| undefined; | undefined;
@ -272,42 +271,32 @@ export type OakSingleComponentMethods<ED extends EntityDict & BaseEntityDict, T
unsetId: () => void; unsetId: () => void;
getId: () => string | undefined; getId: () => string | undefined;
// create: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; // create: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void;
update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
remove: (beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; remove: (beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
} }
export type OakListComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = { export type OakListComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
loadMore: () => Promise<void>; loadMore: () => Promise<void>;
setFilters: (filters: NamedFilterItem<ED, T>[]) => void; setFilters: (filters: NamedFilterItem<ED, T>[], path?: string) => void;
getFilters: () => ED[T]['Selection']['filter'][] | undefined; getFilters: (path?: string) => ED[T]['Selection']['filter'][] | undefined;
getFilterByName: ( getFilterByName: (name: string, path?: string) => ED[T]['Selection']['filter'] | undefined;
name: string addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => void;
) => ED[T]['Selection']['filter'] | undefined; removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => void;
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => void; removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => void;
removeNamedFilter: ( setNamedSorters: (sorters: NamedSorterItem<ED, T>[], path?: string) => void;
filter: NamedFilterItem<ED, T>, getSorters: (path?: string) => ED[T]['Selection']['sorter'] | undefined;
refresh?: boolean getSorterByName: (name: string, path?: string) => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined;
) => void; addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedFilterByName: (name: string, refresh?: boolean) => void; removeNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => void;
setNamedSorters: (sorters: NamedSorterItem<ED, T>[]) => void; removeNamedSorterByName: (name: string, refresh?: boolean, path?: string) => void;
getSorters: () => ED[T]['Selection']['sorter'] | undefined; getPagination: (path?: string) => Pagination | undefined;
getSorterByName: ( setPageSize: (pageSize: number, path?: string) => void;
name: string setCurrentPage: (current: number, path?: string) => void;
) => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined;
addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean) => void;
removeNamedSorter: (
filter: NamedSorterItem<ED, T>,
refresh?: boolean
) => void;
removeNamedSorterByName: (name: string, refresh?: boolean) => void;
getPagination: () => Pagination | undefined;
setPageSize: (pageSize: number) => void;
setCurrentPage: (current: number) => void;
addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
removeItem: (id: string, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; removeItem: (id: string, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void; updateItem: (data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => void;
recoverItem: (id: string) => void; recoverItem: (id: string, path?: string) => void;
}; };
type ComponentOnPropsChangeOption = { type ComponentOnPropsChangeOption = {
@ -341,6 +330,15 @@ export type OakComponentData<
oakDisablePulldownRefresh: boolean; oakDisablePulldownRefresh: boolean;
}; };
export type OakListComoponetData<
ED extends EntityDict & BaseEntityDict,
T extends keyof ED
> = {
oakFilters?: NonNullable<ED[T]['Selection']['filter']>[];
oakSorters?: NonNullable<ED[T]['Selection']['sorter']>[];
oakPagination?: Pagination;
}
export type MakeOakComponent< export type MakeOakComponent<
ED extends EntityDict & BaseEntityDict, ED extends EntityDict & BaseEntityDict,
Cxt extends AsyncContext<ED>, Cxt extends AsyncContext<ED>,
@ -386,7 +384,7 @@ export type WebComponentProps<
IsList extends boolean, IsList extends boolean,
TData extends WechatMiniprogram.Component.DataOption = {}, TData extends WechatMiniprogram.Component.DataOption = {},
TMethod extends WechatMiniprogram.Component.MethodOption = {}> = { TMethod extends WechatMiniprogram.Component.MethodOption = {}> = {
methods: TMethod & Pick<OakCommonComponentMethods<ED, T>, WebComponentCommonMethodNames> methods: TMethod & OakCommonComponentMethods<ED, T>
& (IsList extends true ? Pick<OakListComponentMethods<ED, T>, WebComponentListMethodNames> : Pick<OakSingleComponentMethods<ED, T>, WebComponentSingleMethodNames>); & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
data: TData & OakComponentData<ED, T> & (IsList extends true ? OakListComponentProperties : {}); data: TData & OakComponentData<ED, T> & (IsList extends true ? OakListComoponetData<ED, T> : {});
} }