Umi +ant-design4 proComponent实践demo

创建umi脚手架

yarn create @umijs/umi-app

安装node_modules

yarn

在这里插入图片描述

// 每个包都是可以独立按需安装的 也可以yarn add @ant-design安装所有包
yarn add @ant-design/pro-form --save
yarn add @ant-design/pro-layout --save
yarn add @ant-design/pro-table --save
yarn add @ant-design/pro-list --save
yarn add @ant-design/pro-descriptions --save
yarn add @ant-design/pro-card --save
yarn add @ant-design/pro-skeleton --save

在这里插入图片描述

案例示图
在这里插入图片描述

案例代码

import React, { useState } from 'react';
import { PlusOutlined } from '@ant-design/icons';
import { Button, Tabs, Tag, Space, message } from 'antd';
import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions';
import ProDescriptions from '@ant-design/pro-descriptions';
import type { ProColumns } 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>[] = [
  {
    title: '序号',
    dataIndex: 'index',
    width: 64,
    valueType: 'indexBorder',
  },
  {
    title: '标题',
    dataIndex: 'title',
    copyable: true,
    ellipsis: true,
    search: false,
  },
  {
    title: (_, type) => (type === 'table' ? '状态' : '列表状态'),
    dataIndex: 'state',
    initialValue: 'all',
    filters: true,
    onFilter: true,
    valueType: 'select',
    valueEnum: {
      all: { text: '全部', status: 'Default' },
      open: {
        text: '未解决',
        status: 'Error',
      },
      closed: {
        text: '已解决',
        status: 'Success',
      },
    },
  },
  {
    title: '排序方式',
    key: 'direction',
    hideInTable: true,
    hideInDescriptions: true,
    dataIndex: 'direction',
    filters: true,
    onFilter: true,
    valueType: 'select',
    valueEnum: {
      asc: '正序',
      desc: '倒序',
    },
  },
  {
    title: '标签',
    dataIndex: 'labels',
    width: 120,
    render: (_, row) => (
      <Space>
        {row.labels.map(({ name, color }) => (
          <Tag color={color} key={name}>
            {name}
          </Tag>
        ))}
      </Space>
    ),
  },
  {
    title: '创建时间',
    key: 'since',
    dataIndex: 'created_at',
    valueType: 'dateTime',
  },
  {
    title: 'option',
    valueType: 'option',
    dataIndex: 'id',
    render: (text, row) => [
      <a href={row.url} key="show" target="_blank" rel="noopener noreferrer">
        查看
      </a>,
      <TableDropdown
        key="more"
        onSelect={(key) => message.info(key)}
        menus={[
          { key: 'copy', name: '复制' },
          { key: 'delete', name: '删除' },
        ]}
      />,
    ],
  },
];

export default () => {
  const [type, setType] = useState('table');
  return (
    <>
      <Tabs activeKey={type} onChange={(e) => setType(e)}>
        <Tabs.TabPane tab="table" key="table" />
        <Tabs.TabPane tab="form" key="form" />
        <Tabs.TabPane tab="descriptions" key="descriptions" />
      </Tabs>
      {['table', 'form'].includes(type) && (
        <ProTable<GithubIssueItem>
          columns={columns}
          type={type as 'table'}
          request={async (params = {}) =>
            request<{
              data: GithubIssueItem[];
            }>('https://proapi.azurewebsites.net/github/issues', {
              params,
            })
          }
          pagination={{
            pageSize: 5,
          }}
          rowKey="id"
          dateFormatter="string"
          headerTitle="查询 Table"
          toolBarRender={() => [
            <Button key="3" type="primary">
              <PlusOutlined />
              新建
            </Button>,
          ]}
        />
      )}
      {type === 'descriptions' && (
        <ProDescriptions
          style={{
            background: '#fff',
          }}
          columns={columns as ProDescriptionsItemProps<GithubIssueItem>[]}
          request={async (params) => {
            const msg = await request<{
              data: GithubIssueItem[];
            }>('https://proapi.azurewebsites.net/github/issues', {
              params,
            });
            return {
              ...msg,
              data: msg?.data[0],
            };
          }}
        />
      )}
    </>
  );
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
umi是一款基于React的可扩展企业级前端应用框架,它提供了一套完整的开发和构建工具链,可以帮助开发者快速搭建复杂的单页面应用和多页面应用。umi的设计理念是约定大于配置,通过约定的文件结构可以自动生成路由、动态加载页面和组件等,同时还支持插件机制,可以轻松地集成各种功能和扩展。umi还提供了一些常用的功能和工具,如国际化、权限控制、数据模拟等,方便开发者快速开发高质量的前端应用。 antd-mobile是一个基于React和antd设计体系的移动端UI组件库,它提供了一系列优雅美观的组件,如按钮、导航栏、列表、输入框等,可以帮助开发者快速构建优质的移动端用户界面。antd-mobile的组件风格简约而不简单,同时还支持主题定制和样式覆盖,开发者可以根据自己的需要进行自定义。antd-mobile还提供了一些常用的功能和工具,如表单校验、图片裁剪、手势操作等,方便开发者解决一些常见的问题。 umiantd-mobile可以很好地配合使用umi提供了一套完整的开发框架和工具链,而antd-mobile提供了美观实用的移动端UI组件,开发者可以通过umi搭建整个项目的结构和配置,然后使用antd-mobile的组件来构建用户界面。umiantd-mobile都是社区广泛使用和维护的项目,拥有强大的生态系统和活跃的社区支持,开发者在使用过程中可以获得良好的技术支持和文档资源,提高开发效率和质量。总之,umiantd-mobile是一对强力组合,可以帮助开发者快速构建优质的企业级移动应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hzxOnlineOk

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值