diff --git a/internal/configloaders/admin_ui_config.go b/internal/configloaders/admin_ui_config.go index 8e8e68be..2834e180 100644 --- a/internal/configloaders/admin_ui_config.go +++ b/internal/configloaders/admin_ui_config.go @@ -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 + } } } diff --git a/internal/web/actions/default/settings/ui/index.go b/internal/web/actions/default/settings/ui/index.go index d858967f..24b55a60 100644 --- a/internal/web/actions/default/settings/ui/index.go +++ b/internal/web/actions/default/settings/ui/index.go @@ -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 diff --git a/internal/web/actions/default/settings/user-ui/index.go b/internal/web/actions/default/settings/user-ui/index.go index 7b0d5cbd..6ae2a9b3 100644 --- a/internal/web/actions/default/settings/user-ui/index.go +++ b/internal/web/actions/default/settings/user-ui/index.go @@ -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 { diff --git a/web/views/@default/settings/ui/index.html b/web/views/@default/settings/ui/index.html index 9d29fca5..3736f7ab 100644 --- a/web/views/@default/settings/ui/index.html +++ b/web/views/@default/settings/ui/index.html @@ -85,6 +85,24 @@

在有分页的地方每页显示数量;不能超过100。

+ + 时区 + +
+
+ +
+
+ +
+
+

显示时间使用的时区。

+ + diff --git a/web/views/@default/settings/ui/index.js b/web/views/@default/settings/ui/index.js index 295a9aaf..5d6c3f5f 100644 --- a/web/views/@default/settings/ui/index.js +++ b/web/views/@default/settings/ui/index.js @@ -1,3 +1,36 @@ Tea.context(function () { this.success = NotifyReloadSuccess("保存成功") + + // 时区 + this.timeZoneGroupCode = "asia" + if (this.timeZoneLocation != null) { + this.timeZoneGroupCode = this.timeZoneLocation.group + } + + let oldTimeZoneGroupCode = this.timeZoneGroupCode + let oldTimeZoneName = "" + if (this.timeZoneLocation != null) { + oldTimeZoneName = this.timeZoneLocation.name + } + + this.$delay(function () { + this.$watch("timeZoneGroupCode", function (groupCode) { + if (groupCode == oldTimeZoneGroupCode && oldTimeZoneName.length > 0) { + this.config.timeZone = oldTimeZoneName + return + } + let firstLocation = null + this.timeZoneLocations.forEach(function (v) { + if (firstLocation != null) { + return + } + if (v.group == groupCode) { + firstLocation = v + } + }) + if (firstLocation != null) { + this.config.timeZone = firstLocation.name + } + }) + }) }) \ No newline at end of file diff --git a/web/views/@default/settings/user-ui/index.html b/web/views/@default/settings/user-ui/index.html index 7e5a3920..e793cce8 100644 --- a/web/views/@default/settings/user-ui/index.html +++ b/web/views/@default/settings/user-ui/index.html @@ -78,6 +78,29 @@ + +

其他

+ + + + + +
时区 +
+
+ +
+
+ +
+
+

显示时间使用的时区。

+
+

修改后,在3分钟内生效。

diff --git a/web/views/@default/settings/user-ui/index.js b/web/views/@default/settings/user-ui/index.js index 295a9aaf..5d6c3f5f 100644 --- a/web/views/@default/settings/user-ui/index.js +++ b/web/views/@default/settings/user-ui/index.js @@ -1,3 +1,36 @@ Tea.context(function () { this.success = NotifyReloadSuccess("保存成功") + + // 时区 + this.timeZoneGroupCode = "asia" + if (this.timeZoneLocation != null) { + this.timeZoneGroupCode = this.timeZoneLocation.group + } + + let oldTimeZoneGroupCode = this.timeZoneGroupCode + let oldTimeZoneName = "" + if (this.timeZoneLocation != null) { + oldTimeZoneName = this.timeZoneLocation.name + } + + this.$delay(function () { + this.$watch("timeZoneGroupCode", function (groupCode) { + if (groupCode == oldTimeZoneGroupCode && oldTimeZoneName.length > 0) { + this.config.timeZone = oldTimeZoneName + return + } + let firstLocation = null + this.timeZoneLocations.forEach(function (v) { + if (firstLocation != null) { + return + } + if (v.group == groupCode) { + firstLocation = v + } + }) + if (firstLocation != null) { + this.config.timeZone = firstLocation.name + } + }) + }) }) \ No newline at end of file