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

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 ( import (
"encoding/json" "encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc" "github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
"github.com/iwind/TeaGo/logs" "github.com/iwind/TeaGo/logs"
"reflect" "reflect"
"time"
) )
var sharedAdminUIConfig *systemconfigs.AdminUIConfig = nil var sharedAdminUIConfig *systemconfigs.AdminUIConfig = nil
@@ -45,6 +47,9 @@ func UpdateAdminUIConfig(uiConfig *systemconfigs.AdminUIConfig) error {
} }
sharedAdminUIConfig = uiConfig sharedAdminUIConfig = uiConfig
// timezone
updateTimeZone(uiConfig)
return nil return nil
} }
@@ -76,13 +81,17 @@ func loadAdminUIConfig() (*systemconfigs.AdminUIConfig, error) {
return sharedAdminUIConfig, nil return sharedAdminUIConfig, nil
} }
config := &systemconfigs.AdminUIConfig{} var config = &systemconfigs.AdminUIConfig{}
err = json.Unmarshal(resp.ValueJSON, config) err = json.Unmarshal(resp.ValueJSON, config)
if err != nil { if err != nil {
logs.Println("[UI_MANAGER]" + err.Error()) logs.Println("[UI_MANAGER]" + err.Error())
sharedAdminUIConfig = defaultAdminUIConfig() sharedAdminUIConfig = defaultAdminUIConfig()
return sharedAdminUIConfig, nil return sharedAdminUIConfig, nil
} }
// timezone
updateTimeZone(config)
sharedAdminUIConfig = config sharedAdminUIConfig = config
return sharedAdminUIConfig, nil return sharedAdminUIConfig, nil
} }
@@ -95,5 +104,16 @@ func defaultAdminUIConfig() *systemconfigs.AdminUIConfig {
ShowVersion: true, ShowVersion: true,
ShowFinance: true, ShowFinance: true,
DefaultPageSize: 10, 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 ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders" "github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
"io" "io"
@@ -27,6 +28,15 @@ func (this *IndexAction) RunGet(params struct{}) {
} }
this.Data["config"] = config 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() this.Show()
} }
@@ -40,6 +50,7 @@ func (this *IndexAction) RunPost(params struct {
FaviconFile *actions.File FaviconFile *actions.File
LogoFile *actions.File LogoFile *actions.File
DefaultPageSize int DefaultPageSize int
TimeZone string
Must *actions.Must Must *actions.Must
CSRF *actionutils.CSRF CSRF *actionutils.CSRF
@@ -66,6 +77,7 @@ func (this *IndexAction) RunPost(params struct {
config.ShowFinance = params.ShowFinance config.ShowFinance = params.ShowFinance
config.ShowVersion = params.ShowVersion config.ShowVersion = params.ShowVersion
config.Version = params.Version config.Version = params.Version
config.TimeZone = params.TimeZone
if params.DefaultPageSize > 0 { if params.DefaultPageSize > 0 {
config.DefaultPageSize = params.DefaultPageSize config.DefaultPageSize = params.DefaultPageSize

View File

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

View File

@@ -85,6 +85,24 @@
<p class="comment">在有分页的地方每页显示数量不能超过100。</p> <p class="comment">在有分页的地方每页显示数量不能超过100。</p>
</td> </td>
</tr> </tr>
<tr>
<td>时区</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<select class="ui dropdown" v-model="timeZoneGroupCode">
<option v-for="timeZoneGroup in timeZoneGroups" :value="timeZoneGroup.code">{{timeZoneGroup.name}}</option>
</select>
</div>
<div class="ui field">
<select class="ui dropdown" name="timeZone" v-model="config.timeZone">
<option v-for="timeZoneLocation in timeZoneLocations" :value="timeZoneLocation.name" v-if="timeZoneLocation.group == timeZoneGroupCode">{{timeZoneLocation.name}} ({{timeZoneLocation.offset}})</option>
</select>
</div>
</div>
<p class="comment">显示时间使用的时区。</p>
</td>
</tr>
</table> </table>
<submit-btn></submit-btn> <submit-btn></submit-btn>

View File

@@ -1,3 +1,36 @@
Tea.context(function () { Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功") 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
}
})
})
}) })

View File

@@ -78,6 +78,29 @@
</td> </td>
</tr> </tr>
</table> </table>
<h4>其他</h4>
<table class="ui table definition selectable">
<tr>
<td class="title">时区</td>
<td>
<div class="ui fields inline">
<div class="ui field">
<select class="ui dropdown" v-model="timeZoneGroupCode">
<option v-for="timeZoneGroup in timeZoneGroups" :value="timeZoneGroup.code">{{timeZoneGroup.name}}</option>
</select>
</div>
<div class="ui field">
<select class="ui dropdown" name="timeZone" v-model="config.timeZone">
<option v-for="timeZoneLocation in timeZoneLocations" :value="timeZoneLocation.name" v-if="timeZoneLocation.group == timeZoneGroupCode">{{timeZoneLocation.name}} ({{timeZoneLocation.offset}})</option>
</select>
</div>
</div>
<p class="comment">显示时间使用的时区。</p>
</td>
</tr>
</table>
<p class="comment">修改后在3分钟内生效。</p> <p class="comment">修改后在3分钟内生效。</p>
<submit-btn></submit-btn> <submit-btn></submit-btn>

View File

@@ -1,3 +1,36 @@
Tea.context(function () { Tea.context(function () {
this.success = NotifyReloadSuccess("保存成功") 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
}
})
})
}) })