Commit 6a02cfe6 by 姜雷

添加权限校验

parent 05e43a36
......@@ -112,9 +112,7 @@ class App extends Component {
return <Component {...props} />;
} else {
Toast.fail('无权使用该功能');
const { from } = props.location.state || {
from: { pathname: '/home' },
};
const from = { pathname: '/home' };
return <Redirect to={from} />;
}
};
......
import React from 'react';
import PropTypes from 'prop-types';
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 {
static propTypes = {
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() {
return (
<div className={styles.LoadPage}>
<h2>HomePage</h2>
<Link to="/Repair">报修</Link>
<div onClick={() => this.validate('CSXY0001', '/Repair')}>报修</div>
<br />
<Link to="/RepairDeal">报修处理</Link>
<div onClick={() => this.validate('CSXY0002', '/RepairDeal')}>
报修处理
</div>
<br />
<Link to="/publicCar">约车</Link>
<div onClick={() => this.validate('CSXY0003', '/publicCar')}>约车</div>
<br />
<Link to="/publicCarDeal">约车处理</Link>
<div onClick={() => this.validate('CSXY0004', '/publicCarDeal')}>
约车处理
</div>
</div>
);
}
}
export default Index;
export default props => (
<UserInfoContext>
{({ userinfo }) => <Index userinfo={userinfo} {...props} />}
</UserInfoContext>
);
......@@ -106,7 +106,7 @@ class Login extends Component {
}
};
loginHandle = () => {
const { updateUserInfo, history } = this.props;
const { updateUserInfo } = this.props;
const { code, cellphone } = this.state;
if (!code) {
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