| @@ -430,7 +430,7 @@ td, th { | |||
| <div class="ui message message{{.VersionName}}" style="display: none;"> | |||
| <div id="header"></div> | |||
| </div> | |||
| <div class="ui attached log" onscroll="logScroll({{.VersionName}})" id="log{{.VersionName}}" style="height: 300px !important; overflow: auto;"> | |||
| <div class="ui attached log" onscroll="fn({{.VersionName}})" id="log{{.VersionName}}" style="height: 300px !important; overflow: auto;"> | |||
| <input type="hidden" name="end_line" value> | |||
| <input type="hidden" name="start_line" value> | |||
| <pre id="log_file{{.VersionName}}"></pre> | |||
| @@ -836,7 +836,21 @@ td, th { | |||
| html += "</div>" | |||
| $(`#dir_list${version_name}`).append(html) | |||
| } | |||
| function debounce(fn,delay){ | |||
| let timer; | |||
| return (...args) => { | |||
| // 判断定时器是否存在,清除定时器 | |||
| if (timer) { | |||
| clearTimeout(timer); | |||
| } | |||
| // 重新调用setTimeout | |||
| timer = setTimeout(() => { | |||
| fn.apply(this, args); | |||
| }, delay); | |||
| }; | |||
| } | |||
| const fn = debounce(logScroll, 500) | |||
| function logScroll(version_name) { | |||
| let container = document.querySelector(`#log${version_name}`) | |||
| let scrollTop = container.scrollTop | |||
| @@ -867,7 +881,6 @@ td, th { | |||
| }); | |||
| } | |||
| if([0,1,2,3,4,5,6,7,8,9,10].includes(scrollTop) && scrollLeft==0){ | |||
| let start_line = $(`#log${version_name} input[name=start_line]`).val() | |||
| $.get(`/api/v1/repos/${userName}/${repoPath}/modelarts/train-job/${jobID}/log?version_name=${version_name}&base_line=${start_line}&lines=50&order=asc`, (data) => { | |||
| if (data.Lines == 0){ | |||
| @@ -887,6 +900,7 @@ td, th { | |||
| } | |||
| function scrollAnimation(dom, currentY, targetY, currentX) { | |||
| let needScrollTop = targetY - currentY; | |||
| console.log("---------",needScrollTop) | |||
| let _currentY = currentY; | |||
| setTimeout(() => { | |||
| // 一次调用滑动帧数,每次调用会不一样 | |||
| @@ -894,12 +908,12 @@ td, th { | |||
| const dist = Math.ceil(needScrollTop / 10); | |||
| _currentY += dist; | |||
| //移动一个十分之一 | |||
| dom.scrollTo(currentX || 0, _currentY); | |||
| dom.scrollTo(currentX || 0, _currentY,'smooth'); | |||
| // 如果移动幅度小于十个像素,直接移动,否则递归调用,实现动画效果 | |||
| if (needScrollTop > 10 || needScrollTop < -10) { | |||
| scrollAnimation(dom, _currentY, targetY) | |||
| } else { | |||
| dom.scrollTo(0, targetY) | |||
| dom.scrollTo(0, targetY,'smooth') | |||
| } | |||
| }, 1) | |||
| } | |||