From 90827fd7067b0f390b6d12e2a5a21a92db871683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B4=AA=E6=B4=AA?= <2498601771@qq.com> Date: Mon, 30 Oct 2023 14:37:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20policy=E6=96=B0=E5=BB=BA=E6=97=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B0=8F=E6=97=B6=E4=B8=8D=E5=BE=97=E8=B6=85?= =?UTF-8?q?=E8=BF=8724=E7=AD=89=E6=97=B6=E9=97=B4=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detectionPolicies/PolicyForm.vue | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/views/detections/detectionPolicies/PolicyForm.vue b/src/views/detections/detectionPolicies/PolicyForm.vue index 673f5a99..d93131ea 100644 --- a/src/views/detections/detectionPolicies/PolicyForm.vue +++ b/src/views/detections/detectionPolicies/PolicyForm.vue @@ -165,6 +165,30 @@ import { storageKey, detectionUnitList } from '@/utils/constants' export default { name: 'DetectionForm', data () { + const intervalValidator = (rule, value, callback) => { + const obj = this.handleIntervalByDateType(rule, value, this.triggerObj.intervalVal) + if (!obj.flag && obj.msg) { + callback(new Error(obj.msg)) + } + } + const intervalValValidator = (rule, value) => { + const obj = this.handleIntervalByDateType(rule, this.triggerObj.intervalVal, value) + if (!obj.flag && obj.msg) { + this.$refs.form3.validateField('interval') + } + } + const resetIntervalValidator = (rule, value, callback) => { + const obj = this.handleIntervalByDateType(rule, value, this.triggerObj.resetIntervalVal) + if (!obj.flag && obj.msg) { + callback(new Error(obj.msg)) + } + } + const resetIntervalValValidator = (rule, value) => { + const obj = this.handleIntervalByDateType(rule, this.triggerObj.resetIntervalVal, value) + if (!obj.flag && obj.msg) { + this.$refs.form3.validateField('resetInterval') + } + } return { activeNames: ['1'], rules: { @@ -180,6 +204,10 @@ export default { required: true, message: this.$t('validate.required'), trigger: 'blur' + }, + { + validator: intervalValidator, + trigger: 'blur' } ], intervalVal: [ @@ -187,6 +215,10 @@ export default { required: true, message: this.$t('validate.required'), trigger: 'change' + }, + { + validator: intervalValValidator, + trigger: 'change' } ], resetInterval: [ @@ -194,6 +226,10 @@ export default { required: true, message: this.$t('validate.required'), trigger: 'blur' + }, + { + validator: resetIntervalValidator, + trigger: 'blur' } ], resetIntervalVal: [ @@ -201,6 +237,10 @@ export default { required: true, message: this.$t('validate.required'), trigger: 'change' + }, + { + validator: resetIntervalValValidator, + trigger: 'change' } ] }, @@ -417,6 +457,29 @@ export default { }) } this.$message.error(this.$t('detection.create.informationFilled')) + }, + handleIntervalByDateType (rule, value, type) { + if (value && (type === 'hours' || type === '小时')) { + if (parseInt(value) <= 24) { + return { flag: true } + } else { + return { flag: false, msg: this.$t('policy.dateTimeRangeHours') } + } + } + if (value && (type === 'minutes' || type === '分钟')) { + if (parseInt(value) <= 1440) { + return { flag: true } + } else { + return { flag: false, msg: this.$t('policy.dateTimeRangeMinutes') } + } + } + if (value && (type === 'seconds' || type === '秒')) { + if (parseInt(value) <= 86400) { + return { flag: true } + } else { + return { flag: false, msg: this.$t('policy.dateTimeRangeSeconds') } + } + } } } }