Merge pull request #57 from ronger-x/master

🐛 从用户主页离开提示用户不存在问题修复
This commit is contained in:
ronger 2022-10-30 22:50:18 +08:00 committed by GitHub
commit 84107dacfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 372 additions and 365 deletions

View File

@ -44,14 +44,16 @@
<el-col style="margin-left: 1rem;">
<el-col v-show="comment.commentOriginalCommentId">
<el-col :span="16">
<el-link :underline="false" @click="onRouter('user', comment.commenter.userAccount)" class="text-default"
<el-link :underline="false" @click="onRouter('user', comment.commenter.userAccount)"
class="text-default"
rel="nofollow">{{ comment.commenter.userNickname }}
</el-link>
<small class="text-default" style="margin: 0 0.2rem">回复了</small><span
style="font-weight: bold;"> {{ comment.commentOriginalAuthorNickname }}</span>
</el-col>
<el-col :span="8" class="text-right" style="padding-right: 1rem;">
<el-link :underline="false" @click.native="toggleShowOriginalComment(comment.commentOriginalCommentId)" rel="nofollow"
<el-link :underline="false"
@click.native="toggleShowOriginalComment(comment.commentOriginalCommentId)" rel="nofollow"
title="查看原评论"><i
class="el-icon-reading"></i> 查看原评论
</el-link>
@ -63,7 +65,8 @@
</el-col>
<el-col v-show="!comment.commentOriginalCommentId">
<el-col :span="16">
<el-link :underline="false" @click="onRouter('user', comment.commenter.userAccount)" class="text-default"
<el-link :underline="false" @click="onRouter('user', comment.commenter.userAccount)"
class="text-default"
rel="nofollow">{{ comment.commenter.userNickname }}
</el-link>
</el-col>
@ -92,7 +95,8 @@
<el-col :sm="23" :xl="23" :xs="21" style="padding-bottom: 10px;" v-else>
<el-col style="margin-left: 1rem;">
<el-col :span="16">
<el-link :underline="false" @click="onRouter('user', comment.commenter.userAccount)" class="text-default"
<el-link :underline="false" @click="onRouter('user', comment.commenter.userAccount)"
class="text-default"
rel="nofollow">{{ comment.commenter.userNickname }}
</el-link>
</el-col>
@ -115,7 +119,7 @@
</el-col>
</el-col>
</el-card>
<el-col :id="'original-' + comment.commentOriginalCommentId" style="background-color: #d9d9d9;padding-left: 1.5rem;
<el-col v-if="comment.commentOriginalCommentId" :id="'original-' + comment.commentOriginalCommentId" style="background-color: #d9d9d9;padding-left: 1.5rem;
margin-top: 0.3rem;border-radius: 0.5rem;cursor: pointer;display: none;">
<el-col :span="2" v-show="comment.commentOriginalCommentId">
<p>
@ -133,29 +137,21 @@
</template>
<script>
import Vue from 'vue';
import {mapState} from 'vuex';
import apiConfig from '~/config/api.config';
import Vue from 'vue';
import {mapState} from 'vuex';
import apiConfig from '~/config/api.config';
export default {
export default {
name: "Comment",
props: {
fetching: {
type: Boolean,
default: false
},
user: {
type: Object,
default: false
},
authorId: {
type: Number,
default: false
},
avatar: {
type: String,
default: ''
},
title: {
type: String,
default: ''
@ -165,6 +161,12 @@
required: true
}
},
fetch() {
let {store} = this.$nuxt.context
return Promise.all([
store.dispatch('comment/fetchList', {post_id: this.postId})
])
},
computed: {
...mapState({
comment: state => state.comment.data,
@ -172,7 +174,10 @@
isPostingComment: state => state.comment.posting,
constants: state => state.global.constants,
language: state => state.global.language,
isMobile: state => state.global.isMobile
isMobile: state => state.global.isMobile,
user: state => state.auth.user,
loggedIn: state => state.auth.loggedIn,
avatar: state => state.auth.user?.avatarUrl
}),
isFetching() {
// 1. 宿 tool
@ -357,17 +362,11 @@
}
_ts.contentEditor.setValue('');
_ts.$set(_ts, 'drawer', false);
_ts.getComments();
_ts.$fetch()
}
_ts.$set(_ts, 'loading', false);
})
},
getComments() {
//
this.$store.dispatch('comment/fetchList', {
post_id: this.postId
})
},
gotoLogin() {
this.$emit('gotoLogin');
},
@ -390,7 +389,7 @@
async mounted() {
let _ts = this;
_ts.$store.commit('setActiveMenu', 'post-article');
if (_ts.user) {
if (_ts.loggedIn) {
const responseData = await _ts.$axios.$get('/api/upload/token');
if (responseData) {
_ts.$set(_ts, 'tokenURL', {
@ -405,8 +404,8 @@
//
const previewElements = document.getElementsByClassName("comment-content");
if (previewElements && previewElements.length > 0) {
for (let i in previewElements) {
let previewElement = previewElements[i];
for (let i = 0; i<previewElements.length; i++) {
const previewElement = previewElements[i];
Vue.VditorPreview.codeRender(previewElement, 'zh_CN');
Vue.VditorPreview.highlightRender({
"enable": true,
@ -456,7 +455,7 @@
destroyed() {
this.$store.commit('comment/clearListData')
}
}
}
</script>
<style scoped>

View File

@ -76,7 +76,7 @@ export default {
redirect: {
login: '/login',
logout: false,
home: false
home: '/'
},
strategies: {
local: {

View File

@ -144,7 +144,7 @@
</el-card>
</el-col>
<el-col>
<comment-box :fetching="isFetching" :user="user" :avatar="avatar" :title="article.articleTitle"
<comment-box :fetching="isFetching" :title="article.articleTitle"
:post-id="routeArticleId" :authorId="article.articleAuthorId" @gotoLogin="gotoLogin"></comment-box>
</el-col>
<el-col>
@ -179,12 +179,12 @@ export default {
validate({params, store}) {
return params.article_id && !isNaN(Number(params.article_id))
},
fetch({store, params, error}) {
fetch() {
let {store, params, error} = this.$nuxt.context
return Promise.all([
store
.dispatch('article/fetchDetail', params)
.catch(err => error({statusCode: 404})),
store.dispatch('comment/fetchList', {post_id: params.article_id})
.catch(err => error({statusCode: 404}))
])
},
computed: {
@ -194,7 +194,7 @@ export default {
isMobile: state => state.global.isMobile,
loggedIn: state => state.auth.loggedIn,
user: state => state.auth.user,
avatar: state => state.auth.user.avatarUrl
avatar: state => state.auth.user?.avatarUrl
}),
hasPermissions() {
let account = this.$store.state.auth.user?.nickname;

View File

@ -91,7 +91,7 @@
return true;
}
}
return this.$auth.hasScope('blog_admin');
return this.$auth.hasScope('blog_admin') || this.$auth.hasScope('admin');
}
},
data() {

View File

@ -57,6 +57,7 @@ import {mapState} from 'vuex';
export default {
name: "login",
middleware: 'auth',
auth: 'guest',
data() {
return {
user: {
@ -93,10 +94,6 @@ export default {
_ts.$auth.setUserToken(response.data.token, response.data.refreshToken);
if (_ts.historyUrl) {
window.location.href = _ts.historyUrl
} else {
_ts.$router.push({
name: 'index'
})
}
}
_ts.$set(_ts, 'loginLoading', false);
@ -144,8 +141,14 @@ export default {
}
},
mounted() {
this.$store.commit('setActiveMenu', 'login');
this.$set(this, 'historyUrl', this.$route.query.historyUrl || '');
let _ts = this
_ts.$store.commit('setActiveMenu', 'login');
_ts.$set(_ts, 'historyUrl', _ts.$route.query.historyUrl || '');
// if (_ts.$auth.loggedIn) {
// _ts.$router.push({
// name: 'index'
// })
// }
}
}
</script>

View File

@ -22,7 +22,8 @@ export default {
topic => topic.topicUri === params.topic_uri
)
},
fetch({store, params, query}) {
fetch() {
let {store, params, query} = this.$nuxt.context
params.page = query.page || 1
return Promise.all([
store.dispatch('article/fetchList', params)

View File

@ -61,8 +61,8 @@
</el-link>
</el-popover>
</div>
<div v-if="auth.user">
<div v-if="auth.user.idUser !== user.idUser">
<div v-if="loggedIn">
<div v-if="auth.idUser !== user.idUser">
<el-button type="primary" v-if="isFollow" @click="cancelFollowUser(user.idUser)" plain>取消关注</el-button>
<el-button type="primary" v-else @click="followUser(user.idUser)" plain>关注</el-button>
<el-button v-show="false" @click="gotoChats" plain>聊天</el-button>
@ -122,7 +122,8 @@ export default {
validate({params, store}) {
return params.account
},
fetch({store, params, query, error}) {
fetch() {
let {store, params, query, error} = this.$nuxt.context;
params.page = query.page || 1
return Promise.all([
store
@ -138,6 +139,7 @@ export default {
watch: {
'$route.query': function () {
let _ts = this;
if (_ts.$route.params.account) {
let activeTab = _ts.$route.query.tab || '0'
_ts.$set(_ts, 'activeTab', activeTab)
switch (_ts.activeTab) {
@ -167,6 +169,7 @@ export default {
break
}
}
}
},
computed: {
...mapState({
@ -176,6 +179,7 @@ export default {
portfolios: state => state.user.portfolios,
followers: state => state.user.followers,
followings: state => state.user.followings,
loggedIn: state => state.auth.loggedIn,
auth: state => state.auth.user
})
},
@ -215,8 +219,9 @@ export default {
this.onRouter(key, 1)
},
onRouter(key, page) {
this.$router.push({
path: `/user/${this.$route.params.account}?tab=${key}&page=${page}`
let _ts = this
_ts.$router.push({
path: `/user/${_ts.$route.params.account}?tab=${key}&page=${page}`
})
},
gotoChats() {
@ -227,7 +232,7 @@ export default {
},
followUser(idUser) {
let _ts = this;
if (_ts.auth) {
if (_ts.loggedIn) {
_ts.$axios.$post('/api/follow', {
followingId: idUser,
followingType: 0
@ -241,7 +246,7 @@ export default {
},
cancelFollowUser(idUser) {
let _ts = this;
if (_ts.auth) {
if (_ts.loggedIn) {
_ts.$axios.$post('/api/follow/cancel-follow', {
followingId: idUser,
followingType: 0
@ -265,7 +270,7 @@ export default {
mounted() {
let _ts = this;
this.$store.commit('setActiveMenu', 'user');
if (_ts.auth) {
if (_ts.loggedIn) {
_ts.$axios.$get('/api/follow/is-follow', {
params: {
followingId: _ts.user.idUser,

View File

@ -23,8 +23,6 @@ export default function ({app, $axios, store, redirect}) {
Message.error(message ? message : '服务异常')
} else if (response.data.code === 401) {
app.$auth.logout()
} else if (response.data.code === 402) {
app.$auth.strategy.token.reset()
} else if (response.data.code === 404) {
Message.error('操作失败,请稍后再试......')
} else if (response.data.code === 500) {

View File

@ -8,7 +8,8 @@ export const OPEN_DATA_API_PATH = '/api/open-data'
const getDefaultDashboardData = () => {
return {
dashboard: {}
countUserNum: 0,
countArticleNum: 0
}
}