├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
└── manifest.json
└── src
├── App.css
├── App.js
├── App.test.js
├── index.css
├── index.js
├── logo.svg
├── redux
├── action.js
├── reducer.js
└── store.js
├── request
├── api.js
└── request.js
├── route.js
├── serviceWorker.js
└── views
├── card
├── card.js
└── cardInfo.js
├── echarts
├── bar.js
├── echarts.js
└── line.js
├── editor
├── editHtml.js
└── editor.js
├── header
└── header.js
├── hoc
├── hoc.js
├── index.js
├── lists.js
└── tags.js
├── hooks
└── hooks.js
├── index.js
├── status
└── status.js
└── table
├── form.js
└── table.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### React+Ant Design 管理后台(练手项目)
2 | 涵盖了以下知识点,适合刚开始学习react的同学
3 | #### 基础篇
4 | - 路由的基本使用,包括动态路由的运用
5 | - 父子组件之间的传值
6 | - ref属性的使用
7 | - jsx里的事件循环
8 | - redux的基本使用
9 | - antd相关组件的使用
10 | - mock.js模拟接口数据
11 | #### 进阶篇
12 | - 高阶组件的运用
13 | - Hooks的运用
14 | ---
15 | ### 运行项目
16 | npm i
17 |
18 | npm start
19 |
20 | npm run build (发布)
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-app",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "antd": "^3.18.0",
7 | "axios": "^0.18.0",
8 | "braft-editor": "^2.2.10",
9 | "echarts": "^4.2.1",
10 | "echarts-for-react": "^2.0.15-beta.0",
11 | "react": "^16.8.6",
12 | "react-dom": "^16.8.6",
13 | "react-redux": "^7.0.3",
14 | "react-router-dom": "^5.0.0",
15 | "react-scripts": "3.0.1",
16 | "redux": "^4.0.1"
17 | },
18 | "scripts": {
19 | "start": "react-scripts start",
20 | "build": "react-scripts build",
21 | "test": "react-scripts test",
22 | "eject": "react-scripts eject"
23 | },
24 | "eslintConfig": {
25 | "extends": "react-app"
26 | },
27 | "browserslist": {
28 | "production": [
29 | ">0.2%",
30 | "not dead",
31 | "not op_mini all"
32 | ],
33 | "development": [
34 | "last 1 chrome version",
35 | "last 1 firefox version",
36 | "last 1 safari version"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TangTangJia/react-manage/1a93e91b90cdb14566ec75fc8129140268cd74f1/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
22 | React App
23 |
24 |
25 |
26 |
27 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | @import '~antd/dist/antd.css';
2 | .App {
3 | text-align: center;
4 | }
5 |
6 | .App-logo {
7 | animation: App-logo-spin infinite 20s linear;
8 | height: 40vmin;
9 | pointer-events: none;
10 | }
11 |
12 | .App-header {
13 | background-color: #282c34;
14 | min-height: 100vh;
15 | display: flex;
16 | flex-direction: column;
17 | align-items: center;
18 | justify-content: center;
19 | font-size: calc(10px + 2vmin);
20 | color: white;
21 | }
22 |
23 | .App-link {
24 | color: #61dafb;
25 | }
26 |
27 | @keyframes App-logo-spin {
28 | from {
29 | transform: rotate(0deg);
30 | }
31 | to {
32 | transform: rotate(360deg);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import logo from './logo.svg';
3 | import './App.css';
4 |
5 | function App() {
6 | return (
7 |
23 | );
24 | }
25 |
26 | export default App;
27 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 |
5 | it('renders without crashing', () => {
6 | const div = document.createElement('div');
7 | ReactDOM.render(, div);
8 | ReactDOM.unmountComponentAtNode(div);
9 | });
10 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
4 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 | import Route from './route.js'
7 | import store from "./redux/store.js";
8 | import { Provider } from 'react-redux'
9 | ReactDOM.render(
10 |
11 |
12 | ,
13 | document.getElementById('root'));
14 |
15 | // If you want your app to work offline and load faster, you can change
16 | // unregister() to register() below. Note this comes with some pitfalls.
17 | // Learn more about service workers: https://bit.ly/CRA-PWA
18 | serviceWorker.unregister();
19 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/redux/action.js:
--------------------------------------------------------------------------------
1 | export const increment = () => {
2 | return {
3 | type: "increment"
4 | }
5 | }
6 |
7 | export const decrement = () => {
8 | return {
9 | type: "decrement"
10 | }
11 | }
--------------------------------------------------------------------------------
/src/redux/reducer.js:
--------------------------------------------------------------------------------
1 | export default (state = 1, action) => {
2 | switch (action.type) {
3 | case "increment":
4 | return state + 1
5 | case "decrement":
6 | return state - 1
7 | default:
8 | return state
9 | }
10 | }
--------------------------------------------------------------------------------
/src/redux/store.js:
--------------------------------------------------------------------------------
1 | import { createStore } from 'redux'
2 | import Reducer from './reducer'
3 |
4 | const store = createStore(Reducer)
5 |
6 | export default store
--------------------------------------------------------------------------------
/src/request/api.js:
--------------------------------------------------------------------------------
1 | import { get, post } from './request.js'
2 |
3 | let apiList = {
4 | getData: () => get('/getData'), // 获取表格数据
5 | editData: (data, params) => post('/editData?id=' + params, data),// 修改表格数据
6 | getCard: () => get('/card'), // 获取卡片内容
7 | getHoc: () => get('/getHoc'), // 获取标签、列表内容
8 | getMenus: () => get('/getMenu') // 获取下拉菜单列表
9 | }
10 |
11 | export default apiList
12 |
--------------------------------------------------------------------------------
/src/request/request.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 | // import qs from 'qs'
3 | // axios 配置
4 | axios.defaults.timeout = 10000
5 | axios.defaults.baseURL = 'https://easy-mock.com/mock/5bd6a843bc9d684fc1f12b6e/test'
6 | // 添加请求拦截器
7 | axios.interceptors.request.use(function (config) {
8 | // 在发送请求之前做些什么
9 | return config
10 | }, function (error) {
11 | // 对请求错误做些什么
12 | return Promise.reject(error)
13 | })
14 |
15 | // 添加响应拦截器
16 | axios.interceptors.response.use(function (response) {
17 | // 对响应数据做点什么
18 | const res = response.data
19 | // console.log(res)
20 | if (res.statusCode !== 1) {
21 | // return Promise.reject('error')
22 | return response.data
23 | } else {
24 | return response.data
25 | }
26 | }, function (error) {
27 | // 对响应错误做点什么
28 | return Promise.reject(error)
29 | })
30 |
31 | // GET 请求
32 | export function get(url, params) {
33 | return axios.get(url, {
34 | params: params
35 | })
36 | }
37 |
38 | // POST 请求
39 | export function post(url, data, params) {
40 | // params = qs.stringify(params)
41 | return axios.post(url, data, params)
42 | }
43 |
44 | // put 请求
45 | export function put(url, data, params) {
46 | // params = qs.stringify(params)
47 | // data = qs.stringify(data)
48 | return axios.put(url, data, params)
49 | }
50 |
51 | // delete 请求
52 | export function dele(url, data) {
53 | return axios.delete(url, data)
54 | }
55 |
--------------------------------------------------------------------------------
/src/route.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
3 | import Index from './views/index.js'
4 | import Table from './views/table/table.js'
5 | import Echarts from './views/echarts/echarts.js'
6 | import EditHtml from './views/editor/editHtml.js'
7 | import Card from './views/card/card.js'
8 | import CardInfo from './views/card/cardInfo.js'
9 | import Status from './views/status/status.js'
10 | import Hoc from './views/hoc/index.js'
11 | import Hooks from './views/hooks/hooks.js'
12 | export default class ROUTER extends Component {
13 | render() {
14 | return (
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | )
32 | }
33 | }
34 |
35 | // export default route
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then(response => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then(registration => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then(registration => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/views/card/card.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { Card, Col, Row } from 'antd'
3 | import { Link } from 'react-router-dom'
4 | import $http from '../../request/api.js'
5 | export default class card extends Component {
6 | constructor(props) {
7 | super(props)
8 | this.state = {
9 | data: []
10 | }
11 | }
12 | render() {
13 | return (
14 |
15 |
16 | {this.state.data.map((item, index) => {
17 | return
18 | More} style={{ width: 300 }}>
19 | {
20 | item.content.map((subItem, i) => {
21 | return {subItem}
22 | })
23 | }
24 |
25 |
26 | })
27 | }
28 |
29 |
30 | )
31 | }
32 | componentDidMount() {
33 | $http.getCard().then(res => {
34 | console.log(res)
35 | this.setState({
36 | data: res.data.list
37 | })
38 | })
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/views/card/cardInfo.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 |
3 | export default class cardInfo extends Component {
4 | constructor(props) {
5 | super(props)
6 | this.state = {
7 | id: this.props.match.params.id
8 | }
9 | }
10 | render() {
11 | return (
12 |
13 | 文章id:{this.state.id}
14 |
15 | )
16 | }
17 | componentDidMount() {
18 | console.log(this.state.id)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/views/echarts/bar.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactEcharts from 'echarts-for-react';
3 | export default class bar extends Component {
4 | render() {
5 | return (
6 |
7 |
8 |
9 | )
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/views/echarts/echarts.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { Divider } from 'antd';
3 | import Bar from './bar.js'
4 | import Line from './line.js'
5 | const option = {
6 | xAxis: {
7 | type: 'category',
8 | data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
9 | },
10 | yAxis: {
11 | type: 'value'
12 | },
13 | series: [{
14 | data: [120, 200, 150, 80, 70, 110, 130],
15 | type: 'bar'
16 | }]
17 | }
18 | const lineOption = {
19 | xAxis: {
20 | type: 'category',
21 | data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
22 | },
23 | yAxis: {
24 | type: 'value'
25 | },
26 | series: [{
27 | data: [820, 932, 901, 934, 1290, 1330, 1320],
28 | type: 'line'
29 | }]
30 | }
31 | export default class echarts extends Component {
32 | render() {
33 | return (
34 |
39 | )
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/views/echarts/line.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import ReactEcharts from 'echarts-for-react';
3 | export default class line extends Component {
4 | render() {
5 | return (
6 |
7 |
8 |
9 | )
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/views/editor/editHtml.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import Editor from './editor.js'
3 | export default class editHtml extends Component {
4 | constructor(props) {
5 | super(props)
6 | this.state = {
7 | content: ''
8 | }
9 | }
10 | render() {
11 | return (
12 |
17 | )
18 | }
19 | getContent = (content) => { // 接收子组件数据
20 | console.log(content)
21 | this.setState({
22 | content: content
23 | })
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/views/editor/editor.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import 'braft-editor/dist/index.css'
3 | import BraftEditor from 'braft-editor'
4 | import { Button } from 'antd';
5 | export default class editor extends Component {
6 | state = {
7 | editorState: '', // 设置编辑器初始内容
8 | outputHTML: ''
9 | }
10 | render() {
11 | // const { editorState, outputHTML } = this.state
12 | return (
13 |
14 |
15 |
16 |
17 | )
18 | }
19 | handleChange = (editorState) => {
20 | this.setState({
21 | editorState: editorState
22 | })
23 | }
24 | send = () => {
25 | this.setState({
26 | outputHTML: this.state.editorState.toHTML()
27 | }, () => {
28 | this.props.getContent(this.state.outputHTML) // 将数据传给父组件
29 | })
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/views/header/header.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { connect } from "react-redux"
3 | import * as Action from '../../redux/action'
4 | import { Layout, Avatar, Badge } from 'antd';
5 | const { Header } = Layout;
6 | class header extends Component {
7 | render() {
8 | return (
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | )
19 | }
20 | }
21 | function mapStateToProps(state) {
22 | return { count: state }
23 | }
24 | export default connect(mapStateToProps, Action)(header);
25 |
26 |
--------------------------------------------------------------------------------
/src/views/hoc/hoc.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import $http from '../../request/api.js'
3 | export default (WrappedComponent) => {
4 | class NewComponent extends Component {
5 | constructor() {
6 | super()
7 | this.state = {
8 | list: []
9 | }
10 | }
11 | render() {
12 | return
13 | }
14 | componentDidMount() {
15 | $http.getHoc().then(res => {
16 | console.log(res)
17 | this.setState({
18 | list: res.data.list
19 | })
20 | })
21 | }
22 | }
23 | return NewComponent
24 | }
--------------------------------------------------------------------------------
/src/views/hoc/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import Tags from './tags.js'
3 | import Lists from './lists.js'
4 | export default class index extends Component {
5 | render() {
6 | return (
7 |
8 |
9 |
10 |
11 | )
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/views/hoc/lists.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { List } from 'antd';
3 | import wrapWithComponent from './hoc.js'
4 | class lists extends Component {
5 | render() {
6 | return (
7 |
8 | Header
}
11 | footer={Footer
}
12 | bordered
13 | dataSource={this.props.list}
14 | renderItem={item => {item.desc}}
15 | />
16 |
17 | )
18 | }
19 | }
20 | const Lists = wrapWithComponent(lists)
21 | export default Lists
22 |
--------------------------------------------------------------------------------
/src/views/hoc/tags.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { Tag } from 'antd';
3 | import wrapWithComponent from './hoc.js'
4 | class tags extends Component {
5 | render() {
6 | return (
7 |
8 | {
9 | this.props.list.map((item, index) => {
10 | return {item.title}
11 | })
12 | }
13 |
14 | )
15 | }
16 | }
17 | const Tags = wrapWithComponent(tags)
18 | export default Tags
19 |
--------------------------------------------------------------------------------
/src/views/hooks/hooks.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react'
2 | import { Menu, Dropdown, Button, Icon } from 'antd';
3 | import $http from '../../request/api.js'
4 |
5 | function Down() {
6 | const [menus, setMenu] = useState([])
7 | const [title, setTitle] = useState('城市列表')
8 | useEffect(() => {
9 | $http.getMenus().then(res => {
10 | console.log(res)
11 | setMenu(res.data.list)
12 | })
13 | }, []) // 第二个参数用来优化Effect
14 | const menu = (
15 |
23 | )
24 | return (
25 |
26 |
29 |
30 | )
31 | }
32 |
33 | export default Down
--------------------------------------------------------------------------------
/src/views/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { Layout, Menu, Icon, Avatar, Badge } from 'antd';
3 | import { Link } from 'react-router-dom'
4 | import Header from './header/header.js'
5 | const { Sider, Content } = Layout;
6 | const SubMenu = Menu.SubMenu;
7 | export default class index extends Component {
8 | render() {
9 | return (
10 |
11 |
12 |
18 |
76 |
77 |
78 |
79 | {this.props.children}
80 |
81 |
82 |
83 | )
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/views/status/status.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { Button } from 'antd'
3 | import { connect } from "react-redux"
4 | import * as Action from '../../redux/action'
5 | import { bindActionCreators } from 'redux'
6 | class status extends Component {
7 | render() {
8 | const { increment, decrement } = this.props.changeNum;
9 | return (
10 |
11 |
12 |
13 |
14 | )
15 | }
16 | }
17 | // function mapStateToProps(state) {
18 | // return { count: state }
19 | // }
20 | function mapDispatchToProps(dispatch) {
21 | return {
22 | changeNum: bindActionCreators(Action, dispatch)
23 | }
24 | }
25 | export default connect(null, mapDispatchToProps)(status);
26 |
27 |
--------------------------------------------------------------------------------
/src/views/table/form.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { Form, Input } from 'antd';
3 | class form extends Component {
4 | render() {
5 | const { getFieldDecorator } = this.props.form;
6 | return (
7 |
9 | {getFieldDecorator('name')(
10 |
11 | )
12 | }
13 |
14 |
15 | {getFieldDecorator('age')(
16 |
17 | )
18 | }
19 |
20 |
21 | {getFieldDecorator('gender')(
22 |
23 | )
24 | }
25 |
26 |
27 | )
28 | }
29 | // handleSubmit = (e) => {
30 | // e.preventDefault();
31 | // this.props.form.validateFields((err, values) => {
32 | // // this.props.onSubmit(err, values);
33 | // })
34 | // }
35 | }
36 | const editForm = Form.create()(form);
37 | export default editForm
--------------------------------------------------------------------------------
/src/views/table/table.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { Modal, message, Table, Divider } from 'antd';
3 | import EditForm from './form.js'
4 | import $http from '../../request/api.js'
5 | export default class wallet extends Component {
6 | constructor(props) {
7 | super(props)
8 | this.editForm = React.createRef()
9 | this.state = {
10 | data: [],
11 | columns: [
12 | {
13 | title: '姓名',
14 | dataIndex: 'name',
15 | key: 'name'
16 | },
17 | {
18 | title: '年龄',
19 | dataIndex: 'age',
20 | key: 'age',
21 | },
22 | {
23 | title: '性别',
24 | dataIndex: 'gender',
25 | key: 'gender',
26 | },
27 | {
28 | title: '地址',
29 | dataIndex: 'address',
30 | key: 'address',
31 | },
32 | {
33 | title: '操作',
34 | key: 'action',
35 | render: (text, record) => (
36 |
37 | { this.edit(record) }}>编辑
38 |
39 | 删除
40 |
41 | )
42 | }
43 | ],
44 | visible: false, // 控制弹框显示
45 | id: null // 当前行id
46 | }
47 | }
48 | render() {
49 | // const { getFieldDecorator } = this.props.form;
50 | return (
51 |
52 |
record.id} />
53 |
59 |
60 |
61 |
62 | )
63 | }
64 | componentDidMount() {
65 | this.getData()
66 | }
67 | getData = () => {
68 | $http.getData().then(res => {
69 | console.log(res)
70 | this.setState({
71 | data: res.data.list
72 | })
73 | })
74 | }
75 | delete = () => {
76 | message.success('假装删除');
77 | }
78 | edit = (record) => {
79 | // console.log(record.id)
80 | this.setState({
81 | id: record.id
82 | })
83 | this.setState({
84 | visible: true
85 | })
86 | }
87 | // handleOk = () => {
88 | // this.handleSubmit()
89 | // }
90 | handleCancel = () => {
91 | this.setState({
92 | visible: false
93 | })
94 | this.editForm.current.resetFields() // 重置表单数据
95 | }
96 | handleSubmit = () => {
97 | this.editForm.current.validateFields((err, values) => {
98 | if (!err) {
99 | console.log(values)
100 | $http.editData(values, this.state.id).then(res => { // 因为是模拟的数据 所以修改之后会返回修改后的数据数组 和前面的首次获取数据不是同一个接口
101 | console.log(res)
102 | this.setState({
103 | data: res.data.list,
104 | visible: false
105 | })
106 | message.success('修改成功');
107 | this.editForm.current.resetFields()
108 | })
109 | }
110 | });
111 | }
112 | }
113 |
--------------------------------------------------------------------------------