mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-01 07:20:20 +00:00
dva
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
|
||||
const Example = (props) => {
|
||||
return (
|
||||
<div>
|
||||
Example
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Example.propTypes = {
|
||||
};
|
||||
|
||||
export default Example;
|
||||
+10
-8
@@ -1,14 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Ant Design Admin</title>
|
||||
<meta charset="UTF-8">
|
||||
<title>Demo</title>
|
||||
<link rel="stylesheet" href="index.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="view" style="height:100%"></div>
|
||||
<script src="http://localhost:8080/webpack-dev-server.js"></script>
|
||||
|
||||
<div id="root"></div>
|
||||
|
||||
<script src="common.js"></script>
|
||||
<script src="index.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+15
-24
@@ -1,27 +1,18 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import {Router, Route, IndexRoute,IndexRedirect,Redirect,hashHistory} from 'react-router'
|
||||
import './utils/index.js'
|
||||
import './index.html';
|
||||
import './index.less';
|
||||
import dva from 'dva';
|
||||
|
||||
import App from './view/index'
|
||||
import SignIn from './view/user/signIn'
|
||||
import List from './view/data/list'
|
||||
import Dashboard from './view/user/dashboard'
|
||||
import Error from './view/common/error'
|
||||
import './utils/lib.less'
|
||||
// 1. Initialize
|
||||
const app = dva();
|
||||
|
||||
const routes = (
|
||||
<Router history={hashHistory}>
|
||||
<Route path="/" component={App}>
|
||||
<IndexRedirect to="/dashboard" />
|
||||
<Route path="dashboard" tableName="dashboard" component={Dashboard}/>
|
||||
<Route path="index">
|
||||
<Route path="list" tableName="list" component={List}/>
|
||||
</Route>
|
||||
<Route path="error" tableName="error" component={Error}/>
|
||||
<Redirect from="*" to="error" />
|
||||
</Route>
|
||||
</Router>
|
||||
)
|
||||
// 2. Plugins
|
||||
//app.use({});
|
||||
|
||||
ReactDOM.render(routes, document.getElementById('view'))
|
||||
// 3. Model
|
||||
//app.model(require('./models/example'));
|
||||
|
||||
// 4. Router
|
||||
app.router(require('./router'));
|
||||
|
||||
// 5. Start
|
||||
app.start('#root');
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
export default {
|
||||
|
||||
namespace: 'example',
|
||||
|
||||
state: {},
|
||||
|
||||
subscriptions: {
|
||||
setup({ dispatch, history }) {
|
||||
},
|
||||
},
|
||||
|
||||
effects: {
|
||||
*fetchRemote({ payload }, { call, put }) {
|
||||
},
|
||||
},
|
||||
|
||||
reducers: {
|
||||
fetch(state, action) {
|
||||
return { ...state, ...action.payload };
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import React, { PropTypes } from 'react';
|
||||
import { Router, Route, IndexRoute, Link } from 'dva/router';
|
||||
import IndexPage from './routes/IndexPage';
|
||||
|
||||
export default function({ history }) {
|
||||
return (
|
||||
<Router history={history}>
|
||||
<Route path="/" component={IndexPage} />
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import React, { Component, PropTypes } from 'react';
|
||||
import { connect } from 'dva';
|
||||
import { Link } from 'dva/router';
|
||||
import styles from './IndexPage.less';
|
||||
|
||||
function IndexPage() {
|
||||
return (
|
||||
<div className={styles.normal}>
|
||||
<h1>Welcome to dva!</h1>
|
||||
<hr />
|
||||
<ul className={styles.list}>
|
||||
<li>To get started, edit <code>src/index.js</code> and save to reload.</li>
|
||||
<li><a href="https://github.com/sorrycc/blog/issues/8" target="_blank">Getting Started</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
IndexPage.propTypes = {
|
||||
};
|
||||
|
||||
export default connect()(IndexPage);
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
.normal {
|
||||
margin: 100px;
|
||||
}
|
||||
|
||||
.list {
|
||||
margin-top: 20px;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import request from '../utils/request';
|
||||
|
||||
export async function query() {
|
||||
return request('/api/users');
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import expect from 'expect';
|
||||
import example from '../../models/example';
|
||||
|
||||
describe('example', () => {
|
||||
|
||||
describe('reducer', () => {
|
||||
it('it should save', () => {
|
||||
expect(example.reducers['example/save']({}, { payload: { a: 1 }})).toEqual({ a: 1 });
|
||||
});
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import fetch from 'dva/fetch';
|
||||
|
||||
function parseJSON(response) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
function checkStatus(response) {
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response;
|
||||
}
|
||||
|
||||
const error = new Error(response.statusText);
|
||||
error.response = response;
|
||||
throw error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a URL, returning a promise.
|
||||
*
|
||||
* @param {string} url The URL we want to request
|
||||
* @param {object} [options] The options we want to pass to "fetch"
|
||||
* @return {object} An object containing either "data" or "err"
|
||||
*/
|
||||
export default function request(url, options) {
|
||||
return fetch(url, options)
|
||||
.then(checkStatus)
|
||||
.then(parseJSON)
|
||||
.then((data) => ({ data }))
|
||||
.catch((err) => ({ err }));
|
||||
}
|
||||
Reference in New Issue
Block a user