You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

111 lines
2.7 KiB

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>钉钉授权页面</title>
<meta
name="renderer"
content="webkit"
/>
<meta
http-equiv="X-UA-Compatible"
content="IE=edge,chrome=1"
/>
<meta
http-equiv="Cache-Control"
content="no-cache, no-store, must-revalidate"
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
</head>
<script src="https://g.alicdn.com/dingding/dingtalk-jsapi/3.0.12/dingtalk.open.js"></script>
<script src="./clientid.js"></script>
<script src="./config.js"></script>
<body>
<div id="ding"></div>
<script>
// 页面加载完成后执行登录
window.onload = function () {
getCropId();
};
async function getCropId() {
try {
const res = await fetch(
"http://server001.godoos.com/user/ding/conf"
);
const data = await res.json();
if (data.success) {
await getCode(data.data.id);
} else {
ElMessage.error("获取钉钉配置失败");
}
} catch (e) {
throw e;
}
}
// 获取code登录
async function getCode(corpId) {
dd.runtime.permission.requestAuthCode({
corpId: corpId,
onSuccess: async function (result) {
await toLogin(result.code);
},
onFail: function (err) {
document.getElementById("ding").innerHTML =
JSON.stringify(err);
},
});
}
// 登录接口
async function toLogin(code) {
const data = {
login_type: "dingtalk_workbench",
client_id: GetClientId(),
param: {
code,
},
};
document.getElementById("ding").innerHTML =
JSON.stringify(data);
const res = await fetch(
"http://server001.godoos.com/user/login",
{
method: "POST",
body: JSON.stringify(data),
}
);
const jsondata = await res.json();
if (jsondata.success) {
document.getElementById("ding").innerHTML =
JSON.stringify(jsondata);
// 从本地存储中尝试获取配置信息,若不存在则使用默认空对象
const config = getSystemConfig();
jsondata.data.url = config.userInfo.url;
config.userInfo = jsondata.data;
document.getElementById("ding").innerHTML =
JSON.stringify(config);
setSystemConfig(config);
window.location.href = "http://osadmin.godoos.com/";
// setStorage("Authorization", resData.data.token);
// setStorage("ClientID", resData.data.client_id);
// 缓存用户数据
// const userData = {
// userDept: resData.data.dept,
// userInfo: resData.data.user,
// };
// setStorage("userData", userData);
ElMessage.success("登录成功");
// router.push("/knowledge/#/home");
} else {
ElMessage.error("登录失败");
}
}
</script>
</body>
</html>