fix: 默认时区获取方式修改 (#1200)

This commit is contained in:
ssongliu 2023-05-31 14:03:04 +08:00 committed by GitHub
parent 8dfba82a70
commit b854aa3bfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 10 deletions

View file

@ -345,7 +345,7 @@ var AddBindAndAllowIPs = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "AllowIPs", Value: ""}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "TimeZone", Value: common.LoadTimeZone()}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "TimeZone", Value: common.LoadTimeZoneByCmd()}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "NtpSite", Value: "pool.ntp.org"}).Error; err != nil {

View file

@ -12,6 +12,8 @@ import (
"strconv"
"strings"
"time"
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
)
func CompareVersion(version1 string, version2 string) bool {
@ -153,3 +155,21 @@ func LoadTimeZone() string {
}
return loc.String()
}
func LoadTimeZoneByCmd() string {
loc := time.Now().Location().String()
if _, err := time.LoadLocation(loc); err != nil {
loc = "Asia/Shanghai"
}
std, err := cmd.Exec("timedatectl | grep 'Time zone'")
if err != nil {
return loc
}
fields := strings.Fields(string(std))
if len(fields) != 5 {
return loc
}
if _, err := time.LoadLocation(fields[2]); err != nil {
return loc
}
return fields[2]
}

View file

@ -70,6 +70,7 @@ const onSubmit = async () => {
.then(() => {
loading.value = false;
emit('search');
handleClose();
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
})
.catch(() => {

View file

@ -69,6 +69,7 @@ const onSubmit = async () => {
await updateDaemonJson('Registries', registries.value.replaceAll('\n', ','))
.then(() => {
loading.value = false;
handleClose();
emit('search');
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
})

View file

@ -67,7 +67,6 @@ import { MsgSuccess } from '@/utils/message';
import { loadTimeZone, updateSetting } from '@/api/modules/setting';
import { ElMessageBox, FormInstance } from 'element-plus';
import { Rules } from '@/global/form-rules';
import router from '@/routers';
import { GlobalStore } from '@/store';
import DrawerHeader from '@/components/drawer-header/index.vue';
const globalStore = GlobalStore();
@ -112,11 +111,10 @@ const onSave = async (formEl: FormInstance | undefined) => {
await updateSetting({ key: 'TimeZone', value: form.timeZone })
.then(async () => {
loading.value = false;
router.push({ name: 'entrance', params: { code: globalStore.entrance } });
globalStore.setLogStatus(false);
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
drawerVisiable.value = false;
return;
globalStore.isLogin = false;
let href = window.location.href;
window.open(href, '_self');
})
.catch(() => {
loading.value = false;

View file

@ -22,7 +22,7 @@
<template #footer>
<span class="dialog-footer">
<el-button @click="drawerVisiable = false">{{ $t('commons.button.cancel') }}</el-button>
<el-button :disabled="loading" type="primary" @click="onSavePort()">
<el-button :disabled="loading" type="primary" @click="onSave()">
{{ $t('commons.button.confirm') }}
</el-button>
</span>
@ -53,7 +53,7 @@ const acceptParams = (params: DialogProps): void => {
drawerVisiable.value = true;
};
const onSavePort = async () => {
const onSave = async () => {
if (allowIPs.value) {
let ips = allowIPs.value.split('\n');
for (const ip of ips) {

View file

@ -87,8 +87,15 @@ const onSavePort = async (formEl: FormInstance | undefined) => {
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
emit('search');
handleClose();
if (form.bindDomain) {
let href = window.location.href;
let ipLocal = href.split('//')[1].split(':')[0];
href = href.replaceAll(ipLocal, form.bindDomain);
window.open(href, '_self');
} else {
handleClose();
emit('search');
}
})
.catch(() => {
loading.value = false;