fix🐛: put the rules computed's comma at the end of the previous line

The rules block joined entries with a $first-flag comma the same way
defaultQuery and defaultModel do, but on its own line rather than all
on one -- so the comma for every entry but the first sat at the start
of its line instead of the end of the one before it. @stylistic/comma-style
requires the opposite, and pnpm lint fails on any table with two or
more required insert fields (one comma is enough to trip it; a table
with 0-1 required fields never renders a second entry to get it wrong).
Reproduced first: rendering a four-required-field fixture reported
three comma-style errors, matching what integration testing found on
qa010_widget and qa010_natural.

Fixed by moving the separator so it trails the previous entry instead
of leading the next one: the else branch now emits ",\n  " -- comma,
then the newline and indent -- rather than "\n  , ", so the comma lands
on the line that already has content instead of opening a fresh one.

Also fixed while reproducing, found by the same fixture: dictLabel was
imported whenever any column had a DictType, but it is only called from
the list column's dictionary branch. A table using a dictionary solely
in its insert form (no such column in the list) imported dictLabel and
never called it, tripping no-unused-vars. $hasDict now only gates
useDict; a new $hasDictList gates dictLabel specifically.

Verified against three fixtures via a throwaway go-admin-ui worktree
(deleted afterwards) with hand-written API-module stubs standing in for
F5: the regression fixture (four required fields, confirmed red before
the fix, green after), and the two fixtures from the original F4
verification round (full branch coverage, and the all-flags-off edge
case), all of which stayed green. pnpm type-check and pnpm lint both
ran clean with zero errors, on Node 24.11.0 (this machine's default
node is 20.19.0; the project's engines field wants >=22).
This commit is contained in:
zhangwenjian
2026-09-19 15:21:30 +08:00
parent 0f31feae6f
commit 30bcb57f41
+9 -3
View File
@@ -36,6 +36,7 @@
anything outside itself.
*/ -}}
{{- $hasDict := false -}}
{{- $hasDictList := false -}}
{{- $hasFk := false -}}
{{- $hasDatetime := false -}}
{{- $hasRules := false -}}
@@ -43,6 +44,7 @@
{{- $pkType := "number" -}}
{{- range .Columns -}}
{{- if ne .DictType "" }}{{$hasDict = true}}{{end -}}
{{- if and (eq .IsList "1") (eq .FkTableName "") (ne .DictType "") }}{{$hasDictList = true}}{{end -}}
{{- if ne .FkTableName "" }}{{$hasFk = true}}{{end -}}
{{- if eq .HtmlType "datetime" }}{{$hasDatetime = true}}{{end -}}
{{- if eq .IsQuery "1" }}{{$hasQuery = true}}{{end -}}
@@ -242,8 +244,12 @@ import ProTable from '@/components/ProTable/index.vue'
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 {
@@ -313,12 +319,12 @@ const { t } = useI18n()
directly under the labelled field it failed to validate.
*/}}
const rules = computed<FormRules>(() => ({
{{- $rFirst := true}}
const rules = computed<FormRules>(() => ({ {{$rFirst := true}}
{{- range .Columns}}
{{- if and (eq .IsInsert "1") (eq .IsRequired "1") (not .Pk) (ne .GoField "CreatedAt") (ne .GoField "UpdatedAt") (ne .GoField "DeletedAt") (ne .GoField "UpdateBy") (ne .GoField "CreateBy")}}
{{- $key := printf "gen.%s.%s.%s" $package $business .JsonField}}
{{if $rFirst}}{{$rFirst = false}}{{else}}, {{end}}{{.JsonField}}: [{ required: true, message: t('{{$key}}'), trigger: '{{if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "datetime") (eq .HtmlType "checkbox")}}change{{else}}blur{{end}}' }]
{{- if $rFirst}}{{$rFirst = false}}{{else}},
{{end}}{{.JsonField}}: [{ required: true, message: t('{{$key}}'), trigger: '{{if or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "datetime") (eq .HtmlType "checkbox")}}change{{else}}blur{{end}}' }]
{{- end}}
{{- end}}
}))