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