mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-10 11:26:43 +08:00
修改关注的button,统一处理
This commit is contained in:
127
src/components/Follow/button.vue
Normal file
127
src/components/Follow/button.vue
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
<template>
|
||||||
|
<!--关注的button-->
|
||||||
|
<span>
|
||||||
|
<el-button v-loading="loading" v-if="hasFollow" :size="size" class="follow-btn" icon="el-icon-check" title="取消关注" @click="cancelFollow()" >已关注</el-button>
|
||||||
|
<el-button v-loading="loading" v-else :size="size" class="follow-btn" icon="el-icon-plus" title="关注TA" @click="addFollow()" type="primary">关注</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { mapGetters} from 'vuex';
|
||||||
|
import apiFollow from "@/api/phase2/userfollow.js"
|
||||||
|
export default{
|
||||||
|
name:"followButton",
|
||||||
|
props:{
|
||||||
|
size:{
|
||||||
|
type:String,
|
||||||
|
default:'medium'
|
||||||
|
},
|
||||||
|
data:null,
|
||||||
|
auto:{ //是否自动检查
|
||||||
|
type:Boolean,
|
||||||
|
default:false
|
||||||
|
},
|
||||||
|
has:{
|
||||||
|
type:Boolean,
|
||||||
|
default:false
|
||||||
|
},
|
||||||
|
aid:{
|
||||||
|
type:String,
|
||||||
|
default:''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted(){
|
||||||
|
|
||||||
|
if(this.auto && this.aid){
|
||||||
|
this.autoCheck();
|
||||||
|
}else{
|
||||||
|
this.hasFollow=this.has;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data(){
|
||||||
|
return{
|
||||||
|
loading:false,
|
||||||
|
hasFollow:false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapGetters(['userInfo']),
|
||||||
|
},
|
||||||
|
watch:{
|
||||||
|
has(newVal,oldVal){
|
||||||
|
this.has=newVal;
|
||||||
|
this.hasFollow=newVal;
|
||||||
|
if(newVal!=oldVal && this.auto){
|
||||||
|
this.autoCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
aid(newVal){
|
||||||
|
this.aid=newVal;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
autoCheck(){
|
||||||
|
if(this.aid){
|
||||||
|
apiFollow.checkFllow(this.aid).then(res => {
|
||||||
|
if (res.status == 200) {
|
||||||
|
this.hasFollow = res.result ? true : false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
cancelFollow(){
|
||||||
|
if(this.aid){
|
||||||
|
if(this.userInfo.aid==this.aid){
|
||||||
|
this.$message.error("不能对自己操作");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let $this=this;
|
||||||
|
this.loading=true;
|
||||||
|
apiFollow.remove(this.aid).then(res=>{
|
||||||
|
if(res.status == 200) {
|
||||||
|
$this.hasFollow=false;
|
||||||
|
$this.$message.success("已取消关注");
|
||||||
|
$this.$emit('cancel',$this.aid,$this.data);
|
||||||
|
}else {
|
||||||
|
$this.$message.error("取消关注失败:"+res.message);
|
||||||
|
$this.$emit('error',$this.aid);
|
||||||
|
}
|
||||||
|
this.loading=false;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addFollow(){ //添加关注
|
||||||
|
if(this.aid){
|
||||||
|
if(this.userInfo.aid==this.aid){
|
||||||
|
this.$message.error("不能对自己操作");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let $this=this;
|
||||||
|
this.loading=true;
|
||||||
|
apiFollow.save(this.aid).then(res=>{
|
||||||
|
if(res.status == 200) {
|
||||||
|
$this.hasFollow=true;
|
||||||
|
$this.$message.success("关注成功");
|
||||||
|
$this.$emit('add',$this.aid,$this.data);
|
||||||
|
} else {
|
||||||
|
$this.$message.error("关注失败:"+res.message);
|
||||||
|
$this.$emit('error',$this.aid);
|
||||||
|
}
|
||||||
|
this.loading=false;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.follow-btn{
|
||||||
|
/* margin-top: 18px;
|
||||||
|
height: 40px;
|
||||||
|
width: 140px; */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -23,6 +23,10 @@
|
|||||||
</p>
|
</p>
|
||||||
<p class="portal-summary-text">{{item.userFollow.authorInfo.sign}}</p>
|
<p class="portal-summary-text">{{item.userFollow.authorInfo.sign}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<followButton :data="index" :has="item.has" :aid="item.userFollow.followId" @cancel="myCancelFollow" @add="myAddFollow"></followButton>
|
||||||
|
</div>
|
||||||
|
<!--
|
||||||
<div v-if="pageId == userInfo.aid">
|
<div v-if="pageId == userInfo.aid">
|
||||||
<el-button plain class="btn" icon="el-icon-check" @click="cancel(item)">取消关注</el-button>
|
<el-button plain class="btn" icon="el-icon-check" @click="cancel(item)">取消关注</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -30,6 +34,7 @@
|
|||||||
<el-button class="btn" icon="el-icon-check" v-if="item.has" @click="cancel(item)">取消关注</el-button>
|
<el-button class="btn" icon="el-icon-check" v-if="item.has" @click="cancel(item)">取消关注</el-button>
|
||||||
<el-button type="primary" class="btn" v-else icon="el-icon-plus" @click="toFollow(item)">关注TA</el-button>
|
<el-button type="primary" class="btn" v-else icon="el-icon-plus" @click="toFollow(item)">关注TA</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
</div>
|
</div>
|
||||||
<!--分页没有加-->
|
<!--分页没有加-->
|
||||||
<div style="text-align: center; margin-top:57px;" v-show="follow.count > 0">
|
<div style="text-align: center; margin-top:57px;" v-show="follow.count > 0">
|
||||||
@@ -68,8 +73,12 @@
|
|||||||
</p>
|
</p>
|
||||||
<p class="portal-summary-text">{{maPage.userFollow.authorInfo.sign}}</p>
|
<p class="portal-summary-text">{{maPage.userFollow.authorInfo.sign}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<followButton :has="maPage.has" :aid="maPage.userFollow.aid"></followButton>
|
||||||
|
</div>
|
||||||
|
<!--
|
||||||
<div v-if="pageId == userInfo.aid">
|
<div v-if="pageId == userInfo.aid">
|
||||||
|
|
||||||
<el-button class="btn" icon="el-icon-check" v-if="maPage.has">已关注</el-button>
|
<el-button class="btn" icon="el-icon-check" v-if="maPage.has">已关注</el-button>
|
||||||
<el-button type="primary" class="btn" v-else icon="el-icon-plus" @click="toFollow(maPage)">关注TA</el-button>
|
<el-button type="primary" class="btn" v-else icon="el-icon-plus" @click="toFollow(maPage)">关注TA</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -77,6 +86,7 @@
|
|||||||
<el-button plain class="btn" icon="el-icon-check" v-if="maPage.has" @click="cancel(maPage,2)">取消关注</el-button>
|
<el-button plain class="btn" icon="el-icon-check" v-if="maPage.has" @click="cancel(maPage,2)">取消关注</el-button>
|
||||||
<el-button type="primary" class="btn" v-else icon="el-icon-plus" @click="toFollow(maPage)">关注TA</el-button>
|
<el-button type="primary" class="btn" v-else icon="el-icon-plus" @click="toFollow(maPage)">关注TA</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
-->
|
||||||
</div>
|
</div>
|
||||||
<!--分页没有加-->
|
<!--分页没有加-->
|
||||||
<div style="text-align: center; margin-top:57px;" v-show="page.count > 0">
|
<div style="text-align: center; margin-top:57px;" v-show="page.count > 0">
|
||||||
@@ -96,6 +106,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import followButton from "@/components/Follow/button.vue";
|
||||||
import interactBar from "@/components/Portal/interactBar.vue";
|
import interactBar from "@/components/Portal/interactBar.vue";
|
||||||
import author from "@/components/Portal/authorInfo.vue";
|
import author from "@/components/Portal/authorInfo.vue";
|
||||||
import apiFollow from "@/api/phase2/userfollow.js"
|
import apiFollow from "@/api/phase2/userfollow.js"
|
||||||
@@ -105,7 +116,7 @@ import apiUser from "@/api/system/user.js";
|
|||||||
name:"followList",
|
name:"followList",
|
||||||
components: {
|
components: {
|
||||||
interactBar,
|
interactBar,
|
||||||
// timeShow,
|
followButton,
|
||||||
author
|
author
|
||||||
},
|
},
|
||||||
computed:{
|
computed:{
|
||||||
@@ -157,6 +168,12 @@ import apiUser from "@/api/system/user.js";
|
|||||||
toHome(ava) {
|
toHome(ava) {
|
||||||
this.$router.push({path:this.$xpage.getHomePath(ava.aid)})
|
this.$router.push({path:this.$xpage.getHomePath(ava.aid)})
|
||||||
},
|
},
|
||||||
|
myCancelFollow(dataIndex){ //我关注的,我取消关注
|
||||||
|
//this.follow.list.splice(dataIndex,1);
|
||||||
|
},
|
||||||
|
myAddFollow(dataIndex){ //我关注的,我取消关注
|
||||||
|
//this.follow.list.splice(dataIndex,1);
|
||||||
|
},
|
||||||
toFollow(item) {
|
toFollow(item) {
|
||||||
let id = '';
|
let id = '';
|
||||||
if(this.active == 2) {
|
if(this.active == 2) {
|
||||||
|
|||||||
@@ -242,8 +242,7 @@
|
|||||||
<div class="teacher-remark" v-html="item.authorInfo.sign"></div>
|
<div class="teacher-remark" v-html="item.authorInfo.sign"></div>
|
||||||
</div>
|
</div>
|
||||||
<div style="padding-top:15px;width:70px;">
|
<div style="padding-top:15px;width:70px;">
|
||||||
<el-button v-if="current_teacher_follow" v-loading="loading" type="primary" @click="cancelFollow(item)" size="small">已关注</el-button>
|
<followButton :auto="true" size="small" :aid="item.teacherId"></followButton>
|
||||||
<el-button v-if="!current_teacher_follow" v-loading="loading" type="primary" @click="toFollow(item)" size="small">+ 关注</el-button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -256,7 +255,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { mapGetters } from 'vuex';
|
import { mapGetters } from 'vuex';
|
||||||
|
import followButton from "@/components/Follow/button.vue";
|
||||||
import portalHeader from "@/components/PortalHeader.vue";
|
import portalHeader from "@/components/PortalHeader.vue";
|
||||||
import portalFooter from "@/components/PortalFooter.vue";
|
import portalFooter from "@/components/PortalFooter.vue";
|
||||||
import comments from "@/components/Portal/comments.vue";
|
import comments from "@/components/Portal/comments.vue";
|
||||||
@@ -311,7 +310,8 @@
|
|||||||
videoPlayer,
|
videoPlayer,
|
||||||
myNote,
|
myNote,
|
||||||
noteComments,
|
noteComments,
|
||||||
portalFooter
|
portalFooter,
|
||||||
|
followButton
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -322,7 +322,6 @@
|
|||||||
notePlay: null,
|
notePlay: null,
|
||||||
intTimeNote: '',
|
intTimeNote: '',
|
||||||
courestab: 2,//默认是课程评论
|
courestab: 2,//默认是课程评论
|
||||||
current_teacher_follow: false, // false - 已关注; true - 未关注
|
|
||||||
curCFile: {
|
curCFile: {
|
||||||
converStatus: 4,
|
converStatus: 4,
|
||||||
},
|
},
|
||||||
@@ -474,34 +473,6 @@
|
|||||||
}, 1000*60);
|
}, 1000*60);
|
||||||
|
|
||||||
},
|
},
|
||||||
// 取消关注
|
|
||||||
cancelFollow(item) {
|
|
||||||
this.loading = true;
|
|
||||||
apiFollow.remove(item.teacherId).then(res=>{
|
|
||||||
this.loading = false;
|
|
||||||
if(res.status == 200) {
|
|
||||||
this.current_teacher_follow = false;
|
|
||||||
} else {
|
|
||||||
this.$message.error(res.message);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
//关注功能
|
|
||||||
toFollow(item) {
|
|
||||||
this.loading = true;
|
|
||||||
apiFollow.save(item.teacherId).then(res => {
|
|
||||||
this.loading = false;
|
|
||||||
if (res.status == 200) {
|
|
||||||
this.$message.success("关注成功!");
|
|
||||||
this.current_teacher_follow = true;
|
|
||||||
} else if(res.status == 400){
|
|
||||||
this.$message.warning(res.message);
|
|
||||||
this.current_teacher_follow = false;
|
|
||||||
}else{
|
|
||||||
this.$message.error(res.message);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
//笔记组件触发,播放指定时间
|
//笔记组件触发,播放指定时间
|
||||||
onPlayVideo(contentId,time){
|
onPlayVideo(contentId,time){
|
||||||
//这里需要根据contentId,是否切换到对应的内容的视频的时间
|
//这里需要根据contentId,是否切换到对应的内容的视频的时间
|
||||||
@@ -922,13 +893,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 检查是否已关注
|
|
||||||
apiFollow.checkFllow(item.teacherId).then(res => {
|
|
||||||
if (res.status == 200) {
|
|
||||||
this.current_teacher_follow = res.result ? true : false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
//console.log('加载课程信息失败:'+res.error);
|
//console.log('加载课程信息失败:'+res.error);
|
||||||
|
|||||||
Reference in New Issue
Block a user