From 0b19935e069325cf7ca841176d4b2107303c924c Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Thu, 22 May 2025 00:56:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9A=8F=E6=9C=BA=E5=BB=B6=E8=BF=9F=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/run.py | 21 +++++++++++++++ app/static/css/main.css | 40 +++++++++++++++++++++++++++ app/templates/index.html | 58 +++++++++++++++++++++++++++++++++++++--- quark_auto_save.py | 1 - 4 files changed, 115 insertions(+), 5 deletions(-) diff --git a/app/run.py b/app/run.py index 64791a0..58c77b0 100644 --- a/app/run.py +++ b/app/run.py @@ -25,6 +25,8 @@ import base64 import sys import os import re +import random +import time parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, parent_dir) @@ -683,6 +685,18 @@ def add_task(): # 定时任务执行的函数 def run_python(args): logging.info(f">>> 定时运行任务") + # 检查是否需要随机延迟执行 + if delay := config_data.get("crontab_delay"): + try: + delay_seconds = int(delay) + if delay_seconds > 0: + # 在0到设定值之间随机选择一个延迟时间 + random_delay = random.randint(0, delay_seconds) + logging.info(f">>> 随机延迟执行 {random_delay}秒") + time.sleep(random_delay) + except (ValueError, TypeError): + logging.warning(f">>> 延迟执行设置无效: {delay}") + os.system(f"{PYTHON_PATH} {args}") @@ -708,6 +722,9 @@ def reload_tasks(): logging.info(">>> 重载调度器") logging.info(f"调度状态: {scheduler_state_map[scheduler.state]}") logging.info(f"定时规则: {crontab}") + # 记录延迟执行设置 + if delay := config_data.get("crontab_delay"): + logging.info(f"延迟执行: 0-{delay}秒") logging.info(f"现有任务: {scheduler.get_jobs()}") return True else: @@ -740,6 +757,10 @@ def init(): # 默认定时规则 if not config_data.get("crontab"): config_data["crontab"] = "0 8,18,20 * * *" + + # 默认延迟执行设置 + if "crontab_delay" not in config_data: + config_data["crontab_delay"] = 0 # 初始化插件配置 _, plugins_config_default, task_plugins_config_default = Config.load_plugins() diff --git a/app/static/css/main.css b/app/static/css/main.css index da24ce9..685390c 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -3724,3 +3724,43 @@ input::-moz-list-button { background-color: #f7f7fa; /* 表头悬停背景色 */ cursor: pointer; } + +/* 移除number类型输入框的上下箭头 */ +input.no-spinner::-webkit-outer-spin-button, +input.no-spinner::-webkit-inner-spin-button { + -webkit-appearance: none; + margin: 0; +} + +/* Firefox也需要特别处理 */ +input.no-spinner { + -moz-appearance: textfield; +} + +/* 秒字框正方形样式 */ +.square-append { + width: 32px; + height: 32px; + display: flex; + align-items: center; + justify-content: center; + padding: 0 !important; +} + +/* 确保Crontab和延迟执行框在移动端也保持一行 */ +@media (max-width: 767.98px) { + .row.mb-2 .col-sm-6 { + flex: 0 0 50%; + max-width: 50%; + } + + .row.mb-2 .col-sm-6.pr-1 { + padding-right: 4px !important; + padding-left: 15px !important; + } + + .row.mb-2 .col-sm-6.pl-1 { + padding-left: 4px !important; + padding-right: 15px !important; + } +} diff --git a/app/templates/index.html b/app/templates/index.html index 280f0d9..dd1845b 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -273,11 +273,26 @@ -
-
- Crontab +
+
+
+
+ Crontab +
+ +
+
+
+
+
+ 延迟执行 +
+ +
+ +
+
-
@@ -1438,6 +1453,7 @@ return task; }); + // 获取所有任务父目录 config_data.tasklist.forEach(item => { parentDir = this.getParentDirectory(item.savepath) @@ -3072,6 +3088,40 @@ } }); }, + validateNumberInput(event, field, max) { + // 获取当前输入值 + let value = event.target.value; + // 获取输入框的当前光标位置 + const cursorPosition = event.target.selectionStart; + + // 记录原始长度 + const originalLength = value.length; + + // 移除非数字字符 + const cleanValue = value.replace(/[^\d]/g, ''); + + // 如果有非数字字符被移除 + if (cleanValue !== value) { + // 计算移除了多少个字符 + const diff = originalLength - cleanValue.length; + + // 更新输入框的值 + event.target.value = cleanValue; + + // 调整光标位置(考虑到字符被移除) + setTimeout(() => { + event.target.setSelectionRange(Math.max(0, cursorPosition - diff), Math.max(0, cursorPosition - diff)); + }, 0); + } + + // 确保不超过最大值 + if (cleanValue !== '' && parseInt(cleanValue) > max) { + event.target.value = max.toString(); + } + + // 更新数据模型,如果为空则默认为0 + this.formData[field] = event.target.value === '' ? 0 : parseInt(event.target.value); + }, } }); diff --git a/quark_auto_save.py b/quark_auto_save.py index 9b34d72..4bfb170 100644 --- a/quark_auto_save.py +++ b/quark_auto_save.py @@ -4283,7 +4283,6 @@ def do_save(account, tasklist=[]): ) elif is_new_tree is False: # 明确没有新文件 print(f"任务完成: 没有新的文件需要转存") - print() print()