add api key

This commit is contained in:
xie7654
2025-07-10 16:24:33 +08:00
parent 65bdda6377
commit c6e41c92ee
7 changed files with 112 additions and 78 deletions

View File

@@ -164,12 +164,23 @@ class Command(BaseCommand):
field_config = self.generate_form_field(field)
if field_config:
form_fields.append(field_config)
# useGridFormSchema
grid_form_fields = []
for field in business_fields:
if field.name in ['id']:
continue
field_config = self.generate_grid_form_field(field)
if field_config:
grid_form_fields.append(field_config)
# 生成 useColumns
columns = []
for field in business_fields + core_fields:
columns.append(f" {{\n field: '{field.name}',\n title: '{getattr(field, 'verbose_name', field.name)}',\n }},")
context = get_context(app_name, model_name, model, model_name_snake)
context['form_fields'] = '\n'.join(form_fields)
context['grid_form_fields'] = '\n'.join(grid_form_fields)
context['columns'] = '\n'.join(columns)
data_path = f'../web/apps/web-antd/src/views/{app_name.lower()}/{model_name_snake}/data.ts'
data_code = render_tpl('frontend_data.ts.tpl', context)
@@ -219,4 +230,16 @@ class Command(BaseCommand):
elif isinstance(field, models.BooleanField):
return f''' {{\n component: 'RadioGroup',\n componentProps: {{\n buttonStyle: 'solid',\n options: [\n {{ label: '开启', value: 1 }},\n {{ label: '关闭', value: 0 }},\n ],\n optionType: 'button',\n }},\n defaultValue: 1,\n fieldName: '{field_name}',\n label: '{field_label}',\n }},'''
else:
return f''' {{\n component: 'Input',\n fieldName: '{field_name}',\n label: '{field_label}',\n }},'''
return f''' {{\n component: 'Input',\n fieldName: '{field_name}',\n label: '{field_label}',\n }},'''
def generate_grid_form_field(self, field):
field_name = field.name
field_label = getattr(field, 'verbose_name', field_name)
# 查询表单一般只需要 component/fieldName/label不需要 rules
if isinstance(field, models.CharField):
return f''' {{\n component: 'Input',\n fieldName: '{field_name}',\n label: '{field_label}',\n }},'''
elif isinstance(field, models.IntegerField):
return f''' {{\n component: 'InputNumber',\n fieldName: '{field_name}',\n label: '{field_label}',\n }},'''
# 其他类型同理
else:
return f''' {{\n component: 'Input',\n fieldName: '{field_name}',\n label: '{field_label}',\n }},'''

View File

@@ -23,7 +23,7 @@ ${form_fields}
*/
export function useGridFormSchema(): VbenFormSchema[] {
return [
${form_fields}
${grid_form_fields}
];
}

View File

@@ -20,8 +20,8 @@ const formModel = new ${app_name_camel}${model_name}Model();
const formData = ref<${app_name_camel}${model_name}Api.${app_name_camel}${model_name}>();
const getTitle = computed(() => {
return formData.value?.id
? $$t('ui.actionTitle.edit', [$$t('${app_name}.${model_name_lower}.name')])
: $$t('ui.actionTitle.create', [$$t('${app_name}.${model_name_lower}.name')]);
? $$t('ui.actionTitle.edit', [$$t('${app_name}.${model_name_snake}.name')])
: $$t('ui.actionTitle.create', [$$t('${app_name}.${model_name_snake}.name')]);
});
const [Form, formApi] = useVbenForm({