UNPKG

nyx_server

Version:

Node内容发布

42 lines (36 loc) 983 B
import React from 'react'; import { fromJS } from 'immutable'; import {History} from 'react-router'; import store from '../store'; import { setUserinfo } from '../actions/Project'; const getDatefromLocalStorage = function (id) { if (window.localStorage) { console.log(window.localStorage.getItem(id)); return JSON.parse(window.localStorage.getItem(id) || '{}'); } else { return {}; } }; export default class Userinfo extends React.Component { getUserinfo() { return this.props.userinfo || fromJS({}); } componentDidMount(){ store.dispatch(setUserinfo(getDatefromLocalStorage('nyxUserInfo'))); } render() { const userinfo = this.getUserinfo(); const username = userinfo.get('userName'); return ( <div className="nyx-userinfo"> {username ? <div> <em>{username}</em> <span onClick={this.props.onLogout}>退出</span> </div> : '' } </div> ); } }