fix: 抛弃多页面交互的延时触发,用FefferyInViewport触发多页面交互,避免因为延时触发时,新页面可能还未加载完毕的bug

This commit is contained in:
luoja 2025-04-14 22:22:13 +08:00
parent f67038e65f
commit 2c5d3dad9b
5 changed files with 39 additions and 30 deletions

View File

@ -2,6 +2,9 @@ from server import app
from dash.dependencies import Input, Output, State
import feffery_antd_components as fac
import feffery_utils_components as fuc
import dash
from dash import set_props
from common.utilities.util_apscheduler import get_apscheduler_all_jobs
def color_job_finish_status(status):
@ -130,3 +133,33 @@ app.clientside_callback(
],
prevent_initial_call=True,
)
@app.callback(
Output('main-task-mgmt-jump-to-task-log-job-id-store', 'data'),
Input('task-log-viewport', 'inViewport'),
[
State('main-task-mgmt-jump-to-task-log-job-id-store', 'data'),
State('task-log-get-log-btn', 'nClicks'),
],
prevent_initial_call=True,
)
def jump_to_log_view(inViewport, job_id, nClicks):
if not inViewport or not job_id:
return dash.no_update
from dash_callback.application.task_.task_log_c import get_start_datetime_options_by_job_id
all_job = [{'label': job.job_id, 'value': job.job_id} for job in get_apscheduler_all_jobs()]
set_props(
'task-log-job-id-select',
{'options': all_job},
)
set_props('task-log-job-id-select', {'value': job_id})
all_time_of_job = get_start_datetime_options_by_job_id(job_id)
set_props(
'task-log-start-datetime-select',
{'options': all_time_of_job},
)
set_props('task-log-start-datetime-select', {'value': all_time_of_job[0]['value']})
set_props('task-log-get-log-btn', {'nClicks': (nClicks or 0) + 1})
return None

View File

@ -164,39 +164,12 @@ def show_modal(nClicks, nClicks_, nClicksButton, clickedCustom, recentlyButtonCl
elif dash.ctx.triggered_id == 'task-mgmt-table' and clickedCustom.startswith('view'):
set_props('main-dcc-url', {'pathname': '/task_/task_log'})
job_id = clickedCustom.split(':', 1)[-1]
set_props('task-mgmt-view-jump-job-id', {'data': job_id})
set_props('task-mgmt-view-jump-timeout', {'delay': 1000}) # 1秒后触发jump_to_log_view对view的参数进行填写
set_props('main-task-mgmt-jump-to-task-log-job-id-store', {'data': job_id})
return dash.no_update
MessageManager.error(content='不支持的任务类型')
return dash.no_update
@app.callback(
Input('task-mgmt-view-jump-timeout', 'timeoutCount'),
[
State('task-mgmt-view-jump-job-id', 'data'),
State('task-log-get-log-btn', 'nClicks'),
],
prevent_initial_call=True,
)
def jump_to_log_view(timeoutCount, job_id, nClicks):
from dash_callback.application.task_.task_log_c import get_start_datetime_options_by_job_id
all_job = [{'label': job.job_id, 'value': job.job_id} for job in get_apscheduler_all_jobs()]
set_props(
'task-log-job-id-select',
{'options': all_job},
)
set_props('task-log-job-id-select', {'value': job_id})
all_time_of_job = get_start_datetime_options_by_job_id(job_id)
set_props(
'task-log-start-datetime-select',
{'options': all_time_of_job},
)
set_props('task-log-start-datetime-select', {'value': all_time_of_job[0]['value']})
set_props('task-log-get-log-btn', {'nClicks': (nClicks or 0) + 1})
@app.callback(
Output('task-mgmt-table-add-modal', 'children'),
Input('task-mgmt-table-add-modal', 'visible'),

View File

@ -18,7 +18,7 @@ access_metas = ('任务日志-页面',)
def render_content(menu_access: MenuAccess, **kwargs):
return (
return fuc.FefferyInViewport(
Card(
fac.AntdSpace(
[
@ -79,4 +79,5 @@ def render_content(menu_access: MenuAccess, **kwargs):
style={'width': '100%', 'height': '100%'},
className={'& .ant-card-body': {'height': '100%'}},
),
id='task-log-viewport'
)

View File

@ -58,7 +58,6 @@ def render_content(menu_access: MenuAccess, **kwargs):
icon=fac.AntdIcon(icon='antd-reload'),
),
fuc.FefferyTimeout(id='task-mgmt-view-jump-timeout'),
dcc.Store(id='task-mgmt-view-jump-job-id'),
]
),
Card(

View File

@ -54,4 +54,7 @@ def render():
centered=True,
cancelButtonProps={'style': {'display': 'none'}},
),
#
# >> 多页面交互缓存
dcc.Store(id='main-task-mgmt-jump-to-task-log-job-id-store'),
]