Commit 05e43a36 by 姜雷

添加权限限制

parent 5d02a4f0
...@@ -14,6 +14,7 @@ const service = axios.create({ ...@@ -14,6 +14,7 @@ const service = axios.create({
service.interceptors.request.use( service.interceptors.request.use(
conf => { conf => {
let userId = store.getUserId(); let userId = store.getUserId();
if (/post/.test(conf.method.toLocaleLowerCase())) {
let data = userId let data = userId
? { ? {
...conf.data, ...conf.data,
...@@ -21,6 +22,16 @@ service.interceptors.request.use( ...@@ -21,6 +22,16 @@ service.interceptors.request.use(
} }
: conf.data; : conf.data;
conf.data = data; conf.data = data;
} else {
let data = userId
? {
...conf.params,
userId,
}
: conf.params;
conf.params = data;
}
Toast.loading('Loading...', 10); Toast.loading('Loading...', 10);
conf.headers = { conf.headers = {
...conf.headers, ...conf.headers,
......
...@@ -52,12 +52,10 @@ class ImagePicker extends Component { ...@@ -52,12 +52,10 @@ class ImagePicker extends Component {
done: true, done: true,
})); }));
if (onChange) { if (onChange) {
onChange([ onChange({
{
filesList, filesList,
url: fileUrl, url: fileUrl,
}, });
]);
} }
}; };
createObjectURL = blob => { createObjectURL = blob => {
......
...@@ -7,43 +7,75 @@ import pageIcon from './images/next_pic_btn@2x.png'; ...@@ -7,43 +7,75 @@ import pageIcon from './images/next_pic_btn@2x.png';
class Perview extends Component { class Perview extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
let viewDom = document.getElementById('PerviewWrap'); this.state = {
if (viewDom) { index: props.index,
this.node = viewDom; list: props.data.filter(i => i),
} else { };
viewDom = document.createElement('div');
viewDom.id = 'PerviewWrap';
document.body.appendChild(viewDom);
this.node = viewDom;
} }
} onChangeHandle = index => {
this.setState({
componentWillUnmount() { index: index,
window.document.body.removeChild(this.node); });
} };
goPer = () => {
const { index } = this.state;
if (index === 0) return;
this.setState({
index: index - 1,
});
};
goNext = () => {
const { index, list } = this.state;
if (index + 1 >= list.length) return;
this.setState({
index: index + 1,
});
};
render() { render() {
const { data, index } = this.props; const { index, list } = this.state;
return ( return (
<div> <div>
<div className={styles.content}> <div className={styles.content}>
<div className={styles.imgBox}> <div className={styles.imgBox}>
<Carousel selectedIndex={index} dots={false}> <Carousel
{data.map( selectedIndex={index}
dots={false}
afterChange={this.onChangeHandle}
>
{list.length === 1 ? (
<div>
<img
className={styles.carouselImg}
src={list[0].url || list[0]}
alt=""
/>
</div>
) : (
list.map(
(item, index) => (item, index) =>
item ? <img className={styles.carouselImg} key={index} src={item.url} alt="" /> : null item ? (
<img
className={styles.carouselImg}
key={index}
src={item.url || item}
alt=""
/>
) : null
)
)} )}
</Carousel> </Carousel>
</div> </div>
<div className={styles.footer}> <div className={styles.footer}>
<div className={styles.per}> <div className={styles.per} onClick={this.goPer}>
<div className={styles.leftIcon}> <div className={styles.leftIcon}>
<img src={pageIcon} alt="" /> <img src={pageIcon} alt="" />
</div> </div>
<div>上一张</div> <div>上一张</div>
</div> </div>
<div className={styles.pagination}>1/3</div> <div className={styles.pagination}>
<div className={styles.next}> {index + 1}/{list.length}
</div>
<div className={styles.next} onClick={this.goNext}>
<div>下一张</div> <div>下一张</div>
<div className={styles.rightIcon}> <div className={styles.rightIcon}>
<img src={pageIcon} alt="" /> <img src={pageIcon} alt="" />
......
...@@ -20,12 +20,6 @@ class App extends Component { ...@@ -20,12 +20,6 @@ class App extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.updateUserInfo = data => {
this.setState({
userinfo: { ...this.state.userinfo, ...data },
});
};
this.state = { this.state = {
isWx: is_weixn(), isWx: is_weixn(),
userContext: { userContext: {
...@@ -70,14 +64,14 @@ class App extends Component { ...@@ -70,14 +64,14 @@ class App extends Component {
let params = this.getParams(location.search); let params = this.getParams(location.search);
if (params.code) { if (params.code) {
console.log('fetch UserInfo'); console.log('fetch UserInfo');
console.log('redirect', params, history); console.log('redirect', params);
wxAuth({ wxAuth({
code: params.code, code: params.code,
}) })
.then(res => { .then(res => {
console.log(res); console.log(res);
const { firstLogin, user } = res.data; const { firstLogin, user, author } = res.data;
this.updateUserInfo({ ...user, login: true }); this.updateUserInfo({ ...user, login: true, author });
if (firstLogin) { if (firstLogin) {
history.replace('/login'); history.replace('/login');
} else { } else {
...@@ -90,6 +84,7 @@ class App extends Component { ...@@ -90,6 +84,7 @@ class App extends Component {
}); });
} else { } else {
console.log('go in wxAuth'); console.log('go in wxAuth');
// this.goWechatAuth()
} }
return <div style={{ margin: '60px 24px 0' }}>加载中。。。</div>; return <div style={{ margin: '60px 24px 0' }}>加载中。。。</div>;
...@@ -99,30 +94,29 @@ class App extends Component { ...@@ -99,30 +94,29 @@ class App extends Component {
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APP_ID}&redirect_uri=${rUrl}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`; window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APP_ID}&redirect_uri=${rUrl}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`;
return <div>授权中。。。</div>; return <div>授权中。。。</div>;
}; };
validateUserinfo = (code, Component) => { validateUserinfo = (props, code, Component) => {
const { const {
userContext: { userContext: {
userinfo: { login, author }, userinfo: { login, author },
}, },
} = this.state; } = this.state;
if (!login) { if (!login) {
return this.goWechatAuth(); console.log('no login');
} // product 需要修改为去微信授权
for (let index = 0; index < author.length; index++) {
const element = author[index];
if (element.code === code) {
if (element.type) {
return <Component />; return <Component />;
// return this.goWechatAuth();
}
let item = author.find(i => i.code === code);
if (item.type) {
return <Component {...props} />;
} else { } else {
Toast.fail('无权使用该功能'); Toast.fail('无权使用该功能');
const { from } = this.props.location.state || { const { from } = props.location.state || {
from: { pathname: '/home' }, from: { pathname: '/home' },
}; };
return <Redirect to={from} />; return <Redirect to={from} />;
} }
}
}
return <NoMatch />;
}; };
updateUserInfo = data => { updateUserInfo = data => {
this.setState({ this.setState({
...@@ -142,10 +136,28 @@ class App extends Component { ...@@ -142,10 +136,28 @@ class App extends Component {
<Route exact path="/" render={this.renderIndex} /> <Route exact path="/" render={this.renderIndex} />
<Route path="/home" component={Home} /> <Route path="/home" component={Home} />
<Route path="/login" component={Login} /> <Route path="/login" component={Login} />
<Route path="/publicCar" component={PublicCar} /> <Route
<Route path="/publicCarDeal" component={PublicCarDeal} /> path="/publicCar"
<Route path="/Repair" component={Repair} /> render={props =>
<Route path="/RepairDeal" component={RepairDeal} /> this.validateUserinfo(props, 'CSXY0003', PublicCar)
}
/>
<Route
path="/publicCarDeal"
render={props =>
this.validateUserinfo(props, 'CSXY0004', PublicCarDeal)
}
/>
<Route
path="/Repair"
render={props => this.validateUserinfo(props, 'CSXY0001', Repair)}
/>
<Route
path="/RepairDeal"
render={props =>
this.validateUserinfo(props, 'CSXY0002', RepairDeal)
}
/>
<Route component={NoMatch} /> <Route component={NoMatch} />
</Switch> </Switch>
</UserInfoContext.Provider> </UserInfoContext.Provider>
......
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';
export class Index extends React.Component { export class Index extends React.Component {
static propTypes = { static propTypes = {
...@@ -11,10 +12,13 @@ export class Index extends React.Component { ...@@ -11,10 +12,13 @@ export class Index extends React.Component {
return ( return (
<div className={styles.LoadPage}> <div className={styles.LoadPage}>
<h2>HomePage</h2> <h2>HomePage</h2>
<a href="">功能1</a> <Link to="/Repair">报修</Link>
<a href="">功能2</a> <br />
<a href="">功能3</a> <Link to="/RepairDeal">报修处理</Link>
<a href="">功能4</a> <br />
<Link to="/publicCar">约车</Link>
<br />
<Link to="/publicCarDeal">约车处理</Link>
</div> </div>
); );
} }
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { PullToRefresh } from 'antd-mobile'; import { PullToRefresh, Modal } from 'antd-mobile';
import styles from './style.css'; import styles from './style.css';
import RepairItem from './components/RepairItem'; import RepairItem from './components/RepairItem';
import { fetchRepairList } from '../../api/index'; import { fetchRepairList } from '../../api/index';
import Perview from '../../components/Perview/Perview';
class RepairList extends Component { class RepairList extends Component {
constructor(props) { constructor(props) {
...@@ -16,6 +17,9 @@ class RepairList extends Component { ...@@ -16,6 +17,9 @@ class RepairList extends Component {
pageSize: 50, pageSize: 50,
}, },
list: [], list: [],
perviewVisibility: false,
selectedImgList: [],
perviewIndex: 0,
}; };
} }
componentDidMount() { componentDidMount() {
...@@ -44,7 +48,20 @@ class RepairList extends Component { ...@@ -44,7 +48,20 @@ class RepairList extends Component {
this.setState({ refreshing: false }); this.setState({ refreshing: false });
}, 1000); }, 1000);
}; };
showViewHandle = (list, index) => {
this.setState({
perviewVisibility: true,
perviewIndex: index,
selectedImgList: list,
});
};
resetDialog = () => {
this.setState({
perviewVisibility: false,
});
};
render() { render() {
const { perviewVisibility, selectedImgList, perviewIndex } = this.state;
return ( return (
<div className={styles.repairList}> <div className={styles.repairList}>
<PullToRefresh <PullToRefresh
...@@ -61,11 +78,23 @@ class RepairList extends Component { ...@@ -61,11 +78,23 @@ class RepairList extends Component {
> >
<div className={styles.listInfo}>显示最近半年的报修记录</div> <div className={styles.listInfo}>显示最近半年的报修记录</div>
{this.state.list.length ? ( {this.state.list.length ? (
this.state.list.map(i => <RepairItem key={i.id} data={i} />) this.state.list.map(i => (
<RepairItem key={i.id} data={i} showView={this.showViewHandle} />
))
) : ( ) : (
<div className={styles.noData}>暂无数据</div> <div className={styles.noData}>暂无数据</div>
)} )}
</PullToRefresh> </PullToRefresh>
<Modal
className={styles.perViewDialog}
visible={perviewVisibility}
transparent
maskClosable={true}
onClose={this.resetDialog}
title=""
>
<Perview data={selectedImgList} index={perviewIndex} />
</Modal>
</div> </div>
); );
} }
......
...@@ -157,7 +157,7 @@ class ReprtRepair extends Component { ...@@ -157,7 +157,7 @@ class ReprtRepair extends Component {
this.state.applyForm.uploadImg.map(i => { this.state.applyForm.uploadImg.map(i => {
if (i) { if (i) {
console.log(i); console.log(i);
formData.append('file', i[0]); formData.append('file', i.filesList[0]);
} }
return i; return i;
}); });
......
...@@ -23,9 +23,15 @@ class RepairItem extends Component { ...@@ -23,9 +23,15 @@ class RepairItem extends Component {
dealHandle(data.id); dealHandle(data.id);
} }
}; };
showViewHandle = (e, imgList, index) => {
e.stopPropagation();
const { showView } = this.props;
showView && showView(imgList, index);
};
render() { render() {
const { showDetail } = this.state; const { showDetail } = this.state;
const { data } = this.props; const { data } = this.props;
let imgList = data.uploadImg ? data.uploadImg.split(',') : [];
return ( return (
<div className={styles.wrap}> <div className={styles.wrap}>
<div <div
...@@ -84,9 +90,13 @@ class RepairItem extends Component { ...@@ -84,9 +90,13 @@ class RepairItem extends Component {
</div> </div>
</div>, </div>,
<div key="uploadImg" className={styles.listLine}> <div key="uploadImg" className={styles.listLine}>
{data.uploadImg.split(',')[0] && {imgList[0] &&
data.uploadImg.split(',').map((item, idx) => ( imgList.map((item, idx) => (
<div key={idx} className={styles.imgItem}> <div
key={idx}
className={styles.imgItem}
onClick={e => this.showViewHandle(e, imgList, idx)}
>
<img src={item} alt="" /> <img src={item} alt="" />
</div> </div>
))} ))}
......
...@@ -3,6 +3,7 @@ import { PullToRefresh, Modal, Toast } from 'antd-mobile'; ...@@ -3,6 +3,7 @@ import { PullToRefresh, Modal, Toast } from 'antd-mobile';
import styles from './style.css'; import styles from './style.css';
import RepairItem from '../Repair/components/RepairItem'; import RepairItem from '../Repair/components/RepairItem';
import { fetchReportRepairList, dealRepair } from '../../api/index'; import { fetchReportRepairList, dealRepair } from '../../api/index';
import Perview from '../../components/Perview/Perview';
class RepairDeal extends Component { class RepairDeal extends Component {
constructor(props) { constructor(props) {
...@@ -111,9 +112,23 @@ class RepairDeal extends Component { ...@@ -111,9 +112,23 @@ class RepairDeal extends Component {
] ]
); );
}; };
showViewHandle = (list, index) => {
this.setState({
perviewVisibility: true,
perviewIndex: index,
selectedImgList: list,
});
};
resetDialog = () => {
this.setState({
perviewVisibility: false,
});
};
render() { render() {
return ( const { perviewVisibility, selectedImgList, perviewIndex } = this.state;
return [
<PullToRefresh <PullToRefresh
key="repairList"
damping={60} damping={60}
ref={el => (this.ptr = el)} ref={el => (this.ptr = el)}
style={{ style={{
...@@ -128,13 +143,29 @@ class RepairDeal extends Component { ...@@ -128,13 +143,29 @@ class RepairDeal extends Component {
<div className={styles.listInfo}>显示最近半年的报修记录</div> <div className={styles.listInfo}>显示最近半年的报修记录</div>
{this.state.list.length ? ( {this.state.list.length ? (
this.state.list.map(i => ( this.state.list.map(i => (
<RepairItem key={i.id} data={i} dealHandle={this.dealHandle} /> <RepairItem
key={i.id}
data={i}
dealHandle={this.dealHandle}
showView={this.showViewHandle}
/>
)) ))
) : ( ) : (
<div className={styles.noData}>暂无数据</div> <div className={styles.noData}>暂无数据</div>
)} )}
</PullToRefresh> </PullToRefresh>,
); <Modal
key="repairImgPerview"
className={styles.perViewDialog}
visible={perviewVisibility}
transparent
maskClosable={true}
onClose={this.resetDialog}
title=""
>
<Perview data={selectedImgList} index={perviewIndex} />
</Modal>,
];
} }
} }
......
...@@ -30,3 +30,6 @@ ...@@ -30,3 +30,6 @@
top: 50%; top: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
.perViewDialog {
composes: perViewDialog from '../Repair/style.css';
}
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