适配了commonAspect中select的返回
This commit is contained in:
parent
09addadb36
commit
4e27d91506
|
|
@ -18,8 +18,8 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict, Cxt extends A
|
|||
message: string | null | undefined;
|
||||
}>;
|
||||
refresh<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP, getCount?: true, callback?: (result: Awaited<ReturnType<AD['select']>>) => void): Promise<{
|
||||
data: Partial<ED[T]['Schema']>[];
|
||||
count?: number | undefined;
|
||||
data: Partial<ED[T]["Schema"]>[];
|
||||
count: number | undefined;
|
||||
}>;
|
||||
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): Promise<import("oak-domain/lib/types").AggregationResult<ED[keyof ED]["Schema"]>>;
|
||||
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option?: OP, callback?: (result: Awaited<ReturnType<AD['operate']>>) => void): Promise<{
|
||||
|
|
|
|||
|
|
@ -71,9 +71,9 @@ var Cache = /** @class */ (function (_super) {
|
|||
};
|
||||
Cache.prototype.refresh = function (entity, selection, option, getCount, callback) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var result;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
var _a, ids, count, selection2, data;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, this.exec('select', {
|
||||
entity: entity,
|
||||
selection: selection,
|
||||
|
|
@ -81,8 +81,19 @@ var Cache = /** @class */ (function (_super) {
|
|||
getCount: getCount,
|
||||
}, callback)];
|
||||
case 1:
|
||||
result = (_a.sent()).result;
|
||||
return [2 /*return*/, result];
|
||||
_a = (_b.sent()).result, ids = _a.ids, count = _a.count;
|
||||
selection2 = Object.assign({}, selection, {
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
}
|
||||
});
|
||||
data = this.get(entity, selection2);
|
||||
return [2 /*return*/, {
|
||||
data: data,
|
||||
count: count,
|
||||
}];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -906,9 +906,9 @@ var ListNode = /** @class */ (function (_super) {
|
|||
indexFrom: currentPage3 * pageSize,
|
||||
count: pageSize,
|
||||
}, undefined, getCount, function (_a) {
|
||||
var data = _a.data, count = _a.count;
|
||||
var ids = _a.ids, count = _a.count;
|
||||
_this.pagination.currentPage = currentPage3 + 1;
|
||||
_this.pagination.more = data.length === pageSize;
|
||||
_this.pagination.more = ids.length === pageSize;
|
||||
_this.setLoading(false);
|
||||
if (append) {
|
||||
_this.loadingMore = false;
|
||||
|
|
@ -916,7 +916,6 @@ var ListNode = /** @class */ (function (_super) {
|
|||
if (getCount) {
|
||||
_this.pagination.total = count;
|
||||
}
|
||||
var ids = data.map(function (ele) { return ele.id; });
|
||||
if (append) {
|
||||
_this.ids = (_this.ids || []).concat(ids);
|
||||
}
|
||||
|
|
@ -1320,10 +1319,10 @@ var SingleNode = /** @class */ (function (_super) {
|
|||
SingleNode.prototype.refresh = function () {
|
||||
var _a;
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var projection, filter, err_2;
|
||||
var projection, filter, _b, value, modi$entity, err_2;
|
||||
var _this = this;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
return tslib_1.__generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
// SingleNode如果是ListNode的子结点,则不必refresh(优化,ListNode有义务负责子层对象的数据)
|
||||
if (this.parent && this.parent instanceof ListNode && this.parent.getEntity() === this.getEntity()) {
|
||||
|
|
@ -1339,28 +1338,28 @@ var SingleNode = /** @class */ (function (_super) {
|
|||
if (!(projection && filter)) return [3 /*break*/, 4];
|
||||
this.setLoading(true);
|
||||
this.publish();
|
||||
_b.label = 1;
|
||||
_c.label = 1;
|
||||
case 1:
|
||||
_b.trys.push([1, 3, , 4]);
|
||||
_c.trys.push([1, 3, , 4]);
|
||||
return [4 /*yield*/, this.cache.refresh(this.entity, {
|
||||
data: projection,
|
||||
filter: filter,
|
||||
}, undefined, undefined, function (_a) {
|
||||
var _b = tslib_1.__read(_a.data, 1), value = _b[0];
|
||||
// 对于modi对象,在此缓存
|
||||
if (_this.schema[_this.entity].toModi && value) {
|
||||
var modi$entity = value.modi$entity;
|
||||
_this.modiIds = modi$entity.map(function (ele) { return ele.id; });
|
||||
}
|
||||
}, undefined, undefined, function () {
|
||||
// 刷新后所有的更新都应当被丢弃(子层上可能会自动建立了this.create动作) 这里可能会有问题 by Xc 20230329
|
||||
_this.clean();
|
||||
_this.setLoading(false);
|
||||
_this.clean();
|
||||
})];
|
||||
case 2:
|
||||
_b.sent();
|
||||
_b = tslib_1.__read.apply(void 0, [(_c.sent()).data, 1]), value = _b[0];
|
||||
// 对于modi对象,在此缓存modiIds
|
||||
if (this.schema[this.entity].toModi && value) {
|
||||
modi$entity = value.modi$entity;
|
||||
this.modiIds = modi$entity.map(function (ele) { return ele.id; });
|
||||
this.publish();
|
||||
}
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
err_2 = _b.sent();
|
||||
err_2 = _c.sent();
|
||||
this.setLoading(false);
|
||||
throw err_2;
|
||||
case 4: return [2 /*return*/];
|
||||
|
|
|
|||
|
|
@ -111,7 +111,8 @@ function onPathSet(option) {
|
|||
cascadeActions: cascadeActions_1 && (function () { return cascadeActions_1.call(_this); }),
|
||||
});
|
||||
this.subscribed.push(features.runningTree.subscribeNode(function (path2) {
|
||||
if (path2 === _this.state.oakFullpath) {
|
||||
// 父结点改变,子结点要重渲染
|
||||
if (_this.state.oakFullpath.includes(path2)) {
|
||||
_this.reRender();
|
||||
}
|
||||
}, oakPath2));
|
||||
|
|
|
|||
|
|
@ -93,15 +93,24 @@ export class Cache<
|
|||
getCount?: true,
|
||||
callback?: (result: Awaited<ReturnType<AD['select']>>) => void,
|
||||
) {
|
||||
const { result } = await this.exec('select', {
|
||||
const { result: { ids, count } } = await this.exec('select', {
|
||||
entity,
|
||||
selection,
|
||||
option,
|
||||
getCount,
|
||||
}, callback);
|
||||
return result as {
|
||||
data: Partial<ED[T]['Schema']>[];
|
||||
count?: number;
|
||||
|
||||
const selection2 = Object.assign({}, selection, {
|
||||
filter: {
|
||||
id: {
|
||||
$in: ids,
|
||||
}
|
||||
}
|
||||
});
|
||||
const data = this.get(entity, selection2);
|
||||
return {
|
||||
data: data as Partial<ED[T]['Schema']>[],
|
||||
count,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -988,9 +988,9 @@ class ListNode<
|
|||
},
|
||||
undefined,
|
||||
getCount,
|
||||
({ data, count }) => {
|
||||
({ ids, count }) => {
|
||||
this.pagination.currentPage = currentPage3 + 1;
|
||||
this.pagination.more = data.length === pageSize;
|
||||
this.pagination.more = ids.length === pageSize;
|
||||
this.setLoading(false);
|
||||
if (append) {
|
||||
this.loadingMore = false;
|
||||
|
|
@ -998,8 +998,6 @@ class ListNode<
|
|||
if (getCount) {
|
||||
this.pagination.total = count;
|
||||
}
|
||||
|
||||
const ids = data.map((ele) => ele.id!) as string[];
|
||||
if (append) {
|
||||
this.ids = (this.ids || []).concat(ids);
|
||||
} else {
|
||||
|
|
@ -1407,20 +1405,21 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
this.setLoading(true);
|
||||
this.publish();
|
||||
try {
|
||||
await this.cache.refresh(this.entity, {
|
||||
const { data: [value] } = await this.cache.refresh(this.entity, {
|
||||
data: projection,
|
||||
filter,
|
||||
}, undefined, undefined, ({ data: [value] }) => {
|
||||
// 对于modi对象,在此缓存
|
||||
if (this.schema[this.entity].toModi && value) {
|
||||
const { modi$entity } = value;
|
||||
this.modiIds = (modi$entity as Array<BaseEntityDict['modi']['OpSchema']>).map(ele => ele.id)
|
||||
}
|
||||
|
||||
}, undefined, undefined, () => {
|
||||
// 刷新后所有的更新都应当被丢弃(子层上可能会自动建立了this.create动作) 这里可能会有问题 by Xc 20230329
|
||||
this.clean();
|
||||
this.setLoading(false);
|
||||
this.clean();
|
||||
});
|
||||
// 对于modi对象,在此缓存modiIds
|
||||
if (this.schema[this.entity].toModi && value) {
|
||||
const { modi$entity } = value;
|
||||
this.modiIds = (modi$entity as Array<BaseEntityDict['modi']['OpSchema']>).map(ele => ele.id);
|
||||
this.publish();
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
this.setLoading(false);
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ export async function onPathSet<
|
|||
this.subscribed.push(
|
||||
features.runningTree.subscribeNode(
|
||||
(path2) => {
|
||||
if (path2 === this.state.oakFullpath) {
|
||||
// 父结点改变,子结点要重渲染
|
||||
if (this.state.oakFullpath.includes(path2)) {
|
||||
this.reRender();
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue