Skip to content

Commit

Permalink
feat: change the api, use the egg
Browse files Browse the repository at this point in the history
  • Loading branch information
k-water committed Mar 17, 2018
1 parent bf9f0e3 commit 1c2274b
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 10,321 deletions.
10,225 changes: 0 additions & 10,225 deletions package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@
"eslintConfig": {
"extends": "react-app"
},
"proxy": "http://localhost:8080"
"proxy": "http://localhost:7001"
}
11 changes: 6 additions & 5 deletions src/components/archive/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ class Archive extends Component {
this.getBlogByYear(this.state.year)
}
getBlogByYear(year) {
axios.get('/u/admin/blogs/archive', {
axios.get('/api/archive', {
params: {
year: year
}
})
.then(res => {
if(res.status === 200 && res.data.code === 0) {
this.setState({
data: res.data.body.data,
year: res.data.body.year
data: res.data.data,
year: res.data.year
})
}
})
Expand All @@ -46,6 +46,7 @@ class Archive extends Component {
pageSize: 1,
current: this.state.currentPage,
total: archive.length,
size: 'small',
onChange: ((page, pageSize) => {
this.setState({
currentPage: page
Expand All @@ -66,12 +67,12 @@ class Archive extends Component {
itemLayout="vertical"
header={this.state.year}
pagination={pagination}
dataSource={this.state.data}
dataSource={this.state.data.rows}
className="archive-list"
renderItem={item => (
<List.Item
key={item.title}
extra={timetrans(item.createTime)}
extra={timetrans(item.created_at)}
style={{cursor: 'pointer'}}
>
<List.Item.Meta
Expand Down
19 changes: 10 additions & 9 deletions src/components/collect/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ class Collect extends Component {
document.title = 'Water Blog'
this.getCollectList()
}
getCollectList(pageIndex = 0, pageSize = 10) {
axios.get('/u/star', {
getCollectList(offset = 0, limit = 10) {
axios.get('/api/collect', {
params: {
pageIndex: pageIndex,
pageSize: pageSize
offset,
limit
}
})
.then(res => {
if (res.status === 200 && res.data.code === 0) {
this.setState({
data: res.data.body.data.content,
totalElements: res.data.body.data.totalElements
data: res.data.data,
totalElements: res.data.data.count
})
} else {
message.error(res.data.message)
message.error(res.data.msg)
}
})
.catch(err => {
Expand All @@ -49,13 +49,14 @@ class Collect extends Component {
render() {
const pagination = {
pageSize: 10,
size: 'small',
current: this.state.currentPage,
total: this.state.totalElements,
onChange: ((page, pageSize) => {
this.setState({
currentPage: page
})
this.getCollectList(page - 1)
this.getCollectList(pageSize * (page - 1))
}),
}
return (
Expand All @@ -71,7 +72,7 @@ class Collect extends Component {
header={<div className="collect-header">文章收藏</div>}
itemLayout="vertical"
pagination={pagination}
dataSource={this.state.data}
dataSource={this.state.data.rows}
renderItem={item => (
<List.Item
key={item.title}
Expand Down
24 changes: 12 additions & 12 deletions src/components/comment/commentinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ class CommentInput extends Component {
constructor(props) {
super(props)
this.state = {
commentContent: ''
content: ''
}
this.handleChange = this.handleChange.bind(this)
this.handleSubmit = this.handleSubmit.bind(this)
}
handleChange(event) {
this.setState({
commentContent: event.target.value
content: event.target.value
})
}
handleSubmit() {
if(!this.state.commentContent) {
if(!this.state.content) {
message.error('请先输入内容', 1)
} else if(!Cookies.get("token")) {
message.error('请先登录', 1)
} else {
const blogId = this.props.match.params.id
const userId = Cookies.get("userId")
const username = Cookies.get("username")
const commentContent = this.state.commentContent
const blog_id = this.props.match.params.id
const user_id = Cookies.get('user_id')
const username = Cookies.get('username')
const content = this.state.content
this.props.createComment({
blogId,
userId,
commentContent,
blog_id,
user_id,
content,
username
})
this.setState({
commentContent: ''
content: ''
})
}
}
Expand All @@ -56,7 +56,7 @@ class CommentInput extends Component {
<TextArea
rows={4}
autosize={{minRows: 3}}
value={this.state.commentContent}
value={this.state.content}
ref={(textarea) => this.textarea = textarea}
onChange={this.handleChange}
/>
Expand Down
6 changes: 3 additions & 3 deletions src/components/comment/commentlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class CommentList extends Component {
return (
<div className="comment-list">
{
this.props.desc.comments ?
this.props.desc.comment ?
<List
size="small"
itemLayout="horizontal"
dataSource={this.props.desc.comments}
dataSource={this.props.desc.comment}
renderItem={item => (
<List.Item actions={[
<Tag style={{marginRight: 0}}>{getDateDiff(item.createTime)}</Tag>
<Tag style={{marginRight: 0}}>{getDateDiff(+new Date(item.created_at))}</Tag>
]}>
<List.Item.Meta
avatar={
Expand Down
4 changes: 2 additions & 2 deletions src/components/desc/desc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class Desc extends Component {
</Tag>,
<span style={{marginTop: 10}} key="time">
{
this.props.desc.createTime
? timetrans(this.props.desc.createTime)
this.props.desc.created_at
? timetrans(this.props.desc.created_at)
: null
}
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/headerCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class HeaderCustom extends Component {
onClick={() => {
Cookies.remove("token")
Cookies.remove("username")
Cookies.remove("userId")
Cookies.remove("user_id")
this.props.logout()
}}
>
Expand Down
22 changes: 11 additions & 11 deletions src/components/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class BlogList extends Component {
const tags = this.props.match.params.tags
const catalog = this.props.match.params.catalog
let params = {
order: '',
catalogId: catalog ? catalog : '',
keyword: tags ? tags : '',
pageIndex: 0,
pageSize: 5
offset: 0,
limit: 5,
tags: tags ? tags : '',
catalog_id: catalog ? parseInt(catalog, 10) : '',
order: 'DESC',
}
this.props.getBlogList(params)
}
Expand All @@ -50,11 +50,11 @@ class BlogList extends Component {
currentPage: page
})
let params = {
order: '',
catalogId: catalog ? catalog : '',
keyword: tags ? tags : '',
pageIndex: page - 1,
pageSize: pageSize
offset: pageSize * (page - 1),
limit: 5,
tags: tags ? tags : '',
catalog_id: catalog ? parseInt(catalog, 10) : '',
order: 'DESC'
}
this.props.getBlogList(params)
})
Expand Down Expand Up @@ -108,7 +108,7 @@ class BlogList extends Component {
}/> : null
]}
extra={[
timetrans(item.createTime)
timetrans(item.created_at)
]}
>
<List.Item.Meta
Expand Down
2 changes: 1 addition & 1 deletion src/config/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import NProgress from 'nprogress'
import qs from 'qs'

const API = {
ROOT: process.env.NODE_ENV === 'development' ? '/' : 'http://119.29.151.195:8080'
ROOT: process.env.NODE_ENV === 'development' ? '/' : 'http://119.29.151.195:7002'
}
axios.defaults.baseURL = API.ROOT
axios.interceptors.request.use(function (config) {
Expand Down
8 changes: 4 additions & 4 deletions src/containers/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class Login extends Component {
this.handleChange = this.handleChange.bind(this)
}
login({username, password}) {
axios.post('/users/login', {
axios.post('/api/users/login', {
username,
password
}, {withCredentials:true})
}, { withCredentials: true })
.then(res => {
if(res.status === 200 && res.data.code === 0) {
this.props.loginSuccess(res.data)
Expand All @@ -38,8 +38,8 @@ class Login extends Component {
password: ''
})
} else {
this.props.loginFailure(res.data.message)
message.error(res.data.message, 1)
this.props.loginFailure(res.data.msg)
message.error(res.data.msg, 1)
}
})
.catch(err => {
Expand Down
8 changes: 4 additions & 4 deletions src/containers/register/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class Register extends Component {
this.handleChange = this.handleChange.bind(this)
}
register({username, password}) {
axios.post('/users', {
axios.post('/api/users', {
username,
password
})
.then(res => {
if (res.status === 200 && res.data.code === 0) {
if (res.status === 201 && res.data.code === 0) {
this.props.registerSuccess(res.data)
this.props.handleCancel()
message.success('注册成功, 请登录~', 1)
Expand All @@ -39,8 +39,8 @@ class Register extends Component {
password: ''
})
} else {
this.props.registerFailue(res.data.message)
message.error(res.data.message, 1)
this.props.registerFailue(res.data.msg)
message.error(res.data.msg, 1)
}
})
.catch(err => {
Expand Down
Loading

0 comments on commit 1c2274b

Please sign in to comment.