添加选项时添加 parent 上下文
This commit is contained in:
parent
7ab84b60e6
commit
2499c6b090
|
@ -10,7 +10,8 @@ import {
|
|||
createObject,
|
||||
setVariable,
|
||||
spliceTree,
|
||||
findTreeIndex
|
||||
findTreeIndex,
|
||||
getTree
|
||||
} from '../../utils/helper';
|
||||
import {reaction} from 'mobx';
|
||||
import {FormControlProps, registerFormItem, FormItemBasicConfig} from './Item';
|
||||
|
@ -505,9 +506,18 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
}
|
||||
];
|
||||
}
|
||||
const ctx = createObject(
|
||||
data,
|
||||
Array.isArray(idx)
|
||||
? {
|
||||
parent: getTree(model.options, idx.slice(0, idx.length - 1)),
|
||||
...value
|
||||
}
|
||||
: value
|
||||
);
|
||||
|
||||
let result: any = skipForm
|
||||
? value
|
||||
? ctx
|
||||
: await onOpenDialog(
|
||||
{
|
||||
type: 'dialog',
|
||||
|
@ -518,19 +528,15 @@ export function registerOptionsControl(config: OptionsConfig) {
|
|||
controls: addControls
|
||||
}
|
||||
},
|
||||
data
|
||||
ctx
|
||||
);
|
||||
|
||||
// 单独发请求
|
||||
if (skipForm && addApi) {
|
||||
try {
|
||||
const payload = await env.fetcher(
|
||||
addApi!,
|
||||
createObject(data, result),
|
||||
{
|
||||
method: 'post'
|
||||
}
|
||||
);
|
||||
const payload = await env.fetcher(addApi!, result, {
|
||||
method: 'post'
|
||||
});
|
||||
|
||||
if (!payload.ok) {
|
||||
env.notify('error', payload.msg || '新增失败,请仔细检查');
|
||||
|
|
|
@ -779,6 +779,24 @@ export function findTreeIndex<T extends TreeItem>(
|
|||
return idx.length ? idx : undefined;
|
||||
}
|
||||
|
||||
export function getTree<T extends TreeItem>(
|
||||
tree: Array<T>,
|
||||
idx: Array<number> | number
|
||||
): T | undefined | null {
|
||||
const indexes = Array.isArray(idx) ? idx : [idx];
|
||||
const lastIndex = indexes.pop()!;
|
||||
let list: Array<T> | null = tree;
|
||||
for (let i = 0, len = indexes.length; i < len; i++) {
|
||||
const index = indexes[i];
|
||||
if (!list![index]) {
|
||||
list = null;
|
||||
break;
|
||||
}
|
||||
list = list![index].children as any;
|
||||
}
|
||||
return list ? list[lastIndex] : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤树节点
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue