首先安装钉钉的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);
},
});
});
}
以上!