1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: redis 数据库样式调整,表单拆分

This commit is contained in:
ssongliu 2022-12-20 18:59:26 +08:00 committed by ssongliu
parent 6dedb87349
commit 8bbc286f43
12 changed files with 256 additions and 174 deletions

View File

@ -128,10 +128,9 @@ type UploadRecover struct {
// redis
type RedisConfUpdate struct {
Timeout string `json:"timeout"`
Maxclients string `json:"maxclients"`
Requirepass string `json:"requirepass"`
Maxmemory string `json:"maxmemory"`
Timeout string `json:"timeout"`
Maxclients string `json:"maxclients"`
Maxmemory string `json:"maxmemory"`
}
type RedisConfPersistenceUpdate struct {
Type string `json:"type" validate:"required,oneof=aof rbd"`

View File

@ -40,7 +40,7 @@ func (s *DatabaseRouter) InitDatabaseRouter(Router *gin.RouterGroup) {
cmdRouter.POST("/redis/password", baseApi.ChangeRedisPassword)
cmdRouter.POST("/redis/backup", baseApi.RedisBackup)
cmdRouter.POST("/redis/recover", baseApi.RedisRecover)
cmdRouter.POST("/redis/backuplist/search", baseApi.RedisBackupList)
cmdRouter.POST("/redis/backup/search", baseApi.RedisBackupList)
cmdRouter.POST("/redis/conf/update", baseApi.UpdateRedisConf)
cmdRouter.POST("/redis/conffile/update", baseApi.UpdateRedisConfByFile)
cmdRouter.POST("/redis/persistence/update", baseApi.UpdateRedisPersistenceConf)

View File

@ -120,7 +120,6 @@ export namespace Database {
export interface RedisConfUpdate {
timeout: string;
maxclients: string;
requirepass: string;
maxmemory: string;
}
export interface RedisConfPersistenceUpdate {

View File

@ -83,5 +83,5 @@ export const recoverRedis = (param: Database.RedisRecover) => {
return http.post(`/databases/redis/recover`, param);
};
export const redisBackupRedisRecords = (param: ReqPage) => {
return http.post<ResPage<Database.FileRecord>>(`/databases/redis/backup/records`, param);
return http.post<ResPage<Database.FileRecord>>(`/databases/redis/backup/search`, param);
};

View File

@ -132,6 +132,9 @@ export default {
changePassword: 'Change Password',
logout: 'Logout',
},
service: {
serviceNotStarted: 'The {0} service is not currently started',
},
status: {
running: 'running',
stopped: 'stopped',

View File

@ -134,6 +134,9 @@ export default {
changePassword: '修改密码',
logout: '退出登录',
},
service: {
serviceNotStarted: '当前未启动 {0} 服务',
},
status: {
running: '已启动',
success: '成功',

View File

@ -11,11 +11,7 @@
<Setting ref="settingRef" style="margin-top: 20px" />
<el-card width="30%" v-if="mysqlStatus != 'Running' && !isOnSetting && mysqlIsExist" class="mask-prompt">
<span style="font-size: 14px">{{ $t('database.mysqlBadStatus') }}</span>
<el-button type="primary" link style="font-size: 14px; margin-bottom: 5px" @click="onSetting">
{{ $t('database.setting') }}
</el-button>
<span style="font-size: 14px">{{ $t('database.adjust') }}</span>
<span style="font-size: 14px">{{ $t('commons.service.serviceNotStarted', ['Mysql']) }}</span>
</el-card>
<div v-if="mysqlIsExist" :class="{ mask: mysqlStatus != 'Running' }">
<el-card v-if="!isOnSetting" style="margin-top: 20px">

View File

@ -78,7 +78,7 @@ import Status from '@/views/database/mysql/setting/status/index.vue';
import Variables from '@/views/database/mysql/setting/variables/index.vue';
import SlowLog from '@/views/database/mysql/setting/slow-log/index.vue';
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
import { onUnmounted, reactive, ref } from 'vue';
import { reactive, ref } from 'vue';
import { Codemirror } from 'vue-codemirror';
import { javascript } from '@codemirror/lang-javascript';
import { oneDark } from '@codemirror/theme-one-dark';
@ -239,10 +239,6 @@ const loadMysqlConf = async (path: string) => {
mysqlConf.value = res.data;
};
onUnmounted(() => {
console.log('adasd');
});
defineExpose({
acceptParams,
onClose,

View File

@ -10,24 +10,22 @@
@is-exist="checkExist"
v-model:loading="loading"
></AppStatus>
<el-button style="margin-top: 20px" type="primary" plain @click="goDashboard" icon="Position">
Redis-Commander
</el-button>
<Setting ref="settingRef" style="margin-top: 10px" />
<el-card width="30%" v-if="redisStatus != 'Running' && !isOnSetting && redisIsExist" class="mask-prompt">
<span style="font-size: 14px">{{ $t('database.mysqlBadStatus') }}</span>
<el-button type="primary" link style="font-size: 14px; margin-bottom: 5px" @click="onSetting">
{{ $t('database.setting') }}
</el-button>
<span style="font-size: 14px">{{ $t('database.adjust') }}</span>
<span style="font-size: 14px">{{ $t('commons.service.serviceNotStarted', ['Redis']) }}</span>
</el-card>
<div v-show="redisIsExist" :class="{ mask: redisStatus != 'Running' }">
<Terminal style="margin-top: 10px" ref="terminalRef" />
<el-button style="margin-top: 20px" type="primary" plain @click="goDashboard" icon="Position">
Redis-Commander
</el-button>
<el-button style="margin-top: 20px" type="primary" plain @click="onChangePassword">
{{ $t('database.changePassword') }}
</el-button>
<Terminal :key="isRefresh" style="margin-top: 10px" ref="terminalRef" />
</div>
<Setting ref="settingRef" style="margin-top: 10px" />
<Password ref="passwordRef" @check-exist="initTerminal" @close-terminal="closeTerminal(true)" />
<el-dialog
v-model="commandVisiable"
:title="$t('app.checkTitle')"
@ -52,6 +50,7 @@
<script lang="ts" setup>
import Submenu from '@/views/database/index.vue';
import Setting from '@/views/database/redis/setting/index.vue';
import Password from '@/views/database/redis/password/index.vue';
import Terminal from '@/views/database/redis/terminal/index.vue';
import AppStatus from '@/components/app-status/index.vue';
import { ref } from 'vue';
@ -66,14 +65,17 @@ const settingRef = ref();
const isOnSetting = ref(false);
const redisIsExist = ref(false);
const redisStatus = ref();
const redisName = ref();
const redisCommandPort = ref();
const commandVisiable = ref(false);
const isRefresh = ref();
const onSetting = async () => {
isOnSetting.value = true;
terminalRef.value.onClose();
settingRef.value!.acceptParams({ status: redisStatus.value });
terminalRef.value.onClose(false);
settingRef.value!.acceptParams({ status: redisStatus.value, redisName: redisName.value });
};
const goRouter = async (path: string) => {
@ -95,8 +97,14 @@ const loadDashboardPort = async () => {
redisCommandPort.value = res.data;
};
const passwordRef = ref();
const onChangePassword = async () => {
passwordRef.value!.acceptParams();
};
const checkExist = (data: App.CheckInstalled) => {
redisIsExist.value = data.isExist;
redisName.value = data.name;
redisStatus.value = data.status;
loading.value = false;
if (redisStatus.value === 'Running') {
@ -105,8 +113,18 @@ const checkExist = (data: App.CheckInstalled) => {
}
};
const initTerminal = async () => {
if (redisStatus.value === 'Running') {
terminalRef.value.acceptParams();
}
};
const closeTerminal = async (isKeepShow: boolean) => {
isRefresh.value = !isRefresh.value;
terminalRef.value!.onClose(isKeepShow);
};
const onBefore = () => {
terminalRef.value!.onClose();
closeTerminal(true);
loading.value = true;
};
</script>

View File

@ -0,0 +1,89 @@
<template>
<el-dialog v-model="dialogVisiable" :destroy-on-close="true" :close-on-click-modal="false" width="30%">
<template #header>
<div class="card-header">
<span>{{ $t('database.requirepass') }}</span>
</div>
</template>
<el-form v-loading="loading" ref="formRef" :model="form" label-width="80px">
<el-form-item :label="$t('database.requirepass')" :rules="Rules.requiredInput" prop="password">
<el-input type="password" show-password clearable v-model="form.password" />
</el-form-item>
</el-form>
<ConfirmDialog ref="confirmDialogRef" @confirm="onSubmit"></ConfirmDialog>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisiable = false">{{ $t('commons.button.cancel') }}</el-button>
<el-button type="primary" @click="onSave(formRef)">
{{ $t('commons.button.confirm') }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { Rules } from '@/global/form-rules';
import i18n from '@/lang';
import { ElForm, ElMessage } from 'element-plus';
import { changeRedisPassword } from '@/api/modules/database';
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
const loading = ref(false);
const dialogVisiable = ref(false);
const form = reactive({
password: '',
});
const confirmDialogRef = ref();
const emit = defineEmits(['checkExist', 'closeTerminal']);
type FormInstance = InstanceType<typeof ElForm>;
const formRef = ref<FormInstance>();
const acceptParams = (): void => {
form.password = '';
dialogVisiable.value = true;
};
const onSubmit = async () => {
let param = {
id: 0,
value: form.password,
};
loading.value = true;
emit('closeTerminal');
await changeRedisPassword(param)
.then(() => {
loading.value = false;
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
dialogVisiable.value = false;
emit('checkExist');
})
.catch(() => {
loading.value = false;
});
};
const onSave = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
formEl.validate(async (valid) => {
if (!valid) return;
let params = {
header: i18n.global.t('database.confChange'),
operationInfo: i18n.global.t('database.restartNowHelper'),
submitInputInfo: i18n.global.t('database.restartNow'),
};
confirmDialogRef.value!.acceptParams(params);
});
};
defineExpose({
acceptParams,
});
</script>

View File

@ -3,89 +3,80 @@
<el-card style="margin-top: 5px" v-loading="loading">
<LayoutContent :header="'Redis ' + $t('database.setting')" back-name="Redis" :reload="true">
<el-collapse v-model="activeName" accordion>
<el-collapse-item :title="$t('database.baseSetting')" name="1">
<el-radio-group v-model="confShowType" @change="onChangeMode">
<el-radio-button label="base">{{ $t('database.baseConf') }}</el-radio-button>
<el-radio-button label="all">{{ $t('database.allConf') }}</el-radio-button>
</el-radio-group>
<el-form
v-if="confShowType === 'base'"
:model="form"
ref="formRef"
:rules="rules"
label-width="120px"
>
<el-row style="margin-top: 20px">
<el-col :span="1"><br /></el-col>
<el-col :span="10">
<el-form-item :label="$t('setting.port')" prop="port" :rules="Rules.port">
<el-input clearable type="number" v-model.number="form.port">
<template #append>
<el-button @click="onSavePort()" icon="Collection">
{{ $t('commons.button.save') }}
</el-button>
</template>
</el-input>
<span class="input-help">{{ $t('database.portHelper') }}</span>
</el-form-item>
<el-form-item :label="$t('setting.password')" prop="requirepass">
<el-input type="password" show-password clearable v-model="form.requirepass">
<template #append>
<el-button @click="onSavePassword()" icon="Collection">
{{ $t('commons.button.save') }}
</el-button>
</template>
</el-input>
<span class="input-help">{{ $t('database.requirepassHelper') }}</span>
</el-form-item>
<div v-if="redisStatus === 'Running'">
<el-form-item :label="$t('database.timeout')" prop="timeout">
<el-input clearable type="number" v-model.number="form.timeout" />
<span class="input-help">{{ $t('database.timeoutHelper') }}</span>
</el-form-item>
<el-form-item :label="$t('database.maxclients')" prop="maxclients">
<el-input clearable type="number" v-model.number="form.maxclients" />
</el-form-item>
<el-form-item :label="$t('database.maxmemory')" prop="maxmemory">
<el-input clearable type="number" v-model.number="form.maxmemory" />
<span class="input-help">{{ $t('database.maxmemoryHelper') }}</span>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSave(formRef)">
{{ $t('commons.button.save') }}
</el-button>
</el-form-item>
</div>
</el-col>
</el-row>
</el-form>
<div v-if="confShowType === 'all'">
<codemirror
:autofocus="true"
placeholder="None data"
:indent-with-tab="true"
:tabSize="4"
style="margin-top: 10px; height: calc(100vh - 280px)"
:lineWrapping="true"
:matchBrackets="true"
theme="cobalt"
:styleActiveLine="true"
:extensions="extensions"
v-model="redisConf"
:readOnly="true"
/>
<el-button type="primary" @click="onSaveFile" style="margin-top: 5px">
{{ $t('commons.button.save') }}
</el-button>
</div>
<el-collapse-item :title="$t('database.confChange')" name="1">
<codemirror
:autofocus="true"
placeholder="None data"
:indent-with-tab="true"
:tabSize="4"
style="margin-top: 10px; height: calc(100vh - 280px)"
:lineWrapping="true"
:matchBrackets="true"
theme="cobalt"
:styleActiveLine="true"
:extensions="extensions"
v-model="redisConf"
:readOnly="true"
/>
<el-button type="primary" @click="onSaveFile" style="margin-top: 5px">
{{ $t('commons.button.save') }}
</el-button>
</el-collapse-item>
<el-collapse-item :disabled="redisStatus !== 'Running'" :title="$t('database.status')" name="2">
<Status ref="statusRef" />
</el-collapse-item>
<el-collapse-item
:disabled="redisStatus !== 'Running'"
:title="$t('database.persistence')"
:title="$t('database.performanceTuning')"
name="3"
>
<el-form :model="form" ref="formRef" :rules="rules" label-width="120px">
<el-row style="margin-top: 20px">
<el-col :span="1"><br /></el-col>
<el-col :span="10">
<el-form-item :label="$t('database.timeout')" prop="timeout">
<el-input clearable type="number" v-model.number="form.timeout" />
<span class="input-help">{{ $t('database.timeoutHelper') }}</span>
</el-form-item>
<el-form-item :label="$t('database.maxclients')" prop="maxclients">
<el-input clearable type="number" v-model.number="form.maxclients" />
</el-form-item>
<el-form-item :label="$t('database.maxmemory')" prop="maxmemory">
<el-input clearable type="number" v-model.number="form.maxmemory" />
<span class="input-help">{{ $t('database.maxmemoryHelper') }}</span>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submtiForm(formRef)">
{{ $t('commons.button.save') }}
</el-button>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-collapse-item>
<el-collapse-item :title="$t('database.portSetting')" name="4">
<el-form :model="form" ref="portRef" label-width="120px">
<el-row>
<el-col :span="1"><br /></el-col>
<el-col :span="10">
<el-form-item :label="$t('setting.port')" prop="port" :rules="Rules.port">
<el-input clearable type="number" v-model.number="form.port">
<template #append>
<el-button @click="onSavePort(portRef)" icon="Collection">
{{ $t('commons.button.save') }}
</el-button>
</template>
</el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-collapse-item>
<el-collapse-item
:disabled="redisStatus !== 'Running'"
:title="$t('database.persistence')"
name="5"
>
<Persistence ref="persistenceRef" />
</el-collapse-item>
@ -93,9 +84,9 @@
</LayoutContent>
</el-card>
<ConfirmDialog ref="confirmDialogRef" @confirm="onSubmitSave"></ConfirmDialog>
<ConfirmDialog ref="confirmDialogRef2" @confirm="onChangePort(formRef)"></ConfirmDialog>
<ConfirmDialog ref="confirmDialogRef3" @confirm="onChangePassword()"></ConfirmDialog>
<ConfirmDialog ref="confirmFileRef" @confirm="submtiFile"></ConfirmDialog>
<ConfirmDialog ref="confirmFormRef" @confirm="submtiForm"></ConfirmDialog>
<ConfirmDialog ref="confirmPortRef" @confirm="onChangePort(formRef)"></ConfirmDialog>
</div>
</template>
@ -110,20 +101,18 @@ import { LoadFile } from '@/api/modules/files';
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
import Status from '@/views/database/redis/setting/status/index.vue';
import Persistence from '@/views/database/redis/setting/persistence/index.vue';
import { changeRedisPassword, loadRedisConf, updateRedisConf, updateRedisConfByFile } from '@/api/modules/database';
import { loadRedisConf, updateRedisConf, updateRedisConfByFile } from '@/api/modules/database';
import i18n from '@/lang';
import { Rules } from '@/global/form-rules';
import { ChangePort } from '@/api/modules/app';
const extensions = [javascript(), oneDark];
const confShowType = ref('base');
const loading = ref(false);
const form = reactive({
name: '',
port: 6379,
requirepass: '',
timeout: 0,
maxclients: 0,
maxmemory: 0,
@ -140,63 +129,56 @@ const statusRef = ref();
const persistenceRef = ref();
const redisStatus = ref();
const redisName = ref();
const formRef = ref<FormInstance>();
const redisConf = ref();
const confirmDialogRef = ref();
const confirmDialogRef2 = ref();
const settingShow = ref<boolean>(false);
interface DialogProps {
redisName: string;
status: string;
}
const acceptParams = (prop: DialogProps): void => {
redisStatus.value = prop.status;
redisName.value = prop.redisName;
settingShow.value = true;
loadform();
statusRef.value!.acceptParams({ status: prop.status });
persistenceRef.value!.acceptParams({ status: prop.status });
loadConfFile();
if (redisStatus.value === 'Running') {
statusRef.value!.acceptParams({ status: prop.status });
persistenceRef.value!.acceptParams({ status: prop.status });
}
};
const onClose = (): void => {
settingShow.value = false;
};
const onSavePort = async () => {
const portRef = ref();
const confirmPortRef = ref();
const onSavePort = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
const result = await formEl.validateField('port', callback);
if (!result) {
return;
}
let params = {
header: i18n.global.t('database.confChange'),
operationInfo: i18n.global.t('database.restartNowHelper1'),
operationInfo: i18n.global.t('database.restartNowHelper'),
submitInputInfo: i18n.global.t('database.restartNow'),
};
confirmDialogRef2.value!.acceptParams(params);
confirmPortRef.value!.acceptParams(params);
return;
};
const confirmDialogRef3 = ref();
const onSavePassword = async () => {
let params = {
header: i18n.global.t('database.confChange'),
operationInfo: i18n.global.t('database.restartNowHelper1'),
submitInputInfo: i18n.global.t('database.restartNow'),
};
confirmDialogRef3.value!.acceptParams(params);
};
const onChangePassword = async () => {
loading.value = true;
let param = {
id: 0,
value: form.requirepass,
};
changeRedisPassword(param)
.then(() => {
loading.value = false;
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
})
.finally(() => {
loading.value = false;
});
};
function callback(error: any) {
if (error) {
return error.message;
} else {
return;
}
}
const onChangePort = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
const result = await formEl.validateField('port', callback);
@ -218,33 +200,30 @@ const onChangePort = async (formEl: FormInstance | undefined) => {
loading.value = false;
});
};
function callback(error: any) {
if (error) {
return error.message;
} else {
return;
}
}
const onChangeMode = async () => {
if (confShowType.value === 'all') {
loadredisConf();
} else {
loadform();
}
};
// const onChangePassword = async () => {
// loading.value = true;
// let param = {
// id: 0,
// value: form.requirepass,
// };
// changeRedisPassword(param)
// .then(() => {
// loading.value = false;
// ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
// })
// .finally(() => {
// loading.value = false;
// });
// };
const onSave = async (formEl: FormInstance | undefined) => {
if (confShowType.value === 'all') {
onSaveFile();
}
const submtiForm = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
formEl.validate(async (valid) => {
if (!valid) return;
let param = {
timeout: form.timeout + '',
maxclients: form.maxclients + '',
requirepass: form.requirepass,
maxmemory: form.maxmemory + '',
};
loading.value = true;
@ -268,8 +247,7 @@ const onSaveFile = async () => {
};
confirmDialogRef.value!.acceptParams(params);
};
const onSubmitSave = async () => {
const submtiFile = async () => {
let param = {
file: redisConf.value,
restartNow: true,
@ -293,7 +271,6 @@ const loadform = async () => {
form.name = res.data?.name;
form.timeout = Number(res.data?.timeout);
form.maxclients = Number(res.data?.maxclients);
form.requirepass = res.data?.requirepass;
form.maxmemory = Number(res.data?.maxmemory);
form.port = Number(res.data?.port);
})
@ -302,8 +279,8 @@ const loadform = async () => {
});
};
const loadredisConf = async () => {
let path = `/opt/1Panel/data/apps/redis/${form.name}/conf/redis.conf`;
const loadConfFile = async () => {
let path = `/opt/1Panel/data/apps/redis/${redisName.value}/conf/redis.conf`;
const res = await LoadFile({ path: path });
redisConf.value = res.data;
};

View File

@ -29,13 +29,15 @@ const acceptParams = async (): Promise<void> => {
initTerm();
window.addEventListener('resize', changeTerminalSize);
};
const onClose = async () => {
const onClose = async (isKeepShow: boolean) => {
window.removeEventListener('resize', changeTerminalSize);
if (isWsOpen()) {
terminalSocket && terminalSocket.close();
}
if (!isKeepShow) {
term.dispose();
}
terminalShow.value = false;
terminalShow.value = isKeepShow;
};
const onWSReceive = (message: any) => {