commit
84107dacfa
@ -44,14 +44,16 @@
|
|||||||
<el-col style="margin-left: 1rem;">
|
<el-col style="margin-left: 1rem;">
|
||||||
<el-col v-show="comment.commentOriginalCommentId">
|
<el-col v-show="comment.commentOriginalCommentId">
|
||||||
<el-col :span="16">
|
<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 }}
|
rel="nofollow">{{ comment.commenter.userNickname }}
|
||||||
</el-link>
|
</el-link>
|
||||||
<small class="text-default" style="margin: 0 0.2rem">回复了</small><span
|
<small class="text-default" style="margin: 0 0.2rem">回复了</small><span
|
||||||
style="font-weight: bold;"> {{ comment.commentOriginalAuthorNickname }}</span>
|
style="font-weight: bold;"> {{ comment.commentOriginalAuthorNickname }}</span>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="8" class="text-right" style="padding-right: 1rem;">
|
<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
|
title="查看原评论"><i
|
||||||
class="el-icon-reading"></i> 查看原评论
|
class="el-icon-reading"></i> 查看原评论
|
||||||
</el-link>
|
</el-link>
|
||||||
@ -63,7 +65,8 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
<el-col v-show="!comment.commentOriginalCommentId">
|
<el-col v-show="!comment.commentOriginalCommentId">
|
||||||
<el-col :span="16">
|
<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 }}
|
rel="nofollow">{{ comment.commenter.userNickname }}
|
||||||
</el-link>
|
</el-link>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -92,7 +95,8 @@
|
|||||||
<el-col :sm="23" :xl="23" :xs="21" style="padding-bottom: 10px;" v-else>
|
<el-col :sm="23" :xl="23" :xs="21" style="padding-bottom: 10px;" v-else>
|
||||||
<el-col style="margin-left: 1rem;">
|
<el-col style="margin-left: 1rem;">
|
||||||
<el-col :span="16">
|
<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 }}
|
rel="nofollow">{{ comment.commenter.userNickname }}
|
||||||
</el-link>
|
</el-link>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -115,7 +119,7 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-card>
|
</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;">
|
margin-top: 0.3rem;border-radius: 0.5rem;cursor: pointer;display: none;">
|
||||||
<el-col :span="2" v-show="comment.commentOriginalCommentId">
|
<el-col :span="2" v-show="comment.commentOriginalCommentId">
|
||||||
<p>
|
<p>
|
||||||
@ -133,330 +137,325 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import {mapState} from 'vuex';
|
import {mapState} from 'vuex';
|
||||||
import apiConfig from '~/config/api.config';
|
import apiConfig from '~/config/api.config';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Comment",
|
name: "Comment",
|
||||||
props: {
|
props: {
|
||||||
fetching: {
|
fetching: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
|
||||||
user: {
|
|
||||||
type: Object,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
authorId: {
|
|
||||||
type: Number,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
avatar: {
|
|
||||||
type: String,
|
|
||||||
default: ''
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
default: ''
|
|
||||||
},
|
|
||||||
postId: {
|
|
||||||
type: Number,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
computed: {
|
authorId: {
|
||||||
...mapState({
|
type: Number,
|
||||||
comment: state => state.comment.data,
|
default: false
|
||||||
isFetchingComment: state => state.comment.fetching,
|
|
||||||
isPostingComment: state => state.comment.posting,
|
|
||||||
constants: state => state.global.constants,
|
|
||||||
language: state => state.global.language,
|
|
||||||
isMobile: state => state.global.isMobile
|
|
||||||
}),
|
|
||||||
isFetching() {
|
|
||||||
// 1. 宿主组件还在加载时,列表和 tool 都呈加载状态
|
|
||||||
// 2. 宿主组件加载完成,如果自己还在请求,则列表呈加载状态
|
|
||||||
// 3. 自己已请求完,宿主组件还在加载,列表和 tool 都呈加载状态
|
|
||||||
return this.fetching || this.isFetchingComment
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
data() {
|
title: {
|
||||||
return {
|
type: String,
|
||||||
tokenURL: {
|
default: ''
|
||||||
URL: '',
|
|
||||||
linkToImageURL: '',
|
|
||||||
token: ''
|
|
||||||
},
|
|
||||||
drawer: false,
|
|
||||||
direction: 'btt',
|
|
||||||
initEditor: false,
|
|
||||||
isShow: true,
|
|
||||||
loading: false,
|
|
||||||
commentOriginalCommentId: 0,
|
|
||||||
commentAuthorAvatar: '',
|
|
||||||
commentTitle: ''
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
methods: {
|
postId: {
|
||||||
onRouter(name, data) {
|
type: Number,
|
||||||
this.$router.push(
|
required: true
|
||||||
{
|
}
|
||||||
path: '/user/' + data
|
},
|
||||||
}
|
fetch() {
|
||||||
)
|
let {store} = this.$nuxt.context
|
||||||
|
return Promise.all([
|
||||||
|
store.dispatch('comment/fetchList', {post_id: this.postId})
|
||||||
|
])
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState({
|
||||||
|
comment: state => state.comment.data,
|
||||||
|
isFetchingComment: state => state.comment.fetching,
|
||||||
|
isPostingComment: state => state.comment.posting,
|
||||||
|
constants: state => state.global.constants,
|
||||||
|
language: state => state.global.language,
|
||||||
|
isMobile: state => state.global.isMobile,
|
||||||
|
user: state => state.auth.user,
|
||||||
|
loggedIn: state => state.auth.loggedIn,
|
||||||
|
avatar: state => state.auth.user?.avatarUrl
|
||||||
|
}),
|
||||||
|
isFetching() {
|
||||||
|
// 1. 宿主组件还在加载时,列表和 tool 都呈加载状态
|
||||||
|
// 2. 宿主组件加载完成,如果自己还在请求,则列表呈加载状态
|
||||||
|
// 3. 自己已请求完,宿主组件还在加载,列表和 tool 都呈加载状态
|
||||||
|
return this.fetching || this.isFetchingComment
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
tokenURL: {
|
||||||
|
URL: '',
|
||||||
|
linkToImageURL: '',
|
||||||
|
token: ''
|
||||||
},
|
},
|
||||||
_initEditor(data) {
|
drawer: false,
|
||||||
let _ts = this;
|
direction: 'btt',
|
||||||
let toolbar = [
|
initEditor: false,
|
||||||
'emoji',
|
isShow: true,
|
||||||
'headings',
|
loading: false,
|
||||||
'bold',
|
commentOriginalCommentId: 0,
|
||||||
'italic',
|
commentAuthorAvatar: '',
|
||||||
'strike',
|
commentTitle: ''
|
||||||
'link',
|
}
|
||||||
'|',
|
},
|
||||||
'list',
|
methods: {
|
||||||
'ordered-list',
|
onRouter(name, data) {
|
||||||
'check',
|
this.$router.push(
|
||||||
'outdent',
|
{
|
||||||
'indent',
|
path: '/user/' + data
|
||||||
'|',
|
|
||||||
'quote',
|
|
||||||
'line',
|
|
||||||
'code',
|
|
||||||
'inline-code',
|
|
||||||
'insert-before',
|
|
||||||
'insert-after',
|
|
||||||
'|',
|
|
||||||
'upload',
|
|
||||||
// 'record',
|
|
||||||
'table',
|
|
||||||
'|',
|
|
||||||
'undo',
|
|
||||||
'redo',
|
|
||||||
'|',
|
|
||||||
'edit-mode',
|
|
||||||
{
|
|
||||||
name: 'more',
|
|
||||||
toolbar: [
|
|
||||||
'fullscreen',
|
|
||||||
'both',
|
|
||||||
'preview',
|
|
||||||
'info'
|
|
||||||
],
|
|
||||||
}]
|
|
||||||
return new Vue.Vditor(data.id, {
|
|
||||||
toolbar,
|
|
||||||
mode: 'ir',
|
|
||||||
tab: '\t',
|
|
||||||
cdn: apiConfig.VDITOR,
|
|
||||||
cache: {
|
|
||||||
enable: this.postId ? false : true,
|
|
||||||
id: this.postId ? this.postId : '',
|
|
||||||
},
|
|
||||||
after() {
|
|
||||||
_ts.contentEditor.setValue(data.value ? data.value : '');
|
|
||||||
},
|
|
||||||
hint: {
|
|
||||||
emoji: Vue.emoji
|
|
||||||
},
|
|
||||||
preview: {
|
|
||||||
hljs: {
|
|
||||||
enable: true,
|
|
||||||
lineNumber: true,
|
|
||||||
style: 'github'
|
|
||||||
},
|
|
||||||
markdown: {
|
|
||||||
toc: true,
|
|
||||||
},
|
|
||||||
delay: 500,
|
|
||||||
mode: data.mode,
|
|
||||||
/*url: `${process.env.Server}/api/console/markdown`,*/
|
|
||||||
parse: (element) => {
|
|
||||||
if (element.style.display === 'none') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// LazyLoadImage();
|
|
||||||
// Vue.Vditor.highlightRender({style:'github'}, element, document);
|
|
||||||
},
|
|
||||||
theme: {
|
|
||||||
cdn: apiConfig.VDITOR_CSS
|
|
||||||
}
|
|
||||||
},
|
|
||||||
upload: {
|
|
||||||
max: 10 * 1024 * 1024,
|
|
||||||
url: this.tokenURL.URL,
|
|
||||||
linkToImgUrl: this.tokenURL.linkToImageURL,
|
|
||||||
token: this.tokenURL.token,
|
|
||||||
filename: name => name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').replace('/\\s/g', '')
|
|
||||||
},
|
|
||||||
height: data.height,
|
|
||||||
counter: 102400,
|
|
||||||
resize: {
|
|
||||||
enable: data.resize,
|
|
||||||
},
|
|
||||||
lang: this.$store.state.locale,
|
|
||||||
placeholder: data.placeholder,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
_loadEditor() {
|
|
||||||
let _ts = this;
|
|
||||||
if (!_ts.initEditor) {
|
|
||||||
_ts.$set(_ts, 'initEditor', true);
|
|
||||||
setTimeout(function () {
|
|
||||||
_ts.contentEditor = _ts._initEditor({
|
|
||||||
id: 'contentEditor',
|
|
||||||
mode: 'both',
|
|
||||||
height: 200,
|
|
||||||
placeholder: '', //this.$t('inputContent', this.$store.state.locale)
|
|
||||||
resize: false,
|
|
||||||
value: ''
|
|
||||||
});
|
|
||||||
}, 500);
|
|
||||||
}
|
}
|
||||||
},
|
)
|
||||||
gotoComment(commentId) {
|
|
||||||
console.log(commentId);
|
|
||||||
},
|
|
||||||
replyComment(comment) {
|
|
||||||
let _ts = this;
|
|
||||||
_ts.$set(_ts, 'drawer', true);
|
|
||||||
_ts.$set(_ts, 'commentTitle', comment.commenter.userNickname);
|
|
||||||
_ts.$set(_ts, 'commentAuthorAvatar', comment.commenter.userAvatarURL);
|
|
||||||
_ts.$set(_ts, 'commentOriginalCommentId', comment.idComment);
|
|
||||||
_ts._loadEditor();
|
|
||||||
},
|
|
||||||
showComment() {
|
|
||||||
let _ts = this;
|
|
||||||
_ts.$set(_ts, 'drawer', true);
|
|
||||||
_ts.$set(_ts, 'commentTitle', _ts.title);
|
|
||||||
_ts.$set(_ts, 'commentAuthorAvatar', '');
|
|
||||||
_ts.$set(_ts, 'commentOriginalCommentId', 0);
|
|
||||||
_ts._loadEditor();
|
|
||||||
},
|
|
||||||
async postComment() {
|
|
||||||
let _ts = this;
|
|
||||||
_ts.$set(_ts, 'loading', true);
|
|
||||||
let commentContent = await _ts.contentEditor.getHTML();
|
|
||||||
if (!(commentContent)) {
|
|
||||||
_ts.$message("回帖内容不能为空!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let comment = {
|
|
||||||
commentArticleId: _ts.postId,
|
|
||||||
commentContent: commentContent,
|
|
||||||
commentOriginalCommentId: _ts.commentOriginalCommentId,
|
|
||||||
commentAuthorId: _ts.user.idUser
|
|
||||||
};
|
|
||||||
_ts.$axios.$post('/api/comment/post', comment).then(function (res) {
|
|
||||||
if (res) {
|
|
||||||
if (res.message) {
|
|
||||||
_ts.$message(res.message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_ts.contentEditor.setValue('');
|
|
||||||
_ts.$set(_ts, 'drawer', false);
|
|
||||||
_ts.getComments();
|
|
||||||
}
|
|
||||||
_ts.$set(_ts, 'loading', false);
|
|
||||||
})
|
|
||||||
},
|
|
||||||
getComments() {
|
|
||||||
// 每次重新获取数据时都需要回到评论框顶部,因为都是新数据
|
|
||||||
this.$store.dispatch('comment/fetchList', {
|
|
||||||
post_id: this.postId
|
|
||||||
})
|
|
||||||
},
|
|
||||||
gotoLogin() {
|
|
||||||
this.$emit('gotoLogin');
|
|
||||||
},
|
|
||||||
// 取消回复
|
|
||||||
cancelCommentReply() {
|
|
||||||
this.commentOriginalCommentId = 0
|
|
||||||
},
|
|
||||||
toggleShowOriginalComment(commentId) {
|
|
||||||
let ele = document.getElementById('original-' + commentId);
|
|
||||||
if (ele.style.display === 'none') {
|
|
||||||
ele.style.display = 'block';
|
|
||||||
} else {
|
|
||||||
ele.style.display = 'none';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isAuthor(commentAuthorId) {
|
|
||||||
return this.authorId === commentAuthorId;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async mounted() {
|
_initEditor(data) {
|
||||||
let _ts = this;
|
let _ts = this;
|
||||||
_ts.$store.commit('setActiveMenu', 'post-article');
|
let toolbar = [
|
||||||
if (_ts.user) {
|
'emoji',
|
||||||
const responseData = await _ts.$axios.$get('/api/upload/token');
|
'headings',
|
||||||
if (responseData) {
|
'bold',
|
||||||
_ts.$set(_ts, 'tokenURL', {
|
'italic',
|
||||||
token: responseData.uploadToken || '',
|
'strike',
|
||||||
URL: responseData.uploadURL || '',
|
'link',
|
||||||
linkToImageURL: responseData.linkToImageURL || ''
|
'|',
|
||||||
})
|
'list',
|
||||||
}
|
'ordered-list',
|
||||||
}
|
'check',
|
||||||
|
'outdent',
|
||||||
Vue.nextTick(function () {
|
'indent',
|
||||||
// 评论渲染
|
'|',
|
||||||
const previewElements = document.getElementsByClassName("comment-content");
|
'quote',
|
||||||
if (previewElements && previewElements.length > 0) {
|
'line',
|
||||||
for (let i in previewElements) {
|
'code',
|
||||||
let previewElement = previewElements[i];
|
'inline-code',
|
||||||
Vue.VditorPreview.codeRender(previewElement, 'zh_CN');
|
'insert-before',
|
||||||
Vue.VditorPreview.highlightRender({
|
'insert-after',
|
||||||
"enable": true,
|
'|',
|
||||||
"lineNumber": true,
|
'upload',
|
||||||
"style": "github"
|
// 'record',
|
||||||
}, previewElement, apiConfig.VDITOR);
|
'table',
|
||||||
Vue.VditorPreview.mathRender(previewElement, {
|
'|',
|
||||||
math: {"engine": "KaTeX", "inlineDigit": false, "macros": {}}, cdn: apiConfig.VDITOR
|
'undo',
|
||||||
});
|
'redo',
|
||||||
Vue.VditorPreview.mermaidRender(previewElement, apiConfig.VDITOR);
|
'|',
|
||||||
Vue.VditorPreview.graphvizRender(previewElement, apiConfig.VDITOR);
|
'edit-mode',
|
||||||
Vue.VditorPreview.chartRender(previewElement, apiConfig.VDITOR);
|
{
|
||||||
Vue.VditorPreview.mindmapRender(previewElement, apiConfig.VDITOR);
|
name: 'more',
|
||||||
Vue.VditorPreview.abcRender(previewElement, apiConfig.VDITOR);
|
toolbar: [
|
||||||
Vue.VditorPreview.mediaRender(previewElement);
|
'fullscreen',
|
||||||
Vue.VditorPreview.lazyLoadImageRender(previewElement);
|
'both',
|
||||||
//VditorPreview.outlineRender(previewElement, outLineElement);
|
'preview',
|
||||||
previewElement.addEventListener("click", (event) => {
|
'info'
|
||||||
if (event.target.tagName === "IMG") {
|
],
|
||||||
Vue.VditorPreview.previewImage(event.target);
|
}]
|
||||||
}
|
return new Vue.Vditor(data.id, {
|
||||||
});
|
toolbar,
|
||||||
}
|
mode: 'ir',
|
||||||
}
|
tab: '\t',
|
||||||
// 评论定位
|
cdn: apiConfig.VDITOR,
|
||||||
if (_ts.$route.hash) {
|
cache: {
|
||||||
const element = document.getElementById(_ts.$route.hash.replace('#', ''));
|
enable: this.postId ? false : true,
|
||||||
if (element) {
|
id: this.postId ? this.postId : '',
|
||||||
let actualTop = element.offsetTop;
|
},
|
||||||
let current = element.offsetParent;
|
after() {
|
||||||
while (current !== null) {
|
_ts.contentEditor.setValue(data.value ? data.value : '');
|
||||||
actualTop += current.offsetTop;
|
},
|
||||||
current = current.offsetParent;
|
hint: {
|
||||||
|
emoji: Vue.emoji
|
||||||
|
},
|
||||||
|
preview: {
|
||||||
|
hljs: {
|
||||||
|
enable: true,
|
||||||
|
lineNumber: true,
|
||||||
|
style: 'github'
|
||||||
|
},
|
||||||
|
markdown: {
|
||||||
|
toc: true,
|
||||||
|
},
|
||||||
|
delay: 500,
|
||||||
|
mode: data.mode,
|
||||||
|
/*url: `${process.env.Server}/api/console/markdown`,*/
|
||||||
|
parse: (element) => {
|
||||||
|
if (element.style.display === 'none') {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
window.scroll(0, actualTop);
|
// LazyLoadImage();
|
||||||
|
// Vue.Vditor.highlightRender({style:'github'}, element, document);
|
||||||
|
},
|
||||||
|
theme: {
|
||||||
|
cdn: apiConfig.VDITOR_CSS
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
upload: {
|
||||||
|
max: 10 * 1024 * 1024,
|
||||||
|
url: this.tokenURL.URL,
|
||||||
|
linkToImgUrl: this.tokenURL.linkToImageURL,
|
||||||
|
token: this.tokenURL.token,
|
||||||
|
filename: name => name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').replace('/\\s/g', '')
|
||||||
|
},
|
||||||
|
height: data.height,
|
||||||
|
counter: 102400,
|
||||||
|
resize: {
|
||||||
|
enable: data.resize,
|
||||||
|
},
|
||||||
|
lang: this.$store.state.locale,
|
||||||
|
placeholder: data.placeholder,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
watch: {
|
_loadEditor() {
|
||||||
isFetching(isFetching) {
|
let _ts = this;
|
||||||
if (isFetching) {
|
if (!_ts.initEditor) {
|
||||||
this.cancelCommentReply()
|
_ts.$set(_ts, 'initEditor', true);
|
||||||
}
|
setTimeout(function () {
|
||||||
|
_ts.contentEditor = _ts._initEditor({
|
||||||
|
id: 'contentEditor',
|
||||||
|
mode: 'both',
|
||||||
|
height: 200,
|
||||||
|
placeholder: '', //this.$t('inputContent', this.$store.state.locale)
|
||||||
|
resize: false,
|
||||||
|
value: ''
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
destroyed() {
|
gotoComment(commentId) {
|
||||||
this.$store.commit('comment/clearListData')
|
console.log(commentId);
|
||||||
|
},
|
||||||
|
replyComment(comment) {
|
||||||
|
let _ts = this;
|
||||||
|
_ts.$set(_ts, 'drawer', true);
|
||||||
|
_ts.$set(_ts, 'commentTitle', comment.commenter.userNickname);
|
||||||
|
_ts.$set(_ts, 'commentAuthorAvatar', comment.commenter.userAvatarURL);
|
||||||
|
_ts.$set(_ts, 'commentOriginalCommentId', comment.idComment);
|
||||||
|
_ts._loadEditor();
|
||||||
|
},
|
||||||
|
showComment() {
|
||||||
|
let _ts = this;
|
||||||
|
_ts.$set(_ts, 'drawer', true);
|
||||||
|
_ts.$set(_ts, 'commentTitle', _ts.title);
|
||||||
|
_ts.$set(_ts, 'commentAuthorAvatar', '');
|
||||||
|
_ts.$set(_ts, 'commentOriginalCommentId', 0);
|
||||||
|
_ts._loadEditor();
|
||||||
|
},
|
||||||
|
async postComment() {
|
||||||
|
let _ts = this;
|
||||||
|
_ts.$set(_ts, 'loading', true);
|
||||||
|
let commentContent = await _ts.contentEditor.getHTML();
|
||||||
|
if (!(commentContent)) {
|
||||||
|
_ts.$message("回帖内容不能为空!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let comment = {
|
||||||
|
commentArticleId: _ts.postId,
|
||||||
|
commentContent: commentContent,
|
||||||
|
commentOriginalCommentId: _ts.commentOriginalCommentId,
|
||||||
|
commentAuthorId: _ts.user.idUser
|
||||||
|
};
|
||||||
|
_ts.$axios.$post('/api/comment/post', comment).then(function (res) {
|
||||||
|
if (res) {
|
||||||
|
if (res.message) {
|
||||||
|
_ts.$message(res.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_ts.contentEditor.setValue('');
|
||||||
|
_ts.$set(_ts, 'drawer', false);
|
||||||
|
_ts.$fetch()
|
||||||
|
}
|
||||||
|
_ts.$set(_ts, 'loading', false);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
gotoLogin() {
|
||||||
|
this.$emit('gotoLogin');
|
||||||
|
},
|
||||||
|
// 取消回复
|
||||||
|
cancelCommentReply() {
|
||||||
|
this.commentOriginalCommentId = 0
|
||||||
|
},
|
||||||
|
toggleShowOriginalComment(commentId) {
|
||||||
|
let ele = document.getElementById('original-' + commentId);
|
||||||
|
if (ele.style.display === 'none') {
|
||||||
|
ele.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
ele.style.display = 'none';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isAuthor(commentAuthorId) {
|
||||||
|
return this.authorId === commentAuthorId;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
async mounted() {
|
||||||
|
let _ts = this;
|
||||||
|
_ts.$store.commit('setActiveMenu', 'post-article');
|
||||||
|
if (_ts.loggedIn) {
|
||||||
|
const responseData = await _ts.$axios.$get('/api/upload/token');
|
||||||
|
if (responseData) {
|
||||||
|
_ts.$set(_ts, 'tokenURL', {
|
||||||
|
token: responseData.uploadToken || '',
|
||||||
|
URL: responseData.uploadURL || '',
|
||||||
|
linkToImageURL: responseData.linkToImageURL || ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vue.nextTick(function () {
|
||||||
|
// 评论渲染
|
||||||
|
const previewElements = document.getElementsByClassName("comment-content");
|
||||||
|
if (previewElements && previewElements.length > 0) {
|
||||||
|
for (let i = 0; i<previewElements.length; i++) {
|
||||||
|
const previewElement = previewElements[i];
|
||||||
|
Vue.VditorPreview.codeRender(previewElement, 'zh_CN');
|
||||||
|
Vue.VditorPreview.highlightRender({
|
||||||
|
"enable": true,
|
||||||
|
"lineNumber": true,
|
||||||
|
"style": "github"
|
||||||
|
}, previewElement, apiConfig.VDITOR);
|
||||||
|
Vue.VditorPreview.mathRender(previewElement, {
|
||||||
|
math: {"engine": "KaTeX", "inlineDigit": false, "macros": {}}, cdn: apiConfig.VDITOR
|
||||||
|
});
|
||||||
|
Vue.VditorPreview.mermaidRender(previewElement, apiConfig.VDITOR);
|
||||||
|
Vue.VditorPreview.graphvizRender(previewElement, apiConfig.VDITOR);
|
||||||
|
Vue.VditorPreview.chartRender(previewElement, apiConfig.VDITOR);
|
||||||
|
Vue.VditorPreview.mindmapRender(previewElement, apiConfig.VDITOR);
|
||||||
|
Vue.VditorPreview.abcRender(previewElement, apiConfig.VDITOR);
|
||||||
|
Vue.VditorPreview.mediaRender(previewElement);
|
||||||
|
Vue.VditorPreview.lazyLoadImageRender(previewElement);
|
||||||
|
//VditorPreview.outlineRender(previewElement, outLineElement);
|
||||||
|
previewElement.addEventListener("click", (event) => {
|
||||||
|
if (event.target.tagName === "IMG") {
|
||||||
|
Vue.VditorPreview.previewImage(event.target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 评论定位
|
||||||
|
if (_ts.$route.hash) {
|
||||||
|
const element = document.getElementById(_ts.$route.hash.replace('#', ''));
|
||||||
|
if (element) {
|
||||||
|
let actualTop = element.offsetTop;
|
||||||
|
let current = element.offsetParent;
|
||||||
|
while (current !== null) {
|
||||||
|
actualTop += current.offsetTop;
|
||||||
|
current = current.offsetParent;
|
||||||
|
}
|
||||||
|
window.scroll(0, actualTop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
isFetching(isFetching) {
|
||||||
|
if (isFetching) {
|
||||||
|
this.cancelCommentReply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
destroyed() {
|
||||||
|
this.$store.commit('comment/clearListData')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
@ -76,7 +76,7 @@ export default {
|
|||||||
redirect: {
|
redirect: {
|
||||||
login: '/login',
|
login: '/login',
|
||||||
logout: false,
|
logout: false,
|
||||||
home: false
|
home: '/'
|
||||||
},
|
},
|
||||||
strategies: {
|
strategies: {
|
||||||
local: {
|
local: {
|
||||||
|
@ -144,7 +144,7 @@
|
|||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
<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>
|
:post-id="routeArticleId" :authorId="article.articleAuthorId" @gotoLogin="gotoLogin"></comment-box>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col>
|
<el-col>
|
||||||
@ -179,12 +179,12 @@ export default {
|
|||||||
validate({params, store}) {
|
validate({params, store}) {
|
||||||
return params.article_id && !isNaN(Number(params.article_id))
|
return params.article_id && !isNaN(Number(params.article_id))
|
||||||
},
|
},
|
||||||
fetch({store, params, error}) {
|
fetch() {
|
||||||
|
let {store, params, error} = this.$nuxt.context
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
store
|
store
|
||||||
.dispatch('article/fetchDetail', params)
|
.dispatch('article/fetchDetail', params)
|
||||||
.catch(err => error({statusCode: 404})),
|
.catch(err => error({statusCode: 404}))
|
||||||
store.dispatch('comment/fetchList', {post_id: params.article_id})
|
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -194,7 +194,7 @@ export default {
|
|||||||
isMobile: state => state.global.isMobile,
|
isMobile: state => state.global.isMobile,
|
||||||
loggedIn: state => state.auth.loggedIn,
|
loggedIn: state => state.auth.loggedIn,
|
||||||
user: state => state.auth.user,
|
user: state => state.auth.user,
|
||||||
avatar: state => state.auth.user.avatarUrl
|
avatar: state => state.auth.user?.avatarUrl
|
||||||
}),
|
}),
|
||||||
hasPermissions() {
|
hasPermissions() {
|
||||||
let account = this.$store.state.auth.user?.nickname;
|
let account = this.$store.state.auth.user?.nickname;
|
||||||
|
@ -91,7 +91,7 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.$auth.hasScope('blog_admin');
|
return this.$auth.hasScope('blog_admin') || this.$auth.hasScope('admin');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
@ -57,6 +57,7 @@ import {mapState} from 'vuex';
|
|||||||
export default {
|
export default {
|
||||||
name: "login",
|
name: "login",
|
||||||
middleware: 'auth',
|
middleware: 'auth',
|
||||||
|
auth: 'guest',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
user: {
|
user: {
|
||||||
@ -93,10 +94,6 @@ export default {
|
|||||||
_ts.$auth.setUserToken(response.data.token, response.data.refreshToken);
|
_ts.$auth.setUserToken(response.data.token, response.data.refreshToken);
|
||||||
if (_ts.historyUrl) {
|
if (_ts.historyUrl) {
|
||||||
window.location.href = _ts.historyUrl
|
window.location.href = _ts.historyUrl
|
||||||
} else {
|
|
||||||
_ts.$router.push({
|
|
||||||
name: 'index'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ts.$set(_ts, 'loginLoading', false);
|
_ts.$set(_ts, 'loginLoading', false);
|
||||||
@ -144,8 +141,14 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$store.commit('setActiveMenu', 'login');
|
let _ts = this
|
||||||
this.$set(this, 'historyUrl', this.$route.query.historyUrl || '');
|
_ts.$store.commit('setActiveMenu', 'login');
|
||||||
|
_ts.$set(_ts, 'historyUrl', _ts.$route.query.historyUrl || '');
|
||||||
|
// if (_ts.$auth.loggedIn) {
|
||||||
|
// _ts.$router.push({
|
||||||
|
// name: 'index'
|
||||||
|
// })
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -22,7 +22,8 @@ export default {
|
|||||||
topic => topic.topicUri === params.topic_uri
|
topic => topic.topicUri === params.topic_uri
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
fetch({store, params, query}) {
|
fetch() {
|
||||||
|
let {store, params, query} = this.$nuxt.context
|
||||||
params.page = query.page || 1
|
params.page = query.page || 1
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
store.dispatch('article/fetchList', params)
|
store.dispatch('article/fetchList', params)
|
||||||
|
@ -61,8 +61,8 @@
|
|||||||
</el-link>
|
</el-link>
|
||||||
</el-popover>
|
</el-popover>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="auth.user">
|
<div v-if="loggedIn">
|
||||||
<div v-if="auth.user.idUser !== user.idUser">
|
<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-if="isFollow" @click="cancelFollowUser(user.idUser)" plain>取消关注</el-button>
|
||||||
<el-button type="primary" v-else @click="followUser(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>
|
<el-button v-show="false" @click="gotoChats" plain>聊天</el-button>
|
||||||
@ -122,7 +122,8 @@ export default {
|
|||||||
validate({params, store}) {
|
validate({params, store}) {
|
||||||
return params.account
|
return params.account
|
||||||
},
|
},
|
||||||
fetch({store, params, query, error}) {
|
fetch() {
|
||||||
|
let {store, params, query, error} = this.$nuxt.context;
|
||||||
params.page = query.page || 1
|
params.page = query.page || 1
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
store
|
store
|
||||||
@ -138,33 +139,35 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
'$route.query': function () {
|
'$route.query': function () {
|
||||||
let _ts = this;
|
let _ts = this;
|
||||||
let activeTab = _ts.$route.query.tab || '0'
|
if (_ts.$route.params.account) {
|
||||||
_ts.$set(_ts, 'activeTab', activeTab)
|
let activeTab = _ts.$route.query.tab || '0'
|
||||||
switch (_ts.activeTab) {
|
_ts.$set(_ts, 'activeTab', activeTab)
|
||||||
case "0":
|
switch (_ts.activeTab) {
|
||||||
_ts.$store.dispatch('user/fetchArticleList', {
|
case "0":
|
||||||
account: _ts.$route.params.account,
|
_ts.$store.dispatch('user/fetchArticleList', {
|
||||||
page: _ts.$route.query.page || 1
|
account: _ts.$route.params.account,
|
||||||
})
|
page: _ts.$route.query.page || 1
|
||||||
break;
|
})
|
||||||
case "1":
|
break;
|
||||||
_ts.$store.dispatch('user/fetchPortfolioList', {
|
case "1":
|
||||||
account: _ts.$route.params.account,
|
_ts.$store.dispatch('user/fetchPortfolioList', {
|
||||||
page: _ts.$route.query.page || 1
|
account: _ts.$route.params.account,
|
||||||
})
|
page: _ts.$route.query.page || 1
|
||||||
break;
|
})
|
||||||
case "2":
|
break;
|
||||||
_ts.$store.dispatch('user/fetchFollowingList', {
|
case "2":
|
||||||
account: _ts.$route.params.account,
|
_ts.$store.dispatch('user/fetchFollowingList', {
|
||||||
page: _ts.$route.query.page || 1
|
account: _ts.$route.params.account,
|
||||||
})
|
page: _ts.$route.query.page || 1
|
||||||
break;
|
})
|
||||||
default:
|
break;
|
||||||
_ts.$store.dispatch('user/fetchFollowerList', {
|
default:
|
||||||
account: _ts.$route.params.account,
|
_ts.$store.dispatch('user/fetchFollowerList', {
|
||||||
page: _ts.$route.query.page || 1
|
account: _ts.$route.params.account,
|
||||||
})
|
page: _ts.$route.query.page || 1
|
||||||
break
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -176,6 +179,7 @@ export default {
|
|||||||
portfolios: state => state.user.portfolios,
|
portfolios: state => state.user.portfolios,
|
||||||
followers: state => state.user.followers,
|
followers: state => state.user.followers,
|
||||||
followings: state => state.user.followings,
|
followings: state => state.user.followings,
|
||||||
|
loggedIn: state => state.auth.loggedIn,
|
||||||
auth: state => state.auth.user
|
auth: state => state.auth.user
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -215,8 +219,9 @@ export default {
|
|||||||
this.onRouter(key, 1)
|
this.onRouter(key, 1)
|
||||||
},
|
},
|
||||||
onRouter(key, page) {
|
onRouter(key, page) {
|
||||||
this.$router.push({
|
let _ts = this
|
||||||
path: `/user/${this.$route.params.account}?tab=${key}&page=${page}`
|
_ts.$router.push({
|
||||||
|
path: `/user/${_ts.$route.params.account}?tab=${key}&page=${page}`
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
gotoChats() {
|
gotoChats() {
|
||||||
@ -227,7 +232,7 @@ export default {
|
|||||||
},
|
},
|
||||||
followUser(idUser) {
|
followUser(idUser) {
|
||||||
let _ts = this;
|
let _ts = this;
|
||||||
if (_ts.auth) {
|
if (_ts.loggedIn) {
|
||||||
_ts.$axios.$post('/api/follow', {
|
_ts.$axios.$post('/api/follow', {
|
||||||
followingId: idUser,
|
followingId: idUser,
|
||||||
followingType: 0
|
followingType: 0
|
||||||
@ -241,7 +246,7 @@ export default {
|
|||||||
},
|
},
|
||||||
cancelFollowUser(idUser) {
|
cancelFollowUser(idUser) {
|
||||||
let _ts = this;
|
let _ts = this;
|
||||||
if (_ts.auth) {
|
if (_ts.loggedIn) {
|
||||||
_ts.$axios.$post('/api/follow/cancel-follow', {
|
_ts.$axios.$post('/api/follow/cancel-follow', {
|
||||||
followingId: idUser,
|
followingId: idUser,
|
||||||
followingType: 0
|
followingType: 0
|
||||||
@ -265,7 +270,7 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
let _ts = this;
|
let _ts = this;
|
||||||
this.$store.commit('setActiveMenu', 'user');
|
this.$store.commit('setActiveMenu', 'user');
|
||||||
if (_ts.auth) {
|
if (_ts.loggedIn) {
|
||||||
_ts.$axios.$get('/api/follow/is-follow', {
|
_ts.$axios.$get('/api/follow/is-follow', {
|
||||||
params: {
|
params: {
|
||||||
followingId: _ts.user.idUser,
|
followingId: _ts.user.idUser,
|
||||||
|
@ -23,8 +23,6 @@ export default function ({app, $axios, store, redirect}) {
|
|||||||
Message.error(message ? message : '服务异常')
|
Message.error(message ? message : '服务异常')
|
||||||
} else if (response.data.code === 401) {
|
} else if (response.data.code === 401) {
|
||||||
app.$auth.logout()
|
app.$auth.logout()
|
||||||
} else if (response.data.code === 402) {
|
|
||||||
app.$auth.strategy.token.reset()
|
|
||||||
} else if (response.data.code === 404) {
|
} else if (response.data.code === 404) {
|
||||||
Message.error('操作失败,请稍后再试......')
|
Message.error('操作失败,请稍后再试......')
|
||||||
} else if (response.data.code === 500) {
|
} else if (response.data.code === 500) {
|
||||||
|
@ -8,7 +8,8 @@ export const OPEN_DATA_API_PATH = '/api/open-data'
|
|||||||
|
|
||||||
const getDefaultDashboardData = () => {
|
const getDefaultDashboardData = () => {
|
||||||
return {
|
return {
|
||||||
dashboard: {}
|
countUserNum: 0,
|
||||||
|
countArticleNum: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user