1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import Throttle from '$utils/tool/throttle';
- import user from "$config/user";
- export default <LibMixins>{
- data(){
- return {
- collect:0
- }
- },
- watch:{
- 'info.is_collect':function () {
- return this.setCollect(this.info.is_collect,false);
- }
- },
- methods:{
- // 触发更改关注
- triggerFollow(){
- return this.setCollect(this.collect?0:1,true);
- },
- // 设置是否关注
- setCollect(collect,update:boolean=true){
- if (user.verificationLogin()) {
- if (this.info.room_background_id !== undefined) {
- if(this.collect !== collect){
- this.collect = collect;
- if (this._collect === undefined) {
- this._collect = collect;
- }
- return this.triggerCollect();
- }
- }
- }
- },
- // 请求接口设置
- triggerCollect(){
- if (this._collect !== this.collect) {
- this._collect = this.collect;
- this.$request({
- url: this._collect ? 'Usercollectroom/collect_room':'Usercollectroom/un_collect_room',
- data:{
- rid: this.info.rid
- },
- token:true
- });
- }
- }
- },
- created(){
- this.triggerCollectThrottle = new Throttle({
- call:this,
- first:false,
- handle:this.triggerCollect,
- delay:500
- });
- this.triggerCollect = this.triggerCollectThrottle.supper;
- },
- beforeUnmount() {
- this.triggerCollectThrottle && this.triggerCollectThrottle.destroy();
- }
- }
|