mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-28 15:10:25 +08:00
优化JS代码加载速度
This commit is contained in:
@@ -1,19 +1,31 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/conds/condutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/conds/condutils"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/files"
|
"github.com/iwind/TeaGo/files"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ComponentsAction actions.Action
|
type ComponentsAction actions.Action
|
||||||
|
|
||||||
|
var componentsData = []byte{}
|
||||||
|
|
||||||
func (this *ComponentsAction) RunGet(params struct{}) {
|
func (this *ComponentsAction) RunGet(params struct{}) {
|
||||||
this.AddHeader("Content-Type", "text/javascript; charset=utf-8")
|
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
|
var webRoot string
|
||||||
if Tea.IsTesting() {
|
if Tea.IsTesting() {
|
||||||
webRoot = Tea.Root + "/../web/public/js/components/"
|
webRoot = Tea.Root + "/../web/public/js/components/"
|
||||||
@@ -34,8 +46,8 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
|||||||
logs.Error(err)
|
logs.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.Write(data)
|
buffer.Write(data)
|
||||||
this.Write([]byte{'\n', '\n'})
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
})
|
})
|
||||||
|
|
||||||
// 条件组件
|
// 条件组件
|
||||||
@@ -43,8 +55,12 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Println("ComponentsAction: " + err.Error())
|
logs.Println("ComponentsAction: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
this.WriteString("window.REQUEST_COND_COMPONENTS = ")
|
buffer.WriteString("window.REQUEST_COND_COMPONENTS = ")
|
||||||
this.Write(typesJSON)
|
buffer.Write(typesJSON)
|
||||||
this.Write([]byte{'\n', '\n'})
|
buffer.Write([]byte{'\n', '\n'})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentsData = buffer.Bytes()
|
||||||
|
this.AddHeader("Content-Length", strconv.Itoa(len(componentsData)))
|
||||||
|
this.Write(componentsData)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user