Skip to content

Commit 3a95319

Browse files
committed
初始化dva项目
1 parent 5489711 commit 3a95319

28 files changed

+11922
-3
lines changed

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.6
1+
8

client-dva/.babelrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"targets": {
5+
"browsers": ["Android >= 4.0", "iOS >= 7"]
6+
}
7+
}],
8+
"babel-preset-stage-0",
9+
"react"
10+
],
11+
"plugins": ["transform-decorators-legacy"],
12+
"ignore": [
13+
"node_modules"
14+
]
15+
}

client-dva/component/footer/footer.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import './footer.less';
2+
import React, { Component } from 'react';
3+
import { Link } from 'dva/router';
4+
5+
export default class extends Component {
6+
constructor () {
7+
super();
8+
}
9+
10+
render () {
11+
return (
12+
<ul className="footer">
13+
<li className="footer-item">
14+
<Link to="/index">
15+
<span className="iconfont icon-zhuye" title="主页"/>
16+
<span className="footer-item-text">主页</span>
17+
</Link>
18+
</li>
19+
<li className="footer-item">
20+
<Link to="/today">
21+
<span className="iconfont icon-liebiao" title="今日列表"/>
22+
<span className="footer-item-text">今日列表</span>
23+
</Link>
24+
</li>
25+
<li className="footer-item">
26+
<Link to="/rank">
27+
<span className="iconfont icon-paixingbang" title="排行榜"/>
28+
<span className="footer-item-text">排行榜</span>
29+
</Link>
30+
</li>
31+
<li className="footer-item">
32+
<Link to="/mine">
33+
<span className="iconfont icon-gerenzhongxin" title="个人中心"/>
34+
<span className="footer-item-text">个人中心</span>
35+
</Link>
36+
</li>
37+
</ul>
38+
)
39+
}
40+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.footer {
2+
display: flex;
3+
position: fixed;
4+
width: 100%;
5+
left: 0;
6+
bottom: 0;
7+
height: 50px;
8+
border-top: 1px solid #ccc;
9+
background-color: #fff;
10+
z-index: 10;
11+
.footer-item {
12+
flex: 1;
13+
}
14+
.footer-item a {
15+
flex: 1;
16+
display: flex;
17+
height: 100%;
18+
flex-direction: column;
19+
align-items: center;
20+
justify-content: center;
21+
color: #666;
22+
.footer-item-text {
23+
font-size: 12px;
24+
}
25+
.iconfont {
26+
27+
}
28+
}
29+
}

client-dva/component/header/header.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import './header.less';
2+
import React, { Component } from 'react';
3+
import { connect } from 'dva';
4+
5+
@connect((state) => {
6+
return {
7+
routing: state.routing
8+
}
9+
})
10+
export default class extends Component {
11+
constructor () {
12+
super();
13+
debugger
14+
}
15+
16+
getTitle () {
17+
// let { location: { pathname } } = this.props.routing;
18+
console.log(this.props.routing, 'header.js router change');
19+
let pathname = '';
20+
switch (pathname) {
21+
case '/index':
22+
return '首页';
23+
break;
24+
default:
25+
return '我是早鸟';
26+
}
27+
}
28+
29+
render () {
30+
return (
31+
<div className="header">
32+
<div className="inner">
33+
{this.getTitle()}
34+
</div>
35+
</div>
36+
)
37+
}
38+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.header {
2+
display: flex;
3+
height: 50px;
4+
background-color: #fff;
5+
align-items: center;
6+
justify-content: center;
7+
border-bottom: 1px solid #f0f0f0;
8+
position: fixed;
9+
width: 100%;
10+
top: 0;
11+
left: 0;
12+
z-index: 10;
13+
.inner {
14+
color: #333;
15+
font-size: 20px;
16+
}
17+
}

client-dva/container/home/home.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React, { Component } from 'react';
2+
import { connect } from 'dva';
3+
import { Link } from 'dva/router';
4+
5+
@connect((state) => {
6+
return {
7+
myinfo: state.myinfo,
8+
count: state.count,
9+
};
10+
})
11+
export default class extends Component {
12+
constructor () {
13+
super();
14+
this.state = {
15+
16+
};
17+
}
18+
19+
componentWillMount () {
20+
this.props.dispatch({
21+
type: 'myinfo/getUserName',
22+
payload: 123,
23+
});
24+
}
25+
26+
render () {
27+
let {userName} = this.props.myinfo;
28+
return (
29+
<div className="page-wrap">
30+
123
31+
{userName}
32+
</div>
33+
)
34+
}
35+
}
36+
import './home.less';

client-dva/container/home/home.less

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.main-page {
2+
padding-top: 100px;
3+
.new-wrap {
4+
height: 70px;
5+
padding: 10px 10px 10px 20px;
6+
cursor: pointer;
7+
margin: 20px 0;
8+
.add-icon {
9+
font-size: 30px;
10+
font-weight: bold;
11+
margin-right: 10px;
12+
}
13+
.add-text {
14+
vertical-align: 1px;
15+
}
16+
}
17+
18+
.recently-wrap {
19+
a:last-child .feed-card-item{
20+
margin-bottom: 20px;
21+
}
22+
}
23+
}

client-dva/container/today/today.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { Component } from 'react';
2+
import { connect } from 'dva';
3+
import { Link } from 'dva/router';
4+
5+
@connect()
6+
export default class extends Component {
7+
constructor () {
8+
super();
9+
this.state = {
10+
11+
};
12+
}
13+
14+
componentWillMount () {
15+
}
16+
17+
render () {
18+
return (
19+
<div className="page-wrap">
20+
today
21+
</div>
22+
)
23+
}
24+
}
25+
import './today.less';

client-dva/container/today/today.less

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.main-page {
2+
padding-top: 100px;
3+
.new-wrap {
4+
height: 70px;
5+
padding: 10px 10px 10px 20px;
6+
cursor: pointer;
7+
margin: 20px 0;
8+
.add-icon {
9+
font-size: 30px;
10+
font-weight: bold;
11+
margin-right: 10px;
12+
}
13+
.add-text {
14+
vertical-align: 1px;
15+
}
16+
}
17+
18+
.recently-wrap {
19+
a:last-child .feed-card-item{
20+
margin-bottom: 20px;
21+
}
22+
}
23+
}

client-dva/container/wrap/wrap.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import './wrap.less';
2+
import React, { Component } from 'react';
3+
import Header from '../../component/header/header';
4+
import Footer from '../../component/footer/footer';
5+
import { connect } from 'dva';
6+
7+
@connect((state) => {
8+
return {
9+
routing: state.routing
10+
}
11+
})
12+
export default class extends Component {
13+
constructor () {
14+
super();
15+
this.state = {
16+
17+
};
18+
}
19+
20+
componentDidMount () {
21+
}
22+
23+
render () {
24+
return (
25+
<div className="app-container">
26+
<Header/>
27+
{this.props.children}
28+
<Footer/>
29+
</div>
30+
)
31+
}
32+
}

client-dva/container/wrap/wrap.less

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import "../../style/index.less";
2+
3+
html, body {
4+
height: 100%;
5+
}
6+
7+
.doc {
8+
height: 100%;
9+
}
10+
11+
.app-container {
12+
height: 100%;
13+
position: relative;
14+
}
15+
16+
.page-wrap {
17+
height: 100%;
18+
padding-top: 50px;
19+
padding-bottom: 50px;
20+
overflow: auto;
21+
}

client-dva/model/count.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
namespace: 'count',
3+
state: 0,
4+
reducers: {
5+
add (count) {
6+
debugger
7+
return count + 1
8+
},
9+
minus(count) { return count - 1 },
10+
},
11+
}

client-dva/model/myInfo.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as CONSTANTS from "../../client-react/redux/actionTypes";
2+
import {ajax} from "../util";
3+
4+
export default {
5+
namespace: 'myinfo',
6+
state: {
7+
userName: null,
8+
avatar: null,
9+
continued: null,
10+
getupTime: null,
11+
rank: null,
12+
uid: null,
13+
},
14+
reducers: {
15+
userName (state, {payload}) {
16+
// console.log(arguments);
17+
// debugger
18+
return {
19+
...state,
20+
...payload
21+
}
22+
}
23+
},
24+
effects: {
25+
*getUserName({payload}, {call, put}) {
26+
let getUserNameAPI = () => {
27+
// console.log(arguments);
28+
return ajax({
29+
url: `//localhost:8333/api/myinfo`,
30+
method: 'get'
31+
}).then(res => {
32+
return res;
33+
}).catch(err => {debugger});
34+
};
35+
36+
let res = yield call(getUserNameAPI, 123, 111, 111)
37+
// debugger
38+
// console.log(payload, res);
39+
// yield put({type: 'count/add', payload: 'add'});
40+
yield put({type: 'userName', payload: res})
41+
},
42+
}
43+
}

0 commit comments

Comments
 (0)