Skip to content

Commit db1d1dc

Browse files
committed
用户中心
1 parent 48e8afe commit db1d1dc

File tree

15 files changed

+322
-13
lines changed

15 files changed

+322
-13
lines changed
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
import React from 'react';
22
import PureRenderMixin from 'react-addons-pure-render-mixin';
33

4+
import './style.less';
5+
46
class BuyAndStore extends React.Component {
57
constructor(props, context) {
68
super(props, context);
79
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
810
}
911

10-
1112
render() {
12-
console.log(this.props);
1313
return (
14-
<div>12</div>
14+
<div className="buy-store-container clear-fix">
15+
<div className="item-container float-left">
16+
{
17+
// 是否已经收藏了
18+
this.props.isStore
19+
? <button className="selected" onClick={this.storeClickHandle.bind(this)}>已收藏</button>
20+
: <button onClick={this.storeClickHandle.bind(this)}>收藏</button>
21+
}
22+
</div>
23+
<div className="item-container float-right">
24+
<button onClick={this.buyClickHandle.bind(this)}>购买</button>
25+
</div>
26+
</div>
1527
);
1628
}
29+
buyClickHandle() {
30+
this.props.buyHandle();
31+
}
32+
storeClickHandle() {
33+
this.props.storeHandle();
34+
}
1735
}
1836

19-
// 使用 require.ensure 异步加载,还不支持 ES6 的 export
20-
// export default BuyAndStore
21-
module.exports = BuyAndStore;
37+
export default BuyAndStore;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.buy-store-container {
2+
border-top: 1px solid #f1f1f1;
3+
background-color: #fff;
4+
padding: 10px 0;
5+
.item-container {
6+
width: 50%;
7+
text-align: center;
8+
button {
9+
font-size: 16px;
10+
width: 100px;
11+
background-color: #f1f1f1;
12+
color: #666;
13+
border: 1px solid #666;
14+
padding: 5px 0;
15+
}
16+
button.selected {
17+
color: rgb(233, 32, 61);
18+
border: 1px solid rgb(233, 32, 61);
19+
}
20+
}
21+
}

app/components/Header/index.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PureRenderMixin from 'react-addons-pure-render-mixin';
3+
import { hashHistory } from 'react-router';
34

45
import './style.less';
56

@@ -20,7 +21,12 @@ class Header extends React.Component {
2021
);
2122
}
2223
clickHandle() {
23-
window.history.back();
24+
const backRouter = this.props.backRouter;
25+
if (backRouter) {
26+
hashHistory.push(backRouter);
27+
} else {
28+
window.history.back();
29+
}
2430
}
2531
}
2632

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
3+
4+
import './style.less';
5+
6+
class Item extends React.Component {
7+
constructor(props, context) {
8+
super(props, context);
9+
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
10+
}
11+
render() {
12+
const data = this.props.data;
13+
return (
14+
<div className="clear-fix order-item-container">
15+
<div className="order-item-img float-left">
16+
<img src={data.img} />
17+
</div>
18+
<div className="order-item-comment float-right">
19+
<button>评价</button>
20+
</div>
21+
<div className="order-item-content">
22+
<span>商户:{data.title}</span>
23+
<span>数量:{data.count}</span>
24+
<span>价格:¥{data.price}</span>
25+
</div>
26+
</div>
27+
);
28+
}
29+
}
30+
31+
export default Item;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.order-item-container {
2+
padding: 10px 0;
3+
border-bottom: 1px solid #f1f1f1;
4+
.order-item-img {
5+
width: 120px;
6+
height: 90px;
7+
img {
8+
width: 100%;
9+
height: 100%;
10+
}
11+
}
12+
.order-item-comment {
13+
width: 100px;
14+
text-align: right;
15+
button {
16+
width: 80px;
17+
text-align: center;
18+
background-color: rgb(233, 32, 61);
19+
color: #fff;
20+
padding: 5px 0;
21+
margin-top: 25px;
22+
border: 0;
23+
font-size: 16px;
24+
}
25+
}
26+
.order-item-content {
27+
margin: 0 130px;
28+
span {
29+
color: #666;
30+
display: block;
31+
text-align: left;
32+
line-height: 1.5;
33+
}
34+
}
35+
}

app/components/OrderList/index.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
3+
4+
import Item from './Item';
5+
6+
class OrderList extends React.Component {
7+
constructor(props, context) {
8+
super(props, context);
9+
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
10+
}
11+
12+
render() {
13+
const data = this.props.data;
14+
return (
15+
<div>
16+
{
17+
data.map((e, i) => {
18+
return <Item key={i} data={e} />;
19+
})
20+
}
21+
</div>
22+
);
23+
}
24+
}
25+
26+
module.exports = OrderList;

app/components/UserInfo/index.jsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
3+
4+
import './style.less';
5+
6+
class UserInfo extends React.Component {
7+
constructor(props, context) {
8+
super(props, context);
9+
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
10+
}
11+
12+
render() {
13+
return (
14+
<div className="userinfo-container">
15+
<p>
16+
<i className="icon-user"></i>
17+
&nbsp;
18+
<span>{this.props.username}</span>
19+
</p>
20+
<p>
21+
<i className="icon-map-marker"></i>
22+
&nbsp;
23+
<span>{this.props.city}</span>
24+
</p>
25+
</div>
26+
);
27+
}
28+
}
29+
30+
module.exports = UserInfo;

app/components/UserInfo/style.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.userinfo-container {
2+
background-color: #fff;
3+
padding: 10px;
4+
p {
5+
line-height: 1.5;
6+
color: #666;
7+
}
8+
}

app/containers/Detail/subpage/buy.jsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,34 @@ class Buy extends React.Component {
4949
hashHistory.push('/User/');
5050
}
5151

52-
// 收藏时间
52+
// 收藏事件
5353
storeHandle() {
5454
const loginFlag = this.loginCheck();
5555
if (!loginFlag) {
5656
return;
5757
}
5858

59+
const id = this.props.id;
60+
const storeActions = this.props.storeActions;
61+
if (this.state.isStore) {
62+
//已经收藏,需要取消收藏
63+
storeActions.rm({ id: id });
64+
} else {
65+
//没有收藏,收藏
66+
storeActions.add({ id: id });
67+
}
68+
69+
//修改状态
70+
this.setState({
71+
isStore: !this.state.isStore
72+
});
5973
}
6074

6175
// 验证登录
6276
loginCheck() {
6377
const id = this.props.id;
6478
const userinfo = this.props.userinfo;
65-
if (userinfo.username) {
79+
if (!userinfo.username) {
6680
// 跳转到登陆页
6781
hashHistory.push(`/Login/${encodeURIComponent(`/detail/${id}`)}`);
6882
return false;

app/containers/User/index.jsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,48 @@
1-
import React, { Component } from 'react';
1+
import React from 'react';
2+
import PureRenderMixin from 'react-addons-pure-render-mixin';
3+
import { connect } from 'react-redux';
4+
import { hashHistory } from 'react-router';
5+
import Header from '../../components/Header';
6+
import UserInfo from '../../components/UserInfo';
7+
import OrderList from './subpage/OrderList';
8+
9+
class User extends React.Component {
10+
constructor(props, context) {
11+
super(props, context);
12+
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
13+
}
214

3-
class User extends Component {
415
render() {
16+
const userinfo = this.props.userinfo;
517
return (
618
<div>
7-
user
19+
<Header title="用户中心" backRouter="/"></Header>
20+
<UserInfo username={userinfo.username} city={userinfo.cityName} />
21+
<OrderList username={userinfo.username} />
822
</div>
923
);
1024
}
25+
componentDidMount() {
26+
// 如果未登录,跳转到登录页面
27+
if (!this.props.userinfo.username) {
28+
hashHistory.push('/Login');
29+
}
30+
}
1131
}
1232

13-
export default User;
33+
// -------------------redux react 绑定--------------------
34+
35+
function mapStateToProps(state) {
36+
return {
37+
userinfo: state.userinfo
38+
};
39+
}
40+
41+
function mapDispatchToProps(dispatch) {
42+
return {
43+
};
44+
}
45+
export default connect(
46+
mapStateToProps,
47+
mapDispatchToProps
48+
)(User);

0 commit comments

Comments
 (0)