diff --git a/back/config/const.ts b/back/config/const.ts index 46584588..65f33981 100644 --- a/back/config/const.ts +++ b/back/config/const.ts @@ -1,4 +1,4 @@ -export const LOG_END_SYMBOL = '\n          '; +export const LOG_END_SYMBOL = '     '; export const TASK_COMMAND = 'task'; export const QL_COMMAND = 'ql'; diff --git a/shell/otask.sh b/shell/otask.sh index ee4d979e..9a0d53c1 100644 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -124,8 +124,7 @@ handle_task_after() { local end_timestamp=$(format_timestamp "$time_format" "$etime") local diff_time=$(($end_timestamp - $begin_timestamp)) - echo -e "\n\n## 执行结束... $end_time 耗时 $diff_time 秒" - echo -e "\n     " + echo -e "\n\n## 执行结束... $end_time 耗时 $diff_time 秒     " [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" } diff --git a/shell/update.sh b/shell/update.sh index e09decf0..7a6f0288 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -499,8 +499,7 @@ main() { [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then - eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd - eval echo -e "\\\n          " $cmd + eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒     " $cmd fi if [[ -f $file_path ]]; then diff --git a/src/pages/crontab/index.less b/src/pages/crontab/index.less index 089dcb30..40d4e619 100644 --- a/src/pages/crontab/index.less +++ b/src/pages/crontab/index.less @@ -179,3 +179,15 @@ tr.drop-over-upward td { margin-left: 40px; } } + +.log-modal { + .log-container { + overflow-y: auto; + min-height: 300px; + max-height: calc(80vh - 110px); + max-height: calc(80vh - var(--vh-offset, 110px)); + + padding: 24px; + margin: -24px; + } +} diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index 08ab0d16..c2bd5452 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -34,6 +34,7 @@ const CronLogModal = ({ const [loading, setLoading] = useState(true); const [executing, setExecuting] = useState(true); const [isPhone, setIsPhone] = useState(false); + const scrollInfoRef = useRef({ value: 0, down: true }); const getCronLog = (isFirst?: boolean) => { if (isFirst) { @@ -44,17 +45,19 @@ const CronLogModal = ({ .then(({ code, data }) => { if ( code === 200 && - localStorage.getItem('logCron') === String(cron.id) + localStorage.getItem('logCron') === String(cron.id) && + data !== value ) { const log = data as string; setValue(log || '暂无日志'); - const hasNext = log && !logEnded(log) && !log.includes('重启面板') && !log.includes('任务未运行或运行失败,请尝试手动运行'); + const hasNext = Boolean( + log && + !logEnded(log) && + !log.includes('重启面板') && + !log.includes('任务未运行或运行失败,请尝试手动运行'), + ); setExecuting(hasNext); - setTimeout(() => { - document - .querySelector('#log-flag')! - .scrollIntoView({ behavior: 'smooth' }); - }, 1000); + autoScroll(); if (hasNext) { setTimeout(() => { getCronLog(); @@ -92,11 +95,33 @@ const CronLogModal = ({ }); }; + const autoScroll = () => { + if (!scrollInfoRef.current.down) { + return; + } + + setTimeout(() => { + document + .querySelector('#log-flag')! + .scrollIntoView({ behavior: 'smooth' }); + }, 1000); + }; + const cancel = () => { localStorage.removeItem('logCron'); handleCancel(); }; + const handleScroll = (e) => { + const sTop = e.target.scrollTop; + if (scrollInfoRef.current.down) { + scrollInfoRef.current = { + value: sTop, + down: sTop > scrollInfoRef.current.value, + }; + } + }; + const titleElement = () => { return ( <> @@ -141,24 +166,26 @@ const CronLogModal = ({ , ]} > - {loading ? ( - - ) : ( -
-          {value}
-        
- )} -
+
+ {loading ? ( + + ) : ( +
+            {value}
+          
+ )} +
+
); }; diff --git a/src/utils/const.ts b/src/utils/const.ts index 7bddf45c..51f1fe0b 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -1 +1 @@ -export const LOG_END_SYMBOL = '\n          '; \ No newline at end of file +export const LOG_END_SYMBOL = '     ';