第一步:安装钉钉api
npm install dingtalk-jsapi
第二步:
A.(如果是公共页面运用)
1.新建公共js页面,在js页面引入dingtalk-jsapi并使用
import * as dd from 'dingtalk-jsapi';
export function getCode(callback) {
let corpId = '公司提供给的corpid';
if (dd.env.platform !== "notInDingTalk") {
dd.ready(() => {
//使用SDK 获取免登授权码
dd.runtime.permission.requestAuthCode({
corpId: corpId,
onSuccess: (res) => {
callback(res.code)
},
onFail: (err) => {
//报错以数组格式返回
alert(JSON.stringify(err));
},
});
});
//验证失败
dd.error(function(err) {
alert("进入到error中");
alert(JSON.stringify(err));
});
}
}
2.在需要调用此方法的页面引入
import {getCode}