fix tree
This commit is contained in:
parent
06c70830c9
commit
4f53547cc9
|
|
@ -29,9 +29,12 @@ export const TypeDropdown: FC<{
|
||||||
if (options instanceof Promise) {
|
if (options instanceof Promise) {
|
||||||
options.then((res) => {
|
options.then((res) => {
|
||||||
if (Array.isArray(res)) {
|
if (Array.isArray(res)) {
|
||||||
const list: any = res.map((e: any) => {
|
const list: any = res.map((e: any, idx: number) => {
|
||||||
return {
|
return {
|
||||||
label: arg.opt_get_label(e, "list"),
|
label: arg.opt_get_label(e, "list", {
|
||||||
|
prev: res[idx - 1],
|
||||||
|
next: res[idx + 1],
|
||||||
|
}),
|
||||||
tag: arg.opt_get_label(e, "label"),
|
tag: arg.opt_get_label(e, "label"),
|
||||||
value: e.value,
|
value: e.value,
|
||||||
data: e.data,
|
data: e.data,
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ export const generateField = async (
|
||||||
opt__label: `\
|
opt__label: `\
|
||||||
(
|
(
|
||||||
row: { value: string; label: string; data?: any },
|
row: { value: string; label: string; data?: any },
|
||||||
mode: "list" | "label",
|
mode: "list" | "label", opt: any
|
||||||
) => {
|
) => {
|
||||||
const cols = ${JSON.stringify(
|
const cols = ${JSON.stringify(
|
||||||
getColumn(generateSelect(parseGenField(master.value.checked)))
|
getColumn(generateSelect(parseGenField(master.value.checked)))
|
||||||
|
|
@ -141,7 +141,7 @@ export const generateField = async (
|
||||||
|
|
||||||
const prefix = treePrefix({
|
const prefix = treePrefix({
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
rel__feature, rel__id_parent, row, mode
|
rel__feature, rel__id_parent, row, mode, opt
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isEditor) {
|
if (isEditor) {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export const gen_label = ({
|
||||||
return `\
|
return `\
|
||||||
(
|
(
|
||||||
row: { value: string; label: string; data?: any },
|
row: { value: string; label: string; data?: any },
|
||||||
mode: "list" | "label",
|
mode: "list" | "label", opt: any
|
||||||
) => {
|
) => {
|
||||||
const cols = ${JSON.stringify(cols)};
|
const cols = ${JSON.stringify(cols)};
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ export const gen_label = ({
|
||||||
|
|
||||||
const prefix = treePrefix({
|
const prefix = treePrefix({
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
rel__feature, rel__id_parent, row, mode
|
rel__feature, rel__id_parent, row, mode, opt
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ export const genRelMany = (prop: {
|
||||||
const get_label = `\
|
const get_label = `\
|
||||||
(
|
(
|
||||||
row: { value: string; label: string; data?: any },
|
row: { value: string; label: string; data?: any },
|
||||||
mode: "list" | "label",
|
mode: "list" | "label", opt: any
|
||||||
) => {
|
) => {
|
||||||
const cols = ${JSON.stringify(cols)};
|
const cols = ${JSON.stringify(cols)};
|
||||||
|
|
||||||
|
|
@ -133,7 +133,7 @@ export const genRelMany = (prop: {
|
||||||
|
|
||||||
const prefix = treePrefix({
|
const prefix = treePrefix({
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
rel__feature, rel__id_parent, row, mode
|
rel__feature, rel__id_parent, row, mode, opt
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,11 @@ export type FieldProp = {
|
||||||
) =>
|
) =>
|
||||||
| { value: string; label: string }[]
|
| { value: string; label: string }[]
|
||||||
| Promise<{ value: string; label: string }[]>;
|
| Promise<{ value: string; label: string }[]>;
|
||||||
opt_get_label: (row: any, mode: "list" | "label") => string;
|
opt_get_label: (
|
||||||
|
row: any,
|
||||||
|
mode: "list" | "label",
|
||||||
|
opt?: { next?: any; prev?: any }
|
||||||
|
) => string;
|
||||||
opt_get_value: (arg: {
|
opt_get_value: (arg: {
|
||||||
options: { label: string; value: string; item?: string }[];
|
options: { label: string; value: string; item?: string }[];
|
||||||
fm: FMLocal;
|
fm: FMLocal;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
export const treePrefix = (props: any) => {
|
export const treePrefix = (props: any) => {
|
||||||
if (!props) return "";
|
if (!props) return "";
|
||||||
const { rel__feature, rel__id_parent, row, mode } = props;
|
const { rel__feature, rel__id_parent, row, opt } = props;
|
||||||
|
|
||||||
if (props.mode !== "list") return "";
|
if (props.mode !== "list") return "";
|
||||||
|
const next = opt?.next?.data?.__depth;
|
||||||
|
const prev = opt?.prev?.data?.__depth;
|
||||||
|
|
||||||
if (!rel__feature || !rel__id_parent || !row) return "";
|
if (!rel__feature || !rel__id_parent || !row) return "";
|
||||||
|
|
||||||
|
|
@ -15,10 +17,16 @@ export const treePrefix = (props: any) => {
|
||||||
|
|
||||||
let prefix = ``;
|
let prefix = ``;
|
||||||
if (is_tree && row.data && row.data.__depth) {
|
if (is_tree && row.data && row.data.__depth) {
|
||||||
|
const cur = row.data.__depth;
|
||||||
|
let is_last = false;
|
||||||
|
if (cur !== next) {
|
||||||
|
is_last = true;
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < row.data.__depth; i++) {
|
for (let i = 0; i < row.data.__depth; i++) {
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
if (row.data.__depth === 1) {
|
if (row.data.__depth === 1) {
|
||||||
prefix += "└";
|
prefix += is_last ? "└" : "├";
|
||||||
} else {
|
} else {
|
||||||
prefix += " ";
|
prefix += " ";
|
||||||
}
|
}
|
||||||
|
|
@ -26,7 +34,7 @@ export const treePrefix = (props: any) => {
|
||||||
if (row.data.__depth - 1 !== i) {
|
if (row.data.__depth - 1 !== i) {
|
||||||
prefix += " ";
|
prefix += " ";
|
||||||
} else {
|
} else {
|
||||||
prefix += "└";
|
prefix += is_last ? "└" : "├";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -98,9 +106,6 @@ export const sortTree = (list: any, parent_key: string, pk: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
if (parent.item.id === "f43ac927-9c0d-4241-a837-c0bf1c6a5245") {
|
|
||||||
console.log(parent, item);
|
|
||||||
}
|
|
||||||
item.__depth = parent.depth + 1;
|
item.__depth = parent.depth + 1;
|
||||||
|
|
||||||
meta[item[pk]] = {
|
meta[item[pk]] = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue