forked from huge/frontEnd/hugeOA

Mr Ke
2020-05-27 4991bc08e414f371c624151f671236fcfed0bf01
修改报错问题
4 files modified
63 ■■■■■ changed files
src/components/common/HeadView/index.jsx 9 ●●●●● patch | view | raw | blame | history
src/index.js 41 ●●●● patch | view | raw | blame | history
src/module/login/login.jsx 11 ●●●●● patch | view | raw | blame | history
src/module/menu/menu.jsx 2 ●●● patch | view | raw | blame | history
src/components/common/HeadView/index.jsx
@@ -17,21 +17,22 @@
const history = createHashHistory();
const { Option } = Select;
const menu = (
  <Menu>
const menu = (fun) => {
  return <Menu>
    <Menu.Item>
      <a onClick={() => {
        // 清空用户相关信息
        window.localStorage.setItem('menu', '');
        window.localStorage.setItem('token', '');
        message.success('退出成功!');
        fun({ role: '' });
        window.location.href = window.location.origin + '/#/login';
      }}>
        退出
      </a>
    </Menu.Item>
  </Menu>
);
};
export default function HeadView({ props }) {
  var loginUser = window.localStorage.getItem('loginUser') || '{}';
@@ -81,7 +82,7 @@
                    </Col>
                    <Col style={{ marginRight: 40 }}>
                      {loginUser.trueName}&nbsp;&nbsp;&nbsp;
                      <Dropdown overlay={menu}>
                      <Dropdown overlay={menu(setContext)}>
                        <a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
                          [{loginUser.dept} | {loginUser.post}]<Icon type="caret-down" />
                        </a>
src/index.js
@@ -33,7 +33,7 @@
    super(props);
    this.state = {
      context: {
        role: 'oa',
        role: '',
        roleMenuList: [],
        setContext: this.setContext,
      },
@@ -46,23 +46,26 @@
      ? JSON.parse(window.localStorage.getItem('menusListByRole'))
      : [];
    let role = Object.keys(menusListByRole).reduce((p, n) => {
      if (
        menusListByRole[n].menus
          .reduce((p, n) => {
            if (n.children) {
              return p.concat(n.children);
            } else {
              return p.concat(n);
            }
          }, [])
          .find(({ path }) => path == pathname)
      ) {
        return p.concat(n);
      } else {
        return p;
      }
    }, []);
    let role = Object.keys(menusListByRole)
      .reduce((p, n) => {
        if (
          menusListByRole[n].menus
            .reduce((p, n) => {
              if (n.children) {
                return p.concat(n.children);
              } else {
                return p.concat(n);
              }
            }, [])
            .find(({ path }) => path == pathname)
        ) {
          return p.concat(n);
        } else {
          return p;
        }
      }, [])
      .join('');
    console.log('role', role);
    this.setState({
      context: {
@@ -106,9 +109,9 @@
                </Switch>
                <Layout>
                  <Content>
                    <Route path="/login" component={()=>( <Login setContext={this.setContext}/>)} />
                    {context.role == 'oa' && <OaRouteDom />}
                    {context.role == 'user' && <UserRouteDom />}
                    <Route path="/login" component={Login} />
                  </Content>
                </Layout>
              </Layout>
src/module/login/login.jsx
@@ -12,6 +12,9 @@
import logo from '../../img/logo.png';
import fetch from '../../api/request';
import { oaMenus, userMenus, getMenuListByPermission } from '../../menu';
import { Context } from '../../index';
import { createHashHistory } from 'history';
const history = createHashHistory();
class NormalLoginForm extends React.Component {
  constructor(props) {
@@ -79,9 +82,10 @@
          }
        }));//所有模块菜单
        message.success('登录成功');
        setTimeout(() => {
          this.props.history.push({ pathname: "/index" });
        }, 1500);//延时跳转
        console.log('this props', this.props);
        history.push({ pathname: "/index" });
        this.props.setContext && this.props.setContext({ role: 'oa' })
      }
    })
  }
@@ -139,7 +143,6 @@
          </div>
          <div className="login-div-bottom">2011 10215489广州恒巨信息科技有限公司 版权所有 - 粤ICP备10215489号</div>
        </div>
      </div>
    );
  }
src/module/menu/menu.jsx
@@ -64,7 +64,7 @@
              collapsible={true}
            >
              {
                menusListByRole &&
                menusListByRole && menusListByRole[role] &&
                <MenView
                  history={this.props.history}
                  pathname={selected(menusListByRole[role].menus, this.props.location.pathname)}