mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-23 02:40:56 +00:00
fix🐛: give FK and dict options separate variable names
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.
This commit is contained in:
+10
-10
@@ -80,7 +80,7 @@
|
||||
{{- if ne .FkTableName ""}}
|
||||
<el-select v-model="table.query.{{.JsonField}}" clearable :placeholder="$t('common.selectPlaceholder')">
|
||||
<el-option
|
||||
v-for="item in {{.JsonField}}Options"
|
||||
v-for="item in {{.JsonField}}FkOptions"
|
||||
:key="item.{{.FkLabelId}}"
|
||||
:label="item.{{.FkLabelName}}"
|
||||
:value="item.{{.FkLabelId}}"
|
||||
@@ -89,7 +89,7 @@
|
||||
{{- else if ne .DictType ""}}
|
||||
<el-select v-model="table.query.{{.JsonField}}" clearable :placeholder="$t('common.selectPlaceholder')">
|
||||
<el-option
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
v-for="dict in {{.JsonField}}DictOptions"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
@@ -136,7 +136,7 @@
|
||||
{{- else if ne .DictType ""}}
|
||||
|
||||
<el-table-column :label="$t('{{$key}}')" min-width="{{if .ColWidth}}{{.ColWidth}}{{else}}120{{end}}">
|
||||
<template #default="{ row }">{{ "{{" }} dictLabel({{.JsonField}}Options, row.{{.JsonField}}) {{ "}}" }}</template>
|
||||
<template #default="{ row }">{{ "{{" }} dictLabel({{.JsonField}}DictOptions, row.{{.JsonField}}) {{ "}}" }}</template>
|
||||
</el-table-column>
|
||||
{{- else if eq .HtmlType "datetime"}}
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
{{- if ne .FkTableName ""}}
|
||||
<el-select v-model="form.model.{{.JsonField}}" :placeholder="$t('common.selectPlaceholder')">
|
||||
<el-option
|
||||
v-for="item in {{.JsonField}}Options"
|
||||
v-for="item in {{.JsonField}}FkOptions"
|
||||
:key="item.{{.FkLabelId}}"
|
||||
:label="item.{{.FkLabelName}}"
|
||||
:value="item.{{.FkLabelId}}"
|
||||
@@ -198,7 +198,7 @@
|
||||
{{- else if ne .DictType ""}}
|
||||
<el-select v-model="form.model.{{.JsonField}}" :placeholder="$t('common.selectPlaceholder')">
|
||||
<el-option
|
||||
v-for="dict in {{.JsonField}}Options"
|
||||
v-for="dict in {{.JsonField}}DictOptions"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
@@ -210,7 +210,7 @@
|
||||
{{- else if eq .HtmlType "radio"}}
|
||||
{{- if ne .DictType ""}}
|
||||
<el-radio-group v-model="form.model.{{.JsonField}}">
|
||||
<el-radio v-for="dict in {{.JsonField}}Options" :key="dict.value" :value="dict.value">
|
||||
<el-radio v-for="dict in {{.JsonField}}DictOptions" :key="dict.value" :value="dict.value">
|
||||
{{ "{{" }} dict.label {{ "}}" }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
@@ -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}}
|
||||
|
||||
Reference in New Issue
Block a user