-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b85af33
commit 158b217
Showing
5 changed files
with
91 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,76 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { Switch, Route } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
import { Dispatch, RootState } from '../models'; | ||
import { useDispatch } from 'react-redux'; | ||
import { Dispatch } from '../models'; | ||
import { getRouterData } from '../routes/router'; | ||
import { DefaultProps } from '../'; | ||
|
||
type StateProps = ReturnType<typeof mapState>; | ||
type DispatchProps = ReturnType<typeof mapDispatch>; | ||
type Props = StateProps & | ||
DispatchProps & { | ||
routerData: typeof getRouterData; | ||
}; | ||
type Props = { | ||
routerData: typeof getRouterData; | ||
} & DefaultProps; | ||
|
||
const mapState = ({ global }: RootState) => ({ | ||
// token: global.token, | ||
// userData: global.userData, | ||
}); | ||
export default function Controller(props: Props) { | ||
const { routerData } = props || {}; | ||
const dispatch = useDispatch<Dispatch>(); | ||
// const token = useSelector(({ global }: RootState) => global.token) | ||
const BasicLayout: any = routerData['/'].component; | ||
const UserLayout: any = routerData['/login'].component; | ||
useEffect(() => { | ||
if (!/^(\/login)/.test(window.location.pathname)) { | ||
dispatch.global.verify(); | ||
} | ||
// eslint-disable-next-line | ||
}, []); | ||
return ( | ||
<Switch> | ||
<Route path="/login" render={(props) => <UserLayout {...props} routerData={routerData} />} /> | ||
<Route path="/" render={(props) => <BasicLayout {...props} routerData={routerData} />} /> | ||
</Switch> | ||
); | ||
} | ||
|
||
const mapDispatch: any = (dispatch: Dispatch) => ({ | ||
// verify: dispatch.global.verify, | ||
// verify: global.verify, | ||
}); | ||
// type StateProps = ReturnType<typeof mapState>; | ||
// type DispatchProps = ReturnType<typeof mapDispatch>; | ||
// type Props = StateProps & | ||
// DispatchProps & { | ||
// routerData: typeof getRouterData; | ||
// }; | ||
|
||
class Controller extends React.PureComponent<Props> { | ||
componentDidMount() { | ||
// this.props.verify(); | ||
} | ||
render() { | ||
const { routerData } = this.props; | ||
// console.log('this.props:', this.props) | ||
const BasicLayout = routerData['/'].component; | ||
const UserLayout = routerData['/login'].component; | ||
// isAuthenticated = true 表示身份经过验证 | ||
// 请求是否登录验证 | ||
// if (!this.props.isAuthenticated) { | ||
// return ( | ||
// <span>是否登录的验证</span> | ||
// ); | ||
// } | ||
// resetProps.token = token; | ||
// resetProps.userData = userData; | ||
return ( | ||
<Switch> | ||
<Route path="/login" render={(props) => <UserLayout {...props} routerData={routerData} />} /> | ||
<Route path="/" render={(props) => <BasicLayout {...props} routerData={routerData} />} /> | ||
</Switch> | ||
); | ||
} | ||
} | ||
// const mapState = ({ global }: RootState) => ({ | ||
// // token: global.token, | ||
// // userData: global.userData, | ||
// }); | ||
|
||
// const mapDispatch: any = (dispatch: Dispatch) => ({ | ||
// // verify: dispatch.global.verify, | ||
// // verify: global.verify, | ||
// }); | ||
|
||
// class Controller extends React.PureComponent<Props> { | ||
// componentDidMount() { | ||
// // this.props.verify(); | ||
// } | ||
// render() { | ||
// const { routerData } = this.props; | ||
// // console.log('this.props:', this.props) | ||
// const BasicLayout = routerData['/'].component; | ||
// const UserLayout = routerData['/login'].component; | ||
// // isAuthenticated = true 表示身份经过验证 | ||
// // 请求是否登录验证 | ||
// // if (!this.props.isAuthenticated) { | ||
// // return ( | ||
// // <span>是否登录的验证</span> | ||
// // ); | ||
// // } | ||
// // resetProps.token = token; | ||
// // resetProps.userData = userData; | ||
// return ( | ||
// <Switch> | ||
// <Route path="/login" render={(props) => <UserLayout {...props} routerData={routerData} />} /> | ||
// <Route path="/" render={(props) => <BasicLayout {...props} routerData={routerData} />} /> | ||
// </Switch> | ||
// ); | ||
// } | ||
// } | ||
|
||
export default connect(mapState, mapDispatch)(Controller); | ||
// export default connect(mapState, mapDispatch)(Controller); |