|
|
@@ -1,6 +1,7 @@
|
|
|
import React from 'react'
|
|
|
import { Form, Input, Cascader } from 'antd'
|
|
|
import { connect } from 'dva'
|
|
|
+import { arrayToTree } from '../../utils/baseUtils'
|
|
|
const FormItem = Form.Item
|
|
|
|
|
|
const OtherConfig = ({ dataSourceDetail, dataSource, dataConnect, dispatch, mode }) => {
|
|
|
@@ -12,21 +13,46 @@ const OtherConfig = ({ dataSourceDetail, dataSource, dataConnect, dispatch, mode
|
|
|
wrapperCol: { span: 20 },
|
|
|
};
|
|
|
|
|
|
- let getGroup = () => {
|
|
|
- const { group } = dataSourceDetail;
|
|
|
- const { groupList } = dataSource;
|
|
|
- let g1 = groupList.filter(g => g.code+'' === group+'')[0];
|
|
|
- if(!g1) {
|
|
|
- return ['nogroup']
|
|
|
+ const getParens = (group) => {
|
|
|
+ const groupData = dataSource.groupList;
|
|
|
+ let pgroups = [group];
|
|
|
+ let fgroup = groupData.find(g => g.code === group.pcode);
|
|
|
+ if(fgroup) {
|
|
|
+ pgroups = getParens(fgroup).concat(pgroups);
|
|
|
}
|
|
|
- if(g1.pcode === '-1') {
|
|
|
- return [g1.code]
|
|
|
+ return pgroups;
|
|
|
+ }
|
|
|
+
|
|
|
+ const getGroup = () => {
|
|
|
+ const { group: key } = dataSourceDetail;
|
|
|
+ if(key === '-1') {
|
|
|
+ return ['-1'];
|
|
|
}else {
|
|
|
- let g2 = groupList.filter(g => g.code+'' === g1.pcode+'')[0];
|
|
|
- return [g2.code, g1.code]
|
|
|
+ let group = dataSource.groupList.find(g => g.code === key);
|
|
|
+ if(group) {
|
|
|
+ let groups = getParens(group);
|
|
|
+ let val = groups.map(g => g.code);
|
|
|
+ return val;
|
|
|
+ }else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ const generateGroupOptions = (treeData) => {
|
|
|
+ return treeData.map(t => {
|
|
|
+ t.children = t.children instanceof Array ? t.children : [];
|
|
|
+ return {
|
|
|
+ key: t.code,
|
|
|
+ value: t.code,
|
|
|
+ label: t.label,
|
|
|
+ children: generateGroupOptions(t.children)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const treeData = arrayToTree(dataSource.groupList, '-1', 'code', 'pcode', 'children');
|
|
|
+
|
|
|
return (
|
|
|
<Form className='form-base' size='small'>
|
|
|
<FormItem label='数据源名称' {...formItemLayout}>
|
|
|
@@ -42,22 +68,9 @@ const OtherConfig = ({ dataSourceDetail, dataSource, dataConnect, dispatch, mode
|
|
|
changeOnSelect={true}
|
|
|
expandTrigger='hover'
|
|
|
placeholder='未分组'
|
|
|
- options={[{pcode: '-1', code: 'nogroup', label: '未分组'}].concat(dataSource.groupList).filter(g => g.pcode === '-1').map((p, i)=>{
|
|
|
- return {
|
|
|
- key: p.code,
|
|
|
- value: p.code,
|
|
|
- label: p.label,
|
|
|
- children: dataSource.groupList.filter(g => g.pcode === p.code).map(c => {
|
|
|
- return {
|
|
|
- key: c.code,
|
|
|
- value: c.code,
|
|
|
- label: c.label
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })}
|
|
|
+ options={generateGroupOptions([{pcode: '-1', code: '-1', label: '未分组'}].concat(treeData))}
|
|
|
onChange={(value, items) => {
|
|
|
- let v = value[1] !== undefined ? value[1] : value[0];
|
|
|
+ let v = value[value.length - 1];
|
|
|
dispatch({ type: 'dataSourceDetail/setField', name: 'group', value: v });
|
|
|
}}
|
|
|
|