vue-企业微信绑定和解绑

一、企业微信绑定解绑

项目中需要对账号进行企业微信的绑定和解绑

企业微信页面显示:

<FormItem label="企业微信:">
  {{account.wechat}}
  <span class="link" @click="bindWechat" v-if="!account.wechat">绑定</span>
  <span class="link" @click="unBindWehat" v-else>解绑</span>
</FormItem>

二维码模态框:

<Modal v-model="bindWechatModal">
  <div>
    <iframe height="400" width="400" frameborder="0" :src="bindWechatUrl"></iframe>
  </div>
</Modal>

1.点击绑定微信,显示二维码模态框

bindWechat() {
  let param = {
    redirectUri: location.href.toString().split('?')[0]
  };
  R.Account.buildAuthorizationUrl(param).then(resp => {
    if (resp.code) {
      this.bindWechatModal = true;
      this.bindWechatUrl = resp.body;
    }
  });
}

2.企业微信扫描后,会重新刷新页面
关键就在页面重新渲染,调用mounted里的方法,
扫描后此时this.$route.query.code是有的,所以会调用bindCpAccount方法

mounted() {
  if (this.$route.query.code && !this.account.wechat) {
    this.bindCpAccount();
  }
}

绑定接口

bindCpAccount() {
  let param = {
    code: this.$route.query.code
  };
  R.Account.bindWechat(param).then(resp => {
    if (resp.code) {
      this.$Message.success('绑定成功');
      this.account.wechat = resp.body;
      this.bindWechatModal = false;
      this.$router.push(this.$route.path);
    }
  });
}

此时才算是成功绑定了企业微信,页面也会重新获取到企业微信数据。

3.解绑企业微信:
点击解绑

unBindWehat() {
  this.$Confirm('确定要解绑当前企业微信吗?', '温馨提示').then(() => {
    R.Account.unbindWechat().then(resp => {
      if (resp.code) {
        // window.location.href = this.$route.path; // 解绑后不刷新页面,否则不能出现重新绑定的提示
        this.account.wechat = '';
        // 提示绑定新企业微信
        this.$Message.info('该账号未绑定企业微信,绑定后进行正常操作');
        this.bindWechat();
      } else {
        this.$Message.warn(resp.msg);
      }
    });
  }).catch(() => {});
},

解绑调接口后分两种情况:
(1)解绑后提示重新绑定
不需要 window.location.href = this.$route.path;
需要 this.bindWechat();
以上代码就是提示重新绑定的情况。
(2)解绑后不提示重新绑定
需要 window.location.href = this.$route.path;
不需要 this.bindWechat();

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值