From 4dc39657861b8262e8d20062c82f6f0ee36ecc2f Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 28 Jan 2021 17:04:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96JS=E4=BB=A3=E7=A0=81=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/web/actions/default/ui/components.go | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/internal/web/actions/default/ui/components.go b/internal/web/actions/default/ui/components.go index a135ff38..8e7ca944 100644 --- a/internal/web/actions/default/ui/components.go +++ b/internal/web/actions/default/ui/components.go @@ -1,19 +1,31 @@ package ui import ( + "bytes" "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/conds/condutils" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/files" "github.com/iwind/TeaGo/logs" + "strconv" ) type ComponentsAction actions.Action +var componentsData = []byte{} + func (this *ComponentsAction) RunGet(params struct{}) { this.AddHeader("Content-Type", "text/javascript; charset=utf-8") + if !Tea.IsTesting() && len(componentsData) > 0 { + this.AddHeader("Content-Length", strconv.Itoa(len(componentsData))) + this.Write(componentsData) + return + } + + var buffer = bytes.NewBuffer([]byte{}) + var webRoot string if Tea.IsTesting() { webRoot = Tea.Root + "/../web/public/js/components/" @@ -34,8 +46,8 @@ func (this *ComponentsAction) RunGet(params struct{}) { logs.Error(err) return } - this.Write(data) - this.Write([]byte{'\n', '\n'}) + buffer.Write(data) + buffer.Write([]byte{'\n', '\n'}) }) // 条件组件 @@ -43,8 +55,12 @@ func (this *ComponentsAction) RunGet(params struct{}) { if err != nil { logs.Println("ComponentsAction: " + err.Error()) } else { - this.WriteString("window.REQUEST_COND_COMPONENTS = ") - this.Write(typesJSON) - this.Write([]byte{'\n', '\n'}) + buffer.WriteString("window.REQUEST_COND_COMPONENTS = ") + buffer.Write(typesJSON) + buffer.Write([]byte{'\n', '\n'}) } + + componentsData = buffer.Bytes() + this.AddHeader("Content-Length", strconv.Itoa(len(componentsData))) + this.Write(componentsData) }