2022-01-17 23:04:33 +08:00
|
|
|
import { Schema, observer, useFieldSchema, useField, RecursionField } from '@formily/react';
|
|
|
|
|
|
|
|
function findByUid(schema: Schema, uid: string) {
|
|
|
|
return schema.reduceProperties((buffter, s) => {
|
|
|
|
if (s['x-uid'] === uid) {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
const ss = findByUid(s, uid);
|
|
|
|
if (ss) {
|
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
return buffter;
|
|
|
|
}, null);
|
|
|
|
}
|
|
|
|
|
2022-01-18 15:19:54 +08:00
|
|
|
export function findMenuItem(schema: Schema) {
|
|
|
|
if (!Schema.isSchemaInstance(schema)) {
|
|
|
|
schema = new Schema(schema);
|
|
|
|
}
|
|
|
|
for (const { schema: s } of Schema.getOrderProperties(schema)) {
|
|
|
|
if (s['x-component'] === 'Menu.Item') {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
const ss = findMenuItem(s);
|
|
|
|
if (ss) {
|
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-01-17 23:04:33 +08:00
|
|
|
function findKeys(schema: Schema) {
|
|
|
|
if (!schema) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const keys = [];
|
|
|
|
keys.push(schema.name);
|
|
|
|
while (schema.parent) {
|
|
|
|
if (schema.parent['x-component'] === 'Menu') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
keys.push(schema.parent.name);
|
|
|
|
schema = schema.parent;
|
|
|
|
}
|
|
|
|
return keys.reverse();
|
|
|
|
}
|
|
|
|
|
|
|
|
export function findKeysByUid(schema: Schema, uid: string) {
|
|
|
|
return findKeys(findByUid(schema, uid));
|
|
|
|
}
|