Skip to content

Commit

Permalink
Merge pull request zuiidea#258 from zuiidea/develop
Browse files Browse the repository at this point in the history
add:nprogress,dva-loading
zuiidea authored May 8, 2017
2 parents bf260db + 839a7c5 commit 255b0a9
Showing 15 changed files with 167 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/components/Layout/Header.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import Menus from './Menu'

const SubMenu = Menu.SubMenu

function Header ({ user, logout, switchSider, siderFold, isNavbar, menuPopoverVisible, location, switchMenuPopover, navOpenKeys, changeOpenKeys, menu }) {
const Header = ({ user, logout, switchSider, siderFold, isNavbar, menuPopoverVisible, location, switchMenuPopover, navOpenKeys, changeOpenKeys, menu }) => {
let handleClickMenu = e => e.key === 'logout' && logout()
const menusProps = {
menu,
1 change: 1 addition & 0 deletions src/components/Layout/Header.less
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

.rightWarpper {
display: flex;
padding-right: 16px;
}

.button {
1 change: 0 additions & 1 deletion src/components/Layout/Layout.less
Original file line number Diff line number Diff line change
@@ -69,7 +69,6 @@
height: 100vh;
transition: @transition-ease-out;
box-shadow: @shadow-1;
z-index: 520;
color: #999;

&.light {
2 changes: 1 addition & 1 deletion src/components/Layout/Sider.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import styles from './Layout.less'
import { config } from '../../utils'
import Menus from './Menu'

function Sider ({ siderFold, darkTheme, location, changeTheme, navOpenKeys, changeOpenKeys, menu }) {
const Sider = ({ siderFold, darkTheme, location, changeTheme, navOpenKeys, changeOpenKeys, menu }) => {
const menusProps = {
menu,
siderFold,
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ import { message } from 'antd'

// 1. Initialize
const app = dva({
...createLoading(),
...createLoading({
effects: true,
}),
history: browserHistory,
onError (error) {
message.error(error.message)
81 changes: 31 additions & 50 deletions src/models/app.js
Original file line number Diff line number Diff line change
@@ -8,29 +8,35 @@ export default {
namespace: 'app',
state: {
user: {},
loginButtonLoading: false,
menuPopoverVisible: false,
siderFold: localStorage.getItem(`${prefix}siderFold`) === 'true',
darkTheme: localStorage.getItem(`${prefix}darkTheme`) === 'true',
isNavbar: document.body.clientWidth < 769,
navOpenKeys: JSON.parse(localStorage.getItem(`${prefix}navOpenKeys`)) || [],
},
subscriptions: {

setup ({ dispatch }) {
dispatch({ type: 'queryUser' })
dispatch({ type: 'query' })
let tid
window.onresize = () => {
dispatch({ type: 'changeNavbar' })
clearTimeout(tid)
tid = setTimeout(() => {
dispatch({ type: 'changeNavbar' })
}, 300)
}
},

},
effects: {
*queryUser ({

*query ({
payload,
}, { call, put }) {
const data = yield call(query, parse(payload))
if (data.success && data.user) {
yield put({
type: 'queryUserSuccess',
type: 'querySuccess',
payload: data.user,
})
if (location.pathname === '/login') {
@@ -46,6 +52,7 @@ export default {
}
}
},

*logout ({
payload,
}, { call, put }) {
@@ -56,82 +63,56 @@ export default {
throw (data)
}
},
*switchSider ({
payload,
}, { put }) {
yield put({
type: 'handleSwitchSider',
})
},
*changeTheme ({
payload,
}, { put }) {
yield put({
type: 'handleChangeTheme',
})
},

*changeNavbar ({
payload,
}, { put }) {
if (document.body.clientWidth < 769) {
yield put({ type: 'showNavbar' })
} else {
yield put({ type: 'hideNavbar' })
}, { put, select }) {
const { app } = yield(select(_ => _))
const isNavbar = document.body.clientWidth < 769
if (isNavbar !== app.isNavbar) {
yield put({ type: 'handleNavbar', payload: isNavbar })
}
},
*switchMenuPopver ({
payload,
}, { put }) {
yield put({
type: 'handleSwitchMenuPopver',
})
},

},
reducers: {
queryUserSuccess (state, { payload: user }) {
querySuccess (state, { payload: user }) {
return {
...state,
user,
}
},
showLoginButtonLoading (state) {
return {
...state,
loginButtonLoading: true,
}
},
handleSwitchSider (state) {

switchSider (state) {
localStorage.setItem(`${prefix}siderFold`, !state.siderFold)
return {
...state,
siderFold: !state.siderFold,
}
},
handleChangeTheme (state) {

switchTheme (state) {
localStorage.setItem(`${prefix}darkTheme`, !state.darkTheme)
return {
...state,
darkTheme: !state.darkTheme,
}
},
showNavbar (state) {
return {
...state,
isNavbar: true,
}
},
hideNavbar (state) {

switchMenuPopver (state) {
return {
...state,
isNavbar: false,
menuPopoverVisible: !state.menuPopoverVisible,
}
},
handleSwitchMenuPopver (state) {

handleNavbar (state, { payload }) {
return {
...state,
menuPopoverVisible: !state.menuPopoverVisible,
isNavbar: payload,
}
},

handleNavOpenKeys (state, { payload: navOpenKeys }) {
return {
...state,
37 changes: 17 additions & 20 deletions src/models/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { create, remove, update } from '../services/user'
import { query } from '../services/users'
import { routerRedux } from 'dva/router'
import { parse } from 'qs'

export default {
@@ -36,13 +35,9 @@ export default {
},

effects: {
*requery ({ payload }, { put }) {
yield put(routerRedux.push({
pathname: location.pathname,
query: parse(location.search.substr(1)),
}))
},

*query ({ payload }, { call, put }) {
payload = parse(location.search.substr(1))
const data = yield call(query, payload)
if (data) {
yield put({
@@ -58,44 +53,42 @@ export default {
})
}
},

*'delete' ({ payload }, { call, put }) {
const data = yield call(remove, { id: payload })
if (data.success) {
yield put({ type: 'requery' })
yield put({ type: 'query' })
} else {
throw data
}
},

*create ({ payload }, { call, put }) {
yield put({ type: 'hideModal' })
const data = yield call(create, payload)
if (data.success) {
yield put({ type: 'requery' })
yield put({ type: 'hideModal' })
yield put({ type: 'query' })
} else {
throw data
}
},

*update ({ payload }, { select, call, put }) {
yield put({ type: 'hideModal' })
const id = yield select(({ user }) => user.currentItem.id)
const newUser = { ...payload, id }
const data = yield call(update, newUser)
if (data.success) {
yield put({ type: 'requery' })
yield put({ type: 'hideModal' })
yield put({ type: 'query' })
} else {
throw data
}
},
*switchIsMotion ({
payload,
}, { put }) {
yield put({
type: 'handleSwitchIsMotion',
})
},

},

reducers: {

querySuccess (state, action) {
const { list, pagination } = action.payload
return { ...state,
@@ -105,16 +98,20 @@ export default {
...pagination,
} }
},

showModal (state, action) {
return { ...state, ...action.payload, modalVisible: true }
},

hideModal (state) {
return { ...state, modalVisible: false }
},
handleSwitchIsMotion (state) {

switchIsMotion (state) {
localStorage.setItem('antdAdminUserIsMotion', !state.isMotion)
return { ...state, isMotion: !state.isMotion }
},

},

}
Empty file removed src/models/user/index.js
Empty file.
10 changes: 8 additions & 2 deletions src/routes/app.js
Original file line number Diff line number Diff line change
@@ -5,13 +5,18 @@ import { Layout } from '../components'
import { classnames, config, menu } from '../utils'
import { Helmet } from 'react-helmet'
import '../themes/index.less'
import './app.less'
import NProgress from 'nprogress'
const { prefix } = config

const { Header, Bread, Footer, Sider, styles } = Layout

const App = ({ children, location, dispatch, app }) => {
const App = ({ children, location, dispatch, app, loading }) => {
const { user, siderFold, darkTheme, isNavbar, menuPopoverVisible, navOpenKeys } = app

NProgress.start()
!loading.global && NProgress.done()

const headerProps = {
menu,
user,
@@ -41,7 +46,7 @@ const App = ({ children, location, dispatch, app }) => {
location,
navOpenKeys,
changeTheme () {
dispatch({ type: 'app/changeTheme' })
dispatch({ type: 'app/switchTheme' })
},
changeOpenKeys (openKeys) {
localStorage.setItem(`${prefix}navOpenKeys`, JSON.stringify(openKeys))
@@ -89,6 +94,7 @@ App.propTypes = {
location: PropTypes.object,
dispatch: PropTypes.func,
app: PropTypes.object,
loading: PropTypes.object,
}

export default connect(({ app, loading }) => ({ app, loading }))(App)
Loading

0 comments on commit 255b0a9

Please sign in to comment.