|
|
@@ -1,4 +1,5 @@
|
|
|
import { routerRedux } from 'dva/router'
|
|
|
+import { message } from 'antd'
|
|
|
import * as service from '../services/index'
|
|
|
import { delay } from '../utils/baseUtils'
|
|
|
import URLS from '../constants/url'
|
|
|
@@ -6,6 +7,20 @@ import URLS from '../constants/url'
|
|
|
export default {
|
|
|
namespace: 'chartDesigner',
|
|
|
state: {
|
|
|
+ originData: {
|
|
|
+ code: null,
|
|
|
+ header: { label: '未命名' },
|
|
|
+ baseConfig: { dataSource: { key: '', label: '' }, viewType: { key: '', label: '' } },
|
|
|
+ preparing: { groupBy: [] },
|
|
|
+ aggregateTableConfig: {},
|
|
|
+ dataViewConfig: {},
|
|
|
+ barConfig: { xAxis: { column: {}, granularity: {} }, yAxis: { column: {}, gauge: {} } },
|
|
|
+ pieConfig: { series: [] },
|
|
|
+ style: {},
|
|
|
+ filters: [],
|
|
|
+ chartOption: {},
|
|
|
+ autoRefresh: true
|
|
|
+ },
|
|
|
columns: [{
|
|
|
label: '编号',
|
|
|
name: 'ID',
|
|
|
@@ -104,32 +119,246 @@ export default {
|
|
|
|
|
|
},
|
|
|
filters: [],
|
|
|
- chartOption: {}
|
|
|
+ chartOption: {},
|
|
|
+ autoRefresh: true
|
|
|
},
|
|
|
reducers: {
|
|
|
- setModel(state, action) {
|
|
|
+ /**
|
|
|
+ * 更新model字段值方法1
|
|
|
+ * 1. 为保持撤销重做的功能有效性,能够撤销重做的action动作才使用该通用方法,否则下方写成特殊方法
|
|
|
+ * 2. 对数据刷新没有影响的model字段改变一般用该action
|
|
|
+ */
|
|
|
+ setField(state, action) {
|
|
|
const { name, value } = action;
|
|
|
let obj = {};
|
|
|
obj[name] = value;
|
|
|
let newState = Object.assign({}, state, obj);
|
|
|
return newState;
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 批量更新model字段值方法1
|
|
|
+ */
|
|
|
+ setFields(state, action) {
|
|
|
+ const { fields } = action;
|
|
|
+ let obj = {};
|
|
|
+ fields.map(f => {
|
|
|
+ obj[f.name] = f.value;
|
|
|
+ });
|
|
|
+ let newState = Object.assign({}, state, obj);
|
|
|
+ return newState;
|
|
|
+ },
|
|
|
+ setDataSource(state, action) {
|
|
|
+ const { value } = action;
|
|
|
+ let obj = {};
|
|
|
+ obj['baseConfig'] = value;
|
|
|
+ return Object.assign({}, state, obj);
|
|
|
+ },
|
|
|
+ setColumns(state, action) {
|
|
|
+ const { value } = action;
|
|
|
+ let obj = {};
|
|
|
+ obj['columns'] = value;
|
|
|
+ return Object.assign({}, state, obj);
|
|
|
+ },
|
|
|
+ setAutoRefresh(state, action) {
|
|
|
+ const { value } = action;
|
|
|
+ let obj = {};
|
|
|
+ obj['autoRefresh'] = value;
|
|
|
+ return Object.assign({}, state, obj);
|
|
|
+ },
|
|
|
setChartOption(state, action) {
|
|
|
const { option } = action;
|
|
|
let obj = {};
|
|
|
obj['chartOption'] = option;
|
|
|
- let newState = Object.assign({}, state, obj);
|
|
|
- return newState;
|
|
|
+ return Object.assign({}, state, obj);
|
|
|
+ },
|
|
|
+ reset(state, action) {
|
|
|
+ let obj = Object.assign({}, state, state.originData);
|
|
|
+ console.log(obj);
|
|
|
+ return obj;
|
|
|
}
|
|
|
},
|
|
|
effects: {
|
|
|
- *changeModel(action, { select, call, put }) {
|
|
|
+ /**
|
|
|
+ * 更新model字段值方法2
|
|
|
+ * 可能影响到数据刷新的model字段改变一般用该action
|
|
|
+ */
|
|
|
+ *changeField(action, { select, call, put }) {
|
|
|
+ const { name, value } = action;
|
|
|
+ yield put({ type: 'setField', name, value });
|
|
|
+
|
|
|
+ const chartDesigner = yield select(state => state.present.chartDesigner);
|
|
|
+ const { autoRefresh } = chartDesigner;
|
|
|
+
|
|
|
+ if(autoRefresh) {
|
|
|
+ yield put({ type: 'fetchChartData' });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 批量更新model字段值方法2
|
|
|
+ */
|
|
|
+ *changeFields(action, { select, call, put }) {
|
|
|
+ const { fields } = action;
|
|
|
+ yield put({ type: 'setFields', fields });
|
|
|
+
|
|
|
+ const chartDesigner = yield select(state => state.present.chartDesigner);
|
|
|
+ const { autoRefresh } = chartDesigner;
|
|
|
+ if(autoRefresh) {
|
|
|
+ yield put({ type: 'fetchChartData' });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ *changeDataSource(action, { select, call, put }) {
|
|
|
+ const { value } = action;
|
|
|
+ yield put({ type: 'setDataSource', value });
|
|
|
+ yield put({ type: 'remoteDataColumn', code: value.dataSource.key });
|
|
|
+ },
|
|
|
+ *remoteAdd(action, { select, call, put }) {
|
|
|
+ try{
|
|
|
+ const chartDesigner = yield select(state => state.present.chartDesigner);
|
|
|
+ const { header, baseConfig, preparing, barConfig } = chartDesigner;
|
|
|
+ let body = {}; // 基本属性
|
|
|
+ if(baseConfig.viewType.key == 'bar') {
|
|
|
+ body = {
|
|
|
+ chartName: header.label,
|
|
|
+ chartType: 'Histogram',
|
|
|
+ dataId: baseConfig.dataSource.key,
|
|
|
+ groupBy: preparing.groupBy.map(g => {
|
|
|
+ return {
|
|
|
+ columnName: g.key,
|
|
|
+ columnRamane: g.label
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ chartConfig: {
|
|
|
+ xAxis: {
|
|
|
+ columnName: barConfig.xAxis.column.value,
|
|
|
+ columnRename: barConfig.xAxis.column.label,
|
|
|
+ columnType: barConfig.xAxis.column.type,
|
|
|
+ showDataType: barConfig.xAxis.granularity.value,
|
|
|
+ showDataLable: barConfig.xAxis.granularity.label
|
|
|
+ },
|
|
|
+ yAxis: {
|
|
|
+ columnName: barConfig.yAxis.column.value,
|
|
|
+ columnRename: barConfig.yAxis.column.label,
|
|
|
+ columnType: barConfig.yAxis.column.type,
|
|
|
+ showDataType: barConfig.yAxis.gauge.value,
|
|
|
+ showDataLable: barConfig.yAxis.gauge.label
|
|
|
+ }
|
|
|
+ },
|
|
|
+ isLegend: 1,
|
|
|
+ isTooltip: 1,
|
|
|
+ isTooltip: 1,
|
|
|
+ isToolbox: 1,
|
|
|
+ createBy: "zhuth",
|
|
|
+ describes: ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
+ url: URLS.CHART_ADD,
|
|
|
+ body: body
|
|
|
+ })
|
|
|
+ if(!res.err && res.data.code > 0) {
|
|
|
+ message.success('新增成功!');
|
|
|
+ yield put({ type: 'chart/fetchList' });
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ *remoteModify(action, { select, call, put }) {
|
|
|
+ try{
|
|
|
+ const chartDesigner = yield select(state => state.present.chartDesigner);
|
|
|
+ const { code, header, baseConfig, preparing, barConfig } = chartDesigner;
|
|
|
+ let body = {}; // 基本属性
|
|
|
+ if(baseConfig.viewType.key == 'bar') {
|
|
|
+ body = {
|
|
|
+ chartId: code,
|
|
|
+ chartName: header.label,
|
|
|
+ chartType: 'Histogram',
|
|
|
+ dataId: baseConfig.dataSource.key,
|
|
|
+ groupBy: preparing.groupBy.map(g => {
|
|
|
+ return {
|
|
|
+ columnName: g.key,
|
|
|
+ columnRamane: g.label
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ chartConfig: {
|
|
|
+ xAxis: {
|
|
|
+ columnName: barConfig.xAxis.column.value,
|
|
|
+ columnRename: barConfig.xAxis.column.label,
|
|
|
+ columnType: barConfig.xAxis.column.type,
|
|
|
+ showDataType: barConfig.xAxis.granularity.value,
|
|
|
+ showDataLable: barConfig.xAxis.granularity.label
|
|
|
+ },
|
|
|
+ yAxis: {
|
|
|
+ columnName: barConfig.yAxis.column.value,
|
|
|
+ columnRename: barConfig.yAxis.column.label,
|
|
|
+ columnType: barConfig.yAxis.column.type,
|
|
|
+ showDataType: barConfig.yAxis.gauge.value,
|
|
|
+ showDataLable: barConfig.yAxis.gauge.label
|
|
|
+ }
|
|
|
+ },
|
|
|
+ isLegend: 1,
|
|
|
+ isTooltip: 1,
|
|
|
+ isTooltip: 1,
|
|
|
+ isToolbox: 1,
|
|
|
+ createBy: "zhuth",
|
|
|
+ describes: ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(body);
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
+ url: URLS.CHART_UPDATE,
|
|
|
+ body: body
|
|
|
+ })
|
|
|
+ if(!res.err && res.data.code > 0) {
|
|
|
+ message.success('修改成功!');
|
|
|
+ yield put({ type: 'chart/fetchList' });
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ *remoteDataColumn(action, { select, call, put }) {
|
|
|
+ const code = action.code;
|
|
|
+ console.log(code);
|
|
|
+ try {
|
|
|
+ const res = yield call(service.fetch, {
|
|
|
+ url: URLS.DATASOURCE_DETAIL,
|
|
|
+ body: code
|
|
|
+ });
|
|
|
+ if(!res.err && res.data.code > 0) {
|
|
|
+ let resData = res.data.data;
|
|
|
+ let columnConfig = JSON.parse(resData.columnConfig);
|
|
|
+
|
|
|
+ let columns = columnConfig.map((c, i) => {
|
|
|
+ return {
|
|
|
+ key: i,
|
|
|
+ using: c.isOpen=='1'?true:false,
|
|
|
+ name: c.columnName,
|
|
|
+ label: c.columnLable,
|
|
|
+ dataType: c.dataType,
|
|
|
+ type: c.columnType,
|
|
|
+ selection: [],
|
|
|
+ groupable: c.isGroup=='1'?true:false,
|
|
|
+ bucketizable: c.isSubsection=='1'?true:false,
|
|
|
+ description: c.remarks
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log(columns);
|
|
|
+ yield put({ type: 'setColumns', value: columns });
|
|
|
+ }else {
|
|
|
+ console.log(res);
|
|
|
+ }
|
|
|
+ }catch(e) {
|
|
|
+ console.log(e);
|
|
|
+ yield put({ type: 'list', data: [] });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ *fetchChartData(action, { select, call, put }) {
|
|
|
const chartDesigner = yield select(state => state.present.chartDesigner);
|
|
|
const { baseConfig } = chartDesigner;
|
|
|
const { viewType } = baseConfig;
|
|
|
const viewTypeKey = viewType.key;
|
|
|
- const { name, value } = action;
|
|
|
- yield put({ type: 'setModel', name, value });
|
|
|
+
|
|
|
if(viewTypeKey == 'bar') {
|
|
|
yield put({ type: 'fetchBarData' });
|
|
|
}else if(viewTypeKey == 'pie') {
|
|
|
@@ -150,11 +379,11 @@ export default {
|
|
|
"xAxis": {
|
|
|
"columnRename": barConfig.xAxis.column.value,
|
|
|
"columnType": barConfig.xAxis.column.type,
|
|
|
- "dataType": barConfig.xAxis.granularity.value
|
|
|
+ "showDataType": barConfig.xAxis.granularity.value
|
|
|
},
|
|
|
"yAxis": {
|
|
|
"columnRename": barConfig.yAxis.column.value,
|
|
|
- "dataType": barConfig.yAxis.gauge.value
|
|
|
+ "showDataType": barConfig.yAxis.gauge.value
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -165,18 +394,17 @@ export default {
|
|
|
"xAxis": {
|
|
|
"columnRename": barConfig.xAxis.column.value,
|
|
|
"columnType": barConfig.xAxis.column.type,
|
|
|
- "dataType": barConfig.xAxis.granularity.value
|
|
|
+ "showDataType": barConfig.xAxis.granularity.value
|
|
|
},
|
|
|
"yAxis": {
|
|
|
"columnRename": barConfig.yAxis.column.value,
|
|
|
- "dataType": barConfig.yAxis.gauge.value
|
|
|
+ "showDataType": barConfig.yAxis.gauge.value
|
|
|
}
|
|
|
})
|
|
|
|
|
|
res.viewType = 'bar';
|
|
|
res.data.data.xTitle = barConfig.xAxis?`${barConfig.xAxis.column.label}${barConfig.xAxis.granularity.value?'('+barConfig.xAxis.granularity.label+')':''}`:null
|
|
|
- res.data.data.yTitle = barConfig.yAxis?barConfig.yAxis.column.label:null;
|
|
|
- res.data.data.gauge = barConfig.yAxis?barConfig.yAxis.gauge.label:null;
|
|
|
+ res.data.data.yTitle = barConfig.yAxis?`${barConfig.yAxis.column.label}${barConfig.yAxis.gauge.value?'('+barConfig.yAxis.gauge.label+')':''}`:null
|
|
|
yield put({ type: 'setChartOption', option: res });
|
|
|
|
|
|
}catch(e) {
|