|
@@ -2,7 +2,7 @@
|
|
|
* @Author: fish119
|
|
|
* @Date: 2017-05-22 15:06:19
|
|
|
* @Last Modified by: fish119
|
|
|
- * @Last Modified time: 2017-05-23 12:02:37
|
|
|
+ * @Last Modified time: 2017-05-23 14:17:47
|
|
|
*/
|
|
|
|
|
|
<template>
|
|
@@ -30,7 +30,7 @@
|
|
|
<li class="reply" v-for="(list,index) in data.replies" :key="list.id">
|
|
|
<section class="msg">
|
|
|
<div class="author">
|
|
|
- <router-link :to="{path:'/user',query:{user:list.author.loginname}}" :src="list.author.avatar_url" tag="img" alt="user">
|
|
|
+ <router-link :to="'/user/'+list.author.loginname" :src="list.author.avatar_url" tag="img" alt="user">
|
|
|
</router-link>
|
|
|
<span class="name">{{list.author.loginname}}</span>
|
|
|
<span class="timer">{{index+1}}楼 • {{list.create_at | time_ago}}</span>
|
|
@@ -47,7 +47,7 @@
|
|
|
<mu-icon @click="showReplyToComment(index,true)" class="textsms" value="textsms" :size="16" />
|
|
|
</div>
|
|
|
</section>
|
|
|
- <p v-html="list.content"></p>
|
|
|
+ <p v-html="$options.filters.comment(list.content)"></p>
|
|
|
<div v-if="accesstoken" class="reply_show" v-show="list.reply_show">
|
|
|
<textarea v-model="single_reply" class="reply" placeholder="请输入回复内容..." rows="5"></textarea>
|
|
|
<mu-raised-button @click="replyToComment(index)" label="回复" class="demo-raised-button" primary/>
|
|
@@ -71,42 +71,42 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
-<<script>
|
|
|
+<script>
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- accesstoken:'',
|
|
|
+ accesstoken: '',
|
|
|
data: {
|
|
|
- author:{},
|
|
|
- replies:{}
|
|
|
+ author: {},
|
|
|
+ replies: {}
|
|
|
},
|
|
|
- favorite:false,
|
|
|
- single_reply:'',
|
|
|
- reply:'',
|
|
|
- tips:'',
|
|
|
- showReplyDialog:false
|
|
|
- }
|
|
|
+ favorite: false,
|
|
|
+ single_reply: '',
|
|
|
+ reply: '',
|
|
|
+ tips: '',
|
|
|
+ showReplyDialog: false
|
|
|
+ }
|
|
|
},
|
|
|
- computed:{
|
|
|
- favorite_txt:function(){
|
|
|
- return this.favorite?'取消收藏':'收藏';
|
|
|
+ computed: {
|
|
|
+ favorite_txt: function () {
|
|
|
+ return this.favorite ? '取消收藏' : '收藏';
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
//获取帖子内容
|
|
|
- getTopic(){
|
|
|
+ getTopic() {
|
|
|
const id = this.$route.query.id;
|
|
|
let that = this;
|
|
|
- let url = this.$store.state.svrUrl+'/topic/' + id;
|
|
|
+ let url = this.$store.state.svrUrl + '/topic/' + id;
|
|
|
this.axios.get(url).then(function (response) {
|
|
|
that.data = response.data.data;
|
|
|
- that.data.replies.map(function(item) {
|
|
|
- item.reply_show = false;
|
|
|
+ that.data.replies.map(function (item) {
|
|
|
+ item.reply_show = false;
|
|
|
})
|
|
|
}).catch(function (err) {
|
|
|
-
|
|
|
+
|
|
|
});
|
|
|
- if(this.accesstoken){
|
|
|
+ if (this.accesstoken) {
|
|
|
this.isFavorited();
|
|
|
}
|
|
|
},
|
|
@@ -118,36 +118,37 @@ export default {
|
|
|
this.showReplyDialog = false;
|
|
|
},
|
|
|
// 添加评论
|
|
|
- submit_reply(){
|
|
|
- if(this.reply&&this.reply.length>0){
|
|
|
+ submit_reply() {
|
|
|
+ if (this.reply && this.reply.length > 0) {
|
|
|
let id = this.$route.query.id;
|
|
|
let that = this;
|
|
|
- this.axios.post(this.$store.state.svrUrl+'topic/'+id+'/replies',{
|
|
|
+ this.axios.post(this.$store.state.svrUrl + 'topic/' + id + '/replies', {
|
|
|
accesstoken: that.accesstoken,
|
|
|
- content: that.reply})
|
|
|
- .then(function(res){
|
|
|
+ content: that.reply
|
|
|
+ })
|
|
|
+ .then(function (res) {
|
|
|
console.log(res);
|
|
|
- if(res.status==200&&res.data.success==true){
|
|
|
- that.showReplyMsg(that,'回复成功');
|
|
|
+ if (res.status == 200 && res.data.success == true) {
|
|
|
+ that.showReplyMsg(that, '回复成功');
|
|
|
that.getTopic();
|
|
|
that.reply = '';
|
|
|
- }else{
|
|
|
- that.showReplyMsg(that,'回复失败,请确认无误后再试');
|
|
|
+ } else {
|
|
|
+ that.showReplyMsg(that, '回复失败,请确认无误后再试');
|
|
|
}
|
|
|
})
|
|
|
- .catch(function(err){
|
|
|
- that.showReplyMsg(that,'回复失败,请确认无误后再试');
|
|
|
+ .catch(function (err) {
|
|
|
+ that.showReplyMsg(that, '回复失败,请确认无误后再试');
|
|
|
});
|
|
|
- }else{
|
|
|
- this.showReplyMsg(this,'请输入回复内容...');
|
|
|
+ } else {
|
|
|
+ this.showReplyMsg(this, '请输入回复内容...');
|
|
|
}
|
|
|
},
|
|
|
//收藏主题
|
|
|
- favorTopic(){
|
|
|
+ favorTopic() {
|
|
|
let id = this.$route.query.id;
|
|
|
let that = this;
|
|
|
- let f_method = +this.favorite?'de_collect':'collect';
|
|
|
- this.axios.post(this.$store.state.svrUrl+'topic/'+f_method,{
|
|
|
+ let f_method = +this.favorite ? 'de_collect' : 'collect';
|
|
|
+ this.axios.post(this.$store.state.svrUrl + 'topic/' + f_method, {
|
|
|
accesstoken: that.accesstoken,
|
|
|
topic_id: id
|
|
|
})
|
|
@@ -156,70 +157,70 @@ export default {
|
|
|
isFavorited() {
|
|
|
//收藏
|
|
|
let that = this;
|
|
|
- this.axios.get(this.$store.state.svrUrl+'user/' + that.loginname)
|
|
|
- .then(function(response) {
|
|
|
+ this.axios.get(this.$store.state.svrUrl + 'user/' + that.loginname)
|
|
|
+ .then(function (response) {
|
|
|
// 获取收藏主题数组
|
|
|
let arr = response.data.data.collect_topics;
|
|
|
- //本页主题id
|
|
|
+ //本页主题id
|
|
|
let collect_id = that.data.id;
|
|
|
- //find 本页主题是否在已收藏列表
|
|
|
- arr.find(function(item) {
|
|
|
- if (item.id === collect_id) {
|
|
|
- that.favorite = true;
|
|
|
- }
|
|
|
+ //find 本页主题是否在已收藏列表
|
|
|
+ arr.find(function (item) {
|
|
|
+ if (item.id === collect_id) {
|
|
|
+ that.favorite = true;
|
|
|
+ }
|
|
|
})
|
|
|
- })
|
|
|
+ })
|
|
|
},
|
|
|
//为评论点赞
|
|
|
- like(index){
|
|
|
+ like(index) {
|
|
|
//data.replies
|
|
|
let that = this;
|
|
|
- this.axios.post(this.$store.state.svrUrl+'reply/'+that.data.replies[index].id+'/ups',{
|
|
|
- accesstoken : that.accesstoken
|
|
|
- }).then(function(res){
|
|
|
- if(res.data.error_msg){
|
|
|
- that.showReplyMsg(that,res.data.error_msg);
|
|
|
- }else{
|
|
|
- if(res.data.action=='down'){
|
|
|
- that.data.replies[index].ups.splice(0,1);
|
|
|
- }else{
|
|
|
+ this.axios.post(this.$store.state.svrUrl + 'reply/' + that.data.replies[index].id + '/ups', {
|
|
|
+ accesstoken: that.accesstoken
|
|
|
+ }).then(function (res) {
|
|
|
+ if (res.data.error_msg) {
|
|
|
+ that.showReplyMsg(that, res.data.error_msg);
|
|
|
+ } else {
|
|
|
+ if (res.data.action == 'down') {
|
|
|
+ that.data.replies[index].ups.splice(0, 1);
|
|
|
+ } else {
|
|
|
that.data.replies[index].ups.push('-1');
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
//显示/关闭 对评论进行回复的对话框
|
|
|
- showReplyToComment(index,isShow) {
|
|
|
- this.single_reply = isShow?'@' + this.data.replies[index].author.loginname + ' ':'';
|
|
|
- let arr = this.data.replies;
|
|
|
- arr[index].reply_show = isShow;
|
|
|
- this.$set(arr, index, arr[index]);
|
|
|
+ showReplyToComment(index, isShow) {
|
|
|
+ this.single_reply = isShow ? '@' + this.data.replies[index].author.loginname + ' ' : '';
|
|
|
+ let arr = this.data.replies;
|
|
|
+ arr[index].reply_show = isShow;
|
|
|
+ this.$set(arr, index, arr[index]);
|
|
|
},
|
|
|
//对评论进行回复
|
|
|
- replyToComment(reply){
|
|
|
+ replyToComment(reply) {
|
|
|
let id = this.$route.query.id;
|
|
|
let that = this;
|
|
|
- this.axios.post(this.$store.state.svrUrl+'topic/'+id+'/replies',{
|
|
|
- accesstoken : that.accesstoken,
|
|
|
- content : that.single_reply,
|
|
|
- reply_id : reply.id
|
|
|
- }).then(function(response){
|
|
|
- that.showReplyMsg(that,'回复成功');
|
|
|
+ this.axios.post(this.$store.state.svrUrl + 'topic/' + id + '/replies', {
|
|
|
+ accesstoken: that.accesstoken,
|
|
|
+ content: that.single_reply,
|
|
|
+ reply_id: reply.id
|
|
|
+ }).then(function (response) {
|
|
|
+ that.showReplyMsg(that, '回复成功');
|
|
|
that.getTopic();
|
|
|
that.single_reply = '';
|
|
|
- }).catch(function(error) {
|
|
|
- that.showReplyMsg(that,'回复失败,请确认无误后重试');
|
|
|
+ }).catch(function (error) {
|
|
|
+ that.showReplyMsg(that, '回复失败,请确认无误后重试');
|
|
|
});
|
|
|
},
|
|
|
- showReplyMsg(that,msg){
|
|
|
+ showReplyMsg(that, msg) {
|
|
|
that.tips = msg;
|
|
|
that.showReplyDialog = true;
|
|
|
- setTimeout(function() {
|
|
|
- that.showReplyDialog = false;
|
|
|
+ setTimeout(function () {
|
|
|
+ that.showReplyDialog = false;
|
|
|
}, 1500)
|
|
|
}
|
|
|
},
|
|
|
- created () {
|
|
|
+ created() {
|
|
|
this.accesstoken = localStorage.getItem("accesstoken");
|
|
|
this.loginname = localStorage.getItem("loginname");
|
|
|
this.getTopic();
|
|
@@ -353,20 +354,6 @@ export default {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|