handle.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import Throttle from '$utils/tool/throttle';
  2. import user from "$config/user";
  3. export default <LibMixins>{
  4. data(){
  5. return {
  6. collect:0
  7. }
  8. },
  9. watch:{
  10. 'info.is_collect':function () {
  11. return this.setCollect(this.info.is_collect,false);
  12. }
  13. },
  14. methods:{
  15. // 触发更改关注
  16. triggerFollow(){
  17. return this.setCollect(this.collect?0:1,true);
  18. },
  19. // 设置是否关注
  20. setCollect(collect,update:boolean=true){
  21. if (user.verificationLogin()) {
  22. if (this.info.room_background_id !== undefined) {
  23. if(this.collect !== collect){
  24. this.collect = collect;
  25. if (this._collect === undefined) {
  26. this._collect = collect;
  27. }
  28. return this.triggerCollect();
  29. }
  30. }
  31. }
  32. },
  33. // 请求接口设置
  34. triggerCollect(){
  35. if (this._collect !== this.collect) {
  36. this._collect = this.collect;
  37. this.$request({
  38. url: this._collect ? 'Usercollectroom/collect_room':'Usercollectroom/un_collect_room',
  39. data:{
  40. rid: this.info.rid
  41. },
  42. token:true
  43. });
  44. }
  45. }
  46. },
  47. created(){
  48. this.triggerCollectThrottle = new Throttle({
  49. call:this,
  50. first:false,
  51. handle:this.triggerCollect,
  52. delay:500
  53. });
  54. this.triggerCollect = this.triggerCollectThrottle.supper;
  55. },
  56. beforeUnmount() {
  57. this.triggerCollectThrottle && this.triggerCollectThrottle.destroy();
  58. }
  59. }