Skip to content

Commit

Permalink
chore: Add input detect to prevent overflow (#471)
Browse files Browse the repository at this point in the history
* chore: Add input detect to prevent overflow

Also added some explaination of time

* feat: Fix random value comparison and validation in task templates
  • Loading branch information
Ovler-Young authored Sep 21, 2023
1 parent be81195 commit 6d95f9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 9 additions & 5 deletions web/tpl/task_setTime.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ <h2 class="text-center">设置定时</h2>
</div>
<div id="randtime_content">
<div name="randzone readme">
<label class="control-label">当天随机延时区间(0-604800):</label>
<label class="control-label">当天随机延时区间(0-604800)(604800为一周)</label>
</div>
<div name="randzone">
<label>
<input type="checkbox" id="randtimezonesw" name="randtimezonesw" {% if ontime.randsw %} checked="" {% endif %} >开关
</label>
<input type="number" id="randtimezone1" name="randtimezone1" value="{{ ontime.tz1 }}" class="modal_input" min="0" max="604800"/>~
<input type="number" id="randtimezone2" name="randtimezone2" value="{{ ontime.tz2 }}" class="modal_input" min="0" max="604800"/>秒
<input type="number" id="randtimezone1" name="randtimezone1" value="{{ ontime.tz1 }}" class="modal_input" min="0" max="604800" oninput="if(value<0)value=0;if(value>604800)value=604800"/>~
<input type="number" id="randtimezone2" name="randtimezone2" value="{{ ontime.tz2 }}" class="modal_input" min="0" max="604800" oninput="if(value<0)value=0;if(value>604800)value=604800"/>秒
</div>
</div>

Expand Down Expand Up @@ -70,8 +70,12 @@ <h2 class="text-center">设置定时</h2>
if ($('#randtimezonesw')[0].checked == true){
sendData['tz1'] = parseInt($('#randtimezone1')[0].value);
sendData['tz2'] = parseInt($('#randtimezone2')[0].value);
if (sendData['tz1'] > sendData['tz2']){
$('#run-result').html("<h1 class=\"alert alert-danger text-center\">随机值错误</h1><div><pre>开启随机时tz1 不能小于 tz2</pre></div>").show();
if (sendData['tz1'] >= sendData['tz2']){
$('#run-result').html("<h1 class=\"alert alert-danger text-center\">随机值错误</h1><div><pre>开启随机时tz1 需大于 tz2</pre></div>").show();
return false;
}
if (sendData['tz1'] > 604800 || sendData['tz2'] > 604800){
$('#run-result').html("<h1 class=\"alert alert-danger text-center\">随机值错误</h1><div><pre>随机值不能大于604800</pre></div>").show();
return false;
}
sendData['randsw'] = true;
Expand Down
14 changes: 11 additions & 3 deletions web/tpl/taskmulti.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ <h4 class="modal-title" id="myModalLabel">多任务操作</h4>
</div>
<div id="randtime_content">
<div name="randzone readme">
<label class="control-label">当天随机延时区间(0-604800):</label>
<label class="control-label">当天随机延时区间(0-604800)(604800为一周)</label>
</div>
<div name="randzone">
<input type="number" id="randtimezone1" name="randtimezone1" value="" class="modal_input" min="0" max="604800" oninput="if(value<0)value=0"/>~
<input type="number" id="randtimezone2" name="randtimezone2" value="" class="modal_input" min="0" max="604800" oninput="if(value<0)value=0"/>秒
<input type="number" id="randtimezone1" name="randtimezone1" value="" class="modal_input" min="0" max="604800" oninput="if(value<0)value=0;if(value>604800)value=604800"/>~
<input type="number" id="randtimezone2" name="randtimezone2" value="" class="modal_input" min="0" max="604800" oninput="if(value<0)value=0;if(value>604800)value=604800"/>秒
</div>
</div>
{% endif %}
Expand Down Expand Up @@ -145,6 +145,14 @@ <h4 class="modal-title" id="myModalLabel">多任务操作</h4>
// 'cron_sec' : $('#cron_sec')[0].value,
}
data['settime'] = JSON.stringify(settime_tmp);
if (settime_tmp['randtimezone1'] >= settime_tmp['randtimezone2']){
$('#run-result').html("<h1 class=\"alert alert-danger text-center\">随机值错误</h1><div><pre>开启随机时tz1 需大于 tz2</pre></div>").show();
return false;
}
if (settime_tmp['randtimezone1'] > 604800 || settime_tmp['randtimezone2'] > 604800){
$('#run-result').html("<h1 class=\"alert alert-danger text-center\">随机值错误</h1><div><pre>随机值不能大于604800</pre></div>").show();
return false;
}
}

NProgress.inc();
Expand Down

0 comments on commit 6d95f9f

Please sign in to comment.