feat: custom types can bind a field layout (profile) - layout select in type editor, respected in record form

This commit is contained in:
root
2026-10-17 10:45:04 +08:00
parent 79dada4226
commit 74884ce73a
19 changed files with 109 additions and 92 deletions
@@ -84,7 +84,7 @@ export function RecordEditorDialog({ open, onClose, footprintId, onSaved }: {
() => typesQ.data?.items.find(t => t.id === form.type_id),
[typesQ.data, form.type_id]
);
const profile = getTypeProfile(selectedType?.name);
const profile = getTypeProfile(selectedType?.name, selectedType?.profile);
const parentQ = useQuery({
queryKey: ['parent-candidates', form.type_id],
+1 -1
View File
@@ -86,7 +86,7 @@ export const syncStatus = () => call<SyncStatus>('sync_status');
// ---- footprint type ----
export const listTypes = () => call<{ items: FootprintType[] }>('type_list');
export const upsertType = (p: { id?: number; name: string; icon: string; color: string; sort: number; form_template: FormField[]; closed?: boolean }) =>
export const upsertType = (p: { id?: number; name: string; icon: string; color: string; sort: number; form_template: FormField[]; profile?: string; closed?: boolean }) =>
call<{ item: FootprintType }>('type_upsert', p);
export const deleteType = (id: number) => call<{ ok: true }>('type_delete', { id });
+8 -1
View File
@@ -19,7 +19,14 @@ const PROFILES: Record<string, TypeProfile> = {
const DEFAULT_PROFILE: TypeProfile = { core: ['level', 'role', 'award_grade', 'organizer'] };
export function getTypeProfile(typeName?: string | null): TypeProfile {
export const PROFILE_OPTIONS = [
{ value: '', label: '通用布局(级别/角色/奖等/组织方)' },
...Object.keys(PROFILES).map(k => ({ value: k, label: k + '式布局' })),
];
/** 自定义类型可绑定一种布局(profileKey),否则按类型名匹配,最后回退通用 */
export function getTypeProfile(typeName?: string | null, profileKey?: string | null): TypeProfile {
if (profileKey && PROFILES[profileKey]) return PROFILES[profileKey];
if (!typeName) return DEFAULT_PROFILE;
return PROFILES[typeName] ?? DEFAULT_PROFILE;
}
+1
View File
@@ -20,6 +20,7 @@ export interface FootprintType {
color: string;
sort: number;
form_template: FormField[];
profile?: string | null;
is_builtin: boolean;
closed: boolean;
usage_count?: number;
+8 -1
View File
@@ -7,6 +7,7 @@ import {
Badge, Button, Card, Confirm, Dialog, Field, Input, Select, useToast
} from '@/components/ui';
import { TypeIcon, ICON_CHOICES } from '@/components/common/typeIcons';
import { PROFILE_OPTIONS } from '@/lib/typeProfiles';
const PALETTE = ['#3056d3', '#7c3aed', '#0891b2', '#0f766e', '#16a34a', '#65a30d', '#d97706', '#dc2626', '#db2777', '#64748b'];
@@ -117,6 +118,7 @@ function TypeEditor({ source, onClose, onSaved }: { source: FootprintType | null
const [sort, setSort] = useState(String(source?.sort ?? 100));
const [closed, setClosed] = useState(source?.closed ?? false);
const [fields, setFields] = useState<FormField[]>(source?.form_template ?? []);
const [profile, setProfile] = useState(source?.profile ?? '');
const [error, setError] = useState('');
const saveMut = useMutation({
@@ -137,6 +139,7 @@ function TypeEditor({ source, onClose, onSaved }: { source: FootprintType | null
icon, color,
sort: Number(sort) || 100,
form_template: fields,
profile: profile || undefined,
closed
});
},
@@ -166,6 +169,7 @@ function TypeEditor({ source, onClose, onSaved }: { source: FootprintType | null
>
<div className="flex flex-col gap-4">
<div className="grid grid-cols-[1fr_120px_100px] gap-3">
<Field label="名称" required>
<Input value={name} onChange={e => setName(e.target.value)} placeholder="如:学科竞赛" />
</Field>
@@ -225,7 +229,10 @@ function TypeEditor({ source, onClose, onSaved }: { source: FootprintType | null
</Field>
<div className="border-t border-line pt-3">
<div className="mb-2 flex items-center justify-between">
<Field label="字段布局" hint="决定录入表单的核心字段组合(新建记录时的「类型要素」)">
<Select value={profile} onChange={e => setProfile(e.target.value)} options={PROFILE_OPTIONS} />
</Field>
<div className="mb-2 mt-2 flex items-center justify-between">
<span className="text-[12px] font-semibold text-ink-2">字段模板({fields.length})</span>
<Button
size="sm"