From b854aa3bfea3b805f7d7550bad0211f7caeb2e01 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 31 May 2023 14:03:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=BB=98=E8=AE=A4=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9=20(#1200?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/init/migration/migrations/init.go | 2 +- backend/utils/common/common.go | 20 +++++++++++++++++++ .../views/container/setting/mirror/index.vue | 1 + .../container/setting/registry/index.vue | 1 + .../views/setting/panel/timezone/index.vue | 8 +++----- .../src/views/setting/safe/allowips/index.vue | 4 ++-- .../src/views/setting/safe/domain/index.vue | 11 ++++++++-- 7 files changed, 37 insertions(+), 10 deletions(-) diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index 11edc6bd6..974eac55e 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -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 { diff --git a/backend/utils/common/common.go b/backend/utils/common/common.go index 03ecdc2ec..31e2f8e85 100644 --- a/backend/utils/common/common.go +++ b/backend/utils/common/common.go @@ -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] +} diff --git a/frontend/src/views/container/setting/mirror/index.vue b/frontend/src/views/container/setting/mirror/index.vue index 5754c2a85..32246c607 100644 --- a/frontend/src/views/container/setting/mirror/index.vue +++ b/frontend/src/views/container/setting/mirror/index.vue @@ -70,6 +70,7 @@ const onSubmit = async () => { .then(() => { loading.value = false; emit('search'); + handleClose(); MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); }) .catch(() => { diff --git a/frontend/src/views/container/setting/registry/index.vue b/frontend/src/views/container/setting/registry/index.vue index 7f0e1b3f6..7e28a16fe 100644 --- a/frontend/src/views/container/setting/registry/index.vue +++ b/frontend/src/views/container/setting/registry/index.vue @@ -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')); }) diff --git a/frontend/src/views/setting/panel/timezone/index.vue b/frontend/src/views/setting/panel/timezone/index.vue index 33f9f5d69..aa5ee2db8 100644 --- a/frontend/src/views/setting/panel/timezone/index.vue +++ b/frontend/src/views/setting/panel/timezone/index.vue @@ -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; diff --git a/frontend/src/views/setting/safe/allowips/index.vue b/frontend/src/views/setting/safe/allowips/index.vue index 1f52e66c7..a01e419e4 100644 --- a/frontend/src/views/setting/safe/allowips/index.vue +++ b/frontend/src/views/setting/safe/allowips/index.vue @@ -22,7 +22,7 @@