This commit is contained in:
rizrmd 2024-06-03 04:51:34 -07:00
parent 1e7a992690
commit 8e37da6c64
4 changed files with 71 additions and 64 deletions

View File

@ -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,

View File

@ -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 = [];
cols.map((e) => {
if (data[e]) {
result.push(data[e]);
}
});
return result.join(" - ");
};
if (isEditor) { if (isEditor) {
return row.label; return row.label;
} }
return getLabel(row.item); const result = [];
if (!!row.item && !Array.isArray(row.item)) {
cols.map((e) => {
if (row.item[e]) {
result.push(row.item[e]);
} }
});
return result.join(" - ");
}
return row.label;
}
`; `;
}; };

View File

@ -29,12 +29,12 @@ 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) => {
@ -71,7 +71,7 @@ export const on_load_rel = ({
done([]) done([])
} }
}) })
} }
`; `;
}; };

View File

@ -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 = {};
} }