From 5bb211afcd05c0163c50975cc5b8c849a2520337 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sat, 19 Sep 2026 15:18:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=F0=9F=90=9B:=20Preview=20now=20sets=20tab.M?= =?UTF-8?q?LTBName=20before=20rendering,=20matching=20NOActionsGen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MLTBName (table_name with underscores turned to dashes, e.g. "user_profile" -> "user-profile") is a gorm:"-" field - table.Get never fills it in, the caller has to. NOActionsGen has done so since it existed; Preview never did, so every template's import path that reads it (from '@/api/{PackageName}/{MLTBName}' in vue.go.template, present in both the pre-Vue3 template and F4's rewrite) rendered with the module segment missing - "from '@/api/admin/'" - in the preview dialog only. The real generated file was always correct. Pre-existing, not introduced by this PRD, but worth fixing now: F3/F9 added two more Preview panes (the language packs) on top of an assumption - that Preview's output stands in for what NOActionsGen actually writes - that was never true for this field. Checked the rest of gen.go for the same "only set on the write path" shape; MLTBName is the only one - every other field Preview's templates read comes straight off the sys_tables/sys_columns rows table.Get already loads. Verified with a throwaway harness driving Gen.Preview through a real gin Context and sqlite-backed db, parsing the JSON response and reading back template/vue.go.template's import line. Confirmed red first (temporarily removed the added line): "from '@/api/verify010/'". Restored it: "from '@/api/verify010/verify-widget'". --- app/other/apis/tools/gen.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/other/apis/tools/gen.go b/app/other/apis/tools/gen.go index 49bf3caa..02701620 100644 --- a/app/other/apis/tools/gen.go +++ b/app/other/apis/tools/gen.go @@ -123,6 +123,14 @@ func (e Gen) Preview(c *gin.Context) { } tab, _ := table.Get(db, false) + // MLTBName (table_name with underscores turned to dashes) is a gorm:"-" + // field - table.Get never fills it in, so every template that reads it + // (the .vue/.ts import paths, e.g. "@/api/{PackageName}/{MLTBName}") + // silently rendered it empty here. NOActionsGen has set this since it + // existed (see below); Preview never did, which is why the two paths + // are not interchangeable stand-ins for each other and should not be + // assumed to be. + tab.MLTBName = strings.Replace(tab.TBName, "_", "-", -1) // R2: infer a width for any column the config page left at colWidth's 0 // sentinel, before vue.go.template reads .ColWidth - see column_width.go. applyInferredColumnWidths(tab.Columns)