mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-08 14:37:29 +08:00
fix: Fix alert issue (#10281)
This commit is contained in:
parent
18214095ab
commit
7448953b7d
1 changed files with 42 additions and 60 deletions
|
@ -454,79 +454,61 @@ const allTaskOptions = [
|
|||
{ value: 'panelUpdate', label: 'xpack.alert.panelUpdate', show: isMaster.value },
|
||||
];
|
||||
|
||||
function checkCycle(rule: any, value: any, callback: any) {
|
||||
if (value === '') {
|
||||
callback();
|
||||
function checkRange(value: any, min: number, max: number, callback: any) {
|
||||
const num = Number(value);
|
||||
if (isNaN(num)) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.number')));
|
||||
}
|
||||
if (dialogData.value.rowData.type === 'ssl') {
|
||||
const regex = /^(?:[1-9]|[1-5][0-9]|60)$/;
|
||||
if (!regex.test(value)) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.numberRange', [1, 60])));
|
||||
}
|
||||
} else if (ipTypes.includes(dialogData.value.rowData.type)) {
|
||||
const regex = /^(?:[1-9]|[1-5][0-9]|200)$/;
|
||||
if (!regex.test(value)) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.numberRange', [1, 200])));
|
||||
}
|
||||
} else {
|
||||
const regex = /^(?:[1-9]|[12][0-9]|30)$/;
|
||||
if (!regex.test(value)) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.numberRange', [1, 30])));
|
||||
}
|
||||
if (num < min || num > max) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.numberRange', [min, max])));
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
function checkCycle(rule: any, value: any, callback: any) {
|
||||
if (value === '') return callback();
|
||||
|
||||
const type = dialogData.value.rowData.type;
|
||||
|
||||
if (type === 'ssl') {
|
||||
return checkRange(value, 1, 60, callback);
|
||||
} else if (ipTypes.includes(type)) {
|
||||
return checkRange(value, 1, 200, callback);
|
||||
} else {
|
||||
return checkRange(value, 1, 30, callback);
|
||||
}
|
||||
}
|
||||
|
||||
function checkCount(rule: any, value: any, callback: any) {
|
||||
if (value === '') {
|
||||
callback();
|
||||
if (value === '') return callback();
|
||||
|
||||
const type = dialogData.value.rowData.type;
|
||||
const cycle = dialogData.value.rowData.cycle;
|
||||
|
||||
if (avgTypes.includes(type) || ipTypes.includes(type)) {
|
||||
return checkRange(value, 1, 100, callback);
|
||||
}
|
||||
if (avgTypes.includes(dialogData.value.rowData.type) || ipTypes.includes(dialogData.value.rowData.type)) {
|
||||
const regex = /^(?:[1-9]|[1-9][0-9]|100)$/;
|
||||
if (!regex.test(value)) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.numberRange', [1, 100])));
|
||||
}
|
||||
}
|
||||
if (dialogData.value.rowData.type === 'disk' && dialogData.value.rowData.cycle === 2) {
|
||||
const regex = /^(?:[1-9]|[1-9][0-9]|100)$/;
|
||||
if (!regex.test(value)) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.numberRange', [1, 100])));
|
||||
}
|
||||
if (type === 'disk' && cycle === 2) {
|
||||
return checkRange(value, 1, 100, callback);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
function checkSendCount(rule: any, value: any, callback: any) {
|
||||
if (value === '') {
|
||||
callback();
|
||||
}
|
||||
if (
|
||||
dialogData.value.rowData.type === 'disk' ||
|
||||
avgTypes.includes(dialogData.value.rowData.type) ||
|
||||
ipTypes.includes(dialogData.value.rowData.type)
|
||||
) {
|
||||
const regex = /^(?:[1-9]|[1-4][0-9]|50)$/;
|
||||
if (!regex.test(value)) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.numberRange', [1, 50])));
|
||||
}
|
||||
} else if (noParamTypes.includes(dialogData.value.rowData.type)) {
|
||||
const regex = /^(?:[1-9]|[12][0-9]|30)$/;
|
||||
if (!regex.test(value)) {
|
||||
return callback(new Error(i18n.global.t('commons.rule.numberRange', [1, 30])));
|
||||
}
|
||||
} else {
|
||||
if (dialogData.value.rowData.cycle > 0) {
|
||||
const minValue = 1;
|
||||
const maxValue = dialogData.value.rowData.cycle;
|
||||
const regex = new RegExp(`^(${minValue}|[2-9]|[1-9][0-9]*|${maxValue})$`);
|
||||
if (!regex.test(value) || value > maxValue) {
|
||||
return callback(
|
||||
new Error(i18n.global.t('commons.rule.numberRange', [1, dialogData.value.rowData.cycle])),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value === '') return callback();
|
||||
|
||||
const type = dialogData.value.rowData.type;
|
||||
const cycle = dialogData.value.rowData.cycle;
|
||||
|
||||
if (type === 'disk' || avgTypes.includes(type) || ipTypes.includes(type)) {
|
||||
return checkRange(value, 1, 50, callback);
|
||||
} else if (noParamTypes.includes(type)) {
|
||||
return checkRange(value, 1, 30, callback);
|
||||
} else {
|
||||
if (cycle > 0) {
|
||||
return checkRange(value, 1, cycle, callback);
|
||||
}
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue