diff --git a/components/common/comment/main.vue b/components/common/comment/main.vue
index 6e1f978..4d58be1 100644
--- a/components/common/comment/main.vue
+++ b/components/common/comment/main.vue
@@ -33,7 +33,7 @@
后发布评论
-
+
@@ -131,6 +131,19 @@
+
+
+
+
+
+
@@ -155,23 +168,19 @@ export default {
title: {
type: String,
default: ''
- },
- postId: {
- type: Number,
- required: true
}
},
fetch() {
- let {store} = this.$nuxt.context
+ let {store, params, query} = this.$nuxt.context
return Promise.all([
- store.dispatch('comment/fetchList', {post_id: this.postId})
+ store.dispatch('comment/fetchList', {post_id: params.article_id, page: query.page})
])
},
computed: {
...mapState({
- comment: state => state.comment.data,
- isFetchingComment: state => state.comment.fetching,
- isPostingComment: state => state.comment.posting,
+ comments: state => state.comment.list.data,
+ isFetchingComment: state => state.comment.list.fetching,
+ // isPostingComment: state => state.comment.posting,
constants: state => state.global.constants,
language: state => state.global.language,
isMobile: state => state.global.isMobile,
@@ -200,7 +209,8 @@ export default {
loading: false,
commentOriginalCommentId: 0,
commentAuthorAvatar: '',
- commentTitle: ''
+ commentTitle: '',
+ postId: 0
}
},
methods: {
@@ -384,10 +394,19 @@ export default {
},
isAuthor(commentAuthorId) {
return this.authorId === commentAuthorId;
+ },
+ currentChange(page) {
+ this.$router.push({
+ path: `/article/${this.postId}`,
+ query: {
+ page: page
+ }
+ })
}
},
async mounted() {
let _ts = this;
+ _ts.$set(_ts, 'postId', _ts.$route.params.article_id);
_ts.$store.commit('setActiveMenu', 'post-article');
if (_ts.loggedIn) {
const responseData = await _ts.$axios.$get('/api/upload/token');
@@ -450,6 +469,11 @@ export default {
if (isFetching) {
this.cancelCommentReply()
}
+ },
+ '$route'(to, from) {
+ if ((to.query.page || 1) !== (from.query.page || 1)) {
+ this.$fetch()
+ }
}
},
destroyed() {
diff --git a/pages/article/_article_id.vue b/pages/article/_article_id.vue
index c92d0af..6447cc2 100644
--- a/pages/article/_article_id.vue
+++ b/pages/article/_article_id.vue
@@ -145,7 +145,7 @@
+ :authorId="article.articleAuthorId" @gotoLogin="gotoLogin">
@@ -207,9 +207,6 @@ export default {
},
isAdmin() {
return this.$auth.hasScope('admin') || this.$auth.hasScope('blog_admin');
- },
- routeArticleId() {
- return Number(this.$route.params.article_id);
}
},
head() {
diff --git a/store/comment.js b/store/comment.js
index 8474c2c..e0c4472 100644
--- a/store/comment.js
+++ b/store/comment.js
@@ -9,34 +9,30 @@ export const LIKE_COMMENT_API_PATH = '/like/comment'
const getDefaultListData = () => {
return {
- data: [],
+ comments: [],
pagination: {}
}
}
export const state = () => {
return {
- fetching: false,
- posting: false,
- data: getDefaultListData()
+ list: {
+ fetching: false,
+ data: getDefaultListData()
+ }
}
}
export const mutations = {
// 请求列表
updateListFetching(state, action) {
- state.fetching = action
+ state.list.fetching = action
},
updateListData(state, action) {
- state.data = {
- data: action,
- pagination: {
- page: 1
- }
- }
+ state.list.data = action
},
clearListData(state) {
- state.data = getDefaultListData()
+ state.list.data = getDefaultListData()
},
// 发布评论
@@ -59,28 +55,23 @@ export const mutations = {
}
export const actions = {
- fetchList({ commit, rootState }, params = {}) {
- // const { SortType } = rootState.global.constants
-
- // 修正参数
- // params = Object.assign(
- // {
- // page: 1,
- // per_page: 88
- // },
- // params
- // )
-
- // const isRestart = params.page === 1
- // const isDescSort = params.sort === SortType.Desc
-
- // 清空数据
- // isRestart && commit('updateListData', getDefaultListData())
- // commit('updateListData', getDefaultListData())
+ fetchList({ commit, state }, params = {}) {
+ // 清空已有数据
commit('updateListFetching', true)
+ let currentData = JSON.parse(JSON.stringify(state)).list.data
+ if (Number(params.page) === currentData.pageNum) {
+ commit('updateListFetching', false)
+ return
+ }
+ let data = {
+ page: params.page || 1
+ }
+ commit('updateListData', getDefaultListData())
return this.$axios
- .$get(COMMENT_API_PATH + `${params.post_id}/comments`)
+ .$get(COMMENT_API_PATH + `${params.post_id}/comments`, {
+ params: data
+ })
.then(response => {
// isDescSort && response.result.data.reverse()
commit('updateListData', response)