85 lines
2.1 KiB
JavaScript
85 lines
2.1 KiB
JavaScript
|
// dd.js
|
|||
|
import * as dd from "dingtalk-jsapi";
|
|||
|
|
|||
|
//免密登录
|
|||
|
|
|||
|
export function getCode(callback) {
|
|||
|
let currentUrl = document.location.toString();
|
|||
|
//解析url中包含的corpId
|
|||
|
let corpId = currentUrl.split("corpid=")[1];
|
|||
|
|
|||
|
if (dd.env.platform !== 'notInDingTalk') {
|
|||
|
dd.ready(() => {
|
|||
|
//使用SDK 获取免登授权码
|
|||
|
dd.runtime.permission.requestAuthCode({
|
|||
|
corpId: corpId,
|
|||
|
onSuccess: function (info) {
|
|||
|
// 根据钉钉提供的api 获得code后,再次调用这个callback方法
|
|||
|
// 由于是钉钉获取code是异步操作,不知道什么时候执行完毕
|
|||
|
// callback 函数会等他执行完毕后在自己调用自己
|
|||
|
alert("dd.js", info)
|
|||
|
callback(info.code)
|
|||
|
},
|
|||
|
onFail: (err) => {
|
|||
|
alert('fail')
|
|||
|
alert(JSON.stringify(err))
|
|||
|
}
|
|||
|
})
|
|||
|
})
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 修改标题
|
|||
|
export function setTitle(e) {
|
|||
|
if (dd.env.platform !== 'notInDingTalk') {
|
|||
|
dd.ready(() => {
|
|||
|
// 所有JSAPI组件的调用,必须在dd.ready里面执行。
|
|||
|
dd.biz.navigation.setTitle({
|
|||
|
title: e
|
|||
|
});
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 设置右侧标题
|
|||
|
export function setRight() {
|
|||
|
if (dd.env.platform !== 'notInDingTalk') {
|
|||
|
dd.ready(() => {
|
|||
|
// 所有JSAPI组件的调用,必须在dd.ready里面执行。
|
|||
|
dd.biz.navigation.setRight({
|
|||
|
show: true,
|
|||
|
control: true,
|
|||
|
text: "首页",
|
|||
|
onSuccess: function (res) {
|
|||
|
uni.switchTab({
|
|||
|
url: "/pages/staging/index",
|
|||
|
success: function (data) {
|
|||
|
dd.biz.navigation.setRight({
|
|||
|
show: false,
|
|||
|
control: false,
|
|||
|
text: "首页",
|
|||
|
});
|
|||
|
},
|
|||
|
});
|
|||
|
}
|
|||
|
});
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// 扫码
|
|||
|
export function scan(callBack) {
|
|||
|
dd.ready(() => {
|
|||
|
dd.biz.util.scan({
|
|||
|
type: "all",
|
|||
|
onSuccess: info => {
|
|||
|
// 调用成功时回调
|
|||
|
callBack(info.text)
|
|||
|
},
|
|||
|
onFail: function (err) {
|
|||
|
// 调用失败时回调
|
|||
|
console.log(err)
|
|||
|
}
|
|||
|
});
|
|||
|
});
|
|||
|
}
|