fix: 系统设置部分 bug 解决

This commit is contained in:
ssongliu 2023-02-23 16:56:16 +08:00 committed by ssongliu
parent 0a20aaa3fa
commit f6cdfdc17b
5 changed files with 51 additions and 35 deletions

View File

@ -5,14 +5,14 @@ import (
"encoding/json"
"fmt"
"os"
"path"
"os/exec"
"strings"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/cloud_storage"
"github.com/1Panel-dev/1Panel/backend/utils/files"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
)
@ -205,7 +205,7 @@ func (u *BackupService) Update(req dto.BackupOperate) error {
if err != nil {
return constant.ErrRecordNotFound
}
varMap := make(map[string]string)
varMap := make(map[string]interface{})
if err := json.Unmarshal([]byte(req.Vars), &varMap); err != nil {
return err
}
@ -218,10 +218,12 @@ func (u *BackupService) Update(req dto.BackupOperate) error {
}
if backup.Type == "LOCAL" {
if dir, ok := varMap["dir"]; ok {
if err := updateBackupDir(dir); err != nil {
upMap["vars"] = backup.Vars
_ = backupRepo.Update(req.ID, upMap)
return err
if dirStr, isStr := dir.(string); isStr {
if err := updateBackupDir(dirStr); err != nil {
upMap["vars"] = backup.Vars
_ = backupRepo.Update(req.ID, upMap)
return err
}
}
}
}
@ -295,20 +297,19 @@ func loadLocalDir() (string, error) {
func updateBackupDir(dir string) error {
oldDir := global.CONF.System.Backup
fileOp := files.NewFileOp()
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
return err
}
}
global.Viper.Set("system.backup", path.Join(dir, "backup"))
if err := global.Viper.WriteConfig(); err != nil {
return err
if strings.HasSuffix(oldDir, "/") {
oldDir = oldDir[:strings.LastIndex(oldDir, "/")]
}
if err := fileOp.CopyDir(oldDir, dir); err != nil {
global.Viper.Set("system.backup", oldDir)
_ = global.Viper.WriteConfig()
return err
cmd := exec.Command("cp", "-r", oldDir+"/*", dir)
stdout, err := cmd.CombinedOutput()
if err != nil {
return errors.New(string(stdout))
}
global.CONF.System.Backup = dir
return nil
}

View File

@ -15,7 +15,11 @@
<el-tag v-else round style="margin-left: 10px">{{ $t('setting.upgrading') }}</el-tag>
</h3>
<div style="margin-top: 10px">
<el-link @click="toGithub">
<el-link @click="toDoc">
<el-icon><Document /></el-icon>
<span>{{ $t('setting.doc') }}</span>
</el-link>
<el-link @click="toGithub" style="margin-left: 15px">
<svg-icon style="font-size: 7px; margin-bottom: 3px" iconName="p-huaban88"></svg-icon>
<span style="line-height: 20px">{{ $t('setting.project') }}</span>
</el-link>
@ -23,10 +27,6 @@
<svg-icon style="font-size: 7px; margin-bottom: 3px" iconName="p-bug"></svg-icon>
<span>{{ $t('setting.issue') }}</span>
</el-link>
<el-link @click="toTalk" style="margin-left: 15px">
<svg-icon style="font-size: 7px; margin-bottom: 3px" iconName="p-taolun"></svg-icon>
<span>{{ $t('setting.chat') }}</span>
</el-link>
<el-link @click="toGithubStar" style="margin-left: 15px">
<svg-icon style="font-size: 7px; margin-bottom: 3px" iconName="p-star"></svg-icon>
<span>{{ $t('setting.star') }}</span>
@ -66,7 +66,7 @@ import 'md-editor-v3/lib/style.css';
import { ElMessageBox } from 'element-plus';
import i18n from '@/lang';
import DrawerHeader from '@/components/drawer-header/index.vue';
import { MsgInfo, MsgSuccess } from '@/utils/message';
import { MsgSuccess } from '@/utils/message';
const version = ref();
const upgradeInfo = ref();
@ -79,15 +79,15 @@ const search = async () => {
version.value = res.data.systemVersion;
};
const toDoc = () => {
window.open('https://1panel.cn/docs/', '_blank');
};
const toGithub = () => {
window.open('https://github.com/1Panel-dev/1Panel', '_blank');
};
const toIssue = () => {
window.open('https://github.com/1Panel-dev/1Panel/issues', '_blank');
};
const toTalk = () => {
window.open('https://github.com/1Panel-dev/1Panel', '_blank');
};
const toGithubStar = () => {
window.open('https://github.com/1Panel-dev/1Panel', '_blank');
};
@ -102,7 +102,7 @@ const onLoadUpgradeInfo = async () => {
.then((res) => {
loading.value = false;
if (!res.data) {
MsgInfo(i18n.global.t('setting.noUpgrade'));
MsgSuccess(i18n.global.t('setting.noUpgrade'));
return;
}
upgradeInfo.value = res.data;

View File

@ -82,14 +82,10 @@
</el-button>
</el-form-item>
<div v-if="dialogData.rowData!.type === 'SFTP'">
<el-form-item
:label="$t('setting.address')"
prop="varsJson.address"
:rules="Rules.requiredInput"
>
<el-form-item :label="$t('setting.address')" prop="varsJson.address" :rules="Rules.ip">
<el-input v-model.trim="dialogData.rowData!.varsJson['address']" />
</el-form-item>
<el-form-item :label="$t('setting.port')" prop="varsJson.port" :rules="[Rules.number]">
<el-form-item :label="$t('setting.port')" prop="varsJson.port" :rules="[Rules.port]">
<el-input-number
:min="0"
:max="65535"
@ -107,7 +103,7 @@
v-model="dialogData.rowData!.credential"
/>
</el-form-item>
<el-form-item :label="$t('setting.path')" prop="bucket">
<el-form-item :label="$t('setting.path')" prop="bucket" :rules="[Rules.requiredInput]">
<el-input v-model="dialogData.rowData!.bucket" />
</el-form-item>
</div>
@ -167,6 +163,9 @@ const acceptParams = (params: DialogProps): void => {
dialogData.value.rowData!.varsJson['endpoint'].split('://')[1];
}
}
if (dialogData.value.title === 'create' && dialogData.value.rowData!.type === 'SFTP') {
dialogData.value.rowData.varsJson['port'] = 22;
}
title.value = i18n.global.t('commons.button.' + dialogData.value.title);
drawerVisiable.value = true;
};
@ -186,6 +185,9 @@ const getBuckets = async () => {
loading.value = true;
let item = deepCopy(dialogData.value.rowData!.varsJson);
if (dialogData.value.rowData!.type === 'MINIO') {
dialogData.value.rowData!.varsJson['endpointItem'] = dialogData.value
.rowData!.varsJson['endpointItem'].replace('https://', '')
.replace('http://', '');
item['endpoint'] = endpoints.value + '://' + dialogData.value.rowData!.varsJson['endpointItem'];
item['endpointItem'] = undefined;
}
@ -211,6 +213,7 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
if (!valid) return;
if (!dialogData.value.rowData) return;
if (dialogData.value.rowData!.type === 'MINIO') {
dialogData.value.rowData!.varsJson['endpointItem'].replace('https://', '').replace('http://', '');
dialogData.value.rowData!.varsJson['endpoint'] =
endpoints.value + '://' + dialogData.value.rowData!.varsJson['endpointItem'];
dialogData.value.rowData!.varsJson['endpointItem'] = undefined;

View File

@ -105,7 +105,7 @@
>
{{ $t('commons.button.sync') }}
</el-button>
<span v-show="show">{{ count }} S</span>
<span v-show="show">{{ count }} {{ $t('setting.second') }}</span>
</template>
</el-input>
</el-form-item>
@ -129,6 +129,8 @@ import { useI18n } from 'vue-i18n';
import { useTheme } from '@/hooks/use-theme';
import { MsgError, MsgSuccess } from '@/utils/message';
import Password from '@/views/setting/panel/password/index.vue';
import router from '@/routers';
import { logOutApi } from '@/api/modules/auth';
const loading = ref(false);
const i18n = useI18n();
@ -214,7 +216,15 @@ const onSave = async (formEl: FormInstance | undefined, key: string, val: any) =
value: val + '',
};
await updateSetting(param)
.then(() => {
.then(async () => {
loading.value = false;
MsgSuccess(i18n.t('commons.msg.operationSuccess'));
if (param.key === 'UserName') {
await logOutApi();
router.push({ name: 'login', params: { code: '' } });
globalStore.setLogStatus(false);
return;
}
loading.value = false;
MsgSuccess(i18n.t('commons.msg.operationSuccess'));
search();

View File

@ -59,6 +59,7 @@ import { GlobalStore } from '@/store';
import { reactive, ref } from 'vue';
import { updatePassword } from '@/api/modules/setting';
import DrawerHeader from '@/components/drawer-header/index.vue';
import { logOutApi } from '@/api/modules/auth';
const globalStore = GlobalStore();
const passFormRef = ref<FormInstance>();
@ -113,10 +114,11 @@ const submitChangePassword = async (formEl: FormInstance | undefined) => {
}
loading.value = true;
await updatePassword({ oldPassword: passForm.oldPassword, newPassword: password })
.then(() => {
.then(async () => {
loading.value = false;
passwordVisiable.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
await logOutApi();
router.push({ name: 'login', params: { code: '' } });
globalStore.setLogStatus(false);
})