diff --git a/nezha-fronted/src/components/common/js/validate.js b/nezha-fronted/src/components/common/js/validate.js index e51e9ed8b..7d5c2cf50 100644 --- a/nezha-fronted/src/components/common/js/validate.js +++ b/nezha-fronted/src/components/common/js/validate.js @@ -127,7 +127,7 @@ export function positiveInteger (rule, value, callback) { if (isNaN(Number(value))) { callback(new Error(vm.$t('validate.number'))) } else { - if (Number(value) >= 0 && (parseInt(value) == parseFloat(value))) { + if (Number(value) >= 0) { callback() } else { callback(new Error(vm.$t('validate.positiveInteger'))) @@ -227,3 +227,69 @@ export function dataValidate () { // const DMY = '/((^(3[01]|[12][0-9]|0[1-9])(\\/)(10|12|0[13578])(\\/)((1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(30|[12][0-9]|0[1-9])(\\/)(11|0[469])(\\/)((1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(2[0-8]|1[0-9]|0[1-9])(\\/)(02)(\\/)((1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(29)(\\/)(02)(\\/)([2468][048]00)$)|(^(29)(\\/)(02)(\\/)([3579][26]00)$)|(^(29)(\\/)(02)(\\/)([1][89][0][48])$)|(^(29)(\\/)(02)(\\/)([2-9][0-9][0][48])$)|(^(29)(\\/)(02)(\\/)([1][89][2468][048])$)|(^(29)(\\/)(02)(\\/)([2-9][0-9][2468][048])$)|(^(29)(\\/)(02)(\\/)([1][89][13579][26])$)|(^(29)(\\/)(02)(\\/)([2-9][0-9][13579][26])$))/' // const MDY = } + +// 验证timeout +export function timeoutValidator (rule, value, callback) { + setTimeout(() => { + // 判断是否是数字 + if (isNaN(Number(value))) { + callback(new Error(vm.$t('validate.number'))) + } else { + // 判断是否是正整数 + if (Number(value) >= 0 && (String(value).indexOf('.') == -1)) { + // 判断范围 + if (value >= 1 && value <= 60000) { + callback() + } else { + callback(new Error(vm.$t('validate.timeout'))) + } + } else { + callback(new Error(vm.$t('validate.positiveInteger'))) + } + } + }, 100) +} + +// 验证packageSize +export function packageSizeValidator (rule, value, callback) { + setTimeout(() => { + // 判断是否是数字 + if (isNaN(Number(value))) { + callback(new Error(vm.$t('validate.number'))) + } else { + // 判断是否是正整数 + if (Number(value) >= 0 && (String(value).indexOf('.') == -1)) { + // 判断范围 + if (value >= 1 && value <= 4096) { + callback() + } else { + callback(new Error(vm.$t('validate.packageSize'))) + } + } else { + callback(new Error(vm.$t('validate.positiveInteger'))) + } + } + }, 100) +} + +// 验证maxHops +export function maxHopsValidator (rule, value, callback) { + setTimeout(() => { + // 判断是否是数字 + if (isNaN(Number(value))) { + callback(new Error(vm.$t('validate.number'))) + } else { + // 判断是否是正整数 + if (Number(value) >= 0 && (String(value).indexOf('.') == -1)) { + // 判断范围 + if (value >= 1 && value <= 1000) { + callback() + } else { + callback(new Error(vm.$t('validate.maxHops'))) + } + } else { + callback(new Error(vm.$t('validate.positiveInteger'))) + } + } + }, 100) +} diff --git a/nezha-fronted/src/components/page/tool/ping.vue b/nezha-fronted/src/components/page/tool/ping.vue index c5bdfc4aa..9fb3ec1ef 100644 --- a/nezha-fronted/src/components/page/tool/ping.vue +++ b/nezha-fronted/src/components/page/tool/ping.vue @@ -25,7 +25,7 @@
- + @@ -68,7 +68,7 @@ - +
@@ -76,10 +76,10 @@
- +
- - + +
@@ -153,7 +153,7 @@ import nzDataList from '@/components/common/table/nzDataList' import dataListMixin from '@/components/common/mixin/dataList' import pingTable from '@/components/common/table/tool/pingTable' import VueTagsInput from '@johmun/vue-tags-input' -import { positiveInteger } from '../../common/js/validate' +import { timeoutValidator, packageSizeValidator } from '../../common/js/validate' const ipv4 = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\:\d{0,5})?$/ const ipv6 = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/ export default { @@ -197,13 +197,13 @@ export default { tableData: [], ruleForm: { // 超时时间 - timeout: 30, + timeout: 100, // 包大小 packageSize: 64 }, formRules: { - timeout: [{ validator: positiveInteger, trigger: 'blur' }], - packageSize: [{ validator: positiveInteger, trigger: 'blur' }] + timeout: [{ validator: timeoutValidator, trigger: 'blur' }], + packageSize: [{ validator: packageSizeValidator, trigger: 'blur' }] } } }, diff --git a/nezha-fronted/src/components/page/tool/trace.vue b/nezha-fronted/src/components/page/tool/trace.vue index 4a07f42d9..89d33d64c 100644 --- a/nezha-fronted/src/components/page/tool/trace.vue +++ b/nezha-fronted/src/components/page/tool/trace.vue @@ -24,7 +24,7 @@
- + @@ -67,16 +67,16 @@ - +
- +
- +
@@ -146,7 +146,7 @@ import nzDataList from '@/components/common/table/nzDataList' import dataListMixin from '@/components/common/mixin/dataList' import traceTable from '@/components/common/table/tool/traceTable' import VueTagsInput from '@johmun/vue-tags-input' -import { positiveInteger } from '../../common/js/validate' +import { timeoutValidator, maxHopsValidator } from '../../common/js/validate' const ipv4 = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\:\d{0,5})?$/ const ipv6 = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/ export default { @@ -190,11 +190,11 @@ export default { // 最大跃点数 maxHops: 30, // 超时时间 - timeout: 30 + timeout: 100 }, formRules: { - timeout: [{ validator: positiveInteger, trigger: 'blur' }], - maxHops: [{ validator: positiveInteger, trigger: 'blur' }] + timeout: [{ validator: timeoutValidator, trigger: 'blur' }], + maxHops: [{ validator: maxHopsValidator, trigger: 'blur' }] } } },