From 63205d7238e150bd978b856cce613540309255b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Wed, 14 Jan 2026 01:20:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/template.go | 14 +++++++++++++- pkg/api/template.go | 9 +++++---- web/src/views/app/TemplateDeployModal.vue | 22 ++++++---------------- web/src/views/app/types.ts | 1 + 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/internal/data/template.go b/internal/data/template.go index d4979a5d..2e4d7f73 100644 --- a/internal/data/template.go +++ b/internal/data/template.go @@ -1,6 +1,7 @@ package data import ( + "fmt" "os" "path/filepath" "regexp" @@ -36,7 +37,18 @@ func (r *templateRepo) List() (api.Templates, error) { // Get 获取模版详情 func (r *templateRepo) Get(slug string) (*api.Template, error) { - return r.api.TemplateBySlug(slug) + templates, err := r.api.Templates() + if err != nil { + return nil, err + } + + for _, t := range *templates { + if t.Slug == slug { + return t, nil + } + } + + return nil, fmt.Errorf("template %s not found", slug) } // Callback 模版下载回调 diff --git a/pkg/api/template.go b/pkg/api/template.go index 4f262c66..e0d650cd 100644 --- a/pkg/api/template.go +++ b/pkg/api/template.go @@ -16,10 +16,11 @@ type Template struct { Version string `json:"version"` Compose string `json:"compose"` Environments []struct { - Name string `json:"name"` // 变量名 - Type string `json:"type"` // 变量类型, text, password, number, port, select - Options map[string]string `json:"options,omitempty"` // 下拉框选项,key -> value - Default string `json:"default"` // 默认值 + Name string `json:"name"` // 变量名 + Description string `json:"description"` // 变量描述 + Type string `json:"type"` // 变量类型, text, password, number, port, select + Options map[string]string `json:"options,omitempty"` // 下拉框选项,key -> value + Default string `json:"default"` // 默认值 } `json:"environments"` } diff --git a/web/src/views/app/TemplateDeployModal.vue b/web/src/views/app/TemplateDeployModal.vue index 67187897..4074e742 100644 --- a/web/src/views/app/TemplateDeployModal.vue +++ b/web/src/views/app/TemplateDeployModal.vue @@ -28,7 +28,7 @@ const deployModel = reactive({ name: '', autoStart: true, autoFirewall: false, - envs: {} as Record + envs: {} as Record }) // 初始化环境变量默认值 @@ -41,19 +41,6 @@ const initEnvDefaults = () => { deployModel.envs = envs } -// 根据类型渲染环境变量输入组件 -const getEnvInputType = (env: TemplateEnvironment) => { - switch (env.type) { - case 'password': - return 'password' - case 'number': - case 'port': - return 'number' - default: - return 'text' - } -} - // 获取 select 选项 const getSelectOptions = (env: TemplateEnvironment) => { if (!env.options) return [] @@ -189,7 +176,11 @@ watch( :tab="$gettext('Environment Variables')" > - + diff --git a/web/src/views/app/types.ts b/web/src/views/app/types.ts index 9f0695f1..531d95ec 100644 --- a/web/src/views/app/types.ts +++ b/web/src/views/app/types.ts @@ -20,6 +20,7 @@ export interface Channel { export interface TemplateEnvironment { name: string + description: string type: 'text' | 'password' | 'number' | 'port' | 'select' options?: Record default: string