Skip to content

Commit

Permalink
tag页面和 recommendHome页
Browse files Browse the repository at this point in the history
  • Loading branch information
dsaco committed Aug 9, 2016
1 parent b2006d0 commit 466596f
Show file tree
Hide file tree
Showing 10 changed files with 516 additions and 2 deletions.
37 changes: 37 additions & 0 deletions app/scripts/actions/recommendHomeAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Request from 'superagent'

export const RECEIVE_HOMEADS = 'RECEIVE_HOMEADS'
export const DELETE_HOMEADS = 'DELETE_HOMEADS'

function receiveHomeads(res) {
return {
type: RECEIVE_HOMEADS,
res
}
}
function _deleteHomeAd(id) {
return {
type: DELETE_HOMEADS,
id
}
}

export const fetchHomeads = () => {
return (dispatch) => {
return Request
.get(`/api/recommend/homeads`)
.end(function(err,res){
dispatch(receiveHomeads(res.body.items))
})
}
}

export const deleteHomeAd = (id) => {
return (dispatch) => {
return Request
.del(`/api/recommend/${id}`)
.end((err, res) => {
dispatch(_deleteHomeAd(id))
})
}
}
116 changes: 116 additions & 0 deletions app/scripts/actions/tagAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import Request from 'superagent'

export const TL_RECEIVE_TAG = 'TL_RECEIVE_TAG'
export const TL_RECEIVE_TAG_NEW = 'TL_RECEIVE_TAG_NEW'

export const TL_SET_CLASSIFICATION = 'TL_SET_CLASSIFICATION'
export const TL_REMOVE_CLASSIFICATION = 'TL_REMOVE_CLASSIFICATION'

export const TL_RECOMMEND_TAG = 'TL_RECOMMEND_TAG'
export const TL_DELETE_TAG = 'TL_DELETE_TAG'

function receiveTag(res) {
return {
type: TL_RECEIVE_TAG,
res
}
}
function receiveTagNew(res) {
return {
type: TL_RECEIVE_TAG_NEW,
res
}
}
function _setClassification(tid, cid) {
return {
type: TL_SET_CLASSIFICATION,
tid,
cid
}
}
function _removeClassification(tid, c) {
return {
type: TL_REMOVE_CLASSIFICATION,
tid,
c
}
}
function _recommendTag(tid) {
return {
type: TL_RECOMMEND_TAG,
tid,
}
}
function _deleteTag(tid) {
return {
type: TL_DELETE_TAG,
tid,
}
}
const status = {
filter: '',
page:0,
overload: false,
}
export const fetchTag = (filter) => {

if (filter !== status.filter) {
status.filter = filter
status.page = 0
status.overload = true
} else {
status.overload = false
}
let params = {}
params.page = status.page
if (status.filter !== '') {
params.filter = status.filter
}
return function(dispatch) {
return Request
.get(`/api/tags`)
.query(params)
.end(function(err, res) {
status.page = res.body.nextPage
status.overload ? dispatch(receiveTagNew(res.body)) : dispatch(receiveTag(res.body))
})
}
}

export const setClassification = (tid, cid) => {
return (dispatch, getState) => {
return Request
.post(`/api/tag/${tid}/class/${cid}`)
.end(function(err, res) {
dispatch(_setClassification(tid, cid))
})
}
}
export const removeClassification = (tid, c) => {
return (dispatch, getState) => {
return Request
.del(`/api/tag/${tid}/class/${c}`)
.end(function(err, res) {
dispatch(_removeClassification(tid, c))
})
}
}

export const recommendTag = (tid) => {
return (dispatch) => {
return Request
.post(`/api/recommend/home/${tid}?type=tag`)
.end((err,res) => {
dispatch(_recommendTag(tid))
})
}
}
export const deleteTag = (tid) => {
return (dispatch) => {
return Request
.del(`/api/tag/${tid}`)
.end((err,res) => {
dispatch(_deleteTag(tid))
})
}
}
66 changes: 66 additions & 0 deletions app/scripts/components/RecommendHome/RecommendHome.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React,{ Component } from 'react'
import Reflux from 'reflux'
import { Row, Col } from 'react-bootstrap'
import CDN from '../../widgets/cdn'

export default class RecommendHome extends Component{
constructor(props) {
super(props);

this.state = {}
this.deleteHomeAd = this._deleteHomeAd.bind(this)
}
componentWillMount() {
this.props.fetchHomeads()
}
_deleteHomeAd(id) {
if (confirm('删除这个推荐?')) {
this.props.deleteHomeAd(id)
}
}
render() {

if (this.props.homeads) {
return (
<div className="content">
<Row>
{
this.props.homeads.map( (ad) => {
return (
<Col xs={12} sm={3} lg={3} key={'ad_'+ad.id}>
<div className="box box-widget">
<div className="box-header with-border">
<h3 className="box-title"></h3>
<div className="box-tools pull-right">
<button className="btn btn-box-tool" onClick={() => this.deleteHomeAd(ad.id)}><i className="fa fa-times"></i></button>
</div>
</div>
<div className="box-body">
<ul className="products-list product-list-in-box">
<li className="item">
<div className="product-img">
<img src={ad.image?CDN.show(ad.image):''} alt="Ad Image" />
</div>
<div className="product-info">
<a className="product-title">
{ad.title}
<span className="label label-info pull-right">{ad.type}</span>
</a>
<span className="product-description">{ad.description}</span>
</div>
</li>
</ul>
</div>
</div>
</Col>
)
})
}
</Row>
</div>
)
} else {
return (<div></div>)
}
}
}
17 changes: 17 additions & 0 deletions app/scripts/components/RecommendHome/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { connect } from 'react-redux'
import RecommendHome from './RecommendHome'

import { fetchHomeads, deleteHomeAd } from '../../actions/recommendHomeAction'
const mapActionCreators = {
fetchHomeads,
deleteHomeAd
}

const mapStateToProps = (state) => {
const { homeads } = state.recommendHomeReducer.toJS()
return {
homeads
}
}

export default connect(mapStateToProps, mapActionCreators)(RecommendHome)
Loading

0 comments on commit 466596f

Please sign in to comment.