Skip to content

Commit 1e7432c

Browse files
author
Z-wave
committed
actionCreator
1 parent d9cf625 commit 1e7432c

21 files changed

+136
-171
lines changed

dist/asset-manifest.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"main.css": "static/css/main.c17080f1.css",
3-
"main.js": "static/js/main.fd0901f1.js",
4-
"static\\media\\logo.svg": "static/media/logo.5d5d9eef.svg"
2+
"main.js": "static/js/main.js?76d1b232"
53
}

dist/favicon.ico

-3.78 KB
Binary file not shown.

dist/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>React App</title><link href="/static/css/main.c17080f1.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/static/js/main.fd0901f1.js"></script></body></html>
1+
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><title>react-example</title></head><body><div id="viewport" class="viewport"></div><script type="text/javascript" src="static/js/main.js?76d1b232"></script></body></html>

dist/manifest.json

-15
This file was deleted.

dist/service-worker.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/static/css/main.c17080f1.css

-1
This file was deleted.

dist/static/js/main.fd0901f1.js

-1
This file was deleted.

dist/static/js/main.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/static/media/logo.5d5d9eef.svg

-7
This file was deleted.

src/App.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ReactDOM from 'react-dom';
44
import Router from './router';
55
import axios from 'axios';
66
import { Provider } from 'react-redux'
7-
import store from './store/store'
7+
import store from './redux/store'
88

99
import './components/common/common';
1010
import './assets/scss/common.scss';

src/redux/actionCreator/index.jsx

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import axios from 'axios'
2+
3+
export default {
4+
getIndexData:(data) => {
5+
return async (dispatch,getstate) => {
6+
try {
7+
const res = await axios.get('/v1/topics',{params:data})
8+
9+
if(res.status == 200){
10+
dispatch({
11+
type: "GET_INDEXLIST",
12+
data: res.data.data
13+
});
14+
}
15+
}catch(e){
16+
throw new Error('axios failure')
17+
}
18+
}
19+
},
20+
getDetailData:(id) => {
21+
return async (dispatch,getstate) => {
22+
try {
23+
const res = await axios.get('/v1/topic/'+id)
24+
25+
if(res.status == 200){
26+
console.log(res);
27+
dispatch({
28+
type: "GET_DETAIL",
29+
data: res.data.data
30+
});
31+
}
32+
}catch(e){
33+
throw new Error('axios failure')
34+
}
35+
}
36+
}
37+
}

src/redux/actions/detail.jsx

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function detailList(state={data: {}},action) {
2+
switch(action.type){
3+
case "GET_DETAIL":
4+
return action.data
5+
6+
default:
7+
return state;
8+
}
9+
}

src/redux/actions/indexList.jsx

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function topList(state=[],action) {
2+
switch(action.type){
3+
case "GET_INDEXLIST":
4+
return action.data
5+
default:
6+
return state;
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {combineReducers} from "redux";
2-
import indexList from "./indexList";
3-
import detailList from "./detailList";
2+
import indexList from "../actions/indexList";
3+
import detail from "../actions/detail";
44

55
let Reducers = combineReducers({
66
indexList,
7-
detailList
7+
detail
88
});
99
export default Reducers;

src/store/store.jsx src/redux/store/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {createStore, applyMiddleware} from "redux"
22
import thunk from "redux-thunk"
3-
import Reducers from "./reducers"
3+
import Reducers from "../reducers"
44

55
const store = createStore(Reducers,applyMiddleware(thunk));
66

src/router/index.jsx

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

44
import home from '../views/index/index';
5-
import detail from '../views/detail/detail';
5+
import detail from '../views/detail';
66
import signin from '../views/user/signin';
77
import user from '../views/user/index';
88

src/store/detailList.jsx

-12
This file was deleted.

src/store/indexList.jsx

-14
This file was deleted.

src/views/detail/detail.jsx

-76
This file was deleted.

src/views/detail/index.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 { connect } from 'react-redux'
5+
import {Header,Footer,Profile} from '../../components/common/index';
6+
import ReplyList from "./replies";
7+
import actionCreator from '../../redux/actionCreator'
8+
9+
class App extends React.Component {
10+
constructor(props) {
11+
super(props);
12+
}
13+
14+
componentDidMount() {
15+
let { dispatch,match } = this.props
16+
17+
dispatch(actionCreator.getDetailData(match.params.id));
18+
}
19+
20+
render() {
21+
let {detail} = this.props
22+
let {author = {},replies = []} = detail
23+
24+
return (
25+
<div id="wrapper" className="spacing">
26+
<Header title="主题详情" leftTo="/" />
27+
<div className="artcle p10">
28+
<Profile
29+
author={author}
30+
create_at={detail.create_at}
31+
reply_count={detail.reply_count}
32+
visit_count={detail.visit_count}
33+
last_reply_at={detail.last_reply_at}
34+
/>
35+
</div>
36+
<h1 className="fs20 bg-gray p10">{detail.title}</h1>
37+
<div className="p10" dangerouslySetInnerHTML={{__html:detail.content}}></div>
38+
<div className="box box-items reply_count">
39+
<div className="color-block"></div>
40+
<div className="flex-1 ml10">
41+
<b className="ml5 mr5 color">{detail.reply_count}</b>条回复
42+
</div>
43+
</div>
44+
<ul className="re-list">
45+
<ReplyList replies = {replies}></ReplyList>
46+
</ul>
47+
<Footer />
48+
</div>
49+
)
50+
}
51+
}
52+
53+
export default connect(state => state)(App);

0 commit comments

Comments
 (0)