mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 05:00:25 +08:00
管理界面设置和用户界面设置可以修改时区
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user