Commit 6a02cfe6 by 姜雷

添加权限校验

parent 05e43a36
...@@ -112,9 +112,7 @@ class App extends Component { ...@@ -112,9 +112,7 @@ class App extends Component {
return <Component {...props} />; return <Component {...props} />;
} else { } else {
Toast.fail('无权使用该功能'); Toast.fail('无权使用该功能');
const { from } = props.location.state || { const from = { pathname: '/home' };
from: { pathname: '/home' },
};
return <Redirect to={from} />; return <Redirect to={from} />;
} }
}; };
......
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import styles from './style.css'; import styles from './style.css';
import { Link } from 'react-router-dom'; import { Toast } from 'antd-mobile';
import UserInfoContext from '../../context/userinfo-context';
export class Index extends React.Component { export class Index extends React.Component {
static propTypes = { static propTypes = {
name: PropTypes.string, name: PropTypes.string,
}; };
validate = (code, path) => {
const {
userinfo: { author },
history,
} = this.props;
let item = author.find(i => i.code === code);
if (item.type) {
history.push(path);
return;
} else {
Toast.fail('无权使用该功能');
return;
}
};
render() { render() {
return ( return (
<div className={styles.LoadPage}> <div className={styles.LoadPage}>
<h2>HomePage</h2> <h2>HomePage</h2>
<Link to="/Repair">报修</Link> <div onClick={() => this.validate('CSXY0001', '/Repair')}>报修</div>
<br /> <br />
<Link to="/RepairDeal">报修处理</Link> <div onClick={() => this.validate('CSXY0002', '/RepairDeal')}>
报修处理
</div>
<br /> <br />
<Link to="/publicCar">约车</Link> <div onClick={() => this.validate('CSXY0003', '/publicCar')}>约车</div>
<br /> <br />
<Link to="/publicCarDeal">约车处理</Link> <div onClick={() => this.validate('CSXY0004', '/publicCarDeal')}>
约车处理
</div>
</div> </div>
); );
} }
} }
export default Index; export default props => (
<UserInfoContext>
{({ userinfo }) => <Index userinfo={userinfo} {...props} />}
</UserInfoContext>
);
...@@ -106,7 +106,7 @@ class Login extends Component { ...@@ -106,7 +106,7 @@ class Login extends Component {
} }
}; };
loginHandle = () => { loginHandle = () => {
const { updateUserInfo, history } = this.props; const { updateUserInfo } = this.props;
const { code, cellphone } = this.state; const { code, cellphone } = this.state;
if (!code) { if (!code) {
Toast.fail('请输入短信验证码'); Toast.fail('请输入短信验证码');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment