diff --git a/README.md b/README.md
index 621bfad..2b6c0df 100644
--- a/README.md
+++ b/README.md
@@ -38,3 +38,8 @@ https://github.com/dvajs/dva/tree/master/examples/user-dashboard
├── package.json # 项目信息
└── proxy.config.js # 数据mock配置
```
+## Screenshot
+
+
+
+
diff --git a/assets/anrd-admin-dataList.png b/assets/anrd-admin-dataList.png
new file mode 100644
index 0000000..57d403e
Binary files /dev/null and b/assets/anrd-admin-dataList.png differ
diff --git a/assets/anrd-admin-login.png b/assets/anrd-admin-login.png
new file mode 100644
index 0000000..d9ffb81
Binary files /dev/null and b/assets/anrd-admin-login.png differ
diff --git a/package.json b/package.json
index 4220494..1a51590 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
"dependencies": {
"dva": "^1.0.0",
"keymaster": "^1.6.2",
+ "qs": "^6.2.1",
"react": "^15.1.0",
"react-dom": "^15.1.0"
},
diff --git a/src/components/Layout/Header.jsx b/src/components/Layout/Header.jsx
new file mode 100644
index 0000000..3f0b89e
--- /dev/null
+++ b/src/components/Layout/Header.jsx
@@ -0,0 +1,41 @@
+import React, { PropTypes } from 'react';
+import { Menu, Icon } from 'antd';
+import { Link } from 'dva/router';
+
+function getMenuKeyFromUrl(pathname) {
+ let key = '';
+ try {
+ key = pathname.match(/\/([^\/]*)/i)[1];
+ /* eslint no-empty:0 */
+ } catch (e) {}
+ return key;
+}
+
+function Header({ location }) {
+ return (
+
+ );
+}
+
+Header.propTypes = {
+ location: PropTypes.object,
+};
+
+export default Header;
diff --git a/src/components/Layout/MainLayout.jsx b/src/components/Layout/MainLayout.jsx
new file mode 100644
index 0000000..f50f9b4
--- /dev/null
+++ b/src/components/Layout/MainLayout.jsx
@@ -0,0 +1,23 @@
+import React, { PropTypes } from 'react';
+import styles from './MainLayout.less';
+import Header from './Header';
+
+function MainLayout({ children, location }) {
+ return (
+
+ );
+}
+
+MainLayout.propTypes = {
+ children: PropTypes.element.isRequired,
+ location: PropTypes.object,
+};
+
+export default MainLayout;
diff --git a/src/components/Layout/MainLayout.less b/src/components/Layout/MainLayout.less
new file mode 100644
index 0000000..24e81e9
--- /dev/null
+++ b/src/components/Layout/MainLayout.less
@@ -0,0 +1,16 @@
+
+.normal {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+}
+
+.content {
+ flex: 1;
+ display: flex;
+}
+
+.main {
+ padding: 0 8px;
+ flex: 1 0 auto;
+}
diff --git a/src/models/users.js b/src/models/users.js
index f8fd859..2e786fc 100644
--- a/src/models/users.js
+++ b/src/models/users.js
@@ -1,144 +1,116 @@
-import {create, remove, update, query} from '../services/users'
-import {parse} from 'qs'
+import { create, remove, update, query } from '../services/users'
+import { parse } from 'qs'
export default {
- namespace : 'users',
+ namespace: 'users',
- state : {
+ state: {
list: [],
loading: false,
total: null,
current: 1,
currentItem: {},
modalVisible: false,
- modalType: 'create'
+ modalType: 'create',
},
- subscriptions : {
- setup({dispatch, history}) {
+ subscriptions: {
+ setup({ dispatch, history }) {
history.listen(location => {
if (location.pathname === '/users') {
- dispatch({type: 'query', payload: location.query})
+ dispatch({
+ type: 'query',
+ payload: location.query,
+ })
}
})
- }
+ },
},
- effects : {
- *query({
- payload
- }, {call, put}) {
- yield put({type: 'showLoading'})
- const {data} = yield call(query, parse(payload))
+ effects: {
+ *query({ payload }, { call, put }) {
+ yield put({ type: 'showLoading' })
+ const { data } = yield call(query, parse(payload))
if (data) {
yield put({
type: 'querySuccess',
payload: {
list: data.data,
total: data.page.total,
- current: data.page.current
- }
+ current: data.page.current,
+ },
})
}
},
- * 'delete' ({
- payload
- }, {call, put}) {
- yield put({type: 'showLoading'})
- const {data} = yield call(remove, {id: payload})if (data && data.success) {
- yield put({type: 'deleteSuccess', payload})
+ *'delete'({ payload }, { call, put }) {
+ yield put({ type: 'showLoading' })
+ const { data } = yield call(remove, { id: payload })
+ if (data && data.success) {
+ yield put({
+ type: 'deleteSuccess',
+ payload,
+ })
}
},
- *create({
- payload
- }, {call, put}) {
- yield put({type: 'hideModal'})
- yield put({type: 'showLoading'})
- const {data} = yield call(create, payload)
+ *create({ payload }, { call, put }) {
+ yield put({ type: 'hideModal' })
+ yield put({ type: 'showLoading' })
+ const { data } = yield call(create, payload)
if (data && data.success) {
- yield put({type: 'createSuccess', payload})
+ yield put({
+ type: 'createSuccess',
+ payload,
+ })
}
},
- *update({
- payload
- }, {select, call, put}) {
- yield put({type: 'hideModal'})
- yield put({type: 'showLoading'})
- const id = yield select(({users}) => users.currentItem.id)
- const newUser = {
- ...payload,
- id
- }
- const {data} = yield call(update, newUser)
+ *update({ payload }, { select, call, put }) {
+ yield put({ type: 'hideModal' })
+ yield put({ type: 'showLoading' })
+ const id = yield select(({ users }) => users.currentItem.id)
+ const newUser = { ...payload, id }
+ const { data } = yield call(update, newUser)
if (data && data.success) {
- yield put({type: 'updateSuccess', payload: newUser})
+ yield put({
+ type: 'updateSuccess',
+ payload: newUser,
+ })
}
- }
+ },
},
- reducers : {
+ reducers: {
showLoading(state) {
- return {
- ...state,
- loading: true
- }
+ return { ...state, loading: true }
},
createSuccess(state, action) {
const newUser = action.payload
- return {
- ...state,
- list: [
- newUser, ...state.list
- ],
- loading: false
- }
+ return { ...state, list: [newUser, ...state.list], loading: false }
},
deleteSuccess(state, action) {
const id = action.payload
const newList = state.list.filter(user => user.id !== id)
- return {
- ...state,
- list: newList,
- loading: false
- }
+ return { ...state, list: newList, loading: false }
},
updateSuccess(state, action) {
const updateUser = action.payload
const newList = state.list.map(user => {
if (user.id === updateUser.id) {
- return {
- ...user,
- ...updateUser
- }
+ return { ...user, ...updateUser }
}
return user
})
- return {
- ...state,
- list: newList,
- loading: false
- }
+ return { ...state, list: newList, loading: false }
},
querySuccess(state, action) {
- return {
- ...state,
- ...action.payload,
- loading: false
- }
+ return { ...state, ...action.payload, loading: false }
},
showModal(state, action) {
- return {
- ...state,
- ...action.payload,
- modalVisible: true
- }
+ return { ...state, ...action.payload, modalVisible: true }
},
hideModal(state) {
- return {
- ...state,
- modalVisible: false
- }
- }
- }
+ return { ...state, modalVisible: false }
+ },
+ },
+
}
diff --git a/src/router.js b/src/router.js
index 806b2c7..5a8f4fc 100644
--- a/src/router.js
+++ b/src/router.js
@@ -1,10 +1,9 @@
-import React from 'react';
-import { Router, Route } from 'dva/router';
-import HomePage from './routes/HomePage';
-import NotFound from './routes/NotFound';
-import Users from './routes/Users';
+import React from 'react'
+import { Router, Route } from 'dva/router'
+import HomePage from './routes/HomePage'
+import NotFound from './routes/NotFound'
+import Users from './routes/Users'
-/* eslint react/prop-types:0 */
export default function ({ history }) {
return (
@@ -12,5 +11,5 @@ export default function ({ history }) {
- );
+ )
}
diff --git a/src/routes/Users.jsx b/src/routes/Users.jsx
index 59b9d16..3d5db93 100644
--- a/src/routes/Users.jsx
+++ b/src/routes/Users.jsx
@@ -1,7 +1,7 @@
import React, { PropTypes } from 'react';
import { routerRedux } from 'dva/router';
import { connect } from 'dva';
-import MainLayout from '../components/MainLayout/MainLayout';
+import MainLayout from '../components/Layout/MainLayout';
import styles from './Users.less';
import UserList from '../components/Users/UserList';
import UserSearch from '../components/Users/UserSearch';
diff --git a/src/services/example.js b/src/services/example.js
new file mode 100644
index 0000000..bbf54e3
--- /dev/null
+++ b/src/services/example.js
@@ -0,0 +1,5 @@
+import request from '../utils/request';
+
+export async function query() {
+ return request('/api/users');
+}