import { Route } from 'dva/router'
import RootLayout from '../components/common/rootLayout'
import moment from 'moment'

export default ({ component: Component, ...rest }) => (
    <Route
        {...rest}
        render={props =>{

            if (!window.localStorage.getItem('token')) {
                window.localStorage.setItem("token", "false");
            }else {
                /**
                 * 是否过期
                 * 1.是-----设置isAuthenticated为false
                 */
                const t = moment(+window.localStorage.getItem('expireTime'));
                if(t.isValid() && t.diff(moment()) < 0) {
                    window.localStorage.setItem("token", "false");
                }
            }

            const isAuthenticated = window.localStorage.getItem('token') !== "false";
            return <RootLayout location={props.location} isAuthenticated={isAuthenticated}>
                <Component isAuthenticated={isAuthenticated} {...props} />
            </RootLayout>
        }}
    />
);