vue 钉钉免登授权

首先安装钉钉的jsapi

import * as dd from "dingtalk-jsapi";

判断钉钉浏览器下使用授权

//这种不用鉴权,项目中需要的信息免登授权就可以获取到
let ua = navigator.userAgent.toLowerCase();
   if (ua.match(/DingTalk/i) == "dingtalk") {
      let that = this;
      dd.ready(function (code) {
        /*
         *获得免登授权码,需要的参数为corpid,也就是企业的ID
         *成功调用时返回onSuccess,返回值在function的参数info中,具体操作可以在function中实现
         *返回失败时调用onFail
         */
        dd.runtime.permission.requestAuthCode({
          corpId: localStorage.getItem("corpId"),//链接入口带的corpId,我在router里路由守卫存了起来
          onSuccess: function (info) {
            that.$http
              .post("ding/authToGetUserInfo", {
                tenant_code: localStorage.getItem("tenantCode"),
                code: info.code,//返回的code
              })
              .then((res) => {
                if (res.data.code == 200) {
                  localStorage.setItem("userCode", res.data.data.user_code);
                  Axios.defaults.headers.common["userCode"] =
                    res.data.data.user_code;
                  that.getUser();//获取用户信息
                } else {
                  that.$vux.toast.text("网络有点问题哦");
                }
              });
          },
          onFail: function (err) {
            //获得code值失败
            that.$vux.toast.text(err.errorMessage);
          },
        });
      });
    }

以上!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值