Browse Source

token超期后弹出重新登陆提示框而不是直接跳转到登录页/看板新增立即保存/数据源列默认可分组

zhuth 7 years ago
parent
commit
3b4b933365

+ 50 - 0
src/components/common/rootLayout.jsx

@@ -0,0 +1,50 @@
+import React from 'react'
+import { Modal, Icon, Button } from 'antd'
+import { Redirect } from 'dva/router'
+import './rootLayout.less'
+
+class RootLayout extends React.Component {
+    constructor(props) {
+        super(props);
+        this.state = ({
+            goLogin: false
+        });
+    }
+
+    setGoLogin = () => {
+        this.setState({
+            goLogin: true
+        });
+    }
+
+    render() {
+        const { location, isAuthenticated, children } = this.props;
+        const { goLogin } = this.state;
+        return (<div className='root-layout'>
+            { children }
+            <Modal
+                className='confirm-box'
+                visible={!isAuthenticated}
+                footer={null}
+                closable={false}
+                centered={true}
+            >
+                <div className='confirm-body'>
+                    <div className='confirm-icon'><Icon type="info-circle" /></div>
+                    <div className='confirm-label'>登录已过期</div>
+                    <div className='confirm-button'>
+                        <Button type="primary" onClick={this.setGoLogin}>重新登录</Button>
+                    </div>
+                </div>
+            </Modal>
+            {goLogin && <Redirect
+                to={{
+                    pathname: "/login",
+                    state: { from: location }
+                }}
+            />}
+        </div>)
+    }
+}
+
+export default RootLayout;

+ 32 - 0
src/components/common/rootLayout.less

@@ -0,0 +1,32 @@
+.root-layout {
+    width: 100%;
+    height: 100%;
+}
+.confirm-box {
+    .ant-modal-body {
+        padding: 0;
+        .confirm-body {
+            display: flex;
+            flex-direction: column;
+            text-align: center;
+            .confirm-icon {
+                .anticon {
+                    height: 50px;
+                    line-height: 50px;
+                    font-size: 32px;
+                    color: #FF4D4F;
+                }
+            }
+            .confirm-label {
+                height: 50px;
+                line-height: 50px;
+                font-size: 24px;
+                font-weight: bold;
+            }
+            .confirm-button {
+                height: 48px;
+                line-height: 48px;
+            }
+        }
+    }
+}

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

@@ -186,7 +186,7 @@ class DashboardList extends React.Component {
                                 </Col>
                                 <Col >
                                     <Button onClick={() => {
-                                        dispatch({ type: 'main/redirect', path: { pathname: '/dashboard/create' } });
+                                        dispatch({ type: 'dashboard/remoteQucikAdd' });
                                     }}>
                                         <Icon type="layout" />创建看板
                                     </Button>

+ 28 - 0
src/models/dashboard.js

@@ -126,6 +126,34 @@ export default {
                 message.error('保存失败');
             }
         },
+        *remoteQucikAdd(action, { select, call, put }) {
+            try {
+                const dashboardDesigner = yield select(state => state.present.dashboardDesigner);
+                const { title, items } = dashboardDesigner;
+                let body = {
+                    bdName: title,
+                    bdNote: '',
+                    bdConfiguration: JSON.stringify(items),
+                    thumbnail: '',
+                    createBy: 'zhuth'
+                }
+                console.log('快速新增看板', body);
+                const res = yield call(service.fetch, {
+                    url: URLS.DASHBOARD_ADD,
+                    body: body
+                });
+                console.log('快速新增看板', body, res);
+                if(!res.err && res.data.code > 0) {
+                    yield put({ type: 'fetchList', mandatory: true });
+                    yield put({ type: 'main/redirect', path: '/dashboard/' + res.data.data });
+                }else {
+                    message.error('保存失败: ' + (res.err || res.data.msg));
+                } 
+            }catch(e) {
+                console.log(e);
+                message.error('保存失败');
+            }
+        },
         *remoteModify(action, { select, call, put }) {
             try {
                 const dashboardDesigner = yield select(state => state.present.dashboardDesigner);

+ 3 - 1
src/models/dataSource.js

@@ -231,6 +231,7 @@ export default {
                             dataType: c.dataType,
                             columnType: c.columnType,
                             isGroup: c.groupable?'1':'0',
+                            isFilter: c.filterable?'1':'0',
                             isSubsection: c.bucketizable?'1':'0',
                             isOpen: c.using?'1':'0',
                             remarks: c.description
@@ -343,7 +344,8 @@ export default {
                             alias: d.remarks ? d.remarks.substring(0, 10) : (d),
                             dataType: d.columnType,
                             columnType: getColumnType(d.columnType),
-                            groupable: d.columnType === 'VARCHAR2',
+                            // groupable: d.columnType === 'VARCHAR2',
+                            groupable: true,
                             filterable: true,
                             bucketizable: d.columnType === 'NUMBER',
                             description: d.remarks

+ 17 - 12
src/routes/router.js

@@ -1,6 +1,7 @@
 import React from 'react'
 import { LocaleProvider } from 'antd'
 import { Router, Route, Switch, Redirect } from 'dva/router'
+import RootLayout from '../components/common/rootLayout'
 import Login from '../components/common/login'
 import Register from '../components/common/register'
 import MainLayout from './mainLayout'
@@ -48,17 +49,21 @@ const PrivateRoute = ({ component: Component, ...rest }) => (
                 }
             }
 
-            return (window.localStorage.getItem("token") !== "false" ? true : false) ? (
-                <Component {...props} />
-            ) : (
-                    <Redirect
-                        to={{
-                            pathname: "/login",
-                            state: { from: props.location }
-                        }}
-                    />
-                )
-            }
-        }
+            // return (window.localStorage.getItem("token") !== "false") ? (
+            //     <Component {...props} />
+            // ) : (
+            //         <Redirect
+            //             to={{
+            //                 pathname: "/login",
+            //                 state: { from: props.location }
+            //             }}
+            //         />
+            //     )
+            // }
+            const isAuthenticated = window.localStorage.getItem("token") !== "false";
+            return <RootLayout location={props.location} isAuthenticated={isAuthenticated}>
+                <Component isAuthenticated={isAuthenticated} {...props} />
+            </RootLayout>
+        }}
     />
 );