Skip to content

Commit

Permalink
update dva to dva2.0
Browse files Browse the repository at this point in the history
update dva to dva2.0
  • Loading branch information
fomenyesu committed Jan 3, 2018
1 parent 0afb455 commit 4c38529
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 80 deletions.
2 changes: 1 addition & 1 deletion config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.robot = {

exports.security = {
ignore: '/api/',
domainWhiteList: ['http://10.180.152.49:8080','http://127.0.0.1:8080','http://10.180.144.212:8080','http://localhost:8080'],
domainWhiteList: ['http://127.0.0.1:8080','http://10.180.144.212:8080','http://localhost:8080'],
methodnoallow: {enable: false },
csrf: {
enable: false,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"css-loader": "0.24.0",
"egg-bin": "^3.1.0",
"egg-mock": "^3.2.0",
"egg-oauth2-server": "^2.0.6",
"egg-oauth2-server": "2.0.6",
"eslint": "1.8.0",
"eslint-loader": "1.1.0",
"extract-text-webpack-plugin": "^2.1.0",
Expand Down Expand Up @@ -63,7 +63,8 @@
"csrf": "^3.0.6",
"draft-js-export-html": "0.5.2",
"draftjs-to-html": "^0.7.2",
"dva": "^1.1.0",
"query-string": "^5.0.0",
"dva": "^2.0.1",
"dva-loading": "^0.2.0",
"egg": "^1.11.0",
"egg-cors": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion static/src/models/showApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
},
subscriptions: {
setup({ dispatch, history }) {
return history.listen(({ pathname, query }) => {
return history.listen(({ pathname }) => {
if (pathname === '/showApi') {
dispatch({ type: 'showApi/loadShowApi'});
}
Expand Down
106 changes: 41 additions & 65 deletions static/src/router.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,56 @@
import React, { PropTypes } from 'react'
import { Router } from 'dva/router'
import React from 'react'
import PropTypes from 'prop-types'
import { Router, Switch, Route, Redirect, routerRedux } from 'dva/router'
import dynamic from 'dva/dynamic'
import App from './routes/app'

const cached = {}
const registerModel = (app, model) => {
if (!cached[model.namespace]) {
app.model(model)
cached[model.namespace] = 1
}
}
const { ConnectedRouter } = routerRedux

const Routers = function ({ history, app }) {
const error = dynamic({
app,
component: () => import('./routes/error'),
})
const routes = [
{
path: '/',
component: App,
getIndexRoute (nextState, cb) {
require.ensure([], require => {
registerModel(app, require('./models/tableManager'))
cb(null, { component: require('./routes/tableManager/') })
}, 'tableManager')
},
childRoutes: [{
path: 'showApi',
name: 'showApi',
getComponent (nextState, cb) {
require.ensure([], require => {
registerModel(app, require('./models/showApi'))
cb(null, require('./routes/showApi/'))
}, 'showApi')
},
},{
path: 'tableManager',
name: 'tableManager',
getIndexRoute (nextState, cb) {
require.ensure([], require => {
registerModel(app, require('./models/tableManager'))
cb(null, { component: require('./routes/tableManager/') })
}, 'tableManager')
},

childRoutes: [
{
path: 'create',
name: 'tableManagerCreate',

getComponent(nextState, cb) {
require.ensure([], require => {
registerModel(app, require('./models/tableForm'));
cb(null, require('./routes/tableManager/TableForm'))
}, 'tableManager')
}
},
{
path: 'edit/:id',
name: 'tableManagerEdit',

getComponent(nextState, cb) {
require.ensure([], require => {
registerModel(app, require('./models/tableForm'));
cb(null, require('./routes/tableManager/TableForm'))
}, 'tableManager')
}
}
]
}
],
},
path: '/showApi',
models: () => [import('./models/showApi')],
component: () => import('./routes/showApi/index'),
}, {
path: '/tableManager',
models: () => [import('./models/tableManager')],
component: () => import('./routes/tableManager/index'),
}, {
path: '/tableManager/create',
models: () => [import('./models/tableForm')],
component: () => import('./routes/tableManager/TableForm'),
},{
path: '/tableManager/edit/:id',
models: () => [import('./models/tableForm')],
component: () => import('./routes/tableManager/TableForm'),
}
]

return <Router history={history} routes={routes} />
return (
<ConnectedRouter history={history}>
<App>
<Switch>
<Route exact path='/' render={() => (<Redirect to='/tableManager' />)} />
{
routes.map(({ path, ...dynamics }, key) => (
<Route key={key} exact path={path} component={dynamic({ app, ...dynamics })} />
))
}
<Route component={error} />
</Switch>
</App>
</ConnectedRouter>
)
}

Routers.propTypes = {
history: PropTypes.object,
app: PropTypes.object,
}

export default Routers
export default Routers
4 changes: 3 additions & 1 deletion static/src/routes/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { classnames, config } from '../utils'
import { Helmet } from 'react-helmet'
import '../components/skin.less'
import Cookie from '../utils/js.cookie'
import { withRouter } from 'dva/router'

const { Header, Bread, Footer, Sider, styles } = Layout;
let loginPage = '';
Expand Down Expand Up @@ -127,4 +128,5 @@ App.propTypes = {
loading: PropTypes.bool
}

export default connect(({ app, loading }) => ({ app, loading: loading.models.app }))(App)
export default withRouter(connect(({ app, loading }) => ({ app, loading: loading.models.app }))(App))
// export default connect(({ app, loading }) => ({ app, loading: loading.models.app }))(App)
3 changes: 2 additions & 1 deletion static/src/routes/tableManager/TableForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component, PropTypes } from 'react';
import { connect } from 'dva';
import TableView from './TableView';
import { routerRedux } from 'dva/router'

import { message } from 'antd';
import { attachmentURL } from '../../utils/config';
Expand Down Expand Up @@ -34,7 +35,7 @@ class TableForm extends Component {
}

goBack() {
this.context.router.goBack();
this.props.dispatch(routerRedux.push({pathname: '/tableManager'}));;
}

onSubmit(values) {
Expand Down
9 changes: 7 additions & 2 deletions static/src/routes/tableManager/TableView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Component, PropTypes } from 'react';
import { Input, Form, Button, Upload, Icon, message, DatePicker,Switch } from 'antd';
import moment from 'moment';
import { routerRedux } from 'dva/router'
import { connect } from 'dva';

import config from '../../utils/config';

Expand Down Expand Up @@ -31,7 +33,7 @@ class TableView extends Component {
}

goBack() {
this.context.router.goBack();
this.props.dispatch(routerRedux.push({pathname: '/tableManager'}));;
}

render() {
Expand Down Expand Up @@ -98,4 +100,7 @@ class TableView extends Component {
}
};

export default Form.create()(TableView);

export default connect(({ tableManager }) => {
return {}
})(Form.create()(TableView));
9 changes: 7 additions & 2 deletions static/src/routes/tableManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component, PropTypes } from 'react';
import { connect } from 'dva';
import { Table, Button, Modal,Switch } from 'antd';
import moment from 'moment';
import { routerRedux } from 'dva/router'

const columns = [
{ title: '序号', dataIndex: 'id' },
Expand Down Expand Up @@ -54,9 +55,13 @@ class TableManager extends Component {

toTableManagerForm(id) {
if (id) {
this.context.router.push({ pathname: `/tableManager/edit/${id}` });
this.props.dispatch(routerRedux.push({pathname: `/tableManager/edit/${id}`}));
// yield put(routerRedux.push({pathname: `/tableManager/edit/${id}`}))
// this.context.router.push({ pathname: `/tableManager/edit/${id}` });
} else {
this.context.router.push({ pathname: '/tableManager/create' });
this.props.dispatch(routerRedux.push({pathname: '/tableManager/create'}));
// yield put(routerRedux.push({pathname: '/tableManager/create'}))
// this.context.router.push({ pathname: '/tableManager/create' });
}
}

Expand Down
5 changes: 0 additions & 5 deletions static/src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ module.exports = {
name: 'Restapi Module',
prefix: 'fomenyesu',
footerText: 'Restapi Module 版权所有 © 2017 由 fomenyesu 支持',
logoSrc: 'http://10.180.152.49:7001/public/assets/logo.png',
// logoSrc: './assets/logo.png',
logoText: 'Restapi Module',
needLogin: true,
iconFontUrl: 'http://10.180.152.49:7001/public/assets/znfont.js',
// iconFontUrl: './assets/znfont.js',
devBaseURL: 'http://10.180.152.49:7001',
prdBaseURL: 'http://10.180.152.49:7001',
attachmentURL: 'http://10.180.152.49:7001/public/uploads'
}

0 comments on commit 4c38529

Please sign in to comment.