From 14a415013a96562116da11103adeea93025b73d0 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 30 Jan 2023 13:47:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=80=89?= =?UTF-8?q?=E6=8B=A9cron=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=B9=B4=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1022084 --user=王孝刚 【接口测试】github#21420,接口定时同步 : Cron表达式-自动生成-设置了年, 保存的时候提示错误,不设置年就正常 https://www.tapd.cn/55049933/s/1328305 --- .../sdk-parent/frontend/src/utils/cron.js | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/framework/sdk-parent/frontend/src/utils/cron.js b/framework/sdk-parent/frontend/src/utils/cron.js index bfb2438f61..fcee1a2d08 100644 --- a/framework/sdk-parent/frontend/src/utils/cron.js +++ b/framework/sdk-parent/frontend/src/utils/cron.js @@ -7,21 +7,23 @@ import parser from "cron-parser"; * @return True is expression is valid */ export function cronValidate(cronExpression ){ - try { - parser.parseExpression(cronExpression); - } catch (e) { - return false; - } - if (!cronExpression) { return false; } //alert("校验函数的开始!"); - var cronParams = cronExpression.split(" "); - + let cronParams = cronExpression.split(" "); if (cronParams.length < 6 || cronParams.length > 7) { return false; } + let cronValue = cronExpression; + if(cronExpression.split(" ").length === 7){ + cronValue = cronExpression.substring(0, cronExpression.lastIndexOf(" ")); + } + try { + parser.parseExpression(cronValue); + } catch (e) { + return false; + } //CronTrigger cronTrigger = new CronTrigger(); //cronTrigger.setCronExpression( cronExpression ); @@ -81,15 +83,15 @@ function checkSecondsField(secondsField) { function checkField(secondsField, minimal, maximal) { if (secondsField.indexOf("-") > -1 ) { - var startValue = secondsField.substring(0, secondsField.indexOf( "-" )); - var endValue = secondsField.substring(secondsField.indexOf( "-" ) + 1); + let startValue = secondsField.substring(0, secondsField.indexOf( "-" )); + let endValue = secondsField.substring(secondsField.indexOf( "-" ) + 1); if (!(checkIntValue(startValue, minimal, maximal, true) && checkIntValue(endValue, minimal, maximal, true))) { return false; } try { - var startVal = parseInt(startValue, 10); - var endVal = parseInt(endValue, 10); + let startVal = parseInt(startValue, 10); + let endVal = parseInt(endValue, 10); //return endVal > startVal; return true; } catch (e) { @@ -102,13 +104,13 @@ function checkField(secondsField, minimal, maximal) { } else if (secondsField.indexOf( "*" ) != -1) { return true; } else { - return checkIntValue(secondsField, minimal, maximal); + return checkIntValue(secondsField, minimal, maximal,true); } } function checkIntValue(value, minimal, maximal, checkExtremity) { try { - var val = parseInt(value, 10); + let val = parseInt(value, 10); //判断是否为整数 if (value == val) { if (checkExtremity) { @@ -220,11 +222,11 @@ function checkYearField(yearField) { function checkFieldWithLetter(value, letter, minimalBefore, maximalBefore, minimalAfter, maximalAfter) { - var canBeAlone = false; - var canHaveIntBefore = false; - var canHaveIntAfter = false; - var mustHaveIntBefore = false; - var mustHaveIntAfter = false; + let canBeAlone = false; + let canHaveIntBefore = false; + let canHaveIntAfter = false; + let mustHaveIntBefore = false; + let mustHaveIntAfter = false; if (letter == "L") { canBeAlone = true; @@ -248,8 +250,8 @@ function checkFieldWithLetter(value, letter, minimalBefore, maximalBefore, mustHaveIntAfter = true; } - var beforeLetter = ""; - var afterLetter = ""; + let beforeLetter = ""; + let afterLetter = ""; if (value.indexOf(letter) >= 0 ) { beforeLetter = value.substring( 0, value.indexOf(letter)); @@ -301,9 +303,9 @@ function checkFieldWithLetter(value, letter, minimalBefore, maximalBefore, } */ function checkIncrementField(value, minimal, maximal) { - var start = value.substring(0, value.indexOf("/")); + let start = value.substring(0, value.indexOf("/")); - var increment = value.substring(value.indexOf("/") + 1); + let increment = value.substring(value.indexOf("/") + 1); if (!("*" == start)) { return checkIntValue(start, minimal, maximal, true) && checkIntValue(increment, minimal, maximal, false); @@ -315,16 +317,16 @@ function checkIncrementField(value, minimal, maximal) { function checkListField(value, minimal, maximal ) { - var st = value.split(","); + let st = value.split(","); - var values = new Array(st.length); + let values = new Array(st.length); - for(var j = 0; j < st.length; j++) { + for(let j = 0; j < st.length; j++) { values[j] = st[j]; } - for (var i= 0; i < values.length; i++) { - var currentValue = values[i]; + for (let i= 0; i < values.length; i++) { + let currentValue = values[i]; if (!checkIntValue(currentValue, minimal, maximal, true)) { return false;