From 30bcb57f41298b8f8028cff1184a6e01cbdc5089 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sat, 19 Sep 2026 15:21:30 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B:=20put=20the=20rules=20computed?= =?UTF-8?q?'s=20comma=20at=20the=20end=20of=20the=20previous=20line?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- template/v4/vue.go.template | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/template/v4/vue.go.template b/template/v4/vue.go.template index c2c56c9f..72da9422 100644 --- a/template/v4/vue.go.template +++ b/template/v4/vue.go.template @@ -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(() => ({ - {{- $rFirst := true}} +const rules = computed(() => ({ {{$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}} }))