From 3beb00143aa2aa0b12ea1116dddabe03c775b5d6 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sat, 19 Sep 2026 20:49:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B:=20give=20FK=20and=20dict=20opt?= =?UTF-8?q?ions=20separate=20variable=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A column configured with both FkTableName and DictType -- and reaching a branch of each, e.g. required + IsQuery=1 + IsInsert=1 with HtmlType=radio -- had both blocks declare `const {JsonField}Options`: the dict branch from useDict, the FK branch from ref(). TS2451, Cannot redeclare block-scoped variable, and the page does not compile. This is reachable precisely because FkTableName and DictType do not exclude each other consistently: search, list and the form's select branch check FK first and fall back to dict, but the form's radio branch never looks at FK at all -- it was already established (the $dictUsed/$fkUsed audit two commits back) that a radio column's dict options are used regardless of whatever FkTableName says. A column that is both radio and query-or-insert-select can legitimately need both sources at once, under one shared name. Renamed to {JsonField}DictOptions and {JsonField}FkOptions and updated every consuming branch to the name that matches what it was already branching on: FK branches (search select, form select, the list column's Label function) read FkOptions; dict branches (search select, form select, form radio, the list column's dictLabel call) read DictOptions. Mechanical rename, no new conditions -- each site already knew which source it wanted from its own if/else-if. Verified with team-lead's exact repro (FkTableName + DictType + IsQuery=1 + IsInsert=1 + HtmlType=radio) rendered through the real template.Execute and checked against a throwaway go-admin-ui worktree (deleted afterwards): TS2451 fired twice before this change, zero after -- and the rendered file confirms the search select actually reads kindFkOptions (FK wins search's priority) while the insert radio reads kindDictOptions (radio never checks FK), so both sources are live, not just declared. Re-ran every fixture from every previous round alongside it; all stayed green. pnpm type-check and pnpm lint both zero error, on Node 24.11.0. --- template/v4/vue.go.template | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/template/v4/vue.go.template b/template/v4/vue.go.template index 789ab16b..de42dad0 100644 --- a/template/v4/vue.go.template +++ b/template/v4/vue.go.template @@ -80,7 +80,7 @@ {{- if ne .FkTableName ""}} - + {{- else if eq .HtmlType "datetime"}} @@ -189,7 +189,7 @@ {{- if ne .FkTableName ""}} - + {{ "{{" }} dict.label {{ "}}" }} @@ -318,18 +318,18 @@ defineOptions({ name: '{{.ClassName}}Manage' }) {{- $fkUsed := and (ne .FkTableName "") (or (eq .IsQuery "1") (eq .IsList "1") (and (eq .IsInsert "1") (eq .HtmlType "select"))) -}} {{- if $dictUsed}} -const { {{.DictType}}: {{.JsonField}}Options } = useDict('{{.DictType}}') +const { {{.DictType}}: {{.JsonField}}DictOptions } = useDict('{{.DictType}}') {{- end}} {{- if $fkUsed}} -const {{.JsonField}}Options = ref<{{.FkTableNameClass}}[]>([]) +const {{.JsonField}}FkOptions = ref<{{.FkTableNameClass}}[]>([]) onMounted(async() => { const res = await list{{.FkTableNameClass}}({ pageIndex: 1, pageSize: 100 }) - {{.JsonField}}Options.value = res.data?.list ?? [] + {{.JsonField}}FkOptions.value = res.data?.list ?? [] }) {{- if eq .IsList "1"}} const {{.JsonField}}Label = (value: unknown) => - {{.JsonField}}Options.value.find(item => item.{{.FkLabelId}} === value)?.{{.FkLabelName}} ?? value + {{.JsonField}}FkOptions.value.find(item => item.{{.FkLabelId}} === value)?.{{.FkLabelName}} ?? value {{- end}} {{- end}} {{- end}}