Commit 19710804 by 王树冬

init

parent 4c85e978
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"description": "demo", "description": "demo",
"appid": "wx8566afef50e5f76b", "appid": "wx8566afef50e5f76b",
"setting": { "setting": {
"urlCheck": false, "urlCheck": true,
"es6": false, "es6": false,
"postcss": false, "postcss": false,
"minified": false, "minified": false,
......
...@@ -79,7 +79,11 @@ export function asyncAdd() { ...@@ -79,7 +79,11 @@ export function asyncAdd() {
// 'content-type': 'application/json' // 'content-type': 'application/json'
// } // }
// })) // }))
export const list = createApiAction(LIST, params => api.get('news/list', params)) // export const list = createApiAction(LIST, params => api.get('news/list', params))
export const list = createApiAction(LIST, params => {
console.log('list',params);
return api.get('news/list', params)
})
export default bindActionCreators({ export default bindActionCreators({
list, list,
......
...@@ -27,14 +27,11 @@ import './index.styl' ...@@ -27,14 +27,11 @@ import './index.styl'
state => ({ state => ({
list: state.counter.list, list: state.counter.list,
}), }),
(dispatch) => { (dispatch) => ({
console.log('dispatch', dispatch); getList(params) {
return { dispatch(list(params))
list() {
dispatch(list())
}
} }
}, })
) )
class Index extends Component { class Index extends Component {
...@@ -45,53 +42,69 @@ class Index extends Component { ...@@ -45,53 +42,69 @@ class Index extends Component {
super(props) super(props)
console.log('props', props); console.log('props', props);
// this.state = { date: new Date() } // this.state = { date: new Date() }
props.list() // let params = {
// page: 2, perPage: 2
// }
this.state = {
page: 1, perPage: 10
}
props.getList(this.state)
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps) console.log(this.props, nextProps)
} }
componentWillMount() {
this.props.getList(this.state)
}
componentWillUnmount() { componentWillUnmount() {
} }
componentDidShow() { } componentDidShow() { }
componentDidHide() { } componentDidHide() { }
render() { onShareAppMessage () {
return ( return {
<View className='index'> title: '蜂窝煤',
<View className='news'> path: '/pages/index/index',
<View className='item'> imageUrl: '../../common/image/share.png'
<View className='desc'> }
<View className='title'></View> }
<View className='info'></View> onReachBottom() {
</View> console.log('触发到底部了')
<View className='rightImage'> this.setState({
page: this.state.page + 1
</View> })
</View> const { page, perPage } = this.state
<View> let params = {
{ page: this.state.page + 1, perPage: perPage
this.props.list.map((item, index) => { }
return <View className='item' key={index}> console.log(this.props, 'onReachBottom')
<View className='info'> this.props.getList(params)
<View className='title'>{item.title}</View>
<View className='footer'>
<View className='user'>{item.username}</View>
<View className='comment'>{item.username}</View>
</View>
</View>
<View className='rightImage'><Image calssName='img' src={item.image_url} /></View>
</View>
})
}
</View>
</View>
</View >
)
} }
render() {
return (
<View className='index'>
<View className='news'>
{
this.props.list.map((item, index) => {
return <View className='item' key={index}>
<View className='info'>
<View className='title'>{item.title}</View>
<View className='footer'>
<View className='user'>{item.username}</View>
<View className='comment'>{item.username}</View>
</View>
</View>
<View className='rightImage'><Image calssName='img' src={item.image_url} /></View>
</View>
})
}
</View>
</View >
)
}
} }
export default Index export default Index
...@@ -2,7 +2,7 @@ import { ADD, MINUS, LIST } from '../constants/counter' ...@@ -2,7 +2,7 @@ import { ADD, MINUS, LIST } from '../constants/counter'
const INITIAL_STATE = { const INITIAL_STATE = {
num: 0, num: 0,
list:'' list:[]
} }
export default function counter (state = INITIAL_STATE, action) { export default function counter (state = INITIAL_STATE, action) {
...@@ -19,9 +19,14 @@ export default function counter (state = INITIAL_STATE, action) { ...@@ -19,9 +19,14 @@ export default function counter (state = INITIAL_STATE, action) {
num: state.num - 1 num: state.num - 1
} }
case LIST: case LIST:
let data = state.list.concat(action.payload.data.news)
// Object.assign(state.list, action.payload.data.news)
console.log('data',data)
console.log('state',state)
return { return {
...state, ...state,
list: action.payload.data.news // list: action.payload.data.news
list: data
} }
default: default:
return state return state
......
...@@ -3,7 +3,7 @@ import { HTTP_STATUS, COMMON_STATUS, RESULT_STATUS } from '../const/status.js' ...@@ -3,7 +3,7 @@ import { HTTP_STATUS, COMMON_STATUS, RESULT_STATUS } from '../const/status.js'
// import config from '../config/index.js' // import config from '../config/index.js'
import { logError } from '../utils' import { logError } from '../utils'
const baseURL = "http://beeapi.shudong.wang/v1/" const baseURL = "https://shudong.wang/v1/"
// Taro.request({ // Taro.request({
// url: baseURL + '', // url: baseURL + '',
// data: { // data: {
...@@ -21,6 +21,7 @@ export default { ...@@ -21,6 +21,7 @@ export default {
let { url, data } = params let { url, data } = params
// let token = getApp().globalData.token // let token = getApp().globalData.token
// if (!token) login() // if (!token) login()
console.log('params', params)
let contentType = 'application/x-www-form-urlencoded' let contentType = 'application/x-www-form-urlencoded'
contentType = params.contentType || contentType contentType = params.contentType || contentType
const option = { const option = {
...@@ -41,6 +42,7 @@ export default { ...@@ -41,6 +42,7 @@ export default {
}, },
get(url, data = '') { get(url, data = '') {
let option = { url, data } let option = { url, data }
console.log('data', data)
return this.baseOptions(option) return this.baseOptions(option)
}, },
post: function (url, data, contentType) { post: function (url, data, contentType) {
......
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