:bugs: 返回上一页丢失分页信息问题修复

This commit is contained in:
ronger 2021-02-03 16:10:57 +08:00
parent 30e8cc41bb
commit dbb14c0874
6 changed files with 173 additions and 81 deletions

View File

@ -31,7 +31,7 @@
methods: { methods: {
handleSelectTopic(item) { handleSelectTopic(item) {
this.$router.push({ this.$router.push({
path: '/topic/' + item path: `/topic/${item}?page=1`
}); });
} }
} }

View File

@ -182,7 +182,7 @@ export default {
switch (item) { switch (item) {
case 'topic': case 'topic':
_ts.$router.push({ _ts.$router.push({
path: '/topic/news' path: '/topic/news?page=1'
}) })
break; break;
case 'github': case 'github':

View File

@ -4,31 +4,43 @@
</div> </div>
</template> </template>
<script> <script>
import ArticleList from '~/components/archive/list' import ArticleList from '~/components/archive/list'
import {mapState} from 'vuex'; import {mapState} from 'vuex';
export default { export default {
name: 'Index', name: 'Index',
fetch() { fetch({store, query}) {
return this.$store.dispatch('article/fetchList', {page: 1}) return Promise.all([
}, store.dispatch('article/fetchList', {page: query.page || 1})
components: { ])
ArticleList },
}, watch: {
computed: { '$route.query': function () {
...mapState({ this.$store.dispatch('article/fetchList', {page: this.$route.query.page || 1})
articles: state => state.article.list.data
})
},
methods: {
currentChangeArticle(page) {
this.$store.dispatch('article/fetchList', {page: page})
}
},
mounted() {
this.$store.commit('setActiveMenu', 'index')
} }
},
components: {
ArticleList
},
computed: {
...mapState({
articles: state => state.article.list.data
})
},
methods: {
currentChangeArticle(page) {
this.$router.push({
name: 'index',
query: {
page: page
}
})
}
},
mounted() {
this.$store.commit('setActiveMenu', 'index')
} }
}
</script> </script>
<style> <style>

View File

@ -43,7 +43,8 @@
validate({params, store}) { validate({params, store}) {
return params.portfolio_id && !isNaN(Number(params.portfolio_id)) return params.portfolio_id && !isNaN(Number(params.portfolio_id))
}, },
fetch({store, params, error}) { fetch({store, params, query, error}) {
params.page = query.page || 1
return Promise.all([ return Promise.all([
store store
.dispatch('portfolio/fetchDetail', params) .dispatch('portfolio/fetchDetail', params)
@ -51,6 +52,14 @@
store.dispatch('portfolio/fetchArticleList', params) store.dispatch('portfolio/fetchArticleList', params)
]) ])
}, },
watch: {
'$route.query': function () {
this.$store.dispatch('portfolio/fetchArticleList', {
page: this.$route.query.page || 1,
portfolio_id: this.routePortfolioId
})
}
},
computed: { computed: {
...mapState({ ...mapState({
portfolio: state => state.portfolio.detail.data, portfolio: state => state.portfolio.detail.data,
@ -134,7 +143,11 @@
) )
}, },
currentChangeArticle(page) { currentChangeArticle(page) {
this.$store.dispatch('portfolio/fetchArticleList', {page: page, portfolio_id: this.routePortfolioId}) this.$router.push(
{
path: `/portfolio/${this.routePortfolioId}?page=${page}`
}
)
} }
}, },
mounted() { mounted() {

View File

@ -1,62 +1,77 @@
<template> <template>
<div class="topic-archive-page"> <div class="topic-archive-page">
<topic-nav :currentTopic="defaultParams.topic_uri"></topic-nav> <topic-nav :currentTopic="defaultParams.topic_uri"></topic-nav>
<article-list :articles="articles" @currentChange="currentChangeArticle"/> <article-list :articles="articles" @currentChange="currentChangeArticle"></article-list>
</div> </div>
</template> </template>
<script> <script>
import ArticleList from '~/components/archive/list' import ArticleList from '~/components/archive/list'
import {mapState} from 'vuex'; import {mapState} from 'vuex';
export default { export default {
name: "topicArticleList", name: "topicArticleList",
components: { components: {
ArticleList ArticleList
}, },
validate({params, store}) { validate({params, store}) {
if (params.topic_uri === 'news') { if (params.topic_uri === 'news') {
return true;
}
return params.topic_uri && store.state.topic.data.some(
topic => topic.topicUri === params.topic_uri
)
},
fetch({store, params, query}) {
params.page = query.page || 1
return Promise.all([
store.dispatch('article/fetchList', params)
])
},
watch: {
'$route.query': function () {
let _ts = this
_ts.$store.dispatch('article/fetchList', {
topic_uri: _ts.defaultParams.topic_uri,
page: _ts.defaultParams.page || 1
})
}
},
computed: {
...mapState({
articles: state => state.article.list.data
}),
currentTopic() {
if (this.$route.params.topic_uri === 'news') {
return true; return true;
} }
return params.topic_uri && store.state.topic.data.some( return this.$store.state.topic.data.find(
topic => topic.topicUri === params.topic_uri topic => topic.topicUri === this.$route.params.topic_uri
) )
}, },
fetch({store, params}) { defaultParams() {
return store.dispatch('article/fetchList', params) return {
}, topic_uri: this.$route.params.topic_uri,
computed: { page: this.$route.query.page || 1
...mapState({
articles: state => state.article.list.data
}),
currentTopic() {
if (this.$route.params.topic_uri === 'news') {
return true;
}
return this.$store.state.topic.data.find(
topic => topic.topicUri === this.$route.params.topic_uri
)
},
defaultParams() {
return {
topic_uri: this.$route.params.topic_uri
}
}
},
methods: {
currentChangeArticle(page) {
this.$store.dispatch('article/fetchList', {page: page, topic_uri: this.defaultParams.topic_uri})
}
},
mounted() {
this.$store.commit('setActiveMenu', 'topic');
},
created() {
if (!this.currentTopic) {
this.$router.back()
} }
} }
},
methods: {
currentChangeArticle(page) {
this.$router.push({
path: `/topic/${this.defaultParams.topic_uri}?page=${page}`
})
}
},
mounted() {
this.$store.commit('setActiveMenu', 'topic');
},
created() {
if (!this.currentTopic) {
this.$router.back()
}
} }
}
</script> </script>
<style scoped> <style scoped>

View File

@ -12,11 +12,24 @@
<h3 class="mb-3">{{ user.nickname }}</h3> <h3 class="mb-3">{{ user.nickname }}</h3>
<p class="mb-4" v-html="user.signature"></p> <p class="mb-4" v-html="user.signature"></p>
<div v-if="userExtend" style="margin-bottom: 1rem;"> <div v-if="userExtend" style="margin-bottom: 1rem;">
<el-link v-if="userExtend.blog" class="user-link" title="博客" :underline="false" :href="userExtend.blog" target="_blank"><font-awesome-icon :icon="['fas', 'link']"></font-awesome-icon></el-link> <el-link v-if="userExtend.blog" class="user-link" title="博客" :underline="false" :href="userExtend.blog"
<el-link v-if="userExtend.github" class="user-link" title="github" :underline="false" :href="'https://github.com/' + userExtend.github" target="_blank"><font-awesome-icon :icon="['fab', 'github']"></font-awesome-icon></el-link> target="_blank">
<el-link v-if="userExtend.weibo" class="user-link" title="微博" :underline="false" :href="'https://weibo.com/n/' + userExtend.weibo" target="_blank"><font-awesome-icon :icon="['fab', 'weibo']"></font-awesome-icon></el-link> <font-awesome-icon :icon="['fas', 'link']"></font-awesome-icon>
<el-link v-if="userExtend.weixin" class="user-link" title="微信" :underline="false" :href="userExtend.weixin"><font-awesome-icon :icon="['fab', 'weixin']" target="_blank"></font-awesome-icon></el-link> </el-link>
<el-link v-if="userExtend.qq" class="user-link" title="QQ" :underline="false" :href="userExtend.qq"><font-awesome-icon :icon="['fab', 'qq']" target="_blank"></font-awesome-icon></el-link> <el-link v-if="userExtend.github" class="user-link" title="github" :underline="false"
:href="'https://github.com/' + userExtend.github" target="_blank">
<font-awesome-icon :icon="['fab', 'github']"></font-awesome-icon>
</el-link>
<el-link v-if="userExtend.weibo" class="user-link" title="微博" :underline="false"
:href="'https://weibo.com/n/' + userExtend.weibo" target="_blank">
<font-awesome-icon :icon="['fab', 'weibo']"></font-awesome-icon>
</el-link>
<el-link v-if="userExtend.weixin" class="user-link" title="微信" :underline="false" :href="userExtend.weixin">
<font-awesome-icon :icon="['fab', 'weixin']" target="_blank"></font-awesome-icon>
</el-link>
<el-link v-if="userExtend.qq" class="user-link" title="QQ" :underline="false" :href="userExtend.qq">
<font-awesome-icon :icon="['fab', 'qq']" target="_blank"></font-awesome-icon>
</el-link>
</div> </div>
<div v-if="oauth"> <div v-if="oauth">
<div v-if="oauth.idUser !== user.idUser"> <div v-if="oauth.idUser !== user.idUser">
@ -72,7 +85,8 @@ export default {
validate({params, store}) { validate({params, store}) {
return params.nickname return params.nickname
}, },
fetch({store, params, error}) { fetch({store, params, query, error}) {
params.page = query.page || 1
return Promise.all([ return Promise.all([
store store
.dispatch('user/fetchDetail', params) .dispatch('user/fetchDetail', params)
@ -84,6 +98,38 @@ export default {
store.dispatch('user/fetchFollowingList', params) store.dispatch('user/fetchFollowingList', params)
]) ])
}, },
watch: {
'$route.query': function () {
let _ts = this;
_ts.$set(_ts, 'activeTab', _ts.$route.query.tab)
switch (_ts.activeTab) {
case "0":
_ts.$store.dispatch('user/fetchArticleList', {
nickname: this.$route.params.nickname,
page: this.$route.query.page || 1
})
break;
case "1":
_ts.$store.dispatch('user/fetchPortfolioList', {
nickname: this.$route.params.nickname,
page: this.$route.query.page || 1
})
break;
case "2":
_ts.$store.dispatch('user/fetchFollowerList', {
nickname: this.$route.params.nickname,
page: this.$route.query.page || 1
})
break;
default:
_ts.$store.dispatch('user/fetchFollowingList', {
nickname: this.$route.params.nickname,
page: this.$route.query.page || 1
})
break
}
}
},
computed: { computed: {
...mapState({ ...mapState({
user: state => state.user.data, user: state => state.user.data,
@ -103,19 +149,25 @@ export default {
}, },
methods: { methods: {
currentChangeArticle(page) { currentChangeArticle(page) {
this.$store.dispatch('user/fetchArticleList', {page: page, nickname: this.$route.params.nickname}) this.onRouter(0, page)
}, },
currentChangePortfolio(page) { currentChangePortfolio(page) {
this.$store.dispatch('user/fetchPortfolioList', {page: page, nickname: this.$route.params.nickname}) this.onRouter(1, page)
}, },
currentChangeFollowing(page) { currentChangeFollowing(page) {
this.$store.dispatch('user/fetchFollowingList', {page: page, nickname: this.$route.params.nickname}) this.onRouter(2, page)
}, },
currentChangeFollower(page) { currentChangeFollower(page) {
this.$store.dispatch('user/fetchFollowerList', {page: page, nickname: this.$route.params.nickname}) this.onRouter(3, page)
}, },
handleToggleTab(key) { handleToggleTab(key) {
this.$set(this, 'activeTab', key); this.onRouter(key, 1)
},
onRouter(key, page) {
this.$router.push({
path: `/user/${this.$route.params.nickname}?tab=${key}&page=${page}`
})
}, },
gotoChats() { gotoChats() {
let _ts = this; let _ts = this;