zhuth 6 years ago
parent
commit
280d0cd43b

+ 1 - 1
src/components/dataConnect/list.jsx

@@ -253,7 +253,7 @@ class DataConnect extends React.Component {
                                     </Button>
                                     <Button onClick={() => {
                                         // 设置新增默认值
-                                        dispatch({ type: 'dataConnect/setNewModel', model: { dbType: 'oracle', dbName: 'orcl' } });
+                                        dispatch({ type: 'dataConnect/setNewModel', model: { dbType: 'oracle', dbName: 'orcl', port: 1521 } });
                                         dispatch({ type: 'dataConnect/setNewModelFields', fields: [
                                             { name: 'visibleBox', value: true },
                                             { name: 'boxOperation', value: 'create' }

+ 63 - 21
src/components/dataSourceDetail/dataConnectBox.jsx

@@ -11,7 +11,17 @@ class DataConnectBox extends React.Component {
         super(props);
         this.state = {
             password: '',
-            passwordEditing: false
+            passwordEditing: false,
+            validInfo: {
+                name: { status: 'success', help: '' },
+                dbType: { status: 'success', help: '' },
+                address: { status: 'success', help: '' },
+                port: { status: 'success', help: '' },
+                dbName: { status: 'success', help: '' },
+                userName: { status: 'success', help: '' },
+                password: { status: 'success', help: '' },
+                description: { status: 'success', help: '' },
+            }
         }
     }
 
@@ -36,15 +46,23 @@ class DataConnectBox extends React.Component {
 
     checkValid() {
         const { dataConnect } = this.props;
+        const { validInfo } = this.state;
         const { newOne } = dataConnect;
+        let flag = true;
 
-        return !!newOne && !!newOne.name && !!newOne.dbType && !!newOne.address && !!newOne.port &&
-            !!newOne.dbName && !!newOne.userName && (newOne.boxOperation === 'create' ? !!newOne.password : true);
+        for(let k in validInfo) {
+            if(validInfo[k].status === 'error') {
+                flag = false;
+            }
+        }
+
+        return flag && !!newOne && !!newOne.name && newOne.name.length <= 50 && !!newOne.dbType && !!newOne.address && !!newOne.port &&
+            !!newOne.dbName && !!newOne.userName && newOne.description.length <= 500 && (newOne.boxOperation === 'create' ? !!newOne.password : true);
     }
 
     render() {
         const { dispatch, dataConnect } = this.props;
-        const { password, passwordEditing } = this.state;
+        const { password, passwordEditing, validInfo } = this.state;
         const operation = dataConnect.newOne.boxOperation;
         const disabled = operation === 'view';
 
@@ -92,14 +110,23 @@ class DataConnectBox extends React.Component {
                         className='required'
                         label='链接名'
                         {...formItemLayout}
-                        validateStatus={(dataConnect.newOne.name === undefined || dataConnect.newOne.name) ? 'success' : 'error'}
-                        help={dataConnect.newOne.name === undefined || dataConnect.newOne.name ? '' : '链接名不能为空'}
+                        validateStatus={validInfo.name.status}
+                        help={validInfo.name.help}
                     >
                         <Input
                             disabled={disabled}
                             placeholder="输入数据链接名称"
-                            value={dataConnect.newOne.name}
-                            onChange={(e) => { dispatch({ type: 'dataConnect/setNewModelField', name: 'name', value: e.target.value }) }}
+                            defaultValue={dataConnect.newOne.name}
+                            onChange={e => {
+                                let val = e.target.value;
+                                window.clearTimeout(this.nameTimeout);
+                                this.nameTimeout = window.setTimeout(() => {
+                                    this.setState({
+                                        validInfo: { ...validInfo, name: { status: (!val || (val+'').trim().length > 50 || (val+'').trim().length === 0) ? 'error' : 'success', help: (val+'').trim().length > 50 ? '链接名不能超过50个字符' : ((val+'').trim().length === 0 ? '链接名不能为空' : '') } }
+                                    });
+                                }, 100);
+                            }}
+                            onBlur={(e) => { dispatch({ type: 'dataConnect/setNewModelField', name: 'name', value: e.target.value }) }}
                         >
                         </Input>
                     </FormItem>
@@ -142,8 +169,8 @@ class DataConnectBox extends React.Component {
                                 <Input
                                     disabled={disabled}
                                     placeholder="格式:192.168.1.1"
-                                    value={dataConnect.newOne.address}
-                                    onChange={(e) => {
+                                    defaultValue={dataConnect.newOne.address}
+                                    onBlur={(e) => {
                                         dispatch({ type: 'dataConnect/setNewModelField', name: 'address', value: e.target.value });
                                     }}
                                 />
@@ -159,9 +186,9 @@ class DataConnectBox extends React.Component {
                             >
                                 <InputNumber
                                     disabled={disabled}
-                                    defaultValue={1521}
-                                    value={dataConnect.newOne.port}
-                                    onChange={(value) => {
+                                    defaultValue={dataConnect.newOne.port ? Number(dataConnect.newOne.port) : 1521}
+                                    // value={dataConnect.newOne.port}
+                                    onBlur={(value) => {
                                         dispatch({ type: 'dataConnect/setNewModelField', name: 'port', value: value });
                                     }}
                                 />
@@ -174,9 +201,9 @@ class DataConnectBox extends React.Component {
                     >
                         <Input
                             disabled={disabled}
-                            defaultValue='orcl'
-                            value={dataConnect.newOne.dbName}
-                            onChange={(e) => {
+                            // defaultValue='orcl'
+                            defaultValue={dataConnect.newOne.dbName || 'orcl'}
+                            onBlur={(e) => {
                                 dispatch({ type: 'dataConnect/setNewModelField', name: 'dbName', value: e.target.value });
                             }}
                         />
@@ -192,8 +219,8 @@ class DataConnectBox extends React.Component {
                             >
                                 <Input
                                     disabled={disabled}
-                                    value={dataConnect.newOne.userName}
-                                    onChange={(e) => {
+                                    defaultValue={dataConnect.newOne.userName}
+                                    onBlur={(e) => {
                                         dispatch({ type: 'dataConnect/setNewModelField', name: 'userName', value: e.target.value });
                                     }}
                                 />
@@ -246,12 +273,27 @@ class DataConnectBox extends React.Component {
                             </FormItem>
                         </Col>
                     </Row>
-                    <FormItem className='textarea-desc' label='说明' {...formItemLayout}>
+                    <FormItem
+                        className='textarea-desc'
+                        label='说明'
+                        {...formItemLayout}
+                        validateStatus={validInfo.description.status}
+                        help={validInfo.description.help}
+                    >
                         <Input.TextArea
                             disabled={disabled}
                             autosize={{ minRows: 2 }}
-                            value={dataConnect.newOne.description}
-                            onChange={(e) => {
+                            defaultValue={dataConnect.newOne.description}
+                            onChange={e => {
+                                let val = e.target.value;
+                                window.clearTimeout(this.nameTimeout);
+                                this.nameTimeout = window.setTimeout(() => {
+                                    this.setState({
+                                        validInfo: { ...validInfo, description: { status: (!!val && (val+'').trim().length > 500) ? 'error' : 'success', help: (!!val && (val+'').trim().length > 500) ? '说明不能超过500个字符' : '' } }
+                                    });
+                                }, 100);
+                            }}
+                            onBlur={(e) => {
                                 dispatch({ type: 'dataConnect/setNewModelField', name: 'description', value: e.target.value });
                             }}
                         />

+ 38 - 3
src/components/homePage/index.jsx

@@ -1,5 +1,5 @@
 import React from 'react'
-import { Layout, Tabs } from 'antd'
+import { Layout, Tabs, Dropdown, Menu } from 'antd'
 import { connect } from 'dva'
 import MenuLayout from './sider'
 import DashboardViewToolbar from './toolbar'
@@ -16,6 +16,8 @@ class Home extends React.Component {
         const { tabs } = home;
 
         return tabs.map(t => (
+            // TODO 右键关闭菜单,会报错,先不启用
+            // <TabPane tab={this.generateTabTitle(t.name, t.code)} key={t.code}>
             <TabPane tab={t.name} key={t.code}>
                 <DashboardViewToolbar />
                 <DashboardView code={t.code} config={t.config}/>
@@ -23,6 +25,26 @@ class Home extends React.Component {
         ));
     }
 
+    generateTabTitle = (text, tabKey) => (
+        <Dropdown overlay={this.generateMenu(tabKey)} trigger={["contextMenu"]}>
+            <span style={{ userSelect: "none" }}>{text}</span>
+        </Dropdown>
+    )
+
+    generateMenu = (tabKey) => (
+        <Menu>
+            <Menu.Item key="1" onClick={() => {
+                this.remove(tabKey);
+            }}>关闭</Menu.Item>
+            <Menu.Item key="2"onClick={() => {
+                this.removeOther(tabKey);
+            }}>关闭其他</Menu.Item>
+            <Menu.Item key="3" onClick={() => {
+                this.removeAll();
+            }}>关闭所有</Menu.Item>
+        </Menu>
+    )
+
     onChange = (activeKey) => {
         const { dispatch, home } = this.props;
         const { selectedTab, tabs } = home;
@@ -37,11 +59,24 @@ class Home extends React.Component {
 
     remove = (targetKey) => {
         const { dispatch, home } =  this.props;
-        const { tabs } = home;
-        let tab = tabs.find(t => t.code === targetKey);
+        const { tabs: allTabs } = home;
+        let tab = allTabs.find(t => t.code === targetKey);
         dispatch({ type: 'home/closeTab', tab });
     }
 
+    removeOther = (targetKey) => {
+        const { dispatch, home } =  this.props;
+        const { tabs: allTabs } = home;
+        let tabs = allTabs.filter(t => t.code !== targetKey);
+        let tab = allTabs.find(t => t.code === targetKey);
+        dispatch({ type: 'home/closeTabs', tabs, tab });
+    }
+
+    removeAll = () => {
+        const { dispatch } =  this.props;
+        dispatch({ type: 'home/closeAllTabs' });
+    }
+
     render() {
         const { home } = this.props;
         const { tabs, selectedTab } = home;

+ 1 - 1
src/constants/url.js

@@ -1,4 +1,4 @@
-// const BASE_URL = 'http://10.1.1.168:8094/BI/';
+// const BASE_URL = 'http://10.1.1.168:8081/BI/';
 // const BASE_URL = 'http://10.1.80.78:8011/';
 // const BASE_URL = 'http://218.18.115.198:8888/BI/'
 const BASE_URL = ''

+ 1 - 1
src/models/chart.js

@@ -14,7 +14,7 @@ export default {
             currentGroup: null,
             filterItems: [ // 可选过滤字段
                 { name: 'name', label: '图表名称', type: 'string' },
-                { name: 'description', label: '说明', type: 'string' },
+                { name: 'description', label: '备注', type: 'string' },
                 { name: 'creatorName', label: '创建人', type: 'string' },
                 { name: 'createTime', label: '创建时间', type: 'date' },
                 { name: 'dataSourceCode', label: '数据源', type: 'enum', options: () => {

+ 42 - 12
src/models/home.js

@@ -47,6 +47,18 @@ export default {
             tabs.splice(idx, 1);
             return Object.assign({}, state, { tabs });
         },
+        removeTabs(state, action) {
+            const { tabs: allTabs } = state;
+            const { tabs } = action;
+            for(let i = 0; i < tabs.length; i++) {
+                let idx = allTabs.findIndex(t => t.code === tabs[i].code);
+                allTabs.splice(idx, 1);
+            }
+            return Object.assign({}, state, { tabs: allTabs });
+        },
+        removeAllTabs(state, action) {
+            return Object.assign({}, state, { tabs: [] });
+        },
         setSelectedTab(state, action) {
             return Object.assign({}, state, { selectedTab: action.tab });
         }
@@ -71,26 +83,44 @@ export default {
 
             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,
-                    value: data[key]
-                })
+            console.log(fTab);
+            if(!fTab) {
+                return false;
+            }else {
+                let data = { ...fTab.config };
+                for(let key in data) {
+                    fields.push({
+                        name: key,
+                        value: data[key]
+                    })
+                }
+                yield put({ type: 'dashboardDesigner/reset' });
+                yield put({ type: 'dashboardDesigner/silentSetFields', fields: fields });
             }
-            yield put({ type: 'dashboardDesigner/reset' });
-            yield put({ type: 'dashboardDesigner/silentSetFields', fields: fields });
         },
         *closeTab(action, { select, call, put }) {
-            const home = yield select(state => state.present.home);
-            const { tabs } = home;
             const { tab } = action;
-
             yield put({ type: 'removeTab', tab });
-            if(tabs.length > 0) {
+            const home = yield select(state => state.present.home);
+            const { tabs, selectedTab } = home;
+            if(selectedTab.code === tab.code && tabs.length > 0) {
                 yield put({ type: 'changeTab', tab: tabs[tabs.length - 1] });
             }
         },
+        *closeTabs(action, { select, call, put }) {
+            const { tabs, tab } = action;
+
+            yield put({ type: 'removeTabs', tabs });
+            const home = yield select(state => state.present.home);
+            const { tabs: allTabs } = home;
+            if(allTabs.length > 0) {
+                yield put({ type: 'changeTab', tab });
+            }
+        },
+        *closeAllTabs(action, { select, call, put }) {
+            yield put({ type: 'removeAllTabs' });
+            yield put({ type: 'dashboardDesigner/reset' });
+        },
         *saveCurrentTabDashboardConfig(action, { select, call, put }) {
             const { home, dashboardDesigner } = yield select(state => ({ home: state.present.home, dashboardDesigner: state.present.dashboardDesigner }));
             const { tabs } = home;

+ 0 - 1
src/models/parseChartOption.js

@@ -50,7 +50,6 @@ function barOption(data, barConfig) {
     let yTitle = barConfig.yAxis?`${barConfig.yAxis.column.label}${barConfig.yAxis.gauge.value?'('+barConfig.yAxis.gauge.label+')':''}`:null
     data.serieses = data.serieses || [];
 
-    console.log(barConfig);
     let option = {
         tooltip : {
             trigger: "axis",