Browse Source

数据源分组保存

zhuth 7 years ago
parent
commit
90b7641eb7
2 changed files with 20 additions and 3 deletions
  1. 19 3
      src/components/datasource/otherConfig.jsx
  2. 1 0
      src/models/dataSource.js

+ 19 - 3
src/components/datasource/otherConfig.jsx

@@ -12,6 +12,21 @@ const OtherConfig = ({ dataSource, dataConnect, dispatch, mode }) => {
         wrapperCol: { span: 20 },
     };
 
+    let getGroup = () => {
+        const { group } = dataSource.newOne;
+        const { groupList } = dataSource;
+        let g1 = groupList.filter(g => g.code+'' === group+'')[0];
+        if(!g1) {
+            return ['nogroup']
+        }
+        if(g1.pcode === '-1') {
+            return [g1.code]
+        }else {
+            let g2 = groupList.filter(g => g.code+'' === g1.pcode+'')[0];
+            return [g2.code, g1.code]
+        }
+    }
+
     return (
         <Form className='form-base' size='small'>
             <FormItem label='数据源名称' {...formItemLayout}>
@@ -22,12 +37,12 @@ const OtherConfig = ({ dataSource, dataConnect, dispatch, mode }) => {
             </FormItem>
             <FormItem label='所属分组' {...formItemLayout}>
                 <Cascader
-                    value={dataSource.newOne.group}
+                    value={getGroup()}
                     allowClear={true}
                     changeOnSelect={true}
                     expandTrigger='hover'
 					placeholder='未分组'
-					options={dataSource.groupList.filter(g => g.pcode === '-1').map((p, i)=>{
+					options={[{pcode: '-1', code: 'nogroup', label: '未分组'}].concat(dataSource.groupList).filter(g => g.pcode === '-1').map((p, i)=>{
 						return {
                             key: p.code,
 							value: p.code,
@@ -42,7 +57,8 @@ const OtherConfig = ({ dataSource, dataConnect, dispatch, mode }) => {
 						}
 					})}
 					onChange={(value, items) => {
-                        dispatch({ type: 'dataSource/setNewModelField', name: 'group', value: value });
+                        let v = value[1] !== undefined ? value[1] : value[0];
+                        dispatch({ type: 'dataSource/setNewModelField', name: 'group', value: v });
 					}}
 					
 				>

+ 1 - 0
src/models/dataSource.js

@@ -240,6 +240,7 @@ export default {
                     url: URLS.DATASOURCE_ADD,
                     body: data
                 });
+                console.log(data, res);
                 if(!res.err && res.data.code > 0) {
                     yield put({ type: 'fetchList', mandatory: true });
                     yield put({ type: 'main/redirect', path: { pathname: '/datasource' } });