You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
748 lines
31 KiB
748 lines
31 KiB
1 month ago
|
import dash
|
||
|
import time
|
||
|
import uuid
|
||
|
from dash import dcc
|
||
|
from dash.dependencies import Input, Output, State, ALL
|
||
|
from dash.exceptions import PreventUpdate
|
||
|
import feffery_utils_components as fuc
|
||
|
from server import app
|
||
|
from utils.common import validate_data_not_empty
|
||
|
from api.dasset import get_dasset_tree_api
|
||
|
from api.dassetdict import batch_import_dassetdict_api, download_dassetdict_import_template_api, get_dassetdict_list_api, get_dassetdict_detail_api, add_dassetdict_api, edit_dassetdict_api, delete_dassetdict_api,change_dassetdict_info_api, export_dassetdict_list_api
|
||
|
|
||
|
|
||
|
#树形搜索
|
||
|
app.clientside_callback(
|
||
|
"""(value) => value""",
|
||
|
Output('dasset-tree', 'searchKeyword'),
|
||
|
Input('dasset-input-search', 'value'),
|
||
|
)
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#处理树内节点值
|
||
|
def update_value_with_title(node):
|
||
|
node['value'] = node['title'] # 更新当前节点的 value
|
||
|
if 'children' in node:
|
||
|
for child in node['children']:
|
||
|
update_value_with_title(child) # 递归更新子节点
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
output=dict(
|
||
|
dassetdict_table_data=Output('dassetdict-list-table', 'data', allow_duplicate=True),
|
||
|
dassetdict_table_pagination=Output('dassetdict-list-table', 'pagination', allow_duplicate=True),
|
||
|
dassetdict_table_key=Output('dassetdict-list-table', 'key'),
|
||
|
dassetdict_table_selectedrowkeys=Output('dassetdict-list-table', 'selectedRowKeys'),
|
||
|
api_check_token_trigger=Output('api-check-token', 'data', allow_duplicate=True)
|
||
|
),
|
||
|
inputs=dict(
|
||
|
selected_dasset_tree=Input('dasset-tree', 'selectedKeys'),
|
||
|
search_click=Input('dassetdict-search', 'nClicks'),
|
||
|
refresh_click=Input('dassetdict-refresh', 'nClicks'),
|
||
|
pagination=Input('dassetdict-list-table', 'pagination'),
|
||
|
operations=Input('dassetdict-operations-store', 'data')
|
||
|
),
|
||
|
state=dict(
|
||
|
dict_fn=State('dassetdict-dict_fn-input', 'value'),
|
||
|
data_dict_no=State('dassetdict-data_dict_no-input', 'value'),
|
||
|
dict_fccn=State('dassetdict-dict_fccn-input', 'value'),
|
||
|
status_select=State('dassetdict-status-select', 'value'),
|
||
|
button_perms=State('dassetdict-button-perms-container', 'data')
|
||
|
),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
|
||
|
#create_time_range,
|
||
|
def get_dassetdict_table_data_by_dasset_tree(selected_dasset_tree, search_click, refresh_click, pagination, operations,
|
||
|
dict_fn,data_dict_no, dict_fccn, status_select, button_perms):
|
||
|
"""
|
||
|
获取用户表格数据回调(进行表格相关增删查改操作后均会触发此回调)
|
||
|
"""
|
||
|
#默认总公司100根节点
|
||
|
dasset_id = '100'
|
||
|
if selected_dasset_tree:
|
||
|
dasset_id = int(selected_dasset_tree[0])
|
||
|
query_params = dict(
|
||
|
dasset_id=dasset_id,
|
||
|
dict_fn=dict_fn,
|
||
|
data_dict_no=data_dict_no,
|
||
|
dict_fccn=dict_fccn,
|
||
|
status=status_select,
|
||
|
page_num=1,
|
||
|
page_size=15
|
||
|
)
|
||
|
triggered_id = dash.ctx.triggered_id
|
||
|
if triggered_id == 'dassetdict-list-table':
|
||
|
query_params = dict(
|
||
|
dasset_id=dasset_id,
|
||
|
dict_fn=dict_fn,
|
||
|
data_dict_no=data_dict_no,
|
||
|
dict_fccn=dict_fccn,
|
||
|
status=status_select,
|
||
|
page_num=pagination['current'],
|
||
|
page_size=pagination['pageSize']
|
||
|
)
|
||
|
if selected_dasset_tree or search_click or refresh_click or pagination or operations:
|
||
|
table_info = get_dassetdict_list_api(query_params)
|
||
|
if table_info['code'] == 200:
|
||
|
table_data = table_info['data']['rows']
|
||
|
table_pagination = dict(
|
||
|
pageSize=table_info['data']['page_size'],
|
||
|
current=table_info['data']['page_num'],
|
||
|
showSizeChanger=True,
|
||
|
pageSizeOptions=[10, 30, 50, 100],
|
||
|
showQuickJumper=True,
|
||
|
total=table_info['data']['total']
|
||
|
)
|
||
|
for item in table_data:
|
||
|
if item['status'] == '0':
|
||
|
item['status'] = dict(checked=True) #, disabled=item['dict_id'] == 1
|
||
|
else:
|
||
|
item['status'] = dict(checked=False) #, disabled=item['dict_id'] == 1
|
||
|
item['key'] = str(item['dict_id'])
|
||
|
if item['dict_id'] == 1:
|
||
|
item['operation'] = []
|
||
|
else:
|
||
|
item['operation'] = [
|
||
|
{
|
||
|
'title': '修改',
|
||
|
'icon': 'antd-edit'
|
||
|
} if 'dasset:mates:dassetdict:edit' in button_perms else None,
|
||
|
{
|
||
|
'title': '删除',
|
||
|
'icon': 'antd-delete'
|
||
|
} if 'dasset:mates:dassetdict:delete' in button_perms else None
|
||
|
]
|
||
|
|
||
|
return dict(
|
||
|
dassetdict_table_data=table_data,
|
||
|
dassetdict_table_pagination=table_pagination,
|
||
|
dassetdict_table_key=str(uuid.uuid4()),
|
||
|
dassetdict_table_selectedrowkeys=None,
|
||
|
api_check_token_trigger={'timestamp': time.time()}
|
||
|
)
|
||
|
|
||
|
return dict(
|
||
|
dassetdict_table_data=dash.no_update,
|
||
|
dassetdict_table_pagination=dash.no_update,
|
||
|
dassetdict_table_key=dash.no_update,
|
||
|
dassetdict_table_selectedrowkeys=dash.no_update,
|
||
|
api_check_token_trigger={'timestamp': time.time()}
|
||
|
)
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
# 重置用户搜索表单数据回调
|
||
|
app.clientside_callback(
|
||
|
'''
|
||
|
(reset_click) => {
|
||
|
if (reset_click) {
|
||
|
return [null, null, null, null, null, {'type': 'reset'}]
|
||
|
}
|
||
|
return window.dash_clientside.no_update;
|
||
|
}
|
||
|
''',
|
||
|
[Output('dasset-tree', 'selectedKeys'),
|
||
|
Output('dassetdict-dict_fn-input', 'value'),
|
||
|
Output('dassetdict-data_dict_no-input', 'value'),
|
||
|
Output('dassetdict-dict_fccn-input', 'value'),
|
||
|
Output('dassetdict-status-select', 'value'),
|
||
|
Output('dassetdict-operations-store', 'data')],
|
||
|
Input('dassetdict-reset', 'nClicks'),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
|
||
|
|
||
|
# 隐藏/显示用户搜索表单回调
|
||
|
app.clientside_callback(
|
||
|
'''
|
||
|
(hidden_click, hidden_status) => {
|
||
|
if (hidden_click) {
|
||
|
return [
|
||
|
!hidden_status,
|
||
|
hidden_status ? '隐藏搜索' : '显示搜索'
|
||
|
]
|
||
|
}
|
||
|
return window.dash_clientside.no_update;
|
||
|
}
|
||
|
''',
|
||
|
[Output('dassetdict-search-form-container', 'hidden'),
|
||
|
Output('dassetdict-hidden-tooltip', 'title')],
|
||
|
Input('dassetdict-hidden', 'nClicks'),
|
||
|
State('dassetdict-search-form-container', 'hidden'),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
Output({'type': 'dassetdict-operation-button', 'index': 'edit'}, 'disabled'),
|
||
|
Input('dassetdict-list-table', 'selectedRowKeys'),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def change_dassetdict_edit_button_status(table_rows_selected):
|
||
|
"""
|
||
|
根据选择的表格数据行数控制编辑按钮状态回调 len(table_rows_selected) > 0 or
|
||
|
"""
|
||
|
outputs_list = dash.ctx.outputs_list
|
||
|
if outputs_list:
|
||
|
if table_rows_selected:
|
||
|
if len(table_rows_selected) > 1 :
|
||
|
return True
|
||
|
return False
|
||
|
|
||
|
return True
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
Output({'type': 'dassetdict-operation-button', 'index': 'delete'}, 'disabled'),
|
||
|
Input('dassetdict-list-table', 'selectedRowKeys'),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def change_dassetdict_delete_button_status(table_rows_selected):
|
||
|
"""
|
||
|
根据选择的表格数据行数控制删除按钮状态回调
|
||
|
"""
|
||
|
outputs_list = dash.ctx.outputs_list
|
||
|
if outputs_list:
|
||
|
if table_rows_selected:
|
||
|
if '0' in table_rows_selected:
|
||
|
return True
|
||
|
|
||
|
return False
|
||
|
|
||
|
return True
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
output=dict(
|
||
|
modal_visible=Output('dassetdict-add-modal', 'visible', allow_duplicate=True),
|
||
|
dasset_tree=Output({'type': 'dassetdict_add-form-value', 'index': 'dasset_id'}, 'treeData'),
|
||
|
form_value=Output({'type': 'dassetdict_add-form-value', 'index': ALL}, 'value'),
|
||
|
form_label_validate_status=Output({'type': 'dassetdict_add-form-label', 'index': ALL, 'required': True}, 'validateStatus', allow_duplicate=True),
|
||
|
form_label_validate_info=Output({'type': 'dassetdict_add-form-label', 'index': ALL, 'required': True}, 'help', allow_duplicate=True),
|
||
|
api_check_token_trigger=Output('api-check-token', 'data', allow_duplicate=True)
|
||
|
),
|
||
|
inputs=dict(
|
||
|
add_click=Input('dassetdict-add', 'nClicks')
|
||
|
),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def add_dassetdict_modal(add_click):
|
||
|
"""
|
||
|
显示新增用户弹窗回调
|
||
|
"""
|
||
|
if add_click:
|
||
|
# 获取所有输出表单项对应value的index
|
||
|
form_value_list = [x['id']['index'] for x in dash.ctx.outputs_list[2]]
|
||
|
# 获取所有输出表单项对应label的index
|
||
|
form_label_list = [x['id']['index'] for x in dash.ctx.outputs_list[3]]
|
||
|
|
||
|
dasset_params = dict(dasset_name='')
|
||
|
|
||
|
#过滤搜索框中的雨具配置,tree_info重新负值给treeinfo,2024/07/12,wangwentao
|
||
|
tree_info = get_dasset_tree_api(dasset_params)
|
||
|
|
||
|
|
||
|
if tree_info['code'] == 200:
|
||
|
tree_data = tree_info['data']
|
||
|
#print(1100001,tree_data)
|
||
|
dassetdict_info = dict(dict_id=None, dasset_id=None, data_dict_no=None , tab_name=None, tab_cn_name=None,dict_fn=None, dict_fccn=None, dict_pk=None, dict_dft=None,dict_ft=None, order_asc=None, dict_bc=None, dict_al=None, dict_sg=None , status='0',memo=None, remark=None)
|
||
|
|
||
|
return dict(
|
||
|
modal_visible=True,
|
||
|
dasset_tree=tree_data,
|
||
|
form_value=[dassetdict_info.get(k) for k in form_value_list],
|
||
|
form_label_validate_status=[None] * len(form_label_list),
|
||
|
form_label_validate_info=[None] * len(form_label_list),
|
||
|
api_check_token_trigger={'timestamp': time.time()}
|
||
|
)
|
||
|
|
||
|
return dict(
|
||
|
modal_visible=dash.no_update,
|
||
|
dasset_tree=dash.no_update,
|
||
|
form_value=[dash.no_update] * len(form_value_list),
|
||
|
form_label_validate_status=[dash.no_update] * len(form_label_list),
|
||
|
form_label_validate_info=[dash.no_update] * len(form_label_list),
|
||
|
api_check_token_trigger={'timestamp': time.time()}
|
||
|
)
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
output=dict(
|
||
|
form_label_validate_status=Output({'type': 'dassetdict_add-form-label', 'index': ALL, 'required': True}, 'validateStatus', allow_duplicate=True),
|
||
|
form_label_validate_info=Output({'type': 'dassetdict_add-form-label', 'index': ALL, 'required': True}, 'help', allow_duplicate=True),
|
||
|
modal_visible=Output('dassetdict-add-modal', 'visible', allow_duplicate=True),
|
||
|
operations=Output('dassetdict-operations-store', 'data', allow_duplicate=True),
|
||
|
api_check_token_trigger=Output('api-check-token', 'data', allow_duplicate=True),
|
||
|
global_message_container=Output('global-message-container', 'children', allow_duplicate=True)
|
||
|
),
|
||
|
inputs=dict(
|
||
|
add_confirm=Input('dassetdict-add-modal', 'okCounts')
|
||
|
),
|
||
|
state=dict(
|
||
|
form_value=State({'type': 'dassetdict_add-form-value', 'index': ALL}, 'value'),
|
||
|
form_label=State({'type': 'dassetdict_add-form-label', 'index': ALL, 'required': True}, 'label')
|
||
|
),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def dassetdict_add_confirm(add_confirm, form_value, form_label):
|
||
|
if add_confirm:
|
||
|
# 获取所有输出表单项对应label的index
|
||
|
form_label_output_list = [x['id']['index'] for x in dash.ctx.outputs_list[0]]
|
||
|
# 获取所有输入表单项对应的value及label
|
||
|
form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]}
|
||
|
form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]}
|
||
|
|
||
|
if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]):
|
||
|
params = form_value_state
|
||
|
add_button_result = add_dassetdict_api(params)
|
||
|
|
||
|
if add_button_result['code'] == 200:
|
||
|
return dict(
|
||
|
form_label_validate_status=[None] * len(form_label_output_list),
|
||
|
form_label_validate_info=[None] * len(form_label_output_list),
|
||
|
modal_visible=False,
|
||
|
operations={'type': 'add'},
|
||
|
api_check_token_trigger={'timestamp': time.time()},
|
||
|
global_message_container=fuc.FefferyFancyMessage('新增成功', type='success')
|
||
|
)
|
||
|
|
||
|
return dict(
|
||
|
form_label_validate_status=[None] * len(form_label_output_list),
|
||
|
form_label_validate_info=[None] * len(form_label_output_list),
|
||
|
modal_visible=dash.no_update,
|
||
|
operations=dash.no_update,
|
||
|
api_check_token_trigger={'timestamp': time.time()},
|
||
|
global_message_container=fuc.FefferyFancyMessage('新增失败', type='error')
|
||
|
)
|
||
|
|
||
|
return dict(
|
||
|
form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list],
|
||
|
form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list],
|
||
|
modal_visible=dash.no_update,
|
||
|
operations=dash.no_update,
|
||
|
api_check_token_trigger=dash.no_update,
|
||
|
global_message_container=fuc.FefferyFancyMessage('新增失败', type='error')
|
||
|
)
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
output=dict(
|
||
|
modal_visible=Output('dassetdict-edit-modal', 'visible', allow_duplicate=True),
|
||
|
dasset_tree=Output({'type': 'dassetdict_edit-form-value', 'index': 'dasset_id'}, 'treeData'),
|
||
|
form_value=Output({'type': 'dassetdict_edit-form-value', 'index': ALL}, 'value'),
|
||
|
form_label_validate_status=Output({'type': 'dassetdict_edit-form-label', 'index': ALL, 'required': True}, 'validateStatus', allow_duplicate=True),
|
||
|
form_label_validate_info=Output({'type': 'dassetdict_edit-form-label', 'index': ALL, 'required': True}, 'help', allow_duplicate=True),
|
||
|
edit_row_info=Output('dassetdict-edit-id-store', 'data'),
|
||
|
api_check_token_trigger=Output('api-check-token', 'data', allow_duplicate=True)
|
||
|
),
|
||
|
inputs=dict(
|
||
|
operation_click=Input({'type': 'dassetdict-operation-button', 'index': ALL}, 'nClicks'),
|
||
|
dropdown_click=Input('dassetdict-list-table', 'nClicksDropdownItem')
|
||
|
),
|
||
|
state=dict(
|
||
|
selected_row_keys=State('dassetdict-list-table', 'selectedRowKeys'),
|
||
|
recently_clicked_dropdown_item_title=State('dassetdict-list-table', 'recentlyClickedDropdownItemTitle'),
|
||
|
recently_dropdown_item_clicked_row=State('dassetdict-list-table', 'recentlyDropdownItemClickedRow')
|
||
|
),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def dassetdict_edit_modal(operation_click, dropdown_click,
|
||
|
selected_row_keys, recently_clicked_dropdown_item_title, recently_dropdown_item_clicked_row):
|
||
|
"""
|
||
|
显示编辑字段弹窗回调
|
||
|
"""
|
||
|
trigger_id = dash.ctx.triggered_id
|
||
|
if trigger_id == {'index': 'edit', 'type': 'dassetdict-operation-button'} or (trigger_id == 'dassetdict-list-table' and recently_clicked_dropdown_item_title == '修改'):
|
||
|
# 获取所有输出表单项对应value的index
|
||
|
form_value_list = [x['id']['index'] for x in dash.ctx.outputs_list[2]]
|
||
|
# 获取所有输出表单项对应label的index
|
||
|
form_label_list = [x['id']['index'] for x in dash.ctx.outputs_list[3]]
|
||
|
|
||
|
dasset_params = dict(dasset_name='')
|
||
|
#tree_data = get_dasset_tree_api(dasset_params)['data']
|
||
|
|
||
|
|
||
|
|
||
|
#过滤搜索框中的雨具配置,tree_info重新负值给treeinfo,2024/07/12,wangwentao
|
||
|
tree_info = get_dasset_tree_api(dasset_params)
|
||
|
tree_data = tree_info['data']
|
||
|
#tree_data = remove_statement_config(tree_data_temp) # 递归删除语句,2024/07/11 wangwentao
|
||
|
|
||
|
if trigger_id == {'index': 'edit', 'type': 'dassetdict-operation-button'}:
|
||
|
dict_id = int(selected_row_keys[0])
|
||
|
else:
|
||
|
if recently_clicked_dropdown_item_title == '修改':
|
||
|
dict_id = int(recently_dropdown_item_clicked_row['key'])
|
||
|
else:
|
||
|
raise PreventUpdate
|
||
|
|
||
|
edit_button_info = get_dassetdict_detail_api(dict_id)
|
||
|
if edit_button_info['code'] == 200:
|
||
|
edit_button_result = edit_button_info['data']
|
||
|
dassetdict = edit_button_result['dassetdict']
|
||
|
return dict(
|
||
|
modal_visible=True,
|
||
|
dasset_tree=tree_data,
|
||
|
form_value=[dassetdict.get(k) for k in form_value_list],
|
||
|
form_label_validate_status=[None] * len(form_label_list),
|
||
|
form_label_validate_info=[None] * len(form_label_list),
|
||
|
edit_row_info={'dict_id': dict_id},
|
||
|
api_check_token_trigger={'timestamp': time.time()}
|
||
|
)
|
||
|
|
||
|
return dict(
|
||
|
modal_visible=dash.no_update,
|
||
|
dasset_tree=dash.no_update,
|
||
|
form_value=[dash.no_update] * len(form_value_list),
|
||
|
form_label_validate_status=[dash.no_update] * len(form_label_list),
|
||
|
form_label_validate_info=[dash.no_update] * len(form_label_list),
|
||
|
edit_row_info=dash.no_update,
|
||
|
api_check_token_trigger={'timestamp': time.time()}
|
||
|
)
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
output=dict(
|
||
|
form_label_validate_status=Output({'type': 'dassetdict_edit-form-label', 'index': ALL, 'required': True}, 'validateStatus', allow_duplicate=True),
|
||
|
form_label_validate_info=Output({'type': 'dassetdict_edit-form-label', 'index': ALL, 'required': True}, 'help', allow_duplicate=True),
|
||
|
modal_visible=Output('dassetdict-edit-modal', 'visible', allow_duplicate=True),
|
||
|
operations=Output('dassetdict-operations-store', 'data', allow_duplicate=True),
|
||
|
api_check_token_trigger=Output('api-check-token', 'data', allow_duplicate=True),
|
||
|
global_message_container=Output('global-message-container', 'children', allow_duplicate=True)
|
||
|
),
|
||
|
inputs=dict(
|
||
|
edit_confirm=Input('dassetdict-edit-modal', 'okCounts')
|
||
|
),
|
||
|
state=dict(
|
||
|
edit_row_info=State('dassetdict-edit-id-store', 'data'),
|
||
|
form_value=State({'type': 'dassetdict_edit-form-value', 'index': ALL}, 'value'),
|
||
|
form_label=State({'type': 'dassetdict_edit-form-label', 'index': ALL, 'required': True}, 'label')
|
||
|
),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def dassetdict_edit_confirm(edit_confirm, edit_row_info, form_value, form_label):
|
||
|
if edit_confirm:
|
||
|
# 获取所有输出表单项对应label的index
|
||
|
form_label_output_list = [x['id']['index'] for x in dash.ctx.outputs_list[0]]
|
||
|
# 获取所有输入表单项对应的value及label
|
||
|
form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]}
|
||
|
form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]}
|
||
|
|
||
|
if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]):
|
||
|
params = form_value_state
|
||
|
params['dict_id'] = edit_row_info.get('dict_id') if edit_row_info else None
|
||
|
edit_button_result = edit_dassetdict_api(params)
|
||
|
|
||
|
if edit_button_result['code'] == 200:
|
||
|
return dict(
|
||
|
form_label_validate_status=[None] * len(form_label_output_list),
|
||
|
form_label_validate_info=[None] * len(form_label_output_list),
|
||
|
modal_visible=False,
|
||
|
operations={'type': 'edit'},
|
||
|
api_check_token_trigger={'timestamp': time.time()},
|
||
|
global_message_container=fuc.FefferyFancyMessage('编辑成功', type='success')
|
||
|
)
|
||
|
|
||
|
return dict(
|
||
|
form_label_validate_status=[None] * len(form_label_output_list),
|
||
|
form_label_validate_info=[None] * len(form_label_output_list),
|
||
|
modal_visible=dash.no_update,
|
||
|
operations=dash.no_update,
|
||
|
api_check_token_trigger={'timestamp': time.time()},
|
||
|
global_message_container=fuc.FefferyFancyMessage('编辑失败', type='error')
|
||
|
)
|
||
|
|
||
|
return dict(
|
||
|
form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list],
|
||
|
form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list],
|
||
|
modal_visible=dash.no_update,
|
||
|
operations=dash.no_update,
|
||
|
api_check_token_trigger=dash.no_update,
|
||
|
global_message_container=fuc.FefferyFancyMessage('编辑失败', type='error')
|
||
|
)
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
[Output('dassetdict-operations-store', 'data', allow_duplicate=True),
|
||
|
Output('api-check-token', 'data', allow_duplicate=True),
|
||
|
Output('global-message-container', 'children', allow_duplicate=True)],
|
||
|
[Input('dassetdict-list-table', 'recentlySwitchDataIndex'),
|
||
|
Input('dassetdict-list-table', 'recentlySwitchStatus'),
|
||
|
Input('dassetdict-list-table', 'recentlySwitchRow')],
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def table_switch_dassetdict_status(recently_switch_data_index, recently_switch_status, recently_switch_row):
|
||
|
"""
|
||
|
表格内切换字段状态回调
|
||
|
"""
|
||
|
if recently_switch_data_index:
|
||
|
if recently_switch_status:
|
||
|
params = dict(dict_id=int(recently_switch_row['key']), status='0', type='status')
|
||
|
else:
|
||
|
params = dict(dict_id=int(recently_switch_row['key']), status='1', type='status')
|
||
|
edit_button_result = edit_dassetdict_api(params)
|
||
|
if edit_button_result['code'] == 200:
|
||
|
|
||
|
return [
|
||
|
{'type': 'switch-status'},
|
||
|
{'timestamp': time.time()},
|
||
|
fuc.FefferyFancyMessage('修改成功', type='success')
|
||
|
]
|
||
|
|
||
|
return [
|
||
|
{'type': 'switch-status'},
|
||
|
{'timestamp': time.time()},
|
||
|
fuc.FefferyFancyMessage('修改失败', type='error')
|
||
|
]
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
#dassetdict-delete-confirm-modal
|
||
|
@app.callback(
|
||
|
[Output('dassetdict-delete-text', 'children'),
|
||
|
Output('dassetdict-delete-confirm-modal', 'visible'),
|
||
|
Output('dassetdict-delete-ids-store', 'data')],
|
||
|
[Input({'type': 'dassetdict-operation-button', 'index': ALL}, 'nClicks'),
|
||
|
Input('dassetdict-list-table', 'nClicksDropdownItem')
|
||
|
],
|
||
|
[State('dassetdict-list-table', 'selectedRowKeys'),
|
||
|
State('dassetdict-list-table', 'recentlyClickedDropdownItemTitle'),
|
||
|
State('dassetdict-list-table', 'recentlyDropdownItemClickedRow')],
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def dassetdict_delete_modal(operation_click, dropdown_click,
|
||
|
selected_row_keys, recently_clicked_dropdown_item_title, recently_dropdown_item_clicked_row):
|
||
|
"""
|
||
|
显示删除字段二次确认弹窗回调
|
||
|
"""
|
||
|
trigger_id = dash.ctx.triggered_id
|
||
|
if trigger_id == {'index': 'delete', 'type': 'dassetdict-operation-button'} or (trigger_id == 'dassetdict-list-table' and recently_clicked_dropdown_item_title == '删除'):
|
||
|
|
||
|
if trigger_id == {'index': 'delete', 'type': 'dassetdict-operation-button'}:
|
||
|
dict_ids = ','.join(selected_row_keys)
|
||
|
else:
|
||
|
if recently_clicked_dropdown_item_title == '删除':
|
||
|
dict_ids = recently_dropdown_item_clicked_row['key']
|
||
|
else:
|
||
|
raise PreventUpdate
|
||
|
|
||
|
return [
|
||
|
f'是否确认删除字典编号为{dict_ids}的字段?',
|
||
|
True,
|
||
|
{'dict_ids': dict_ids}
|
||
|
]
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
[Output('dassetdict-operations-store', 'data', allow_duplicate=True),
|
||
|
Output('api-check-token', 'data', allow_duplicate=True),
|
||
|
Output('global-message-container', 'children', allow_duplicate=True)],
|
||
|
Input('dassetdict-delete-confirm-modal', 'okCounts'),
|
||
|
State('dassetdict-delete-ids-store', 'data'),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
|
||
|
def dassetdict_delete_confirm(delete_confirm, dict_ids_data):
|
||
|
"""
|
||
|
删除用户弹窗确认回调,实现删除操作
|
||
|
"""
|
||
|
print(5555555555,delete_confirm, dict_ids_data)
|
||
|
if delete_confirm:
|
||
|
|
||
|
params = dict_ids_data
|
||
|
delete_button_info = delete_dassetdict_api(params)
|
||
|
if delete_button_info['code'] == 200:
|
||
|
return [
|
||
|
{'type': 'delete'},
|
||
|
{'timestamp': time.time()},
|
||
|
fuc.FefferyFancyMessage('删除成功', type='success')
|
||
|
]
|
||
|
|
||
|
return [
|
||
|
dash.no_update,
|
||
|
{'timestamp': time.time()},
|
||
|
fuc.FefferyFancyMessage('删除失败', type='error')
|
||
|
]
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
# 显示元数据字段导入弹窗及重置上传弹窗组件状态回调
|
||
|
app.clientside_callback(
|
||
|
'''
|
||
|
(nClicks) => {
|
||
|
if (nClicks) {
|
||
|
return [
|
||
|
true,
|
||
|
[],
|
||
|
[],
|
||
|
false
|
||
|
];
|
||
|
}
|
||
|
return [
|
||
|
false,
|
||
|
window.dash_clientside.no_update,
|
||
|
window.dash_clientside.no_update,
|
||
|
window.dash_clientside.no_update
|
||
|
];
|
||
|
}
|
||
|
''',
|
||
|
[Output('dassetdict-import-confirm-modal', 'visible'),
|
||
|
Output('dassetdict-upload-choose', 'listUploadTaskRecord'),
|
||
|
Output('dassetdict-upload-choose', 'defaultFileList'),
|
||
|
Output('dassetdict-import-update-check', 'checked')],
|
||
|
Input('dassetdict-import', 'nClicks'),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
output=dict(
|
||
|
confirm_loading=Output('dassetdict-import-confirm-modal', 'confirmLoading'),
|
||
|
modal_visible=Output('batch-result-modal', 'visible',allow_duplicate=True), #add
|
||
|
batch_result=Output('batch-result-content', 'children',allow_duplicate=True), #add
|
||
|
operations=Output('dassetdict-operations-store', 'data', allow_duplicate=True),
|
||
|
api_check_token_trigger=Output('api-check-token', 'data', allow_duplicate=True),
|
||
|
global_message_container=Output('global-message-container', 'children', allow_duplicate=True)
|
||
|
),
|
||
|
inputs=dict(
|
||
|
import_confirm=Input('dassetdict-import-confirm-modal', 'okCounts')
|
||
|
),
|
||
|
state=dict(
|
||
|
list_upload_task_record=State('dassetdict-upload-choose', 'listUploadTaskRecord'),
|
||
|
is_update=State('dassetdict-import-update-check', 'checked')
|
||
|
),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def dassetdict_import_confirm(import_confirm, list_upload_task_record, is_update):
|
||
|
"""
|
||
|
元数据字段导入弹窗确认回调,实现批量导入用户操作
|
||
|
"""
|
||
|
if import_confirm:
|
||
|
if list_upload_task_record:
|
||
|
url = list_upload_task_record[-1].get('url')
|
||
|
batch_param = dict(url=url, is_update=is_update)
|
||
|
batch_import_result = batch_import_dassetdict_api(batch_param)
|
||
|
if batch_import_result.get('code') == 200:
|
||
|
return dict(
|
||
|
confirm_loading=False,
|
||
|
modal_visible=True if batch_import_result.get('message') else False,
|
||
|
batch_result=batch_import_result.get('message'),
|
||
|
operations={'type': 'batch-import'},
|
||
|
api_check_token_trigger={'timestamp': time.time()},
|
||
|
global_message_container=fuc.FefferyFancyMessage('导入成功', type='success')
|
||
|
)
|
||
|
|
||
|
return dict(
|
||
|
confirm_loading=False,
|
||
|
modal_visible=True,
|
||
|
batch_result=batch_import_result.get('message'),
|
||
|
operations=dash.no_update,
|
||
|
api_check_token_trigger={'timestamp': time.time()},
|
||
|
global_message_container=fuc.FefferyFancyMessage('导入失败', type='error')
|
||
|
)
|
||
|
else:
|
||
|
return dict(
|
||
|
confirm_loading=False,
|
||
|
modal_visible=dash.no_update,
|
||
|
batch_result=dash.no_update,
|
||
|
operations=dash.no_update,
|
||
|
api_check_token_trigger=dash.no_update,
|
||
|
global_message_container=fuc.FefferyFancyMessage('请上传需要导入的文件', type='error')
|
||
|
)
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
@app.callback(
|
||
|
[Output('dassetdict-export-container', 'data', allow_duplicate=True),
|
||
|
Output('dassetdict-export-complete-judge-container', 'data'),
|
||
|
Output('api-check-token', 'data', allow_duplicate=True),
|
||
|
Output('global-message-container', 'children', allow_duplicate=True)],
|
||
|
[Input('dassetdict-export', 'nClicks'),
|
||
|
Input('download-dassetdict-import-template', 'nClicks')],
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def export_dassetdict_list(export_click, download_click):
|
||
|
"""
|
||
|
导出元数据字段管理信息回调
|
||
|
"""
|
||
|
trigger_id = dash.ctx.triggered_id
|
||
|
if export_click or download_click:
|
||
|
|
||
|
if trigger_id == 'dassetdict-export':
|
||
|
export_dassetdict_res = export_dassetdict_list_api({})
|
||
|
if export_dassetdict_res.status_code == 200:
|
||
|
export_dassetdict = export_dassetdict_res.content
|
||
|
|
||
|
return [
|
||
|
dcc.send_bytes(export_dassetdict, f'元数据字段管理信息_{time.strftime("%Y%m%d%H%M%S", time.localtime())}.xlsx'),
|
||
|
{'timestamp': time.time()},
|
||
|
{'timestamp': time.time()},
|
||
|
fuc.FefferyFancyMessage('导出成功', type='success')
|
||
|
]
|
||
|
|
||
|
return [
|
||
|
dash.no_update,
|
||
|
dash.no_update,
|
||
|
{'timestamp': time.time()},
|
||
|
fuc.FefferyFancyMessage('导出失败', type='error')
|
||
|
]
|
||
|
|
||
|
|
||
|
if trigger_id == 'download-dassetdict-import-template':
|
||
|
download_template_res = download_dassetdict_import_template_api()
|
||
|
if download_template_res.status_code == 200:
|
||
|
download_template = download_template_res.content
|
||
|
|
||
|
return [
|
||
|
dcc.send_bytes(download_template, f'元数据字段管理导入模板_{time.strftime("%Y%m%d%H%M%S", time.localtime())}.xlsx'),
|
||
|
{'timestamp': time.time()},
|
||
|
{'timestamp': time.time()},
|
||
|
fuc.FefferyFancyMessage('下载成功', type='success')
|
||
|
]
|
||
|
|
||
|
return [
|
||
|
dash.no_update,
|
||
|
dash.no_update,
|
||
|
{'timestamp': time.time()},
|
||
|
fuc.FefferyFancyMessage('下载失败', type='error')
|
||
|
]
|
||
|
|
||
|
|
||
|
raise PreventUpdate
|
||
|
|
||
|
|
||
|
@app.callback(
|
||
|
Output('dassetdict-export-container', 'data', allow_duplicate=True),
|
||
|
Input('dassetdict-export-complete-judge-container', 'data'),
|
||
|
prevent_initial_call=True
|
||
|
)
|
||
|
def reset_dassetdict_export_status(data):
|
||
|
"""
|
||
|
导出完成后重置下载组件数据回调,防止重复下载文件
|
||
|
"""
|
||
|
time.sleep(0.5)
|
||
|
if data:
|
||
|
|
||
|
return None
|
||
|
|
||
|
raise PreventUpdate
|