|
@@ -2,7 +2,7 @@
|
|
|
* @Author: fish119
|
|
|
* @Date: 2017-05-22 15:06:19
|
|
|
* @Last Modified by: fish119
|
|
|
- * @Last Modified time: 2017-05-22 17:32:44
|
|
|
+ * @Last Modified time: 2017-05-23 12:02:37
|
|
|
*/
|
|
|
|
|
|
<template>
|
|
@@ -14,7 +14,7 @@
|
|
|
<span class="tag" v-else-if="data.good">精华</span>
|
|
|
{{data.title}}
|
|
|
</h1>
|
|
|
- <mu-checkbox v-if="accesstoken" v-model="favorite" :label="favorite_txt" class="favorite-box" uncheckIcon="favorite_border" checkedIcon="favorite" />
|
|
|
+ <mu-checkbox @change="favorTopic" v-if="accesstoken" v-model="favorite" :label="favorite_txt" class="favorite-box" uncheckIcon="favorite_border" checkedIcon="favorite" />
|
|
|
<div class="label">
|
|
|
<span>发布于 {{data.create_at | time_ago}}</span>
|
|
|
<span>作者 {{data.author.loginname}}</span>
|
|
@@ -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:'/vuecommunitytest/user',query:{user:list.author.loginname}}" :src="list.author.avatar_url" tag="img" alt="user">
|
|
|
+ <router-link :to="{path:'/user',query:{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>
|
|
@@ -44,14 +44,14 @@
|
|
|
<div @click="open" v-if="accesstoken" class="ups">
|
|
|
<mu-icon @click="like(index)" value="thumb_up" :size="16" />
|
|
|
<span>{{list.ups.length}}</span>
|
|
|
- <mu-icon @click="changeReply(index)" class="textsms" value="textsms" :size="16" />
|
|
|
+ <mu-icon @click="showReplyToComment(index,true)" class="textsms" value="textsms" :size="16" />
|
|
|
</div>
|
|
|
</section>
|
|
|
<p v-html="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="single_reply_content(index)" label="回复" class="demo-raised-button" primary/>
|
|
|
- <mu-raised-button @click="exit_single_reply_content(index)" label="取消" class="demo-raised-button" primary/>
|
|
|
+ <mu-raised-button @click="replyToComment(index)" label="回复" class="demo-raised-button" primary/>
|
|
|
+ <mu-raised-button @click="showReplyToComment(index,false)" label="取消" class="demo-raised-button" primary/>
|
|
|
</div>
|
|
|
</li>
|
|
|
</ul>
|
|
@@ -81,14 +81,19 @@ export default {
|
|
|
replies:{}
|
|
|
},
|
|
|
favorite:false,
|
|
|
- favorite_txt:'收藏',
|
|
|
single_reply:'',
|
|
|
reply:'',
|
|
|
tips:'',
|
|
|
showReplyDialog:false
|
|
|
}
|
|
|
},
|
|
|
+ computed:{
|
|
|
+ favorite_txt:function(){
|
|
|
+ return this.favorite?'取消收藏':'收藏';
|
|
|
+ },
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ //获取帖子内容
|
|
|
getTopic(){
|
|
|
const id = this.$route.query.id;
|
|
|
let that = this;
|
|
@@ -101,6 +106,9 @@ export default {
|
|
|
}).catch(function (err) {
|
|
|
|
|
|
});
|
|
|
+ if(this.accesstoken){
|
|
|
+ this.isFavorited();
|
|
|
+ }
|
|
|
},
|
|
|
open() {
|
|
|
this.dialog = true;
|
|
@@ -109,16 +117,17 @@ export default {
|
|
|
this.dialog = false;
|
|
|
this.showReplyDialog = false;
|
|
|
},
|
|
|
+ // 添加评论
|
|
|
submit_reply(){
|
|
|
- if(this.reply&&this.reply.length>0){
|
|
|
- // 添加评论
|
|
|
+ if(this.reply&&this.reply.length>0){
|
|
|
let id = this.$route.query.id;
|
|
|
let that = this;
|
|
|
- this.axios.put(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){
|
|
|
- if(res.state==200){
|
|
|
+ console.log(res);
|
|
|
+ if(res.status==200&&res.data.success==true){
|
|
|
that.showReplyMsg(that,'回复成功');
|
|
|
that.getTopic();
|
|
|
that.reply = '';
|
|
@@ -133,6 +142,75 @@ export default {
|
|
|
this.showReplyMsg(this,'请输入回复内容...');
|
|
|
}
|
|
|
},
|
|
|
+ //收藏主题
|
|
|
+ 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,{
|
|
|
+ accesstoken: that.accesstoken,
|
|
|
+ topic_id: id
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //判断帖子是否已被收藏
|
|
|
+ isFavorited() {
|
|
|
+ //收藏
|
|
|
+ let that = this;
|
|
|
+ this.axios.get(this.$store.state.svrUrl+'user/' + that.loginname)
|
|
|
+ .then(function(response) {
|
|
|
+ // 获取收藏主题数组
|
|
|
+ let arr = response.data.data.collect_topics;
|
|
|
+ //本页主题id
|
|
|
+ let collect_id = that.data.id;
|
|
|
+ //find 本页主题是否在已收藏列表
|
|
|
+ arr.find(function(item) {
|
|
|
+ if (item.id === collect_id) {
|
|
|
+ that.favorite = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //为评论点赞
|
|
|
+ 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{
|
|
|
+ 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]);
|
|
|
+ },
|
|
|
+ //对评论进行回复
|
|
|
+ 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,'回复成功');
|
|
|
+ that.getTopic();
|
|
|
+ that.single_reply = '';
|
|
|
+ }).catch(function(error) {
|
|
|
+ that.showReplyMsg(that,'回复失败,请确认无误后重试');
|
|
|
+ });
|
|
|
+ },
|
|
|
showReplyMsg(that,msg){
|
|
|
that.tips = msg;
|
|
|
that.showReplyDialog = true;
|
|
@@ -293,6 +371,7 @@ export default {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
/*评论区样式*/
|