from dash import dcc, html import feffery_antd_components as fac import callbacks.test_c from api.test import get_test_list_api def render(*args, **kwargs): button_perms = kwargs.get('button_perms') test_params = dict(page_num=1, page_size=10) table_info = get_test_list_api(test_params) table_data = [] page_num = 1 page_size = 10 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(tag='正常', color='blue') else: item['status'] = dict(tag='停用', color='volcano') item['key'] = str(item['test_id']) item['operation'] = [ { 'content': '修改', 'type': 'link', 'icon': 'antd-edit' } if 'system:test:edit' in button_perms else {}, { 'content': '删除', 'type': 'link', 'icon': 'antd-delete' } if 'system:test:remove' in button_perms else {}, ] return [ dcc.Store(id='test-button-perms-container', data=button_perms), # 用于导出成功后重置dcc.Download的状态,防止多次下载文件 dcc.Store(id='test-export-complete-judge-container'), # 绑定的导出组件 dcc.Download(id='test-export-container'), # 测试管理模块操作类型存储容器 dcc.Store(id='test-operations-store'), dcc.Store(id='test-operations-store-bk'), # 测试管理模块修改操作行key存储容器 dcc.Store(id='test-edit-id-store'), # 测试管理模块删除操作行key存储容器 dcc.Store(id='test-delete-ids-store'), fac.AntdRow( [ fac.AntdCol( [ fac.AntdRow( [ fac.AntdCol( html.Div( [ fac.AntdForm( [ fac.AntdSpace( [ fac.AntdFormItem( fac.AntdInput( id='test-test_name-input', placeholder='请输入测试名称', autoComplete='off', allowClear=True, style={'width': 210} ), label='测试名称' ), fac.AntdFormItem( fac.AntdInput( id='test-test_group-input', placeholder='请输入测试分组', autoComplete='off', allowClear=True, style={'width': 210} ), label='测试分组' ), fac.AntdFormItem( fac.AntdSelect( id='test-status-select', placeholder='岗位状态', options=[ { 'label': '正常', 'value': '0' }, { 'label': '停用', 'value': '1' } ], style={'width': 200} ), label='测试状态' ), fac.AntdFormItem( fac.AntdButton( '搜索', id='test-search', type='primary', icon=fac.AntdIcon(icon='antd-search') ) ), fac.AntdFormItem( fac.AntdButton( '重置', id='test-reset', icon=fac.AntdIcon(icon='antd-sync') ) ) ], style={'paddingBottom': '10px'} ), ], layout='inline', ) ], id='test-search-form-container', hidden=False ), ) ] ), fac.AntdRow( [ fac.AntdCol( fac.AntdSpace( [ fac.AntdButton( [ fac.AntdIcon(icon='antd-plus'), '新增', ], id={ 'type': 'test-operation-button', 'index': 'add' }, style={ 'color': '#1890ff', 'background': '#e8f4ff', 'border-color': '#a3d3ff' } ) if 'system:test:add' in button_perms else [], fac.AntdButton( [ fac.AntdIcon(icon='antd-edit'), '修改', ], id={ 'type': 'test-operation-button', 'index': 'edit' }, disabled=True, style={ 'color': '#71e2a3', 'background': '#e7faf0', 'border-color': '#d0f5e0' } ) if 'system:test:edit' in button_perms else [], fac.AntdButton( [ fac.AntdIcon(icon='antd-minus'), '删除', ], id={ 'type': 'test-operation-button', 'index': 'delete' }, disabled=True, style={ 'color': '#ff9292', 'background': '#ffeded', 'border-color': '#ffdbdb' } ) if 'system:test:remove' in button_perms else [], fac.AntdButton( [ fac.AntdIcon(icon='antd-arrow-down'), '导出', ], id='test-export', style={ 'color': '#ffba00', 'background': '#fff8e6', 'border-color': '#ffe399' } ) if 'system:test: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='test-hidden', shape='circle' ), id='test-hidden-tooltip', title='隐藏搜索' ) ), html.Div( fac.AntdTooltip( fac.AntdButton( [ fac.AntdIcon(icon='antd-sync'), ], id='test-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='test-list-table', data=table_data, columns=[ { 'dataIndex': 'test_id', 'title': '测试编号', 'renderOptions': { 'renderType': 'ellipsis' } }, { 'dataIndex': 'test_name', 'title': '测试名称', 'renderOptions': { 'renderType': 'ellipsis' } }, { 'dataIndex': 'test_group', 'title': '测试分组', 'renderOptions': { 'renderType': 'ellipsis' } }, { 'dataIndex': 'status', 'title': '状态', 'renderOptions': { 'renderType': 'tags' } }, { 'dataIndex': 'create_time', 'title': '创建时间', 'renderOptions': { 'renderType': 'ellipsis' } }, { 'title': '操作', 'dataIndex': 'operation', 'renderOptions': { 'renderType': 'button' } } ], rowSelectionType='checkbox', rowSelectionWidth=50, bordered=True, pagination={ 'pageSize': page_size, 'current': page_num, 'showSizeChanger': True, 'pageSizeOptions': [10, 30, 50, 100], 'showQuickJumper': True, 'total': total }, mode='server-side', style={ 'width': '100%', 'padding-right': '10px' } ), text='数据加载中' ), ) ] ), ], span=24 ) ], gutter=5 ), # 新增和编辑测试表单modal fac.AntdModal( [ fac.AntdForm( [ fac.AntdFormItem( fac.AntdInput( id={ 'type': 'test-form-value', 'index': 'test_name' }, placeholder='请输入测试名称', allowClear=True, style={ 'width': 350 } ), label='测试名称', required=True, id={ 'type': 'test-form-label', 'index': 'test_name', 'required': True } ), fac.AntdFormItem( fac.AntdInput( id={ 'type': 'test-form-value', 'index': 'test_group' }, placeholder='请输入测试分组', allowClear=True, style={ 'width': 350 } ), label='测试分组', required=True, id={ 'type': 'test-form-label', 'index': 'test_group', 'required': True } ), fac.AntdFormItem( fac.AntdRadioGroup( id={ 'type': 'test-form-value', 'index': 'status' }, options=[ { 'label': '正常', 'value': '0' }, { 'label': '停用', 'value': '1' }, ], defaultValue='0', style={ 'width': 350 } ), label='测试状态', id={ 'type': 'test-form-label', 'index': 'status', 'required': False } ), ], labelCol={ 'span': 6 }, wrapperCol={ 'span': 18 } ) ], id='test-modal', mask=False, width=580, renderFooter=True, okClickClose=False ), # 删除测试二次确认modal fac.AntdModal( fac.AntdText('是否确认删除?', id='test-delete-text'), id='test-delete-confirm-modal', visible=False, title='提示', renderFooter=True, centered=True ), ]