ProComponents(适用于中后台的页面系列组件)学习: 重型列表页面组件(二)

一、概述

      一个列表页面一般包括:页面的标题、面包屑(即页面路径)、页面的tab标签(可选)、工具栏按纽、表格(带高级搜索,排序等功能)、底部悬浮操作栏等。

这就需要用到:

       (1)页面容器组件PageContainer: 自带标题、面包屑、tab标签栏、右上角公用操作按纽栏、底部按纽操作栏。

       (2)高级表格组件ProTable:  自带搜索查询(高级查询)、表格分页、排序、列设置、刷新、全屏等功能及与服务端交互的能力。 

 

三、代码重点分析:

(1)页面容器组件PageContainer :

<PageContainer
  content="欢迎使用 ProLayout 组件"
  tabList={[
    {
      tab: '基本信息',
      key: 'base',
    },
    {
      tab: '详细信息',
      key: 'info',
    },
  ]}
  extra={[
    <Button key="3">操作</Button>,
    <Button key="2">操作</Button>,
    <Button key="1" type="primary">
      主操作
    </Button>,
  ]}
  footer={[
    <Button key="rest">重置</Button>,
    <Button key="submit" type="primary">
      提交
    </Button>,
  ]}
>
  {children}
</PageContainer>

(2)高级表格组件ProTable:

import React, { useRef } from 'react';
import { PlusOutlined, EllipsisOutlined } from '@ant-design/icons';
import { Button, Tag, Space, Menu, Dropdown } from 'antd';
import type { ProColumns, ActionType } from '@ant-design/pro-table';
import ProTable, { TableDropdown } from '@ant-design/pro-table';
import request from 'umi-request';

type GithubIssueItem = {
  url: string;
  id: number;
  number: number;
  title: string;
  labels: {
    name: string;
    color: string;
  }[];
  state: string;
  comments: number;
  created_at: string;
  updated_at: string;
  closed_at?: string;
};

const columns: ProColumns<GithubIssueItem>[] = [
  {
    dataIndex: 'index',
    valueType: 'indexBorder',
    width: 48,
  },
  {
    title: '标题',
    dataIndex: 'title',
    copyable: true,
    ellipsis: true,
    tip: '标题过长会自动收缩',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '此项为必填项',
        },
      ],
    },
  },
  {
    title: '状态',
    dataIndex: 'state',
    filters: true,
    onFilter: true,
    valueType: 'select',
    valueEnum: {
      all: { text: '全部', status: 'Default' },
      open: {
        text: '未解决',
        status: 'Error',
      },
      closed: {
        text: '已解决',
        status: 'Success',
        disabled: true,
      },
      processing: {
        text: '解决中',
        status: 'Processing',
      },
    },
  },
  {
    title: '标签',
    dataIndex: 'labels',
    search: false,
    renderFormItem: (_, { defaultRender }) => {
      return defaultRender(_);
    },
    render: (_, record) => (
      <Space>
        {record.labels.map(({ name, color }) => (
          <Tag color={color} key={name}>
            {name}
          </Tag>
        ))}
      </Space>
    ),
  },
  {
    title: '创建时间',
    key: 'showTime',
    dataIndex: 'created_at',
    valueType: 'date',
    sorter: true,
    hideInSearch: true,
  },
  {
    title: '创建时间',
    dataIndex: 'created_at',
    valueType: 'dateRange',
    hideInTable: true,
    search: {
      transform: (value) => {
        return {
          startTime: value[0],
          endTime: value[1],
        };
      },
    },
  },
  {
    title: '操作',
    valueType: 'option',
    render: (text, record, _, action) => [
      <a
        key="editable"
        onClick={() => {
          action?.startEditable?.(record.id);
        }}
      >
        编辑
      </a>,
      <a href={record.url} target="_blank" rel="noopener noreferrer" key="view">
        查看
      </a>,
      <TableDropdown
        key="actionGroup"
        onSelect={() => action?.reload()}
        menus={[
          { key: 'copy', name: '复制' },
          { key: 'delete', name: '删除' },
        ]}
      />,
    ],
  },
];

const menu = (
  <Menu>
    <Menu.Item key="1">1st item</Menu.Item>
    <Menu.Item key="2">2nd item</Menu.Item>
    <Menu.Item key="3">3rd item</Menu.Item>
  </Menu>
);

export default () => {
  const actionRef = useRef<ActionType>();
  return (
    <ProTable<GithubIssueItem>
      columns={columns}
      actionRef={actionRef}
      request={async (params = {}, sort, filter) => {
        console.log(sort, filter);
        return request<{
          data: GithubIssueItem[];
        }>('https://proapi.azurewebsites.net/github/issues', {
          params,
        });
      }}
      editable={{
        type: 'multiple',
      }}
      rowKey="id"
      search={{
        labelWidth: 'auto',
      }}
      form={{
        // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下
        syncToUrl: (values, type) => {
          if (type === 'get') {
            return {
              ...values,
              created_at: [values.startTime, values.endTime],
            };
          }
          return values;
        },
      }}
      pagination={{
        pageSize: 5,
      }}
      dateFormatter="string"
      headerTitle="高级表格"
      toolBarRender={() => [
        <Button key="button" icon={<PlusOutlined />} type="primary">
          新建
        </Button>,
        <Dropdown key="menu" overlay={menu}>
          <Button>
            <EllipsisOutlined />
          </Button>
        </Dropdown>,
      ]}
    />
  );
};

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的麦粒肿诊断专家系统的实现代码: ```python # 定义规则库 rules = { 'R1': {'premise': ['毛囊皮根微红肿'], 'conclusion': '轻型'}, 'R2': {'premise': ['鼻塞流涕'], 'conclusion': '外感风热'}, 'R3': {'premise': ['舌苔薄黄', '胃纳差'], 'conclusion': '胃肠积热'}, 'R4': {'premise': ['眼睑局部明显红肿'], 'conclusion': '重型'}, 'R5': {'premise': ['眼睑局部红肿', '顶尖有脓点'], 'conclusion': '重型'}, 'R6': {'premise': ['脓点破溃'], 'conclusion': '晚期'}, 'R7': {'premise': ['轻型', '外感风热'], 'conclusion': '轻风热型'}, 'R8': {'premise': ['重型', '外感风热'], 'conclusion': '重风热型'}, 'R9': {'premise': ['重型', '胃肠积热'], 'conclusion': '重积热型'}, 'R10': {'premise': ['轻型'], 'conclusion': '散瘌法'}, 'R11': {'premise': ['晚期'], 'conclusion': '外敷药物'}, 'R12': {'premise': ['轻风热型'], 'conclusion': '散瘌加罐'}, 'R13': {'premise': ['重风热型'], 'conclusion': '挑瘌加罐'}, 'R14': {'premise': ['重积热型'], 'conclusion': '放血法'} } # 定义事实库,包含用户输入的症状信息 facts = [] # 获取用户输入的症状信息 def get_symptoms(): symptoms = input("请描述您的症状,多个症状请用空格隔开:") return symptoms.split() # 匹配规则并推理出结论 def infer(): for rule in rules.values(): if all(p in facts for p in rule['premise']): return rule['conclusion'] return None # 执行诊断 def diagnose(): # 获取用户输入的症状信息 symptoms = get_symptoms() # 将症状信息加入事实库 facts.extend(symptoms) # 进行推理 conclusion = infer() # 输出诊断结果 if conclusion: print("您可能患有%s,建议采取%s的治疗方法。" % (conclusion, conclusion)) else: print("暂时无法确定您的病情,请输入更多症状信息。") # 执行诊断 diagnose() ``` 该程序根据用户输入的症状信息,从规则库匹配相应的规则,并推理出相应的结论,最终输出诊断结果。用户可以不断输入症状信息,程序会根据已知的症状信息进行不断推理,直到确定诊断结果为止。需要注意的是,该程序只是一个简单的示例,实际使用时需要根据具体的需求进行修改和完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值