一些小的修正
This commit is contained in:
parent
e5320e868d
commit
c4971901b8
|
|
@ -219,7 +219,14 @@ class ListNode<ED extends EntityDict,
|
||||||
getChild(path: string): SingleNode<ED, T, Cxt, AD> {
|
getChild(path: string): SingleNode<ED, T, Cxt, AD> {
|
||||||
const idx = parseInt(path, 10);
|
const idx = parseInt(path, 10);
|
||||||
assert(typeof idx === 'number');
|
assert(typeof idx === 'number');
|
||||||
return this.children[idx];
|
if (idx < this.children.length) {
|
||||||
|
return this.children[idx];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const idx2 = idx - this.children.length;
|
||||||
|
// assert(idx2 < this.newBorn.length); // 在删除结点时可能还是会跑到
|
||||||
|
return this.newBorn[idx2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getChildren() {
|
getChildren() {
|
||||||
|
|
@ -242,16 +249,12 @@ class ListNode<ED extends EntityDict,
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(value: SelectRowShape<ED[T]['OpSchema'], ED[T]['Selection']['data']>[]) {
|
setValue(value: SelectRowShape<ED[T]['OpSchema'], ED[T]['Selection']['data']>[]) {
|
||||||
|
this.children = [];
|
||||||
value.forEach(
|
value.forEach(
|
||||||
(ele, idx) => {
|
(ele, idx) => {
|
||||||
if (this.children[idx]) {
|
const node = new SingleNode(this.entity, this.schema, this.cache, this.projection, this.projectionShape, this);
|
||||||
this.children[idx].setValue(ele);
|
this.children[idx] = node;
|
||||||
}
|
node.setValue(ele);
|
||||||
else {
|
|
||||||
const node = new SingleNode(this.entity, this.schema, this.cache, this.projection, this.projectionShape, this);
|
|
||||||
this.children[idx] = node;
|
|
||||||
node.setValue(ele);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -562,7 +565,7 @@ class SingleNode<ED extends EntityDict,
|
||||||
const projection2 = await projection();
|
const projection2 = await projection();
|
||||||
return projection2[attr].filter;
|
return projection2[attr].filter;
|
||||||
} : projection[attr].filter;
|
} : projection[attr].filter;
|
||||||
const sorters = typeof projection === 'function' ? async () => {
|
const sorters = typeof projection === 'function' ? async () => {
|
||||||
const projection2 = await projection();
|
const projection2 = await projection();
|
||||||
return projection2[attr].sorter;
|
return projection2[attr].sorter;
|
||||||
} : projection[attr].sorter;
|
} : projection[attr].sorter;
|
||||||
|
|
@ -686,7 +689,7 @@ class SingleNode<ED extends EntityDict,
|
||||||
const projection = await this.getProjection();
|
const projection = await this.getProjection();
|
||||||
if (this.id) {
|
if (this.id) {
|
||||||
this.refreshing = true;
|
this.refreshing = true;
|
||||||
const { result: [ value ]} = await this.cache.refresh(this.entity, {
|
const { result: [value] } = await this.cache.refresh(this.entity, {
|
||||||
data: projection,
|
data: projection,
|
||||||
filter: {
|
filter: {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
|
@ -980,15 +983,18 @@ export class RunningTree<ED extends EntityDict, Cxt extends Context<ED>, AD exte
|
||||||
|
|
||||||
async getValue(path: string) {
|
async getValue(path: string) {
|
||||||
const node = this.findNode(path);
|
const node = this.findNode(path);
|
||||||
let value: ReturnType<typeof node.getValue> | undefined = node.getValue();
|
if (node) {
|
||||||
|
let value: ReturnType<typeof node.getValue> | undefined = node.getValue();
|
||||||
|
|
||||||
if (node.isDirty()) {
|
if (node.isDirty()) {
|
||||||
const operation = await node.composeOperation();
|
const operation = await node.composeOperation();
|
||||||
const projection = await node.getProjection();
|
const projection = await node.getProjection();
|
||||||
value = (await this.applyOperation(node.getEntity(), cloneDeep(value), operation!, projection, path));
|
value = (await this.applyOperation(node.getEntity(), cloneDeep(value), operation!, projection, path));
|
||||||
|
}
|
||||||
|
|
||||||
|
return value instanceof Array ? value : [value];
|
||||||
}
|
}
|
||||||
|
return [undefined];
|
||||||
return value instanceof Array ? value : [value];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isDirty(path: string) {
|
isDirty(path: string) {
|
||||||
|
|
@ -1227,7 +1233,7 @@ export class RunningTree<ED extends EntityDict, Cxt extends Context<ED>, AD exte
|
||||||
const parentNode = this.findNode(parent);
|
const parentNode = this.findNode(parent);
|
||||||
|
|
||||||
const node = parentNode.getChild(path);
|
const node = parentNode.getChild(path);
|
||||||
assert (parentNode instanceof ListNode && node instanceof SingleNode); // 现在应该不可能remove一个list吧,未来对list的处理还要细化
|
assert(parentNode instanceof ListNode && node instanceof SingleNode); // 现在应该不可能remove一个list吧,未来对list的处理还要细化
|
||||||
if (node.getValue().id) {
|
if (node.getValue().id) {
|
||||||
// 如果有id,说明是删除数据
|
// 如果有id,说明是删除数据
|
||||||
await this.getAspectProxy().operate({
|
await this.getAspectProxy().operate({
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,4 @@ export * from './types/Feature';
|
||||||
export * from './types/ExceptionRoute';
|
export * from './types/ExceptionRoute';
|
||||||
export { BasicFeatures } from './features';
|
export { BasicFeatures } from './features';
|
||||||
export * from './features/cache';
|
export * from './features/cache';
|
||||||
|
export * from './features/upload';
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ type OakComponentMethods<ED extends EntityDict, T extends keyof ED> = {
|
||||||
subscribed?: () => void;
|
subscribed?: () => void;
|
||||||
subscribe: () => void;
|
subscribe: () => void;
|
||||||
unsubscribe: () => void;
|
unsubscribe: () => void;
|
||||||
reRender: (extra?: any) => Promise<void>;
|
reRender: (extra?: Record<string, any>) => Promise<void>;
|
||||||
pushNode: (path?: string, options?: Pick<CreateNodeOptions<ED, keyof ED>, 'updateData' | 'beforeExecute' | 'afterExecute'>) => void;
|
pushNode: (path?: string, options?: Pick<CreateNodeOptions<ED, keyof ED>, 'updateData' | 'beforeExecute' | 'afterExecute'>) => void;
|
||||||
removeNode: (parent: string, path: string) => void;
|
removeNode: (parent: string, path: string) => void;
|
||||||
setUpdateData: (attr: string, input: any) => void;
|
setUpdateData: (attr: string, input: any) => void;
|
||||||
|
|
@ -223,7 +223,7 @@ function createPageOptions<ED extends EntityDict,
|
||||||
newOakActions: Array,
|
newOakActions: Array,
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async reRender() {
|
async reRender(extra) {
|
||||||
if (this.data.oakFullpath) {
|
if (this.data.oakFullpath) {
|
||||||
const $rows = await features.runningTree.getValue(this.data.oakFullpath);
|
const $rows = await features.runningTree.getValue(this.data.oakFullpath);
|
||||||
const data = await formData.call(this, $rows as any, features);
|
const data = await formData.call(this, $rows as any, features);
|
||||||
|
|
@ -254,6 +254,9 @@ function createPageOptions<ED extends EntityDict,
|
||||||
oakLegalActions,
|
oakLegalActions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (extra) {
|
||||||
|
assign(data, extra);
|
||||||
|
}
|
||||||
|
|
||||||
this.setData(data);
|
this.setData(data);
|
||||||
}
|
}
|
||||||
|
|
@ -679,7 +682,7 @@ function createComponentOptions<ED extends EntityDict,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async reRender() {
|
async reRender(extra) {
|
||||||
if (this.data.oakFullpath) {
|
if (this.data.oakFullpath) {
|
||||||
const $rows = await features.runningTree.getValue(this.data.oakFullpath);
|
const $rows = await features.runningTree.getValue(this.data.oakFullpath);
|
||||||
const data = await formData.call(this, $rows as any, features);
|
const data = await formData.call(this, $rows as any, features);
|
||||||
|
|
@ -711,6 +714,9 @@ function createComponentOptions<ED extends EntityDict,
|
||||||
});
|
});
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
if (extra) {
|
||||||
|
assign(data, extra);
|
||||||
|
}
|
||||||
this.setData(data);
|
this.setData(data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -721,7 +727,9 @@ function createComponentOptions<ED extends EntityDict,
|
||||||
if (path2 && parent2) {
|
if (path2 && parent2) {
|
||||||
const oakFullpath2 = `${parent2}.${path2}`;
|
const oakFullpath2 = `${parent2}.${path2}`;
|
||||||
if (oakFullpath2 !== this.data.oakFullpath) {
|
if (oakFullpath2 !== this.data.oakFullpath) {
|
||||||
this.data.oakFullpath = oakFullpath2;
|
this.setData({
|
||||||
|
oakFullpath: oakFullpath2,
|
||||||
|
});
|
||||||
this.reRender();
|
this.reRender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -852,7 +860,10 @@ function createComponentOptions<ED extends EntityDict,
|
||||||
async ready() {
|
async ready() {
|
||||||
const { oakPath, oakParent } = this.data;
|
const { oakPath, oakParent } = this.data;
|
||||||
if (oakParent && oakPath) {
|
if (oakParent && oakPath) {
|
||||||
this.data.oakFullpath = `${oakParent}.${oakPath}`;
|
const oakFullpath = `${oakParent}.${oakPath}`;
|
||||||
|
this.setData({
|
||||||
|
oakFullpath,
|
||||||
|
});
|
||||||
this.reRender();
|
this.reRender();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue