1.创建项目

  1. yarn create umi

image.png
解决,找到当前安装目录下的md文件删除c前面的部分
image.png

  1. create-umi

image.png
image.png

选择完成后 安装依赖 有点慢

  1. yarn或者yarn install

2.如何新建一个页面

2.1新增路由

  1. //config/route.ts
  2. export default [
  3. {
  4. path: '/',
  5. component: '../layouts/BlankLayout',
  6. routes: [
  7. {
  8. path: '/user',
  9. component: '../layouts/UserLayout',
  10. routes: [
  11. {
  12. name: 'login',
  13. path: '/user/login',
  14. component: './User/login',
  15. },
  16. ],
  17. },
  18. {
  19. path: '/',
  20. component: '../layouts/SecurityLayout',
  21. routes: [
  22. {
  23. path: '/',
  24. component: '../layouts/BasicLayout',
  25. authority: ['admin', 'user'],
  26. routes: [
  27. {
  28. path: '/',
  29. redirect: '/welcome',
  30. },
  31. //这里是新增得路由页面
  32. {
  33. path:"/new",
  34. icon:"PieChartOutlined",
  35. name:'new',
  36. component:'./News'
  37. },
  38. {
  39. path: '/welcome',
  40. name: 'welcome',
  41. icon: 'smile',
  42. component: './Welcome',
  43. },
  44. {
  45. path: '/admin',
  46. name: 'admin',
  47. icon: 'crown',
  48. component: './Admin',
  49. authority: ['admin'],
  50. routes: [
  51. {
  52. path: '/admin/sub-page',
  53. name: 'sub-page',
  54. icon: 'smile',
  55. component: './Welcome',
  56. authority: ['admin'],
  57. },
  58. ],
  59. },
  60. {
  61. name: 'list.table-list',
  62. icon: 'table',
  63. path: '/list',
  64. component: './TableList',
  65. },
  66. {
  67. component: './404',
  68. },
  69. ],
  70. },
  71. {
  72. component: './404',
  73. },
  74. ],
  75. },
  76. ],
  77. },
  78. {
  79. component: './404',
  80. },
  81. ];

2.2配置国际化

  1. //locales/zh-CN/menu.ts
  2. export default {
  3. 'menu.welcome': '欢迎',
  4. 'menu.more-blocks': '更多区块',
  5. 'menu.home': '首页',
  6. 'menu.admin': '管理页',
  7. 'menu.admin.sub-page': '二级管理页',
  8. 'menu.login': '登录',
  9. 'menu.register': '注册',
  10. 'menu.register.result': '注册结果',
  11. 'menu.dashboard': 'Dashboard',
  12. 'menu.dashboard.analysis': '分析页',
  13. 'menu.dashboard.monitor': '监控页',
  14. 'menu.dashboard.workplace': '工作台',
  15. 'menu.exception.403': '403',
  16. 'menu.exception.404': '404',
  17. 'menu.exception.500': '500',
  18. 'menu.form': '表单页',
  19. 'menu.form.basic-form': '基础表单',
  20. 'menu.form.step-form': '分步表单',
  21. 'menu.form.step-form.info': '分步表单(填写转账信息)',
  22. 'menu.form.step-form.confirm': '分步表单(确认转账信息)',
  23. 'menu.form.step-form.result': '分步表单(完成)',
  24. 'menu.form.advanced-form': '高级表单',
  25. 'menu.list': '列表页',
  26. 'menu.list.table-list': '查询表格',
  27. 'menu.list.basic-list': '标准列表',
  28. 'menu.list.card-list': '卡片列表',
  29. 'menu.list.search-list': '搜索列表',
  30. 'menu.list.search-list.articles': '搜索列表(文章)',
  31. 'menu.list.search-list.projects': '搜索列表(项目)',
  32. 'menu.list.search-list.applications': '搜索列表(应用)',
  33. 'menu.profile': '详情页',
  34. 'menu.profile.basic': '基础详情页',
  35. 'menu.profile.advanced': '高级详情页',
  36. 'menu.result': '结果页',
  37. 'menu.result.success': '成功页',
  38. 'menu.result.fail': '失败页',
  39. 'menu.exception': '异常页',
  40. 'menu.exception.not-permission': '403',
  41. 'menu.exception.not-find': '404',
  42. 'menu.exception.server-error': '500',
  43. 'menu.exception.trigger': '触发错误',
  44. 'menu.account': '个人页',
  45. 'menu.account.center': '个人中心',
  46. 'menu.account.settings': '个人设置',
  47. 'menu.account.trigger': '触发报错',
  48. 'menu.account.logout': '退出登录',
  49. 'menu.editor': '图形编辑器',
  50. 'menu.editor.flow': '流程编辑器',
  51. 'menu.editor.mind': '脑图编辑器',
  52. 'menu.editor.koni': '拓扑编辑器',
  53. //这里是新增得页面国际化
  54. 'menu.new':'新的页面'
  55. };

2.3配置导航头部

  1. //src/pages/News/index.tsx
  2. import React, { FC, useRef } from 'react';
  3. import { PlusOutlined, EllipsisOutlined } from '@ant-design/icons';
  4. import { Button, Tag, Space, Menu, Dropdown } from 'antd';
  5. import type { ProColumns, ActionType } from '@ant-design/pro-table';
  6. import ProTable, { TableDropdown } from '@ant-design/pro-table';
  7. import request from 'umi-request';
  8. import { PageHeaderWrapper } from '@ant-design/pro-layout';
  9. type GithubIssueItem = {
  10. url: string;
  11. id: number;
  12. number: number;
  13. title: string;
  14. labels: {
  15. name: string;
  16. color: string;
  17. }[];
  18. state: string;
  19. comments: number;
  20. created_at: string;
  21. updated_at: string;
  22. closed_at?: string;
  23. };
  24. const columns: ProColumns<GithubIssueItem>[] = [
  25. {
  26. dataIndex: 'index',
  27. valueType: 'indexBorder',
  28. width: 48,
  29. },
  30. {
  31. title: '标题',
  32. dataIndex: 'title',
  33. copyable: true,
  34. ellipsis: true,
  35. tip: '标题过长会自动收缩',
  36. formItemProps: {
  37. rules: [
  38. {
  39. required: true,
  40. message: '此项为必填项',
  41. },
  42. ],
  43. },
  44. },
  45. {
  46. title: '状态',
  47. dataIndex: 'state',
  48. filters: true,
  49. onFilter: true,
  50. valueType: 'select',
  51. valueEnum: {
  52. all: { text: '全部', status: 'Default' },
  53. open: {
  54. text: '未解决',
  55. status: 'Error',
  56. },
  57. closed: {
  58. text: '已解决',
  59. status: 'Success',
  60. disabled: true,
  61. },
  62. processing: {
  63. text: '解决中',
  64. status: 'Processing',
  65. },
  66. },
  67. },
  68. {
  69. title: '标签',
  70. dataIndex: 'labels',
  71. search: false,
  72. renderFormItem: (_, { defaultRender }) => {
  73. return defaultRender(_);
  74. },
  75. render: (_, record) => (
  76. <Space>
  77. {record.labels.map(({ name, color }) => (
  78. <Tag color={color} key={name}>
  79. {name}
  80. </Tag>
  81. ))}
  82. </Space>
  83. ),
  84. },
  85. {
  86. title: '创建时间',
  87. key: 'showTime',
  88. dataIndex: 'created_at',
  89. valueType: 'date',
  90. sorter: true,
  91. hideInSearch: true,
  92. },
  93. {
  94. title: '创建时间',
  95. dataIndex: 'created_at',
  96. valueType: 'dateRange',
  97. hideInTable: true,
  98. search: {
  99. transform: (value) => {
  100. return {
  101. startTime: value[0],
  102. endTime: value[1],
  103. };
  104. },
  105. },
  106. },
  107. {
  108. title: '操作',
  109. valueType: 'option',
  110. render: (text, record, _, action) => [
  111. <a
  112. key="editable"
  113. onClick={() => {
  114. action?.startEditable?.(record.id);
  115. }}
  116. >
  117. 编辑
  118. </a>,
  119. <a href={record.url} target="_blank" rel="noopener noreferrer" key="view">
  120. 查看
  121. </a>,
  122. <TableDropdown
  123. key="actionGroup"
  124. onSelect={() => action?.reload()}
  125. menus={[
  126. { key: 'copy', name: '复制' },
  127. { key: 'delete', name: '删除' },
  128. ]}
  129. />,
  130. ],
  131. },
  132. ];
  133. const menu = (
  134. <Menu>
  135. <Menu.Item key="1">1st item</Menu.Item>
  136. <Menu.Item key="2">2nd item</Menu.Item>
  137. <Menu.Item key="3">3rd item</Menu.Item>
  138. </Menu>
  139. );
  140. const New: FC = () => {
  141. const actionRef = useRef<ActionType>();
  142. return (
  143. <PageHeaderWrapper>
  144. <ProTable<GithubIssueItem>
  145. columns={columns}
  146. actionRef={actionRef}
  147. request={async (params = {}, sort, filter) => {
  148. console.log(sort, filter);
  149. return request<{
  150. data: GithubIssueItem[];
  151. }>('https://proapi.azurewebsites.net/github/issues', {
  152. params,
  153. });
  154. }}
  155. editable={{
  156. type: 'multiple',
  157. }}
  158. rowKey="id"
  159. search={{
  160. labelWidth: 'auto',
  161. }}
  162. form={{
  163. // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下
  164. syncToUrl: (values, type) => {
  165. if (type === 'get') {
  166. return {
  167. ...values,
  168. created_at: [values.startTime, values.endTime],
  169. };
  170. }
  171. return values;
  172. },
  173. }}
  174. pagination={{
  175. pageSize: 5,
  176. }}
  177. dateFormatter="string"
  178. headerTitle="高级表格"
  179. toolBarRender={() => [
  180. <Button key="button" icon={<PlusOutlined />} type="primary">
  181. 新建
  182. </Button>,
  183. <Dropdown key="menu" overlay={menu}>
  184. <Button>
  185. <EllipsisOutlined />
  186. </Button>
  187. </Dropdown>,
  188. ]}
  189. />
  190. </PageHeaderWrapper>
  191. );
  192. };
  193. export default New;