From fbce84c580bbd8edf8ae45b62813ba561109059d Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 24 Mar 2023 11:30:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(components):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95=E6=8E=92=E5=BA=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/chats/_account.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pages/chats/_account.vue b/pages/chats/_account.vue index a515cc0..0798f47 100644 --- a/pages/chats/_account.vue +++ b/pages/chats/_account.vue @@ -8,7 +8,7 @@ 发送 - +
@@ -167,6 +167,9 @@ export default { content: await _ts.contentEditor.getHTML() } _ts.messages.push(message); + _ts.messages.sort((a, b) => { + return b.dataId - a.dataId; + }); _ts.contentEditor.setValue('') _ts.$axios.$post('/api/openai/chat', { message: message.content @@ -178,6 +181,9 @@ export default { dataId: new Date().getTime(), content: res[0].message.content }); + _ts.messages.sort((a, b) => { + return b.dataId - a.dataId; + }); }); } }, From e1686c9c6ff1c14e9bc9fb1239430d84a10201a4 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 24 Mar 2023 11:59:37 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(components):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=88=86=E9=A1=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index a5f4999..8a85999 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -20,7 +20,7 @@ export default { }, watch: { '$route'(to, from) { - if (from.query.page && to.query.page) { + if ((to.query.page || 1) !== (from.query.page || 1)) { this.$router.go() } } From 1fff1791ecf58bd5e4d8088a99a7e3a0d985e423 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 24 Mar 2023 15:20:25 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat(components):=20=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=A2=9E=E5=8A=A0=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/common/comment/main.vue | 46 +++++++++++++++++++------- pages/article/_article_id.vue | 5 +-- store/comment.js | 53 +++++++++++++----------------- 3 files changed, 58 insertions(+), 46 deletions(-) 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)