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