JSONEditor.js
19.8 KB
-
🐛 fix(model, web): robust JSON handling; remove datatypes dep; stabilize JSONEditor manual mode · 70719d4a- Why: - Eliminate `gorm.io/datatypes` for a single field and fix scan errors when drivers return JSON as string. - Prevent JSONEditor manual mode from locking on invalid JSON and from appending stray characters after “Fill Template”. - What: - Backend (`model/prefill_group.go`): - Replaced `datatypes.JSON` with `JSONValue` (based on `json.RawMessage`) for `PrefillGroup.Items`. - Implemented `sql.Scanner` and `driver.Valuer` to accept both `[]byte` and `string`. - Implemented `MarshalJSON`/`UnmarshalJSON` to preserve raw JSON in API without base64. - Converted comments to Chinese. - Frontend (`web/src/components/common/ui/JSONEditor.js`): - Added `manualText` buffer for manual mode to avoid input being overridden by external value. - Only propagate `onChange` when manual text is valid JSON; otherwise show error but do not block typing. - Safe manual-mode rendering: derive rows from `manualText` and avoid calling `split` on non-strings. - Improved mode toggle: populate `manualText` from visual data; validate before switching back to visual. - Fixed “Fill Template” to sync `manualText`, `jsonData`, and `onChange` to avoid stray trailing characters. - Impact: - Resolves: “unsupported Scan, storing driver.Value type string into type *json.RawMessage”. - Resolves: `value.split is not a function` in manual mode. - Resolves: extra `s` appended after inserting template. - API shape and DB column type remain the same (`gorm:"type:json"`); no `go.mod` changes. - Lints pass for modified files. Files changed: - model/prefill_group.go - web/src/components/common/ui/JSONEditor.jst0ng7u committed