管理界面设置和用户界面设置可以修改时区

This commit is contained in:
GoEdgeLab
2022-03-26 10:23:03 +08:00
parent 5d94af5229
commit 09943a39ce
7 changed files with 152 additions and 1 deletions

View File

@@ -3,10 +3,12 @@ package configloaders
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/logs"
"reflect"
"time"
)
var sharedAdminUIConfig *systemconfigs.AdminUIConfig = nil
@@ -45,6 +47,9 @@ func UpdateAdminUIConfig(uiConfig *systemconfigs.AdminUIConfig) error {
}
sharedAdminUIConfig = uiConfig
// timezone
updateTimeZone(uiConfig)
return nil
}
@@ -76,13 +81,17 @@ func loadAdminUIConfig() (*systemconfigs.AdminUIConfig, error) {
return sharedAdminUIConfig, nil
}
config := &systemconfigs.AdminUIConfig{}
var config = &systemconfigs.AdminUIConfig{}
err = json.Unmarshal(resp.ValueJSON, config)
if err != nil {
logs.Println("[UI_MANAGER]" + err.Error())
sharedAdminUIConfig = defaultAdminUIConfig()
return sharedAdminUIConfig, nil
}
// timezone
updateTimeZone(config)
sharedAdminUIConfig = config
return sharedAdminUIConfig, nil
}
@@ -95,5 +104,16 @@ func defaultAdminUIConfig() *systemconfigs.AdminUIConfig {
ShowVersion: true,
ShowFinance: true,
DefaultPageSize: 10,
TimeZone: nodeconfigs.DefaultTimeZoneLocation,
}
}
// 修改时区
func updateTimeZone(config *systemconfigs.AdminUIConfig) {
if len(config.TimeZone) > 0 {
location, err := time.LoadLocation(config.TimeZone)
if err == nil && time.Local != location {
time.Local = location
}
}
}

View File

@@ -3,6 +3,7 @@ package ui
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"io"
@@ -27,6 +28,15 @@ func (this *IndexAction) RunGet(params struct{}) {
}
this.Data["config"] = config
// 时区
this.Data["timeZoneGroups"] = nodeconfigs.FindAllTimeZoneGroups()
this.Data["timeZoneLocations"] = nodeconfigs.FindAllTimeZoneLocations()
if len(config.TimeZone) == 0 {
config.TimeZone = nodeconfigs.DefaultTimeZoneLocation
}
this.Data["timeZoneLocation"] = nodeconfigs.FindTimeZoneLocation(config.TimeZone)
this.Show()
}
@@ -40,6 +50,7 @@ func (this *IndexAction) RunPost(params struct {
FaviconFile *actions.File
LogoFile *actions.File
DefaultPageSize int
TimeZone string
Must *actions.Must
CSRF *actionutils.CSRF
@@ -66,6 +77,7 @@ func (this *IndexAction) RunPost(params struct {
config.ShowFinance = params.ShowFinance
config.ShowVersion = params.ShowVersion
config.Version = params.Version
config.TimeZone = params.TimeZone
if params.DefaultPageSize > 0 {
config.DefaultPageSize = params.DefaultPageSize

View File

@@ -3,6 +3,7 @@ package userui
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"io"
@@ -24,6 +25,15 @@ func (this *IndexAction) RunGet(params struct{}) {
}
this.Data["config"] = config
// 时区
this.Data["timeZoneGroups"] = nodeconfigs.FindAllTimeZoneGroups()
this.Data["timeZoneLocations"] = nodeconfigs.FindAllTimeZoneLocations()
if len(config.TimeZone) == 0 {
config.TimeZone = nodeconfigs.DefaultTimeZoneLocation
}
this.Data["timeZoneLocation"] = nodeconfigs.FindTimeZoneLocation(config.TimeZone)
this.Show()
}
@@ -36,6 +46,7 @@ func (this *IndexAction) RunPost(params struct {
ShowFinance bool
FaviconFile *actions.File
LogoFile *actions.File
TimeZone string
Must *actions.Must
CSRF *actionutils.CSRF
@@ -57,6 +68,7 @@ func (this *IndexAction) RunPost(params struct {
config.ShowVersion = params.ShowVersion
config.Version = params.Version
config.ShowFinance = params.ShowFinance
config.TimeZone = params.TimeZone
// 上传Favicon文件
if params.FaviconFile != nil {