From 2642d0959d88dd028c665b80fe0b727ef80a204c Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sun, 27 Sep 2026 16:07:10 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B:=20leave=20the=20form=20out=20o?= =?UTF-8?q?f=20a=20generated=20page=20with=20nothing=20to=20enter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A table whose columns are all its key and ones the framework fills in got an add button and an edit link opening an empty form. The page now leaves out both, the dialog, useForm and the API calls only the form used. A page with anything to enter is generated byte for byte as before. --- .../apis/tools/gen_audit_columns_test.go | 36 +++++++++++++++++++ template/v4/vue.go.template | 32 +++++++++++------ 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/app/other/apis/tools/gen_audit_columns_test.go b/app/other/apis/tools/gen_audit_columns_test.go index 018f8a41..4a34ac9c 100644 --- a/app/other/apis/tools/gen_audit_columns_test.go +++ b/app/other/apis/tools/gen_audit_columns_test.go @@ -200,6 +200,42 @@ func TestAuditTimestampsCanBeListedAndQueried(t *testing.T) { } } +// A table whose only columns are its key and the ones the framework fills in +// leaves the create/edit dialog nothing to show. The page used to render it +// anyway: an add button and an edit link opening an empty form. +func TestAPageWithNothingToEnterHasNoForm(t *testing.T) { + g := newGenEnv(t) + const table = "gau_stamp" + tableID := g.importTable(t, table, `id int NOT NULL AUTO_INCREMENT PRIMARY KEY, + create_by bigint NULL, + update_by bigint NULL, + created_at datetime(3) NULL, + updated_at datetime(3) NULL, + deleted_at bigint NOT NULL DEFAULT 0`) + + if code := callHandler(t, g.db, Gen{}.GenCode, "/", tableID); code != http.StatusOK { + t.Fatalf("generation failed with response code %d", code) + } + vue := g.page(t, table) + for _, unwanted := range []string{" @@ -112,9 +120,11 @@ {{- end}} + {{- if $hasForm}} + {{- end}} @@ -273,18 +287,14 @@ import ProTable from '@/components/ProTable/index.vue' {{- if $hasDatetime}} import DateCell from '@/components/DateCell/index.vue' {{- end}} -{{- if $hasDict}} -{{- if $hasDictList}} -import { useTable, useForm, useRemove, useDict, dictLabel } from '@/composables' -{{- else}} -import { useTable, useForm, useRemove, useDict } from '@/composables' -{{- end}} -{{- else}} -import { useTable, useForm, useRemove } from '@/composables' -{{- end}} +import { useTable{{if $hasForm}}, useForm{{end}}, useRemove{{if $hasDict}}, useDict{{if $hasDictList}}, dictLabel{{end}}{{end}} } from '@/composables' +{{- if $hasForm}} import { add{{.ClassName}}, del{{.ClassName}}, get{{.ClassName}}, list{{.ClassName}}, update{{.ClassName}} } from '@/api/{{.PackageName}}/{{.MLTBName}}' +{{- else}} +import { del{{.ClassName}}, list{{.ClassName}} } from '@/api/{{.PackageName}}/{{.MLTBName}}' +{{- end}} import type { {{.ClassName}}, {{.ClassName}}Query } from '@/api/{{.PackageName}}/{{.MLTBName}}' {{- /* Two columns pointing at the same foreign table must not import it twice -- @@ -386,6 +396,7 @@ const rules = computed(() => ({ {{$rFirst := true}} {{- end}} })) {{- end}} +{{- if $hasForm}} const form = useForm<{{.ClassName}}, {{$pkType}}>({ defaultModel: () => ({{"{"}} {{.PkJsonField}}: undefined{{range .Columns}}{{if and (eq .IsInsert "1") (not .Pk) (ne .GoField "CreatedAt") (ne .GoField "UpdatedAt") (ne .GoField "DeletedAt") (ne .GoField "UpdateBy") (ne .GoField "CreateBy")}}, {{.JsonField}}: {{if eq .DefaultValue ""}}undefined{{else if eq .GoType "int"}}{{.DefaultValue}}{{else}}'{{js .DefaultValue}}'{{end}}{{end}}{{end}} {{"}"}}), @@ -396,6 +407,7 @@ const form = useForm<{{.ClassName}}, {{$pkType}}>({ api: { get: get{{.ClassName}}, add: add{{.ClassName}}, update: update{{.ClassName}} }, onSuccess: () => table.getList() }) +{{- end}} const { remove } = useRemove({ api: del{{.ClassName}},