将很多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, {
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 = {},

View File

@ -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 () {

View File

@ -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<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);
} */
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);
addItem: function (data, beforeExecute, afterExecute, path) {
return _this.addItem(data, beforeExecute, afterExecute, path);
},
removeItem: function (id, beforeExecute, afterExecute) {
return _this.removeItem(id, beforeExecute, afterExecute);
removeItem: function (id, beforeExecute, afterExecute, path) {
return _this.removeItem(id, beforeExecute, afterExecute, path);
},
updateItem: function (data, id, action, beforeExecute, afterExecute) {
return _this.updateItem(data, id, action, beforeExecute, afterExecute);
updateItem: function (data, id, action, beforeExecute, afterExecute, path) {
return _this.updateItem(data, id, action, beforeExecute, afterExecute, path);
},
setFilters: function (filters) {
return _this.setFilters(filters);
setFilters: function (filters, path) {
return _this.setFilters(filters, path);
},
addNamedFilter: function (filter, refresh) {
return _this.addNamedFilter(filter, refresh);
addNamedFilter: function (filter, refresh, path) {
return _this.addNamedFilter(filter, refresh, path);
},
removeNamedFilter: function (filter, refresh) {
return _this.removeNamedFilter(filter, refresh);
removeNamedFilter: function (filter, refresh, path) {
return _this.removeNamedFilter(filter, refresh, path);
},
removeNamedFilterByName: function (name, refresh) {
return _this.removeNamedFilterByName(name, refresh);
removeNamedFilterByName: function (name, refresh, path) {
return _this.removeNamedFilterByName(name, refresh, path);
},
setNamedSorters: function (sorters) {
return _this.setNamedSorters(sorters);
setNamedSorters: function (sorters, path) {
return _this.setNamedSorters(sorters, path);
},
addNamedSorter: function (sorter, refresh) {
return _this.addNamedSorter(sorter, refresh);
addNamedSorter: function (sorter, refresh, path) {
return _this.addNamedSorter(sorter, refresh, path);
},
removeNamedSorter: function (sorter, refresh) {
return _this.removeNamedSorter(sorter, refresh);
removeNamedSorter: function (sorter, refresh, path) {
return _this.removeNamedSorter(sorter, refresh, path);
},
removeNamedSorterByName: function (name, refresh) {
return _this.removeNamedSorterByName(name, refresh);
removeNamedSorterByName: function (name, refresh, path) {
return _this.removeNamedSorterByName(name, refresh, path);
},
setPageSize: function (pageSize) {
return _this.setPageSize(pageSize);
setPageSize: function (pageSize, path) {
return _this.setPageSize(pageSize, path);
},
setCurrentPage: function (current) {
return _this.setCurrentPage(current);
setCurrentPage: function (current, path) {
return _this.setCurrentPage(current, path);
},
loadMore: function () {
return _this.loadMore();
}
});
}
else {
Object.assign(methodProps, {
/* create: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
return this.create(data, beforeExecute, afterExecute);
}, */
update: function (data, action, beforeExecute, afterExecute) {
return _this.update(data, action, beforeExecute, afterExecute);
update: function (data, action, beforeExecute, afterExecute, path) {
return _this.update(data, action, beforeExecute, afterExecute, path);
},
remove: function (beforeExecute, afterExecute) {
return _this.remove(beforeExecute, afterExecute);
remove: function (beforeExecute, afterExecute, path) {
return _this.remove(beforeExecute, afterExecute, path);
},
});
}
if (methods) {
var _loop_1 = function (m) {
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>;
setState: (data: Partial<ComponentData<ED, T, FormedData, TData>>, callback?: () => void) => 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>> = {
subscribed: Array<() => void>;
features: BasicFeatures<ED, Cxt, FrontCxt, CommonAspectDict<ED, Cxt>>;
@ -68,7 +68,7 @@ export declare type ComponentFullThisType<ED extends EntityDict & BaseEntityDict
props: ComponentProps<true, {}>;
setState: (data: Partial<OakComponentData<ED, T>>, callback?: () => void) => 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<{
data?: ((option: {
features: BasicFeatures<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>> & FD;
@ -108,6 +108,7 @@ export declare type OakListComponentProperties = {
oakFilters: ObjectConstructor;
oakSorters: ObjectConstructor;
oakIsPicker: BooleanConstructor;
oakPagination: ObjectConstructor;
};
export declare type OakNavigateToParameters<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
oakId?: string;
@ -162,30 +163,30 @@ export declare type OakSingleComponentMethods<ED extends EntityDict & BaseEntity
setId: (id: string) => void;
unsetId: () => void;
getId: () => string | undefined;
update: (data: ED[T]['Update']['data'], action?: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void;
remove: (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>, path?: string) => void;
};
export declare type OakListComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
loadMore: () => Promise<void>;
setFilters: (filters: NamedFilterItem<ED, T>[]) => void;
getFilters: () => ED[T]['Selection']['filter'][] | undefined;
getFilterByName: (name: string) => ED[T]['Selection']['filter'] | undefined;
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => void;
removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => void;
removeNamedFilterByName: (name: string, refresh?: boolean) => void;
setNamedSorters: (sorters: NamedSorterItem<ED, T>[]) => void;
getSorters: () => ED[T]['Selection']['sorter'] | undefined;
getSorterByName: (name: string) => 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;
removeItem: (id: string, 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>) => void;
recoverItem: (id: string) => void;
setFilters: (filters: NamedFilterItem<ED, T>[], path?: string) => void;
getFilters: (path?: string) => ED[T]['Selection']['filter'][] | undefined;
getFilterByName: (name: string, path?: string) => ED[T]['Selection']['filter'] | undefined;
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => void;
setNamedSorters: (sorters: NamedSorterItem<ED, T>[], path?: string) => void;
getSorters: (path?: string) => ED[T]['Selection']['sorter'] | undefined;
getSorterByName: (name: string, path?: string) => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined;
addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedSorter: (filter: NamedSorterItem<ED, T>, 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<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => 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>, path?: string) => void;
recoverItem: (id: string, path?: string) => void;
};
declare type ComponentOnPropsChangeOption = {
path?: string;
@ -212,12 +213,17 @@ export declare type OakComponentData<ED extends EntityDict & BaseEntityDict, T e
oakLegalActions?: ED[T]['Action'][];
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 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<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>);
data: TData & OakComponentData<ED, T> & (IsList extends true ? OakListComponentProperties : {});
methods: TMethod & OakCommonComponentMethods<ED, T> & OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
data: TData & OakComponentData<ED, T> & (IsList extends true ? OakListComoponetData<ED, T> : {});
};
export {};

View File

@ -197,6 +197,18 @@ export function reRender<
Object.assign(data, {
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) {
if (data[k] === undefined) {
Object.assign(data, {

View File

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

View File

@ -216,8 +216,12 @@ abstract class OakComponentBase<
addItem<T extends keyof ED>(
data: Omit<ED[T]['CreateSingle']['data'], 'id'>,
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.state.oakFullpath,
data,
@ -229,10 +233,14 @@ abstract class OakComponentBase<
removeItem(
id: string,
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.state.oakFullpath,
path2,
id,
beforeExecute,
afterExecute
@ -244,10 +252,14 @@ abstract class OakComponentBase<
id: string,
action?: ED[T]['Action'],
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.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<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'],
action?: ED[T]['Action'],
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.state.oakFullpath,
path2,
data,
action,
beforeExecute,
@ -281,10 +300,14 @@ abstract class OakComponentBase<
remove(
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.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<ED, T>[]) {
setFilters(filters: NamedFilterItem<ED, T>[], 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<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.state.oakFullpath,
path2,
namedFilter,
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.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<ED, T>[]) {
setNamedSorters(namedSorters: NamedSorterItem<ED, T>[], 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<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.state.oakFullpath,
path2,
namedSorter,
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.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
);
}
@ -660,71 +721,62 @@ export function createComponent<
return this.clean(path);
},
};
if (option.isList) {
Object.assign(methodProps, {
addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
return this.addItem(data, beforeExecute, afterExecute);
addItem: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => {
return this.addItem(data, beforeExecute, afterExecute, path);
},
removeItem: (id: string, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
return this.removeItem(id, beforeExecute, afterExecute);
removeItem: (id: string, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => {
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>) => {
return this.updateItem(data, id, action, beforeExecute, afterExecute);
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, path);
},
setFilters: (filters: NamedFilterItem<ED, T>[]) => {
return this.setFilters(filters);
setFilters: (filters: NamedFilterItem<ED, T>[], path?: string) => {
return this.setFilters(filters, path);
},
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => {
return this.addNamedFilter(filter, refresh);
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => {
return this.addNamedFilter(filter, refresh, path);
},
removeNamedFilter: (
filter: NamedFilterItem<ED, T>,
refresh?: boolean
) => {
return this.removeNamedFilter(filter, refresh);
removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => {
return this.removeNamedFilter(filter, refresh, path);
},
removeNamedFilterByName: (name: string, refresh?: boolean) => {
return this.removeNamedFilterByName(name, refresh);
removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => {
return this.removeNamedFilterByName(name, refresh, path);
},
setNamedSorters: (sorters: NamedSorterItem<ED, T>[]) => {
return this.setNamedSorters(sorters);
setNamedSorters: (sorters: NamedSorterItem<ED, T>[], path?: string) => {
return this.setNamedSorters(sorters, path);
},
addNamedSorter: (sorter: NamedSorterItem<ED, T>, refresh?: boolean) => {
return this.addNamedSorter(sorter, refresh);
addNamedSorter: (sorter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => {
return this.addNamedSorter(sorter, refresh, path);
},
removeNamedSorter: (
sorter: NamedSorterItem<ED, T>,
refresh?: boolean
) => {
return this.removeNamedSorter(sorter, refresh);
removeNamedSorter: (sorter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => {
return this.removeNamedSorter(sorter, refresh, path);
},
removeNamedSorterByName: (name: string, refresh?: boolean) => {
return this.removeNamedSorterByName(name, refresh);
removeNamedSorterByName: (name: string, refresh?: boolean, path?: string) => {
return this.removeNamedSorterByName(name, refresh, path);
},
setPageSize: (pageSize: number) => {
return this.setPageSize(pageSize);
setPageSize: (pageSize: number, path?: string) => {
return this.setPageSize(pageSize, path);
},
setCurrentPage: (current: number) => {
return this.setCurrentPage(current);
setCurrentPage: (current: number, path?: string) => {
return this.setCurrentPage(current, path);
},
loadMore: () => {
return this.loadMore();
}
} as Record<WebComponentListMethodNames, Function>);
}
else {
Object.assign(methodProps, {
/* create: (data: Omit<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
return this.create(data, beforeExecute, afterExecute);
}, */
update: (data: ED[T]['Update']['data'], action: ED[T]['Action'], beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
return this.update(data, action, beforeExecute, afterExecute);
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, path);
},
remove: (beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => {
return this.remove(beforeExecute, afterExecute);
remove: (beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>, path?: string) => {
return this.remove(beforeExecute, afterExecute, path);
},
} as Record<WebComponentSingleMethodNames, Function>);
}
if (methods) {
for (const m in methods) {

View File

@ -113,7 +113,7 @@ export type ComponentPublicThisType<
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 type ComponentFullThisType<
ED extends EntityDict & BaseEntityDict,
@ -135,7 +135,7 @@ export type ComponentFullThisType<
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 type OakComponentOption<
ED extends EntityDict & BaseEntityDict,
@ -193,6 +193,7 @@ export type OakListComponentProperties = {
oakFilters: ObjectConstructor;
oakSorters: ObjectConstructor;
oakIsPicker: BooleanConstructor;
oakPagination: ObjectConstructor;
}
export type OakNavigateToParameters<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
@ -230,9 +231,7 @@ export type OakCommonComponentMethods<
setMessage: (data: MessageProps) => void;
consumeMessage: () => MessageProps | undefined;
reRender: (extra?: Record<string, any>) => void;
getFreshValue: (
path?: string
) =>
getFreshValue: (path?: string) =>
| Partial<ED[keyof ED]['Schema']>[]
| Partial<ED[keyof ED]['Schema']>
| undefined;
@ -272,42 +271,32 @@ export type OakSingleComponentMethods<ED extends EntityDict & BaseEntityDict, T
unsetId: () => void;
getId: () => string | undefined;
// 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;
remove: (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>, path?: string) => void;
}
export type OakListComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
loadMore: () => Promise<void>;
setFilters: (filters: NamedFilterItem<ED, T>[]) => void;
getFilters: () => ED[T]['Selection']['filter'][] | undefined;
getFilterByName: (
name: string
) => ED[T]['Selection']['filter'] | undefined;
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean) => void;
removeNamedFilter: (
filter: NamedFilterItem<ED, T>,
refresh?: boolean
) => void;
removeNamedFilterByName: (name: string, refresh?: boolean) => void;
setNamedSorters: (sorters: NamedSorterItem<ED, T>[]) => void;
getSorters: () => ED[T]['Selection']['sorter'] | undefined;
getSorterByName: (
name: string
) => 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;
setFilters: (filters: NamedFilterItem<ED, T>[], path?: string) => void;
getFilters: (path?: string) => ED[T]['Selection']['filter'][] | undefined;
getFilterByName: (name: string, path?: string) => ED[T]['Selection']['filter'] | undefined;
addNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedFilter: (filter: NamedFilterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedFilterByName: (name: string, refresh?: boolean, path?: string) => void;
setNamedSorters: (sorters: NamedSorterItem<ED, T>[], path?: string) => void;
getSorters: (path?: string) => ED[T]['Selection']['sorter'] | undefined;
getSorterByName: (name: string, path?: string) => NonNullable<ED[T]['Selection']['sorter']>[number] | undefined;
addNamedSorter: (filter: NamedSorterItem<ED, T>, refresh?: boolean, path?: string) => void;
removeNamedSorter: (filter: NamedSorterItem<ED, T>, 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<ED[T]['CreateSingle']['data'], 'id'>, beforeExecute?: () => Promise<void>, afterExecute?: () => Promise<void>) => void;
removeItem: (id: string, 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>) => void;
recoverItem: (id: string) => 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>, path?: string) => 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, 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<ED[T]['Selection']['filter']>[];
oakSorters?: NonNullable<ED[T]['Selection']['sorter']>[];
oakPagination?: Pagination;
}
export type MakeOakComponent<
ED extends EntityDict & BaseEntityDict,
Cxt extends AsyncContext<ED>,
@ -386,7 +384,7 @@ export type WebComponentProps<
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>);
data: TData & OakComponentData<ED, T> & (IsList extends true ? OakListComponentProperties : {});
methods: TMethod & OakCommonComponentMethods<ED, T>
& OakListComponentMethods<ED, T> & OakSingleComponentMethods<ED, T>;
data: TData & OakComponentData<ED, T> & (IsList extends true ? OakListComoponetData<ED, T> : {});
}