|
@@ -1,30 +1,58 @@
|
|
|
-// import React, { Component } from 'react'
|
|
|
-// import BaseLayout from './baseLayout';
|
|
|
|
|
|
-// const ULR_NO_LAYOUT = ['/', '/home', '/class', '/my'];
|
|
|
|
|
|
-// class Index extends Component {
|
|
|
-// componentDidMount() {
|
|
|
-// }
|
|
|
-// renderBody = () => {
|
|
|
-// const {location: {pathname}, children } = this.props;
|
|
|
-// if (ULR_NO_LAYOUT.includes(pathname)) {
|
|
|
-// return (<BaseLayout {...this.props} />);
|
|
|
-// }
|
|
|
-// return (
|
|
|
-// <React.Fragment>
|
|
|
-// {children}
|
|
|
-// </React.Fragment>
|
|
|
-// );
|
|
|
-// }
|
|
|
-
|
|
|
-// render() {
|
|
|
-// return (
|
|
|
-// <React.Fragment>
|
|
|
-// {this.renderBody()}
|
|
|
-// </React.Fragment>
|
|
|
-// )
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// export default Index;
|
|
|
+import React, { Component } from 'react'
|
|
|
+import qs from 'qs';
|
|
|
+import { config, request , util } from 'utils';
|
|
|
+class Index extends Component {
|
|
|
+ constructor(props) {
|
|
|
+ super(props)
|
|
|
+ this.state = {
|
|
|
+ token: null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ componentDidMount() {
|
|
|
+ this.getUpdateToken()
|
|
|
+ }
|
|
|
+ getUpdateToken = (value) => {
|
|
|
+ let user = util.auth.getUser();
|
|
|
+ if (!user) {
|
|
|
+ util.auth.removeToken();
|
|
|
+ }
|
|
|
+ let data = {};
|
|
|
+ data['client_id'] = ClientIdCms;
|
|
|
+ data['client_secret'] = ClientSecretCms;
|
|
|
+ data['applicationKey'] = 'wechatcp';
|
|
|
+ data['grant_type'] = "client_credentials";
|
|
|
+ data['autoRefresh'] = true;
|
|
|
+ let strData = qs.stringify(data);
|
|
|
+ request({
|
|
|
+ url: config.api.getOperationToken,
|
|
|
+ method: 'post',
|
|
|
+ data: strData,
|
|
|
+ dataHeader: { headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' } }
|
|
|
+ }).then((data) => {
|
|
|
+ if (data.success) {
|
|
|
+ var user = util.auth.getUser();
|
|
|
+ if (user) {
|
|
|
+ util.auth.setUser(user);
|
|
|
+ }
|
|
|
+ util.auth.setToken(data.result.access_token);
|
|
|
+ this.setState({ token: data.result.access_token })
|
|
|
+ } else {
|
|
|
+ util.auth.removeToken();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ renderBody = () => {
|
|
|
+ const { children } = this.props;
|
|
|
+ return (
|
|
|
+ <React.Fragment>
|
|
|
+ {children}
|
|
|
+ </React.Fragment>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ render() {
|
|
|
+ return this.state.token ? <React.Fragment>{this.renderBody()}</React.Fragment> : <div /> ;
|
|
|
+ }
|
|
|
+}
|
|
|
+export default Index;
|