fix
This commit is contained in:
parent
1e7a992690
commit
8e37da6c64
|
|
@ -26,7 +26,6 @@ export const TypeDropdown: FC<{
|
||||||
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) => {
|
||||||
console.log({e})
|
|
||||||
return {
|
return {
|
||||||
label: arg.opt_get_label(e),
|
label: arg.opt_get_label(e),
|
||||||
value: e.value,
|
value: e.value,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
export const gen_label = ({
|
export const gen_label = ({
|
||||||
pk,
|
pk,
|
||||||
table,
|
table,
|
||||||
select
|
select,
|
||||||
}: {
|
}: {
|
||||||
pk: string;
|
pk: string;
|
||||||
table: string;
|
table: string;
|
||||||
|
|
@ -16,21 +16,22 @@ export const gen_label = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
return `\
|
return `\
|
||||||
(row: { value: string; label: string; item?: any }) => {
|
(row: { value: string; label: string; item?: any }) => {
|
||||||
const cols = ${JSON.stringify(cols)};
|
const cols = ${JSON.stringify(cols)};
|
||||||
const getLabel = (data: any) => {
|
|
||||||
const result = [];
|
if (isEditor) {
|
||||||
cols.map((e) => {
|
return row.label;
|
||||||
if (data[e]) {
|
}
|
||||||
result.push(data[e]);
|
const result = [];
|
||||||
}
|
if (!!row.item && !Array.isArray(row.item)) {
|
||||||
});
|
cols.map((e) => {
|
||||||
return result.join(" - ");
|
if (row.item[e]) {
|
||||||
};
|
result.push(row.item[e]);
|
||||||
if (isEditor) {
|
|
||||||
return row.label;
|
|
||||||
}
|
}
|
||||||
return getLabel(row.item);
|
});
|
||||||
}
|
return result.join(" - ");
|
||||||
|
}
|
||||||
|
return row.label;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -29,49 +29,49 @@ export const on_load_rel = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
return `\
|
return `\
|
||||||
(arg: {
|
(arg: {
|
||||||
reload: () => Promise<void>;
|
reload: () => Promise<void>;
|
||||||
orderBy?: Record<string, "asc" | "desc">;
|
orderBy?: Record<string, "asc" | "desc">;
|
||||||
paging: { take: number; skip: number };
|
paging: { take: number; skip: number };
|
||||||
mode: 'count' | 'query'
|
mode: 'count' | 'query'
|
||||||
}) => {
|
}) => {
|
||||||
if (isEditor) return [${JSON.stringify(sample)}];
|
if (isEditor) return [${JSON.stringify(sample)}];
|
||||||
|
|
||||||
return new Promise(async (done) => {
|
return new Promise(async (done) => {
|
||||||
if (arg.mode === 'count') {
|
if (arg.mode === 'count') {
|
||||||
return await db.${table}.count();
|
return await db.${table}.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = await db.${table}.findMany({
|
||||||
|
select: ${JSON.stringify(select)},
|
||||||
|
orderBy: arg.orderBy || {
|
||||||
|
${pk}: "desc"
|
||||||
|
},
|
||||||
|
...arg.paging,
|
||||||
|
});
|
||||||
|
if(items.length){
|
||||||
|
const cols = ${JSON.stringify(cols)};
|
||||||
|
const getLabel = (data: any) => {
|
||||||
|
const result = [];
|
||||||
|
cols.map((e) => {
|
||||||
|
if(data[e]){
|
||||||
|
result.push(data[e]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result.join(" - ");
|
||||||
}
|
}
|
||||||
|
done(items.map((e) => {
|
||||||
const items = await db.${table}.findMany({
|
return {
|
||||||
select: ${JSON.stringify(select)},
|
value: e.${pk},
|
||||||
orderBy: arg.orderBy || {
|
label: getLabel(e),
|
||||||
${pk}: "desc"
|
data: e,
|
||||||
},
|
}
|
||||||
...arg.paging,
|
}))
|
||||||
});
|
} else {
|
||||||
if(items.length){
|
done([])
|
||||||
const cols = ${JSON.stringify(cols)};
|
}
|
||||||
const getLabel = (data: any) => {
|
})
|
||||||
const result = [];
|
}
|
||||||
cols.map((e) => {
|
|
||||||
if(data[e]){
|
|
||||||
result.push(data[e]);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return result.join(" - ");
|
|
||||||
}
|
|
||||||
done(items.map((e) => {
|
|
||||||
return {
|
|
||||||
value: e.${pk},
|
|
||||||
label: getLabel(e),
|
|
||||||
data: e,
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
} else {
|
|
||||||
done([])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -54,13 +54,20 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (should_load) {
|
if (should_load) {
|
||||||
const res = on_load({ fm });
|
const on_load_result = on_load({ fm });
|
||||||
|
let result = undefined;
|
||||||
if (typeof res === "object" && res instanceof Promise) {
|
if (
|
||||||
fm.data = await res;
|
typeof on_load_result === "object" &&
|
||||||
|
on_load_result instanceof Promise
|
||||||
|
) {
|
||||||
|
result = await on_load_result;
|
||||||
} else {
|
} else {
|
||||||
fm.data = res;
|
result = on_load_result;
|
||||||
}
|
}
|
||||||
|
if (!!result) {
|
||||||
|
fm.data = result;
|
||||||
|
}
|
||||||
|
|
||||||
if (!fm.data) {
|
if (!fm.data) {
|
||||||
fm.data = {};
|
fm.data = {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue