chartDesigner.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. import { message } from 'antd'
  2. import * as service from '../services/index'
  3. import URLS from '../constants/url'
  4. import parseChartOption from './parseChartOption'
  5. import moment from 'moment'
  6. function getBodyFilters(filters) {
  7. return filters.filter(f => f.using).map(f => {
  8. let { name, operator, type, value1, value2 } = f;
  9. let bodyFilter = {
  10. columnName: name,
  11. columnType: type,
  12. symbol: operator,
  13. value: value1
  14. };
  15. if(type === 'scale' && operator === 'between') {
  16. bodyFilter['value'] = value1 + ',' + value2;
  17. }else if(type === 'time') {
  18. let v1 = moment(value1).format('YYYY-MM-DD');
  19. let v2 = moment(value2).format('YYYY-MM-DD');
  20. if(operator === 'between') {
  21. bodyFilter['value'] = v1 + ',' + v2;
  22. }else {
  23. bodyFilter['value'] = v1;
  24. }
  25. }
  26. return bodyFilter;
  27. });
  28. }
  29. export default {
  30. namespace: 'chartDesigner',
  31. state: {
  32. originData: {
  33. code: null,
  34. creatorCode: null,
  35. creatorName: null,
  36. header: { label: '无标题' },
  37. baseConfig: { dataSource: { }, viewType: '' },
  38. aggregateTableConfig: { targetColumn: {}, statistics: [], groupBy: [] },
  39. dataViewConfig: { viewColumns: [], sortColumn: {key: ''}, sortType: 'asc', count: 25 },
  40. barConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} }, groupBy: {key:''} },
  41. lineConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} }, groupBy: {key:''} },
  42. pieConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} } },
  43. scatterConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} }, groupBy: {key:''} },
  44. styleConfig: { visibleIndex: true },
  45. filters: [],
  46. chartOption: {},
  47. dirty: false,
  48. fetchConfig: {}
  49. },
  50. columns: [],
  51. allPermission: [
  52. { value: 'owner', name: '创建人' },
  53. { value: 'anyone', name: '所有人' }
  54. ],
  55. header: { label: '无标题' },
  56. baseConfig: {
  57. dataSource: {},
  58. viewType: ''
  59. },
  60. aggregateTableConfig: { targetColumn: {}, statistics: [], groupBy: [] },
  61. dataViewConfig: { viewColumns: [], sortColumn: {key: ''}, sortType: 'asc', count: 25 },
  62. barConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} }, groupBy: {key:''} },
  63. lineConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} }, groupBy: {key:''} },
  64. pieConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} } },
  65. scatterConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} }, groupBy: {key:''} },
  66. styleConfig: { visibleIndex: true },
  67. otherConfig:{ },
  68. description: '',
  69. filters: [],
  70. chartOption: {},
  71. dirty: false,
  72. fetchConfig: {}
  73. },
  74. reducers: {
  75. /**
  76. * 更新model字段值
  77. * 1. 进入撤销重做历史
  78. */
  79. setField(state, action) {
  80. const { name, value } = action;
  81. let obj = {};
  82. obj[name] = value;
  83. let newState = Object.assign({}, state, obj);
  84. return Object.assign({}, newState, {dirty: true});
  85. },
  86. /**
  87. * 批量更新model字段值
  88. * 1. 进入撤销重做历史
  89. */
  90. setFields(state, action) {
  91. const { fields } = action;
  92. let obj = {};
  93. fields.map(f => (obj[f.name] = f.value));
  94. let newState = Object.assign({}, state, obj);
  95. return Object.assign({}, newState, {dirty: true});
  96. },
  97. /**
  98. * 更新model字段值
  99. * 1. 不进入撤销重做历史
  100. */
  101. silentSetField(state, action) {
  102. const { name, value } = action;
  103. let obj = {};
  104. obj[name] = value;
  105. let newState = Object.assign({}, state, obj);
  106. return newState;
  107. },
  108. /**
  109. * 批量更新model字段值
  110. * 1. 不进入撤销重做历史
  111. */
  112. silentSetFields(state, action) {
  113. const { fields } = action;
  114. let obj = {};
  115. fields.map(f => (obj[f.name] = f.value));
  116. let newState = Object.assign({}, state, obj);
  117. return newState;
  118. },
  119. reset(state, action) {
  120. let newState = Object.assign({}, state, state.originData);
  121. return Object.assign({}, newState);
  122. },
  123. setDirty(state, action) {
  124. const { dirty } = action;
  125. let newState = Object.assign({}, state, { dirty });
  126. console.log(newState);
  127. return newState;
  128. }
  129. },
  130. effects: {
  131. /**
  132. * 初始化批量更新model字段值
  133. * 触发数据刷新、不进入撤销重做历史
  134. */
  135. *defaultChangeFields(action, { select, call, put }) {
  136. const { fields } = action;
  137. yield put({ type: 'silentSetFields', fields });
  138. const { autoRefresh } = action;
  139. if(autoRefresh === undefined ? true : autoRefresh) {
  140. yield put({ type: 'fetchChartData' });
  141. }
  142. },
  143. /**
  144. * 更新model字段值
  145. * 可能影响到数据刷新的model字段改变一般用该action
  146. */
  147. *changeField(action, { select, call, put }) {
  148. const { name, value } = action;
  149. yield put({ type: 'setField', name, value });
  150. const { autoRefresh } = action;
  151. if(autoRefresh === undefined ? true : autoRefresh) {
  152. yield put({ type: 'fetchChartData' });
  153. }
  154. },
  155. /**
  156. * 批量更新model字段值
  157. */
  158. *changeFields(action, { select, call, put }) {
  159. const { fields } = action;
  160. yield put({ type: 'setFields', fields });
  161. const { autoRefresh } = action;
  162. if(autoRefresh === undefined ? true : autoRefresh) {
  163. yield put({ type: 'fetchChartData' });
  164. }
  165. },
  166. *changeDataSource(action, { select, call, put }) {
  167. const { code } = action;
  168. yield put({ type: 'remoteDataColumn', code });
  169. },
  170. *remoteQucikAdd(action, { select, call, put }) {
  171. try{
  172. const { dataSource } = action;
  173. yield put({ type: 'silentSetFields', fields: [
  174. { name: 'baseConfig', value: { dataSource: dataSource.code, viewType: '' } }
  175. ] });
  176. const chartDesigner = yield select(state => state.present.chartDesigner);
  177. const { baseConfig, styleConfig } = chartDesigner;
  178. let body = {
  179. chartName: dataSource.name + '_未命名',
  180. dataId: baseConfig.dataSource,
  181. groupBy: baseConfig.groupBy && baseConfig.groupBy.key ? [{
  182. columnName: baseConfig.groupBy.key,
  183. columnRamane: baseConfig.groupBy.label
  184. }] : [],
  185. describes: '',
  186. style: JSON.stringify(styleConfig),
  187. chartConfig: '{}',
  188. chartType: '',
  189. };
  190. console.log('快速新增图表', body);
  191. const res = yield call(service.fetch, {
  192. url: URLS.CHART_ADD,
  193. body: body
  194. })
  195. console.log('快速新增图表', body, res);
  196. if(!res.err && res.data.data > 0) {
  197. yield put({ type: 'chart/fetchList', mandatory: true });
  198. yield put({ type: 'main/redirect', path: '/chart/' + res.data.data });
  199. // yield put({ type: 'chart/remoteDetail', code: res.data.data });
  200. }else {
  201. message.error('新增失败: ' + (res.err || res.data.msg));
  202. }
  203. }catch(e) {
  204. console.error(e);
  205. message.error('新增失败');
  206. }
  207. },
  208. /**
  209. * 复制新增
  210. */
  211. *remoteCopyAdd(action, { select, call, put }) {
  212. try{
  213. yield put({ type: 'chart/remoteModify' });
  214. const { newHeaderLabel } = action;
  215. const chartDesigner = yield select(state => state.present.chartDesigner);
  216. const { baseConfig, pieConfig, lineConfig, barConfig, scatterConfig, aggregateTableConfig,
  217. dataViewConfig, otherConfig, description, group, styleConfig } = chartDesigner;
  218. let body = {
  219. chartName: newHeaderLabel,
  220. dataId: baseConfig.dataSource,
  221. describes: description || '',
  222. style: JSON.stringify(styleConfig),
  223. otherConfig: JSON.stringify(otherConfig),
  224. chartsGroup: group ? group : '-1',
  225. }; // 基本属性
  226. if(baseConfig.viewType === 'bar') {
  227. body.chartType = 'Histogram';
  228. body.chartConfig = JSON.stringify(barConfig);
  229. body.groupBy = barConfig.groupBy ? [{
  230. columnName: barConfig.groupBy.key,
  231. columnRamane: barConfig.groupBy.label
  232. }] : [];
  233. }else if(baseConfig.viewType === 'pie') {
  234. body.chartType = 'Pie';
  235. body.chartConfig = JSON.stringify(pieConfig);
  236. }else if(baseConfig.viewType === 'line') {
  237. body.chartType = 'Line';
  238. body.chartConfig = JSON.stringify(lineConfig);
  239. body.groupBy = lineConfig.groupBy ? [{
  240. columnName: lineConfig.groupBy.key,
  241. columnRamane: lineConfig.groupBy.label
  242. }] : [];
  243. }else if(baseConfig.viewType === 'scatter') {
  244. body.chartType = 'scatter';
  245. body.chartConfig = JSON.stringify(scatterConfig);
  246. body.groupBy = scatterConfig.groupBy ? [{
  247. columnName: scatterConfig.groupBy.key,
  248. columnRamane: scatterConfig.groupBy.label
  249. }] : [];
  250. }else if(baseConfig.viewType === 'aggregateTable') {
  251. body.chartType = 'population';
  252. body.chartConfig = JSON.stringify(aggregateTableConfig);
  253. body.groupBy = aggregateTableConfig.groupBy && aggregateTableConfig.groupBy.length > 0 ? aggregateTableConfig.groupBy.map(g => {
  254. return {
  255. columnName: g.key,
  256. columnRamane: g.label
  257. }
  258. }) : [];
  259. }else if(baseConfig.viewType === 'dataView') {
  260. body.chartType = 'individual';
  261. body.chartConfig = JSON.stringify(dataViewConfig);;
  262. }else {
  263. body.chartType = '';
  264. body.chartConfig = JSON.stringify({});
  265. }
  266. const res = yield call(service.fetch, {
  267. url: URLS.CHART_ADD,
  268. body: body
  269. })
  270. console.log('复制新增', body, res);
  271. if(!res.err && res.data.code > 0) {
  272. yield put({ type: 'chart/fetchList', mandatory: true });
  273. yield put({ type: 'main/redirect', path: '/chart/' + res.data.data , reload: true});
  274. }else {
  275. message.error('创建副本失败: ' + (res.err || res.data.msg));
  276. }
  277. }catch(e) {
  278. console.error(e);
  279. message.error('创建副本失败');
  280. }
  281. },
  282. *remoteDataColumn(action, { select, call, put }) {
  283. const code = action.code;
  284. try {
  285. const res = yield call(service.fetch, {
  286. url: URLS.DATASOURCE_QUERY_DATACOLUMNS,
  287. body: code
  288. });
  289. console.log('获得图表关联数据源列数据', code, res);
  290. if(!res.err && res.data.code > 0) {
  291. let resData = res.data.data;
  292. let columns = resData.map((c, i) => {
  293. return {
  294. key: i,
  295. name: c.columnName,
  296. label: c.columnRaname,
  297. type: c.columnType,
  298. groupable: c.isGroup==='1'?true:false,
  299. filterable: c.isFilter==='1'?true:false,
  300. bucketizable: c.isSubsection==='1'?true:false,
  301. selection: []
  302. }
  303. })
  304. yield put({ type: 'silentSetField', name: 'columns', value: columns });
  305. }else {
  306. message.error('请求列数据失败:' + (res.err || res.data.msg));
  307. yield put({ type: 'silentSetField', name: 'columns', value: [] });
  308. }
  309. }catch(e) {
  310. message.error('请求列数据失败');
  311. yield put({ type: 'silentSetField', name: 'columns', value: [] });
  312. }
  313. },
  314. *fetchChartData(action, { select, call, put }) {
  315. const chartDesigner = yield select(state => state.present.chartDesigner);
  316. const { baseConfig } = chartDesigner;
  317. const { viewType } = baseConfig;
  318. yield put({ type: 'silentSetField', name: 'fetchConfig', value: {} });
  319. if(viewType === 'bar') {
  320. const { barConfig } = chartDesigner;
  321. if(barConfig.xAxis.column.value && barConfig.yAxis.column.value) {
  322. yield put({ type: 'fetchBarData' });
  323. }else {
  324. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  325. }
  326. }else if(viewType === 'pie') {
  327. const { pieConfig } = chartDesigner;
  328. if(pieConfig.xAxis.column.value && pieConfig.yAxis.column.value) {
  329. yield put({ type: 'fetchPieData' });
  330. }else {
  331. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  332. }
  333. }else if(viewType === 'line') {
  334. const { lineConfig } = chartDesigner;
  335. if(lineConfig.xAxis.column.value && lineConfig.yAxis.column.value) {
  336. yield put({ type: 'fetchLineData' });
  337. }else {
  338. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  339. }
  340. }else if(viewType === 'scatter') {
  341. const { scatterConfig } = chartDesigner;
  342. if(scatterConfig.xAxis.column.value && scatterConfig.yAxis.column.value) {
  343. yield put({ type: 'fetchScatterData' });
  344. }else {
  345. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  346. }
  347. }else if(viewType === 'dataView') {
  348. const { dataViewConfig } = chartDesigner;
  349. if(dataViewConfig.viewColumns.length > 0 &&
  350. dataViewConfig.sortColumn.key &&
  351. dataViewConfig.sortType &&
  352. dataViewConfig.count) {
  353. yield put({ type: 'fetchDataViewData' });
  354. }else {
  355. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  356. }
  357. }else if(viewType === 'aggregateTable') {
  358. const { aggregateTableConfig } = chartDesigner;
  359. if(aggregateTableConfig.targetColumn.name && aggregateTableConfig.statistics.length > 0) {
  360. yield put({ type: 'fetchAggregateTableData' });
  361. }else {
  362. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  363. }
  364. }else {
  365. console.log('no viewType......')
  366. }
  367. },
  368. *fetchBarData(action, { select, call, put }) {
  369. try {
  370. const chartDesigner = yield select(state => state.present.chartDesigner);
  371. const { code, barConfig, filters } = chartDesigner;
  372. const body = {
  373. id: code,
  374. groups: barConfig.groupBy && barConfig.groupBy.key ? [barConfig.groupBy.key] : [],
  375. xAxis: {
  376. columnRename: barConfig.xAxis.column.value,
  377. columnType: barConfig.xAxis.column.type,
  378. showDataType: barConfig.xAxis.granularity.value
  379. },
  380. yAxis: {
  381. columnRename: barConfig.yAxis.column.value,
  382. showDataType: barConfig.yAxis.gauge.value
  383. },
  384. filters: getBodyFilters(filters)
  385. };
  386. let res = yield call(service.fetch, {
  387. url: URLS.CHART_BAR_OPTION,
  388. body: body
  389. });
  390. console.log('请求柱状图数据', body, res);
  391. if(!res.err && res.data.code > 0) {
  392. let option = parseChartOption('bar', res.data.data, barConfig);
  393. yield put({ type: 'silentSetField', name: 'chartOption', value: option });
  394. }else {
  395. message.error('请求柱状图数据失败: ' + (res.err || res.data.msg));
  396. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  397. }
  398. yield put({ type: 'silentSetField', name: 'fetchConfig', value: body });
  399. }catch(e) {
  400. console.error(e);
  401. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  402. message.error('请求柱状图数据失败');
  403. }
  404. },
  405. *fetchPieData(action, { select, call, put }) {
  406. try {
  407. const chartDesigner = yield select(state => state.present.chartDesigner);
  408. const { code, pieConfig, filters } = chartDesigner;
  409. const body = {
  410. id: code,
  411. legendData: {
  412. columnRename: pieConfig.xAxis.column.value,
  413. columnType: pieConfig.xAxis.column.type,
  414. showDataType: pieConfig.xAxis.granularity.value
  415. },
  416. series: {
  417. columnRename: pieConfig.yAxis.column.value,
  418. columnName: pieConfig.yAxis.column.label,
  419. showDataType: pieConfig.yAxis.gauge.value
  420. },
  421. filters: getBodyFilters(filters)
  422. };
  423. let res = yield call(service.fetch, {
  424. url: URLS.CHART_PIE_OPTION,
  425. body: body
  426. });
  427. console.log('请求饼图数据', body, res);
  428. if(!res.err && res.data.code > 0) {
  429. let option = parseChartOption('pie', res.data.data, pieConfig);
  430. yield put({ type: 'silentSetField', name: 'chartOption', value: option });
  431. }else {
  432. message.error('请求饼图数据失败: ' + (res.err || res.data.msg));
  433. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  434. }
  435. yield put({ type: 'silentSetField', name: 'fetchConfig', value: body });
  436. }catch(e) {
  437. console.error(e);
  438. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  439. message.error('请求饼图数据失败');
  440. }
  441. },
  442. *fetchLineData(action, { select, call, put }) {
  443. try {
  444. const chartDesigner = yield select(state => state.present.chartDesigner);
  445. const { code, lineConfig, filters } = chartDesigner;
  446. const body = {
  447. id: code,
  448. xAxis: {
  449. columnRename: lineConfig.xAxis.column.value,
  450. columnType: lineConfig.xAxis.column.type
  451. },
  452. yAxis: {
  453. columnRename: lineConfig.yAxis.column.value,
  454. showDataType: lineConfig.yAxis.gauge.value
  455. },
  456. groups: lineConfig.groupBy && lineConfig.groupBy.key ? [lineConfig.groupBy.key] : [],
  457. filters: getBodyFilters(filters)
  458. };
  459. let res = yield call(service.fetch, {
  460. url: URLS.CHART_LINE_OPTION,
  461. body: body
  462. });
  463. console.log('请求折线图数据', body, res);
  464. if(!res.err && res.data.code > 0) {
  465. let option = parseChartOption('line', res.data.data, lineConfig);
  466. yield put({ type: 'silentSetField', name: 'chartOption', value: option });
  467. }else {
  468. message.error('请求折线图数据失败: ' + (res.err || res.data.msg));
  469. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  470. }
  471. yield put({ type: 'silentSetField', name: 'fetchConfig', value: body });
  472. }catch(e) {
  473. console.error(e);
  474. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  475. message.error('请求折线图数据失败');
  476. }
  477. },
  478. *fetchScatterData(action, { select, call, put }) {
  479. try {
  480. const chartDesigner = yield select(state => state.present.chartDesigner);
  481. const { code, scatterConfig, filters } = chartDesigner;
  482. const body = {
  483. id: code,
  484. xAxis: {
  485. columnRename: scatterConfig.xAxis.column.value,
  486. columnType: scatterConfig.xAxis.column.type
  487. },
  488. yAxis: {
  489. columnRename: scatterConfig.yAxis.column.value,
  490. showDataType: scatterConfig.yAxis.gauge.value
  491. },
  492. groups: scatterConfig.groupBy && scatterConfig.groupBy.key ? [scatterConfig.groupBy.key] : [],
  493. filters: getBodyFilters(filters)
  494. };
  495. let res = yield call(service.fetch, {
  496. url: URLS.CHART_SCATTER_OPTION,
  497. body: body
  498. });
  499. console.log('请求散点图数据', body, res);
  500. if(!res.err && res.data.code > 0) {
  501. let option = parseChartOption('scatter', res.data.data, scatterConfig);
  502. yield put({ type: 'silentSetField', name: 'chartOption', value: option });
  503. }else {
  504. message.error('请求散点图数据失败: ' + (res.err || res.data.msg));
  505. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  506. }
  507. yield put({ type: 'silentSetField', name: 'fetchConfig', value: body });
  508. }catch(e) {
  509. console.error(e);
  510. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  511. message.error('请求散点图数据失败');
  512. }
  513. },
  514. *fetchDataViewData(action, { select, call, put }) {
  515. try {
  516. const chartDesigner = yield select(state => state.present.chartDesigner);
  517. const { code, dataViewConfig, filters } = chartDesigner;
  518. const body = {
  519. id: code,
  520. columnListName: dataViewConfig.viewColumns.map(c => c.name),
  521. sortColumn: dataViewConfig.sortColumn.key,
  522. sort: dataViewConfig.sortType,
  523. showLine: dataViewConfig.count,
  524. filters: getBodyFilters(filters)
  525. };
  526. let res = yield call(service.fetch, {
  527. url: URLS.CHART_DATAVIEW_OPTION,
  528. body: body
  529. });
  530. console.log('请求表格数据', body, res);
  531. if(!res.err && res.data.code > 0) {
  532. let option = parseChartOption('dataView', res.data.data, dataViewConfig);
  533. yield put({ type: 'silentSetField', name: 'chartOption', value: option });
  534. }else {
  535. message.error('请求列表数据失败: ' + (res.err || res.data.msg));
  536. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  537. }
  538. yield put({ type: 'silentSetField', name: 'fetchConfig', value: body });
  539. }catch(e) {
  540. console.error(e);
  541. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  542. message.error('请求列表数据失败');
  543. }
  544. },
  545. *fetchAggregateTableData(action, { select, call, put }) {
  546. try {
  547. const chartDesigner = yield select(state => state.present.chartDesigner);
  548. const { code, aggregateTableConfig, filters } = chartDesigner;
  549. const { targetColumn, statistics } = aggregateTableConfig;
  550. const body = {
  551. id: code,
  552. columnName: targetColumn.name,
  553. operatorList: statistics,
  554. groupByList: aggregateTableConfig.groupBy && aggregateTableConfig.groupBy.length > 0 ? aggregateTableConfig.groupBy.map(g => g.key) : [],
  555. filters: getBodyFilters(filters)
  556. };
  557. let res = yield call(service.fetch, {
  558. url: URLS.CHART_AGGREGATETABLE_OPTION,
  559. body: body
  560. });
  561. console.log('获得总体统计数据', body, res);
  562. if(!res.err && res.data.code > 0) {
  563. let option = parseChartOption('aggregateTable', res.data.data, aggregateTableConfig);
  564. yield put({ type: 'silentSetField', name: 'chartOption', value: option });
  565. }else {
  566. message.error('请求统计数据失败: ' + (res.err || res.data.msg));
  567. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  568. }
  569. yield put({ type: 'silentSetField', name: 'fetchConfig', value: body });
  570. }catch(e) {
  571. console.error(e);
  572. yield put({ type: 'silentSetField', name: 'chartOption', value: {} });
  573. message.error('请求统计数据失败');
  574. }
  575. }
  576. },
  577. subscriptions: {
  578. setup({ dispatch, history }) {
  579. return history.listen(({ pathname, query }) => {
  580. });
  581. },
  582. },
  583. };