diff --git a/package.json b/package.json index d445600a9705af11634f971d98536d61c84a691a..be15b815c52ad3a4dbf938ac248d7e1e89428eaf 100755 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "bizcharts-plugin-slider": "^2.0.1", "classnames": "^2.2.5", "dva": "^2.1.0", + "dva-loading": "^1.0.4", "enquire-js": "^0.1.1", "fastclick": "^1.0.6", "lodash": "^4.17.4", diff --git a/src/index.js b/src/index.js index 844b84a48e57a0e8d1fe51970718500f6e5da0a2..6da92a1c968117e29aaf675c7d1c49e56eb2fe9a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,19 +1,21 @@ import '@babel/polyfill'; import dva from 'dva'; +import createHistory from 'history/createHashHistory'; +import createLoading from 'dva-loading'; import 'moment/locale/zh-cn'; import FastClick from 'fastclick'; import './rollbar'; import onError from './error'; -// import browserHistory from 'history/createBrowserHistory'; + import './index.less'; // 1. Initialize const app = dva({ - // history: browserHistory(), + history: createHistory(), onError, }); // 2. Plugins -// app.use({}); +app.use(createLoading()); // 3. Register global model app.model(require('./models/global').default); diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 2df22a33dce2401445afcaf8cd62dd70c01077b9..4caebc70cb3e4b5e7471436faa1cfc1ac81e8faa 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -220,9 +220,9 @@ class BasicLayout extends React.PureComponent { } } -export default connect(state => ({ - currentUser: state.user.currentUser, - collapsed: state.global.collapsed, - fetchingNotices: state.global.fetchingNotices, - notices: state.global.notices, +export default connect(({ user, global, loading }) => ({ + currentUser: user.currentUser, + collapsed: global.collapsed, + fetchingNotices: loading.effects['global/fetchNotices'], + notices: global.notices, }))(BasicLayout); diff --git a/src/models/activities.js b/src/models/activities.js index 262fc082a47441a4cc0e7116ac712eb324527f72..76a7d502e3565de535f3c58a5d51c79ef8647228 100644 --- a/src/models/activities.js +++ b/src/models/activities.js @@ -5,24 +5,15 @@ export default { state: { list: [], - loading: true, }, effects: { *fetchList(_, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(queryActivities); yield put({ type: 'saveList', payload: Array.isArray(response) ? response : [], }); - yield put({ - type: 'changeLoading', - payload: false, - }); }, }, @@ -33,11 +24,5 @@ export default { list: action.payload, }; }, - changeLoading(state, action) { - return { - ...state, - loading: action.payload, - }; - }, }, }; diff --git a/src/models/chart.js b/src/models/chart.js index 6922a7511e3c4e9f51d399b728d65a4c98be4aed..17bd30614d7b2577c5154f0bd1415a3b9e6c2b7c 100644 --- a/src/models/chart.js +++ b/src/models/chart.js @@ -19,10 +19,6 @@ export default { effects: { *fetch(_, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(fakeChartData); yield put({ type: 'save', @@ -45,7 +41,6 @@ export default { return { ...state, ...payload, - loading: false, }; }, clear() { @@ -62,11 +57,5 @@ export default { radarData: [], }; }, - changeLoading(state, { payload }) { - return { - ...state, - loading: payload, - }; - }, }, }; diff --git a/src/models/form.js b/src/models/form.js index afae2044f8fa95249d64c60f01f3be81d155b78a..64a1d49794b9b059564eadf7fce0bb9dbde5a8a3 100644 --- a/src/models/form.js +++ b/src/models/form.js @@ -12,50 +12,23 @@ export default { receiverName: 'Alex', amount: '500', }, - regularFormSubmitting: false, - stepFormSubmitting: false, - advancedFormSubmitting: false, }, effects: { - *submitRegularForm({ payload }, { call, put }) { - yield put({ - type: 'changeRegularFormSubmitting', - payload: true, - }); + *submitRegularForm({ payload }, { call }) { yield call(fakeSubmitForm, payload); - yield put({ - type: 'changeRegularFormSubmitting', - payload: false, - }); message.success('提交成功'); }, *submitStepForm({ payload }, { call, put }) { - yield put({ - type: 'changeStepFormSubmitting', - payload: true, - }); yield call(fakeSubmitForm, payload); yield put({ type: 'saveStepFormData', payload, }); - yield put({ - type: 'changeStepFormSubmitting', - payload: false, - }); yield put(routerRedux.push('/form/step-form/result')); }, - *submitAdvancedForm({ payload }, { call, put }) { - yield put({ - type: 'changeAdvancedFormSubmitting', - payload: true, - }); + *submitAdvancedForm({ payload }, { call }) { yield call(fakeSubmitForm, payload); - yield put({ - type: 'changeAdvancedFormSubmitting', - payload: false, - }); message.success('提交成功'); }, }, @@ -70,23 +43,5 @@ export default { }, }; }, - changeRegularFormSubmitting(state, { payload }) { - return { - ...state, - regularFormSubmitting: payload, - }; - }, - changeStepFormSubmitting(state, { payload }) { - return { - ...state, - stepFormSubmitting: payload, - }; - }, - changeAdvancedFormSubmitting(state, { payload }) { - return { - ...state, - advancedFormSubmitting: payload, - }; - }, }, }; diff --git a/src/models/global.js b/src/models/global.js index bbbee7025d035bfa6953f3c14374872a82189083..55841e16d053db3bf4c92b94ce877cd6601d4965 100644 --- a/src/models/global.js +++ b/src/models/global.js @@ -6,15 +6,10 @@ export default { state: { collapsed: false, notices: [], - fetchingNotices: false, }, effects: { *fetchNotices(_, { call, put }) { - yield put({ - type: 'changeNoticeLoading', - payload: true, - }); const data = yield call(queryNotices); yield put({ type: 'saveNotices', @@ -49,7 +44,6 @@ export default { return { ...state, notices: payload, - fetchingNotices: false, }; }, saveClearedNotices(state, { payload }) { @@ -58,12 +52,6 @@ export default { notices: state.notices.filter(item => item.type !== payload), }; }, - changeNoticeLoading(state, { payload }) { - return { - ...state, - fetchingNotices: payload, - }; - }, }, subscriptions: { diff --git a/src/models/list.js b/src/models/list.js index d047b8262cef95e1d16bd73e77f88ab3208ac98f..147eeca6e1465f52e833d7617bf5b31ff1b0ff5b 100644 --- a/src/models/list.js +++ b/src/models/list.js @@ -5,39 +5,22 @@ export default { state: { list: [], - loading: false, }, effects: { *fetch({ payload }, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(queryFakeList, payload); yield put({ type: 'queryList', payload: Array.isArray(response) ? response : [], }); - yield put({ - type: 'changeLoading', - payload: false, - }); }, *appendFetch({ payload }, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(queryFakeList, payload); yield put({ type: 'appendList', payload: Array.isArray(response) ? response : [], }); - yield put({ - type: 'changeLoading', - payload: false, - }); }, }, @@ -54,11 +37,5 @@ export default { list: state.list.concat(action.payload), }; }, - changeLoading(state, action) { - return { - ...state, - loading: action.payload, - }; - }, }, }; diff --git a/src/models/login.js b/src/models/login.js index ff45a61227534b3db704465ee596acce6f2723b5..05c1913ec173a28c77c733cdbe9b5981f6f2b044 100644 --- a/src/models/login.js +++ b/src/models/login.js @@ -10,10 +10,6 @@ export default { effects: { *login({ payload }, { call, put }) { - yield put({ - type: 'changeSubmitting', - payload: true, - }); const response = yield call(fakeAccountLogin, payload); yield put({ type: 'changeLoginStatus', @@ -50,13 +46,6 @@ export default { ...state, status: payload.status, type: payload.type, - submitting: false, - }; - }, - changeSubmitting(state, { payload }) { - return { - ...state, - submitting: payload, }; }, }, diff --git a/src/models/profile.js b/src/models/profile.js index ce36dfc60e4577f8d4ca0eb0e328495cfe0be066..7c9d01986447a096eeffbf064bae253b8b8d5905 100644 --- a/src/models/profile.js +++ b/src/models/profile.js @@ -5,43 +5,25 @@ export default { state: { basicGoods: [], - basicLoading: true, advancedOperation1: [], advancedOperation2: [], advancedOperation3: [], - advancedLoading: true, }, effects: { *fetchBasic(_, { call, put }) { - yield put({ - type: 'changeLoading', - payload: { basicLoading: true }, - }); const response = yield call(queryBasicProfile); yield put({ type: 'show', payload: response, }); - yield put({ - type: 'changeLoading', - payload: { basicLoading: false }, - }); }, *fetchAdvanced(_, { call, put }) { - yield put({ - type: 'changeLoading', - payload: { advancedLoading: true }, - }); const response = yield call(queryAdvancedProfile); yield put({ type: 'show', payload: response, }); - yield put({ - type: 'changeLoading', - payload: { advancedLoading: false }, - }); }, }, @@ -52,11 +34,5 @@ export default { ...payload, }; }, - changeLoading(state, { payload }) { - return { - ...state, - ...payload, - }; - }, }, }; diff --git a/src/models/project.js b/src/models/project.js index 4ad17d820e9621aa7658b1ab933d99d1112157d6..f68bef5302d79ae1a11b3300521f8198a9a1d957 100644 --- a/src/models/project.js +++ b/src/models/project.js @@ -5,24 +5,15 @@ export default { state: { notice: [], - loading: true, }, effects: { *fetchNotice(_, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(queryProjectNotice); yield put({ type: 'saveNotice', payload: Array.isArray(response) ? response : [], }); - yield put({ - type: 'changeLoading', - payload: false, - }); }, }, @@ -33,11 +24,5 @@ export default { notice: action.payload, }; }, - changeLoading(state, action) { - return { - ...state, - loading: action.payload, - }; - }, }, }; diff --git a/src/models/register.js b/src/models/register.js index 003494b7f265ab9938e0a88ce3d5bf4e84462e7c..164ccae111f01ca166fa9d5abf9645eb1087d7cf 100644 --- a/src/models/register.js +++ b/src/models/register.js @@ -9,19 +9,11 @@ export default { effects: { *submit(_, { call, put }) { - yield put({ - type: 'changeSubmitting', - payload: true, - }); const response = yield call(fakeRegister); yield put({ type: 'registerHandle', payload: response, }); - yield put({ - type: 'changeSubmitting', - payload: false, - }); }, }, @@ -32,11 +24,5 @@ export default { status: payload.status, }; }, - changeSubmitting(state, { payload }) { - return { - ...state, - submitting: payload, - }; - }, }, }; diff --git a/src/models/rule.js b/src/models/rule.js index 8b36ba3f59905395bbf70e42534ab65cdbccfe6f..9ae968f8d0204c32e02a9f9fa0cb4f8785c4c7ef 100644 --- a/src/models/rule.js +++ b/src/models/rule.js @@ -8,57 +8,30 @@ export default { list: [], pagination: {}, }, - loading: true, }, effects: { *fetch({ payload }, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(queryRule, payload); yield put({ type: 'save', payload: response, }); - yield put({ - type: 'changeLoading', - payload: false, - }); }, *add({ payload, callback }, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(addRule, payload); yield put({ type: 'save', payload: response, }); - yield put({ - type: 'changeLoading', - payload: false, - }); - if (callback) callback(); }, *remove({ payload, callback }, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(removeRule, payload); yield put({ type: 'save', payload: response, }); - yield put({ - type: 'changeLoading', - payload: false, - }); - if (callback) callback(); }, }, @@ -70,11 +43,5 @@ export default { data: action.payload, }; }, - changeLoading(state, action) { - return { - ...state, - loading: action.payload, - }; - }, }, }; diff --git a/src/models/user.js b/src/models/user.js index 197e3626e45970a1a2796ca11fd91fc513bec01f..b45afc3aa2655536e6d5360a64d116964decfdc1 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -5,25 +5,16 @@ export default { state: { list: [], - loading: false, currentUser: {}, }, effects: { *fetch(_, { call, put }) { - yield put({ - type: 'changeLoading', - payload: true, - }); const response = yield call(queryUsers); yield put({ type: 'save', payload: response, }); - yield put({ - type: 'changeLoading', - payload: false, - }); }, *fetchCurrent(_, { call, put }) { const response = yield call(queryCurrent); @@ -41,12 +32,6 @@ export default { list: action.payload, }; }, - changeLoading(state, action) { - return { - ...state, - loading: action.payload, - }; - }, saveCurrentUser(state, action) { return { ...state, diff --git a/src/routes/Dashboard.js b/src/routes/Dashboard.js index 8c108bcb86bbeb9af588c6fcf55deb6c3536ccc4..1e9bc820f85e5a7d100bbe5e2e7d9322fa95ed12 100644 --- a/src/routes/Dashboard.js +++ b/src/routes/Dashboard.js @@ -37,7 +37,7 @@ class Dashboard extends PureComponent { }); } render() { - const { user: { list, loading } } = this.props; + const { user: { list }, loading } = this.props; return (