@@ -5,8 +5,7 @@ import { NavLink, Link, Switch, Route, Redirect } from 'react-router-dom';
55import './home.css' ;
66import cloudstudio from '../../static/cloudstudio.svg' ;
77
8- import api from '../../api' ;
9- import i18n from '../../utils/i18n' ;
8+ import Mask from './mask' ;
109import Stripe from '../../share/stripe' ;
1110import Bell from '../bell' ;
1211import Profile from './profile' ;
@@ -17,15 +16,27 @@ import Plugin from '../plugin';
1716import Setting from '../setting' ;
1817import About from '../about' ;
1918
19+ import api from '../../api' ;
20+ import i18n from '../../utils/i18n' ;
21+
2022class Home extends Component {
21- state = {
22- isBellOn : false ,
23- isProfileOn : false ,
23+ constructor ( props ) {
24+ super ( props ) ;
25+ this . state = {
26+ loaded : false ,
27+ isMaskOn : true ,
28+ isBellOn : false ,
29+ isProfileOn : false ,
30+ } ;
31+ this . fetchUserProfile ( ) ;
2432 }
2533
2634 render ( ) {
27- const { isBellOn, isProfileOn } = this . state ;
35+ const { loaded , isMaskOn , isBellOn, isProfileOn } = this . state ;
2836 const { isMbarOn, wsCount, hideMbar } = this . props ;
37+ if ( loaded && isMaskOn ) {
38+ return < Mask /> ;
39+ }
2940 return (
3041 < div id = "dash-container" onClick = { this . turnOffPanel } >
3142 < div className = "dash-mbar" >
@@ -54,20 +65,22 @@ class Home extends Component {
5465 < NavLink className = "nav-item" activeClassName = "active" to = "/dashboard/plugin" > { i18n ( 'global.plugin' ) } </ NavLink >
5566 < NavLink className = "nav-item" activeClassName = "active" to = "/dashboard/setting" > { i18n ( 'global.setting' ) } </ NavLink >
5667 </ div >
57- < Bell on = { isBellOn } togglePanel = { this . toggleBellPanel } />
58- < Profile on = { isProfileOn } togglePanel = { this . toggleProfilePanel } />
68+ { ! isMaskOn && < Bell on = { isBellOn } togglePanel = { this . toggleBellPanel } /> }
69+ { ! isMaskOn && < Profile on = { isProfileOn } togglePanel = { this . toggleProfilePanel } /> }
5970 </ div >
6071 < div className = "dash-main" >
6172 < Banner />
6273 < div className = "dash-view" >
63- < Switch >
64- < Route exact path = "/dashboard/workspace" component = { Workspace } > </ Route >
65- < Route exact path = "/dashboard/workspace/create" component = { Create } > </ Route >
66- < Route path = "/dashboard/plugin" component = { Plugin } > </ Route >
67- < Route exact path = "/dashboard/setting" component = { Setting } > </ Route >
68- < Route exact path = "/dashboard/about" component = { About } > </ Route >
69- < Redirect to = "/dashboard/workspace" />
70- </ Switch >
74+ { ! isMaskOn && (
75+ < Switch >
76+ < Route exact path = "/dashboard/workspace" component = { Workspace } > </ Route >
77+ < Route exact path = "/dashboard/workspace/create" component = { Create } > </ Route >
78+ < Route path = "/dashboard/plugin" component = { Plugin } > </ Route >
79+ < Route exact path = "/dashboard/setting" component = { Setting } > </ Route >
80+ < Route exact path = "/dashboard/about" component = { About } > </ Route >
81+ < Redirect to = "/dashboard/workspace" />
82+ </ Switch >
83+ ) }
7184 </ div >
7285 </ div >
7386 </ div >
@@ -95,8 +108,6 @@ class Home extends Component {
95108 state : ( historyState && historyState . state ) ? historyState . state : undefined ,
96109 } , '*' ) ;
97110 gtag ( 'config' , 'UA-65952334-9' , { 'page_path' : window . location . pathname } ) ;
98- // 获取工作空间数量信息
99- this . fetchWorkspaceCount ( ) ;
100111 // 缩放页面时,关闭 mbar
101112 window . addEventListener ( 'resize' , ( ) => {
102113 const { isMbarOn } = this . props ;
@@ -106,7 +117,24 @@ class Home extends Component {
106117 } ) ;
107118 }
108119
109- fetchWorkspaceCount ( ) {
120+ fetchUserProfile = ( ) => {
121+ api . getUserProfile ( ) . then ( res => {
122+ this . setState ( { loaded : true } ) ;
123+ if ( res . code === 0 ) {
124+ if ( ! / ^ d t i d _ [ a - z 0 - 9 ] + / i. test ( res . data . global_key ) ) {
125+ this . props . logIn ( res . data ) ;
126+ this . setState ( { isMaskOn : false } ) ;
127+ // 获取工作空间数量信息
128+ this . fetchWorkspaceCount ( ) ;
129+ }
130+ } else {
131+ window . top . postMessage ( { path : '/intro' } , '*' ) ;
132+ window . location . href = '/intro' ;
133+ }
134+ } ) ;
135+ }
136+
137+ fetchWorkspaceCount = ( ) => {
110138 const { storeWorkspace } = this . props ;
111139 // 获取工作空间
112140 // 获取创建工作空间数量限制
@@ -165,9 +193,8 @@ const mapState = (state) => {
165193
166194const mapDispatch = ( dispatch ) => {
167195 return {
168- storeWorkspace : ( payload ) => {
169- dispatch ( { type : 'STORE_WORKSPACE' , payload } )
170- } ,
196+ logIn : ( payload ) => dispatch ( { type : 'USER_LOG_IN' , payload } ) ,
197+ storeWorkspace : ( payload ) => dispatch ( { type : 'STORE_WORKSPACE' , payload } ) ,
171198 hideMbar : ( ) => dispatch ( { type : 'SWITCH_MBAR_TO_OFF' } ) ,
172199 }
173200}
0 commit comments