Skip to content

Commit 1d79ffd

Browse files
author
Z-wave
committed
index redux
1 parent 05bb25c commit 1d79ffd

16 files changed

+9698
-166
lines changed

README.md

+2,228
Large diffs are not rendered by default.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"react-grid-layout": "^0.10.0-beta1",
3434
"react-router": "^4.2.0",
3535
"react-router-dom": "^4.2.2",
36+
"react-redux": "^5.0.7",
37+
"redux": "^3.7.2",
38+
"redux-thunk": "^2.2.0",
3639
"sass-loader": "^6.0.6",
3740
"style-loader": "0.19.0",
3841
"sw-precache-webpack-plugin": "0.11.4",

react-example.rar

-126 KB
Binary file not shown.

src/assets/scss/common.scss

+6-6
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ $view-width:640px !default;
104104
//*font------------------------------------------------------------------------------*/
105105
@font-face {
106106
font-family: 'iconfont'; /* project id 580276 */
107-
src: url('//at.alicdn.com/t/font_580276_eu3j0dmg7pe0o1or.eot');
108-
src: url('//at.alicdn.com/t/font_580276_eu3j0dmg7pe0o1or.eot?#iefix') format('embedded-opentype'),
109-
url('//at.alicdn.com/t/font_580276_eu3j0dmg7pe0o1or.woff') format('woff'),
110-
url('//at.alicdn.com/t/font_580276_eu3j0dmg7pe0o1or.ttf') format('truetype'),
111-
url('//at.alicdn.com/t/font_580276_eu3j0dmg7pe0o1or.svg#iconfont') format('svg');
112-
}
107+
src: url('//at.alicdn.com/t/font_580276_ts03f1ux1tdl5wmi.eot');
108+
src: url('//at.alicdn.com/t/font_580276_ts03f1ux1tdl5wmi.eot?#iefix') format('embedded-opentype'),
109+
url('//at.alicdn.com/t/font_580276_ts03f1ux1tdl5wmi.woff') format('woff'),
110+
url('//at.alicdn.com/t/font_580276_ts03f1ux1tdl5wmi.ttf') format('truetype'),
111+
url('//at.alicdn.com/t/font_580276_ts03f1ux1tdl5wmi.svg#iconfont') format('svg');
112+
}
113113
%iconfont{
114114
font-family:"iconfont"!important;
115115
font-size:R(16);

src/assets/scss/wallet.scss

-25
This file was deleted.

src/assets/scss/zmxy.scss

-48
This file was deleted.

src/components/common/common.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
global.ROOT_URL = process.env.NODE_ENV !== 'production' ? '' : 'https://cnodejs.org/api';
22

3+
global.isLoad = true
4+
35
global.getQueryString = function(name){
46
return decodeURIComponent((new RegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(location.href)||[,""])[1].replace(/\+/g,'%20'))||null;
57
}

src/components/common/index.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class Header extends Component {
2222
<header className="index-bar">
2323
{back}
2424
<span className="title">{title}</span>
25-
<a className="iconfont question"></a>
2625
</header>
2726
);
2827
}

src/router/index.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import React from 'react';
22
import { BrowserRouter, HashRouter, Switch, Route, Redirect} from 'react-router-dom';
33

44
import home from '../views/index';
5-
import product from '../views/order/product';
5+
import detail from '../views/detail';
66

77

88
const routes = [
99
{ path: '/',
1010
exact: true,
1111
component: home
1212
},
13-
{ path: '/order/product',
13+
{ path: '/detail/:id',
1414
exact: false,
15-
component: product
15+
component: detail
1616
}
1717
];
1818

src/store/actions.jsx

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1+
import axios from 'axios';
2+
13
export function setPageTitle (data) {
24
return (dispatch, getState) => {
35
dispatch({ type: 'SET_PAGE_TITLE', data: data })
46
}
5-
}
7+
}
68

7-
export function setInfoList (data) {
9+
export function setIndexList (data) {
810
return (dispatch, getState) => {
9-
// 使用fetch实现异步请求
10-
// window.fetch('/api/getInfoList', {
11-
// method: 'GET',
12-
// headers: {
13-
// 'Content-Type': 'application/json'
14-
// }
15-
// }).then(res => {
16-
// return res.json()
17-
// }).then(data => {
18-
// let { code, data } = data
19-
// if (code === 0) {
20-
// dispatch({ type: 'SET_INFO_LIST', data: data })
21-
// }
22-
// })
11+
axios.get('/v1/topics',{
12+
params:data
13+
}).then(data => {
14+
if(data.status == 200){
15+
dispatch({ type: 'SET_INDEX_LIST', data: data.data.data })
16+
global.isLoad = true
17+
}
18+
})
2319
}
24-
}
20+
}

src/store/index.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
// applyMiddleware: redux通过该函数来使用中间件
2+
// createStore: 用于创建store实例
13
import { applyMiddleware, createStore } from 'redux'
4+
5+
// 中间件,作用:如果不使用该中间件,当我们dispatch一个action时,需要给dispatch函数传入action对象;但如果我们使用了这个中间件,那么就可以传入一个函数,这个函数接收两个参数:dispatch和getState。这个dispatch可以在将来的异步请求完成后使用,对于异步action很有用
26
import thunk from 'redux-thunk'
3-
import reducers from './reducers.jsx'
7+
8+
// 引入reducer
9+
import reducers from './reducers'
410

511
// 创建store实例
612
let store = createStore(
713
reducers,
14+
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
815
applyMiddleware(thunk)
916
)
1017

src/store/reducers.jsx

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
import { combineReducers } from 'redux'
2-
import defaultState from './state.jsx'
1+
// 工具函数,用于组织多个reducer,并返回reducer集合
2+
import {combineReducers} from 'redux'
3+
// 默认值
4+
import defaultState from './state'
35

4-
function pageTitle (state = defaultState.pageTitle, action) {
5-
switch (action.type) {
6-
case 'SET_PAGE_TITLE':
7-
return action.data
8-
default:
9-
return state
10-
}
6+
// 一个reducer就是一个函数
7+
function pageTitle(state = defaultState.pageTitle, action) {
8+
// 不同的action有不同的处理逻辑
9+
switch (action.type) {
10+
case 'SET_PAGE_TITLE':
11+
return action.data
12+
default:
13+
return state
14+
}
1115
}
1216

13-
function infoList (state = defaultState.infoList, action) {
14-
switch (action.type) {
15-
case 'SET_INFO_LIST':
16-
return action.data
17-
default:
18-
return state
19-
}
17+
function indexList(state = defaultState.indexList, action) {
18+
switch (action.type) {
19+
case 'SET_INDEX_LIST':
20+
return action.data
21+
default:
22+
return state
23+
}
2024
}
2125

2226
// 导出所有reducer
23-
export default combineReducers({
24-
pageTitle,
25-
infoList
26-
})
27+
export default combineReducers({pageTitle, indexList})

src/store/state.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export default {
22
pageTitle: '首页',
3-
infoList: []
3+
indexList: []
44
}

src/views/detail.jsx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { Component } from 'react';
2+
import {Route,BrowserRouter, Switch,Link} from 'react-router-dom';
3+
import axios from 'axios';
4+
import {Header,Footer} from '../components/common/index';
5+
6+
class App extends React.Component {
7+
constructor(props) {
8+
super(props);
9+
this.state = {
10+
data:{
11+
author:{}
12+
}
13+
};
14+
}
15+
16+
componentDidMount() {
17+
let id = this.props.match.params.id
18+
19+
axios.get('/v1/topic/'+id).then((res)=>{
20+
this.setState({
21+
data:res.data.data
22+
})
23+
})
24+
}
25+
26+
27+
render() {
28+
let {author} = this.state.data
29+
console.log(author);
30+
return (
31+
<div id="wrapper" className="spacing">
32+
<Header title="主题详情" leftTo="/" />
33+
<div className="box box-items">
34+
<div className="pic">
35+
<img src={author.avatar_url} alt="" />
36+
</div>
37+
<div className="flex-1 ml5">
38+
<p>{author.loginname}</p>
39+
<p>1天前</p>
40+
</div>
41+
<div className="flex-1 text-right">
42+
<p>7/849</p>
43+
<p>2小时前</p>
44+
</div>
45+
</div>
46+
<Footer />
47+
</div>
48+
);
49+
}
50+
}
51+
52+
53+
export default App;

0 commit comments

Comments
 (0)