from dash import dcc, html import feffery_antd_components as fac from flask import session from utils.common import find_title_and_path from api.vecset import get_vecset_list_api from api.dasset import get_dasset_tree_api from config.global_config import ApiBaseUrlConfig import callbacks.dataint_c.vecset_c as cddc def render(*args, **kwargs): button_perms = kwargs.get('button_perms') dasset_params = dict(dasset_name='') vecset_params = dict(page_num=1, page_size=15) tree_info = get_dasset_tree_api(dasset_params) table_info = get_vecset_list_api(vecset_params) #print(666,tree_info['data']) # 定义转换后的数据 tree_data = [] # 遍历 A 中的第一层数据 for item in tree_info['data']: # 创建新的字典,只保留 title 和 key new_item = { 'title': item['title'], 'key': item['key'], 'children': [] } # 遍历 children 列表 for child in item['children']: # 创建新的子项字典,只保留 title 和 key new_child = { 'title': child['title'], 'key': child['key'] } new_item['children'].append(new_child) # 将新项添加到 tree_data 中 tree_data.append(new_item) # tree_data = [ # { # 'title': '公司总资产', # 'key': '100', # 'children': [ # {'title': '资讯数据资产', 'key': '101'}, # {'title': '财务数据资产', 'key': '102'}, # {'title': '其他数据资产', 'key': '121'}, # ], # }, # ] table_data = [] page_num = 1 page_size = 15 total = 0 if table_info['code'] == 200: table_data = table_info['data']['rows'] page_num = table_info['data']['page_num'] page_size = table_info['data']['page_size'] total = table_info['data']['total'] for item in table_data: if item['status'] == '0': item['status'] = dict(checked=True) else: item['status'] = dict(checked=False) item['key'] = str(item['onum']) item['operation'] = [ { 'title': '修改', 'type': 'link', 'icon': 'antd-edit' } if 'dataint:vecset:edit' in button_perms else None, { 'title': '删除', 'type': 'link', 'icon': 'antd-delete' } if 'dataint:vecset:delete' in button_perms else None, ] return [ dcc.Store(id='vecset-button-perms-container', data=button_perms), # 用于导出成功后重置dcc.Download的状态,防止多次下载文件 dcc.Store(id='vecset-export-complete-judge-container'), # 绑定的导出组件 dcc.Download(id='vecset-export-container'), # 字段管理模块操作类型存储容器 dcc.Store(id='vecset-operations-store'), # 字段管理模块修改操作行key存储容器 dcc.Store(id='vecset-edit-id-store'), # 字段管理模块删除操作行key存储容器 dcc.Store(id='vecset-delete-ids-store'), fac.AntdRow( [ fac.AntdCol( [ fac.AntdInput( id='vdasset-input-search', placeholder='请输入数据资产名称', autoComplete='off', allowClear=True, prefix=fac.AntdIcon( icon='antd-search' ), style={ 'width': '85%' } ), fac.AntdTree( id='vdasset-tree', treeData=tree_data, defaultExpandAll=True, showLine=False, style={ 'margin-top': '10px', 'font-size': '14px', # 内联样式中设置字体大小 'color': 'black', # 内联样式中设置字体颜色 } ) ], span=4 ), fac.AntdCol( [ fac.AntdRow( [ fac.AntdCol( html.Div( [ fac.AntdForm( [ fac.AntdSpace( [ fac.AntdFormItem( fac.AntdInput( id='vecset-stab_name-input', placeholder='请输入表名称', autoComplete='off', allowClear=True, style={ 'width': 160 } ), label='表 名 称' ), fac.AntdFormItem( fac.AntdInput( id='vecset-squery-input', placeholder='请输入查询语句', autoComplete='off', allowClear=True, style={ 'width': 160 } ), label='查询语句' ), fac.AntdFormItem( fac.AntdInput( id='vecset-sanal_plan-input', placeholder='请输入分析方法', autoComplete='off', allowClear=True, style={ 'width': 160 } ), label='分析方法' ), fac.AntdFormItem( fac.AntdSelect( id='vecset-status-select', placeholder='字段状态', options=[ { 'label': '正常', 'value': '0' }, { 'label': '停用', 'value': '1' } ], style={ 'width': 160 } ), label='字段状态' ), fac.AntdFormItem( fac.AntdButton( '搜索', id='vecset-search', type='primary', icon=fac.AntdIcon( icon='antd-search' ) ) ), fac.AntdFormItem( fac.AntdButton( '重置', id='vecset-reset', icon=fac.AntdIcon( icon='antd-sync' ) ) ) ], style={ 'paddingBottom': '10px' } ), # fac.AntdSpace( # [ # # fac.AntdFormItem( # # fac.AntdInput( # # id='vecset-sanal_plan-input', # # placeholder='请输入分析方法', # # autoComplete='off', # # allowClear=True, # # style={ # # 'width': 240 # # } # # ), # # label='分析方法' # # ), # # fac.AntdFormItem( # # fac.AntdDateRangePicker( # # id='vecset-create_time-range', # # style={ # # 'width': '240px' # # } # # ), # # label='创建时间' # # ), # ], # style={ # 'paddingBottom': '10px' # } # ), ], layout='inline', ) ], id='vecset-search-form-container', hidden=False ), ) ] ), fac.AntdRow( [ fac.AntdCol( fac.AntdSpace( [ fac.AntdButton( [ fac.AntdIcon( icon='antd-plus' ), '新增', ], id='vecset-add', style={ 'color': '#1890ff', 'background': '#e8f4ff', 'border-color': '#a3d3ff' } ) if 'dataint:vecset:add' in button_perms else [], fac.AntdButton( [ fac.AntdIcon( icon='antd-edit' ), '修改', ], id={ 'type': 'vecset-operation-button', 'index': 'edit' }, #disabled=True, style={ 'color': '#71e2a3', 'background': '#e7faf0', 'border-color': '#d0f5e0' } ) if 'dataint:vecset:edit' in button_perms else [], fac.AntdButton( [ fac.AntdIcon( icon='antd-minus' ), '删除', ], id={ 'type': 'vecset-operation-button', 'index': 'delete' }, #disabled=True, style={ 'color': '#ff9292', 'background': '#ffeded', 'border-color': '#ffdbdb' } ) if 'dataint:vecset:delete' in button_perms else [], fac.AntdButton( [ fac.AntdIcon( icon='antd-arrow-up' ), '导入', ], id='vecset-import', style={ 'color': '#909399', 'background': '#f4f4f5', 'border-color': '#d3d4d6' } ) if 'dataint:vecset:import' in button_perms else [], fac.AntdButton( [ fac.AntdIcon( icon='antd-arrow-down' ), '导出', ], id='vecset-export', style={ 'color': '#ffba00', 'background': '#fff8e6', 'border-color': '#ffe399' } ) if 'dataint:vecset:export' in button_perms else [], ], style={ 'paddingBottom': '10px' } ), span=16 ), fac.AntdCol( fac.AntdSpace( [ html.Div( fac.AntdTooltip( fac.AntdButton( [ fac.AntdIcon( icon='antd-search' ), ], id='vecset-hidden', shape='circle' ), id='vecset-hidden-tooltip', title='隐藏搜索' ) ), html.Div( fac.AntdTooltip( fac.AntdButton( [ fac.AntdIcon( icon='antd-sync' ), ], id='vecset-refresh', shape='circle' ), title='刷新' ) ), ], style={ 'float': 'right', 'paddingBottom': '10px' } ), span=8, style={ 'paddingRight': '10px' } ) ], gutter=5 ), fac.AntdRow( [ fac.AntdCol( fac.AntdSpin( fac.AntdTable( id='vecset-list-table', data=table_data, columns=[ { 'dataIndex': 'onum', 'title': '序号', 'width': 80, 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'dataIndex': 'stab_name', 'title': '表名称', #'width': 100, #'align': 'left', # 左对齐 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'dataIndex': 'squery', 'title': '查询语句', #'width': 120, #'align': 'left', # 左对齐 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'dataIndex': 'sanal_plan', 'title': '分析方法', #'width': 80, 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'dataIndex': 'sintnt_term', 'title': '意图词', #'width': 120, 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'dataIndex': 'ssql', 'title': '参考sql', 'width': 260, 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'dataIndex': 'sim_thrsh', 'title': '相似阈值', #'width': 120, 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'dataIndex': 'status', 'title': '状态', #'width': 70, 'renderOptions': { 'renderType': 'switch' }, }, { 'dataIndex': 'update_by', 'title': '负责人', #'width': 100, 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'dataIndex': 'update_time', 'title': '更新时间', #'width': 100, 'renderOptions': { 'renderType': 'ellipsis' }, }, { 'title': '操作', 'dataIndex': 'operation', 'renderOptions': { 'renderType': 'dropdown', 'dropdownProps': { 'title': '更多' } }, } ], rowSelectionType='checkbox', rowSelectionWidth=50, bordered=True, maxWidth=1800, maxHeight=500, style={'width': '100%','text-align': 'center','paddingRight': '10px'}, pagination={ 'pageSize': page_size, 'current': page_num, 'showSizeChanger': True, 'pageSizeOptions': [15, 30, 50], 'showQuickJumper': True, 'total': total }, mode='server-side' ), text='数据加载中' ), ) ] ), ], span=20 ) ], gutter=5 ), # 新增语句配置表单modal fac.AntdModal( [ fac.AntdForm( [ fac.AntdRow( [ fac.AntdCol( fac.AntdFormItem( fac.AntdTreeSelect( id={ 'type': 'vecset_add-form-value', 'index': 'dasset_id' }, placeholder='请选择资产名', treeData=[], treeNodeFilterProp='title', style={ 'width': '100%' #'width': '495px' } ), label='归属资产名', required=True, id={ 'type': 'vecset_add-form-label', 'index': 'dasset_id', 'required': False }, labelCol={ 'offset': 1 } ), span=12 ), fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_add-form-value', 'index': 'stab_name' }, placeholder='请输入表名', allowClear=True, style={ 'width': '100%' } ), label='表名', required=False, id={ 'type': 'vecset_add-form-label', 'index': 'stab_name', 'required': True } ), span=12 ) ], gutter=5 ), fac.AntdRow( [ fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_add-form-value', 'index': 'squery' }, placeholder='请输入查询语句', allowClear=True, style={ 'width': '100%' } ), label='查询语句', required=True, id={ 'type': 'vecset_add-form-label', 'index': 'squery', 'required': True } ), span=12 ), fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_add-form-value', 'index': 'sanal_plan' }, placeholder='请输入分析方法', allowClear=True, style={ 'width': '100%' } ), label='分析方法', id={ 'type': 'vecset_add-form-label', 'index': 'sanal_plan', 'required': False }, ), span=12 ) ], gutter=5 ), fac.AntdRow( [ fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_add-form-value', 'index': 'ssql' }, placeholder='请输入参考sql', allowClear=True, style={ 'width': '100%' } ), label='参考sql', id={ 'type': 'vecset_add-form-label', 'index': 'ssql', 'required': False }, ), span=12 ), fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_add-form-value', 'index': 'sintnt_term' }, placeholder='请输入意图词', allowClear=True, style={ 'width': '100%' } ), label='意图词', id={ 'type': 'vecset_add-form-label', 'index': 'sintnt_term', 'required': False }, ), span=12 ) ], gutter=5 ), fac.AntdRow( [ fac.AntdCol( fac.AntdFormItem( fac.AntdSelect( id={ 'type': 'vecset_add-form-value', 'index': 'status' }, placeholder='请选择字段状态', options=[ { 'label': '正常', 'value': '0' }, { 'label': '停用', 'value': '1' }, ], style={ 'width': '100%' } ), label='字段状态', required=True, id={ 'type': 'vecset_add-form-label', 'index': 'status', 'required': False }, ), span=12 ), fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_add-form-value', 'index': 'sim_thrsh' }, placeholder='请输入相似阈值', allowClear=True, style={ 'width': '100%' } ), label='相似阈值', id={ 'type': 'vecset_add-form-label', 'index': 'sim_thrsh', 'required': False }, ), span=12 ) ], gutter=5 ) ], labelCol={ 'span': 8 }, wrapperCol={ 'span': 16 }, style={ 'marginRight': '10px' } ) ], id='vecset-add-modal', title='新增字段', mask=False, width=650, renderFooter=True, okClickClose=False ), # 编辑表单modal fac.AntdModal( [ fac.AntdForm( [ fac.AntdRow( [ fac.AntdCol( fac.AntdFormItem( fac.AntdTreeSelect( id={ 'type': 'vecset_edit-form-value', 'index': 'dasset_id' }, placeholder='请选择资产名', treeData=[], treeNodeFilterProp='title', style={ 'width': '100%' #'width': '495px' } ), label='归属资产名', required=True, id={ 'type': 'vecset_edit-form-label', 'index': 'dasset_id', 'required': False }, labelCol={ 'offset': 1 } ), span=12 ), fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_edit-form-value', 'index': 'stab_name' }, placeholder='请输入表名', allowClear=True, style={ 'width': '100%' } ), label='表名', required=False, id={ 'type': 'vecset_edit-form-label', 'index': 'stab_name', 'required': True } ), span=12 ) ], gutter=5 ), fac.AntdRow( [ fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_edit-form-value', 'index': 'squery' }, placeholder='请输入查询语句', allowClear=True, style={ 'width': '100%' } ), label='查询语句', required=True, id={ 'type': 'vecset_edit-form-label', 'index': 'squery', 'required': True } ), span=12 ), fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_edit-form-value', 'index': 'sanal_plan' }, placeholder='请输入分析方法', allowClear=True, style={ 'width': '100%' } ), label='分析方法', id={ 'type': 'vecset_edit-form-label', 'index': 'sanal_plan', 'required': False }, ), span=12 ) ], gutter=5 ), fac.AntdRow( [ fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_edit-form-value', 'index': 'ssql' }, placeholder='请输入参考sql', allowClear=True, style={ 'width': '100%' } ), label='参考sql', id={ 'type': 'vecset_edit-form-label', 'index': 'ssql', 'required': False }, ), span=12 ), fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_edit-form-value', 'index': 'sintnt_term' }, placeholder='请输入意图词', allowClear=True, style={ 'width': '100%' } ), label='意图词', id={ 'type': 'vecset_edit-form-label', 'index': 'sintnt_term', 'required': False }, ), span=12 ) ], gutter=5 ), fac.AntdRow( [ fac.AntdCol( fac.AntdFormItem( fac.AntdSelect( id={ 'type': 'vecset_edit-form-value', 'index': 'status' }, placeholder='请选择字段状态', options=[ { 'label': '正常', 'value': '0' }, { 'label': '停用', 'value': '1' }, ], style={ 'width': '100%' } ), label='字段状态', required=True, id={ 'type': 'vecset_edit-form-label', 'index': 'status', 'required': False }, ), span=12 ), fac.AntdCol( fac.AntdFormItem( fac.AntdInput( id={ 'type': 'vecset_edit-form-value', 'index': 'sim_thrsh' }, placeholder='请输入相似阈值', allowClear=True, style={ 'width': '100%' } ), label='相似阈值', id={ 'type': 'vecset_edit-form-label', 'index': 'sim_thrsh', 'required': False }, ), span=12 ) ], gutter=5 ) ], labelCol={ 'span': 8 }, wrapperCol={ 'span': 16 }, style={ 'marginRight': '10px' } ) ], id='vecset-edit-modal', title='编辑字段', mask=False, width=650, renderFooter=True, okClickClose=False ), # 删除用户二次确认modal fac.AntdModal( fac.AntdText('是否确认删除?', id='vecset-delete-text'), id='vecset-delete-confirm-modal', visible=False, title='提示', renderFooter=True, centered=True ), # ] # 语句配置导入modal fac.AntdModal( [ html.Div( fac.AntdDraggerUpload( id='vecset-upload-choose', apiUrl=f'{ApiBaseUrlConfig.BaseUrl}/common/upload', apiUrlExtraParams={'taskPath': 'vecsetUpload'}, downloadUrl=f'{ApiBaseUrlConfig.BaseUrl}/common/caches', downloadUrlExtraParams={'taskPath': 'vecsetUpload', 'token': session.get('Authorization')}, headers={'Authorization': 'Bearer ' + session.get('Authorization')}, fileTypes=['xls', 'xlsx'], fileListMaxLength=1, text='语句配置导入', hint='点击或拖拽文件至此处进行上传' ), style={ 'marginTop': '10px' } ), html.Div( [ fac.AntdCheckbox( id='vecset-import-update-check', checked=False ), fac.AntdText( '是否更新已经存在的语句配置数据', style={ 'marginLeft': '5px' } ) ], style={ 'textAlign': 'center', 'marginTop': '10px' } ), html.Div( [ fac.AntdText('仅允许导入xls、xlsx格式文件。'), fac.AntdButton( '下载模板', id='download-vecset-import-template', type='link' ) ], style={ 'textAlign': 'center', 'marginTop': '10px' } ) ], id='vecset-import-confirm-modal', visible=False, title='语句配置导入', width=600, renderFooter=True, centered=True, okText='导入', confirmAutoSpin=True, loadingOkText='导入中', okClickClose=False ), fac.AntdModal( fac.AntdText( id='batch-result-content', className={ 'whiteSpace': 'break-spaces' } ), id='batch-result-modal', visible=False, title='语句配置导入结果', renderFooter=False, centered=True ), ]