|
|
@@ -1,11 +1,9 @@
|
|
|
/**
|
|
|
* 首页model
|
|
|
*/
|
|
|
-import { routerRedux } from 'dva/router'
|
|
|
import { message } from 'antd'
|
|
|
import * as service from '../services/index'
|
|
|
import URLS from '../constants/url'
|
|
|
-import moment from 'moment'
|
|
|
|
|
|
export default {
|
|
|
namespace: 'home',
|
|
|
@@ -17,7 +15,8 @@ export default {
|
|
|
menuAutoExpandParent: true,
|
|
|
menuCollected: [{},{},{},{},{}],
|
|
|
tabs: [],
|
|
|
- selectedTabKey: null,
|
|
|
+ selectedTab: null,
|
|
|
+ collectionDashboards: [], // 已收藏报表
|
|
|
}
|
|
|
},
|
|
|
reducers: {
|
|
|
@@ -43,14 +42,13 @@ export default {
|
|
|
},
|
|
|
removeTab(state, action) {
|
|
|
const { tabs } = state;
|
|
|
- const { tabKey } = action;
|
|
|
- let idx = tabs.findIndex(t => t.code === tabKey);
|
|
|
+ const { tab } = action;
|
|
|
+ let idx = tabs.findIndex(t => t.code === tab.code);
|
|
|
tabs.splice(idx, 1);
|
|
|
return Object.assign({}, state, { tabs });
|
|
|
},
|
|
|
setSelectedTab(state, action) {
|
|
|
- const { tabs } = state;
|
|
|
- return Object.assign({}, state, { selectedTabKey: action.tabKey });
|
|
|
+ return Object.assign({}, state, { selectedTab: action.tab });
|
|
|
}
|
|
|
},
|
|
|
effects: {
|
|
|
@@ -59,21 +57,21 @@ export default {
|
|
|
const { tabs } = home;
|
|
|
const { tab } = action;
|
|
|
if(tabs.findIndex(t => t.code === tab.code) > -1) {
|
|
|
- yield put({ type: 'changeTab', tabKey: tab.code });
|
|
|
+ yield put({ type: 'changeTab', tab: tab });
|
|
|
}else {
|
|
|
yield put({ type: 'addTab', tab });
|
|
|
- yield put({ type: 'changeTab', tabKey: tab.code });
|
|
|
+ yield put({ type: 'changeTab', tab: tab });
|
|
|
}
|
|
|
},
|
|
|
*changeTab(action, { select, call, put }) {
|
|
|
const home = yield select(state => state.present.home);
|
|
|
- const { tabs, selectedTabKey } = home;
|
|
|
- const { tabKey } = action;
|
|
|
+ const { tabs } = home;
|
|
|
+ const { tab } = action;
|
|
|
let fields = [];
|
|
|
|
|
|
- yield put({ type: 'setSelectedTab', tabKey });
|
|
|
- let tab = tabs.find(t => t.code === tabKey);
|
|
|
- let data = { ...tab.config };
|
|
|
+ yield put({ type: 'setSelectedTab', tab });
|
|
|
+ let fTab = tabs.find(t => t.code === tab.code);
|
|
|
+ let data = { ...fTab.config };
|
|
|
for(let key in data) {
|
|
|
fields.push({
|
|
|
name: key,
|
|
|
@@ -85,24 +83,82 @@ export default {
|
|
|
},
|
|
|
*closeTab(action, { select, call, put }) {
|
|
|
const home = yield select(state => state.present.home);
|
|
|
- const { tabs, selectedTabKey } = home;
|
|
|
- const { tabKey } = action;
|
|
|
+ const { tabs } = home;
|
|
|
+ const { tab } = action;
|
|
|
|
|
|
- yield put({ type: 'removeTab', tabKey });
|
|
|
+ yield put({ type: 'removeTab', tab });
|
|
|
if(tabs.length > 0) {
|
|
|
- yield put({ type: 'changeTab', tabKey: tabs[tabs.length - 1].code });
|
|
|
+ yield put({ type: 'changeTab', tab: tabs[tabs.length - 1] });
|
|
|
}
|
|
|
},
|
|
|
*saveCurrentTabDashboardConfig(action, { select, call, put }) {
|
|
|
const { home, dashboardDesigner } = yield select(state => ({ home: state.present.home, dashboardDesigner: state.present.dashboardDesigner }));
|
|
|
const { tabs } = home;
|
|
|
- const { config, code } = action;
|
|
|
+ const { code } = action;
|
|
|
let idx = tabs.findIndex(t => t.code === code);
|
|
|
if(idx > -1) {
|
|
|
tabs[idx].config = { ...dashboardDesigner }
|
|
|
}
|
|
|
yield put({ type: 'setField', name: 'tabs', value: tabs });
|
|
|
- }
|
|
|
+ },
|
|
|
+ *fetchCollectionDashboardList(action, { select, call, put }) {
|
|
|
+ try {
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
+ url: URLS.DASHBOARD_COLLECTION_LIST,
|
|
|
+ method: 'GET'
|
|
|
+ });
|
|
|
+ if(!res.err && res.data.code > 0) {
|
|
|
+ const list = res.data.data.map(d => ({
|
|
|
+ code: d.id + '',
|
|
|
+ name: d.name
|
|
|
+ }));
|
|
|
+ yield put({ type: 'setField', name: 'collectionDashboards', value: list });
|
|
|
+ }else {
|
|
|
+ message.error('获取收藏列表失败: ' + (res.err || res.data.msg));
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ message.error('获取收藏列表失败: ' + e.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ *collect(action, { select, put, call }) {
|
|
|
+ try{
|
|
|
+ const home = yield select(state => state.present.home);
|
|
|
+ const { data } = action;
|
|
|
+ const { collectionDashboards } = home;
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
+ url: URLS.DASHBOARD_COLLECT_ADD,
|
|
|
+ body: {}
|
|
|
+ });
|
|
|
+ if(!res.err && res.data.code > 0) {
|
|
|
+ collectionDashboards.unshift({ code: data.code, name: data.name });
|
|
|
+ yield put({ type: 'setField', name: 'collectionDashboards', value: collectionDashboards });
|
|
|
+ }else {
|
|
|
+ message.error('添加收藏失败: ' + (res.err || res.data.msg));
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ message.error('添加收藏失败: ' + e.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ *uncollect(action, { select, put, call }) {
|
|
|
+ try{
|
|
|
+ const home = yield select(state => state.present.home);
|
|
|
+ const { data } = action;
|
|
|
+ const { collectionDashboards } = home;
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
+ url: URLS.DASHBOARD_COLLECT_REMOVE,
|
|
|
+ body: {}
|
|
|
+ });
|
|
|
+ if(!res.err && res.data.code > 0) {
|
|
|
+ let idx = collectionDashboards.findIndex(d => d.code === data.code);
|
|
|
+ collectionDashboards.splice(idx, 1);
|
|
|
+ yield put({ type: 'setField', name: 'collectionDashboards', value: collectionDashboards });
|
|
|
+ }else {
|
|
|
+ message.error('添加收藏失败: ' + (res.err || res.data.msg));
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ message.error('添加收藏失败: ' + e.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
subscriptions: {
|
|
|
setup({ dispatch, history }) {
|