Browse Source

首页报表收藏偶尔会重复添加的问题

zhuth 6 years ago
parent
commit
dfb19687ef
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/models/home.js

+ 7 - 1
src/models/home.js

@@ -180,6 +180,9 @@ export default {
                 const home = yield select(state => state.present.home);
                 const { data } = action;
                 const { collectionDashboards } = home;
+                if(collectionDashboards.findIndex(d => d.code === data.code) > -1) {
+                    return;
+                }
                 const res = yield call(service.fetch, {
                     url: URLS.DASHBOARD_COLLECT_ADD + '/' + data.code
                 });
@@ -198,11 +201,14 @@ export default {
                 const home = yield select(state => state.present.home);
                 const { data } = action;
                 const { collectionDashboards } = home;
+                let idx = collectionDashboards.findIndex(d => d.code === data.code);
+                if(idx === -1) {
+                    return;
+                }
                 const res = yield call(service.fetch, {
                     url: URLS.DASHBOARD_COLLECT_REMOVE + '/' + data.code
                 });
                 if(res.code > 0) {
-                    let idx = collectionDashboards.findIndex(d => d.code === data.code);
                     collectionDashboards.splice(idx, 1);
                     yield put({ type: 'setField', name: 'collectionDashboards', value: collectionDashboards });
                 }else {