1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-16 18:54:43 +08:00

fix: 解决 mysql 慢日志设置修改失败的问题

This commit is contained in:
ssongliu 2023-03-16 10:52:07 +08:00 committed by f2c-ci-robot[bot]
parent 11f4bc2c89
commit 9080824a59
5 changed files with 31 additions and 32 deletions

View File

@ -10643,9 +10643,9 @@
} }
}, },
"node_modules/webpack": { "node_modules/webpack": {
"version": "5.75.0", "version": "5.76.1",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.75.0.tgz", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.76.1.tgz",
"integrity": "sha512-piaIaoVJlqMsPtX/+3KTTO6jfvrSYgauFVdt8cr9LTHKmcq/AMd4mhzsiP7ZF/PGRNPGA8336jldh9l2Kt2ogQ==", "integrity": "sha512-4+YIK4Abzv8172/SGqObnUjaIHjLEuUasz9EwQj/9xmPPkYJy2Mh03Q/lJfSD3YLzbxy5FeTq5Uw0323Oh6SJQ==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"@types/eslint-scope": "^3.7.3", "@types/eslint-scope": "^3.7.3",
@ -18679,9 +18679,9 @@
} }
}, },
"webpack": { "webpack": {
"version": "5.75.0", "version": "5.76.1",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.75.0.tgz", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.76.1.tgz",
"integrity": "sha512-piaIaoVJlqMsPtX/+3KTTO6jfvrSYgauFVdt8cr9LTHKmcq/AMd4mhzsiP7ZF/PGRNPGA8336jldh9l2Kt2ogQ==", "integrity": "sha512-4+YIK4Abzv8172/SGqObnUjaIHjLEuUasz9EwQj/9xmPPkYJy2Mh03Q/lJfSD3YLzbxy5FeTq5Uw0323Oh6SJQ==",
"peer": true, "peer": true,
"requires": { "requires": {
"@types/eslint-scope": "^3.7.3", "@types/eslint-scope": "^3.7.3",

View File

@ -77,7 +77,7 @@ const timeOptions = ref([
const searchLogs = async () => { const searchLogs = async () => {
const res = await logContainer(logSearch); const res = await logContainer(logSearch);
logInfo.value = res.data; logInfo.value = res.data || '';
nextTick(() => { nextTick(() => {
const state = view.value.state; const state = view.value.state;
view.value.dispatch({ view.value.dispatch({

View File

@ -96,7 +96,7 @@ const handleClose = async () => {
const searchLogs = async () => { const searchLogs = async () => {
const res = await logContainer(logSearch); const res = await logContainer(logSearch);
logInfo.value = res.data; logInfo.value = res.data || '';
nextTick(() => { nextTick(() => {
const state = view.value.state; const state = view.value.state;
view.value.dispatch({ view.value.dispatch({

View File

@ -13,7 +13,7 @@
<div style="float: left"> <div style="float: left">
<el-input type="number" v-model.number="variables.long_query_time" /> <el-input type="number" v-model.number="variables.long_query_time" />
</div> </div>
<el-button style="float: left; margin-left: 10px" @click="openSlowLogs"> <el-button style="float: left; margin-left: 10px" @click="changeSlowLogs">
{{ $t('commons.button.save') }} {{ $t('commons.button.save') }}
</el-button> </el-button>
<div style="float: left; margin-left: 20px"> <div style="float: left; margin-left: 20px">
@ -56,7 +56,7 @@ import { updateMysqlVariables } from '@/api/modules/database';
import { dateFormatForName } from '@/utils/util'; import { dateFormatForName } from '@/utils/util';
import i18n from '@/lang'; import i18n from '@/lang';
import { loadBaseDir } from '@/api/modules/setting'; import { loadBaseDir } from '@/api/modules/setting';
import { MsgError, MsgSuccess } from '@/utils/message'; import { MsgError, MsgInfo, MsgSuccess } from '@/utils/message';
const extensions = [javascript(), oneDark]; const extensions = [javascript(), oneDark];
const slowLogs = ref(); const slowLogs = ref();
@ -65,7 +65,7 @@ const handleReady = (payload) => {
view.value = payload.view; view.value = payload.view;
}; };
const detailShow = ref(); const detailShow = ref();
const isOnEdit = ref(); const currentStatus = ref();
const confirmDialogRef = ref(); const confirmDialogRef = ref();
@ -88,17 +88,18 @@ const acceptParams = async (params: DialogProps): Promise<void> => {
variables.slow_query_log = params.variables.slow_query_log; variables.slow_query_log = params.variables.slow_query_log;
variables.long_query_time = Number(params.variables.long_query_time); variables.long_query_time = Number(params.variables.long_query_time);
if (variables.slow_query_log === 'ON') {
currentStatus.value = true;
detailShow.value = true;
const pathRes = await loadBaseDir(); const pathRes = await loadBaseDir();
let path = `${pathRes.data}/apps/mysql/${mysqlName.value}/data/1Panel-slow.log`; let path = `${pathRes.data}/apps/mysql/${mysqlName.value}/data/1Panel-slow.log`;
if (variables.slow_query_log === 'ON') {
detailShow.value = true;
loadMysqlSlowlogs(path); loadMysqlSlowlogs(path);
}
timer = setInterval(() => { timer = setInterval(() => {
if (variables.slow_query_log === 'ON' && isWatch.value) { if (variables.slow_query_log === 'ON' && isWatch.value) {
loadMysqlSlowlogs(path); loadMysqlSlowlogs(path);
} }
}, 1000 * 5); }, 1000 * 5);
}
oldVariables.value = { ...variables }; oldVariables.value = { ...variables };
}; };
const emit = defineEmits(['loading']); const emit = defineEmits(['loading']);
@ -106,11 +107,6 @@ const emit = defineEmits(['loading']);
const handleSlowLogs = async () => { const handleSlowLogs = async () => {
if (variables.slow_query_log === 'ON') { if (variables.slow_query_log === 'ON') {
detailShow.value = true; detailShow.value = true;
isOnEdit.value = true;
return;
}
if (isOnEdit.value) {
detailShow.value = false;
return; return;
} }
let params = { let params = {
@ -121,7 +117,7 @@ const handleSlowLogs = async () => {
confirmDialogRef.value!.acceptParams(params); confirmDialogRef.value!.acceptParams(params);
}; };
const openSlowLogs = () => { const changeSlowLogs = () => {
if (!(variables.long_query_time > 0 && variables.long_query_time <= 600)) { if (!(variables.long_query_time > 0 && variables.long_query_time <= 600)) {
MsgError(i18n.global.t('database.thresholdRangeHelper')); MsgError(i18n.global.t('database.thresholdRangeHelper'));
return; return;
@ -135,7 +131,7 @@ const openSlowLogs = () => {
}; };
const onCancle = async () => { const onCancle = async () => {
variables.slow_query_log = variables.slow_query_log === 'ON' ? 'OFF' : 'ON'; variables.slow_query_log = currentStatus.value ? 'ON' : 'OFF';
}; };
const onSave = async () => { const onSave = async () => {
@ -151,10 +147,9 @@ const onSave = async () => {
await updateMysqlVariables(param) await updateMysqlVariables(param)
.then(() => { .then(() => {
emit('loading', false); emit('loading', false);
isOnEdit.value = false; currentStatus.value = variables.slow_query_log === 'ON';
if (variables.slow_query_log !== 'ON') { detailShow.value = variables.slow_query_log === 'ON';
detailShow.value = false; oldVariables.value.slow_query_log = variables.slow_query_log;
}
MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
}) })
.catch(() => { .catch(() => {
@ -163,6 +158,10 @@ const onSave = async () => {
}; };
const onDownload = async () => { const onDownload = async () => {
if (!slowLogs.value) {
MsgInfo(i18n.global.t('database.noData'));
return;
}
const downloadUrl = window.URL.createObjectURL(new Blob([slowLogs.value])); const downloadUrl = window.URL.createObjectURL(new Blob([slowLogs.value]));
const a = document.createElement('a'); const a = document.createElement('a');
a.style.display = 'none'; a.style.display = 'none';
@ -174,7 +173,7 @@ const onDownload = async () => {
const loadMysqlSlowlogs = async (path: string) => { const loadMysqlSlowlogs = async (path: string) => {
const res = await LoadFile({ path: path }); const res = await LoadFile({ path: path });
slowLogs.value = res.data; slowLogs.value = res.data || '';
nextTick(() => { nextTick(() => {
const state = view.value.state; const state = view.value.state;
view.value.dispatch({ view.value.dispatch({

View File

@ -79,7 +79,7 @@ import type { ElForm } from 'element-plus';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';
import { addHost, editHost, testByInfo, GetGroupList } from '@/api/modules/host'; import { addHost, editHost, testByInfo, GetGroupList } from '@/api/modules/host';
import i18n from '@/lang'; import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message'; import { MsgError, MsgSuccess } from '@/utils/message';
const loading = ref(); const loading = ref();
@ -165,7 +165,7 @@ const submitAddHost = (formEl: FormInstance | undefined, ops: string) => {
if (res.data) { if (res.data) {
MsgSuccess(i18n.global.t('terminal.connTestOk')); MsgSuccess(i18n.global.t('terminal.connTestOk'));
} else { } else {
MsgSuccess(i18n.global.t('terminal.connTestFailed')); MsgError(i18n.global.t('terminal.connTestFailed'));
} }
}); });
} }