Add File
This commit is contained in:
110
main/x/ding.html
Normal file
110
main/x/ding.html
Normal file
@@ -0,0 +1,110 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>知识体</title>
|
||||
<script src="js/axios.min.js"></script>
|
||||
<script src="https://g.alicdn.com/dingding/dingtalk-jsapi/3.0.25/dingtalk.open.js"></script>
|
||||
<style>
|
||||
/* 清除HTML和body的默认边距 */
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden; /* 防止出现滚动条 */
|
||||
height: 100%; /* 确保body占满整个窗口 */
|
||||
}
|
||||
|
||||
/* 设置iframe样式 */
|
||||
iframe {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none; /* 去掉边框 */
|
||||
display: block; /* 避免底部空白 */
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="console"></div>
|
||||
|
||||
<script>
|
||||
const url = new URL(window.location.href);
|
||||
var Agent_Kasn = url.searchParams.get('sn');
|
||||
var kagent; //配置信息
|
||||
|
||||
var console_out = document.getElementById("console");
|
||||
|
||||
dd.ready(function() {
|
||||
// SDK 初始化成功
|
||||
console_out.innerHTML="SDK 初始化成功<br>";
|
||||
|
||||
|
||||
axios.get('/api/kagent_cfg/'+this.Agent_Kasn).then(response => {
|
||||
kagent = response.data;
|
||||
//智能体名称
|
||||
console_out.innerHTML += `智能体名称: ${kagent.title}<br>`;
|
||||
document.title= kagent.title+"_系统登录";
|
||||
|
||||
if ("dingtalk" in kagent){
|
||||
var redirect_uri=window.location.protocol+"//"+url.hostname;
|
||||
if (window.location.port==""){
|
||||
redirect_uri = redirect_uri+'/api/dingtalk_auth_code'
|
||||
}else{
|
||||
redirect_uri = redirect_uri+':'+window.location.port+'/api/dingtalk_auth_code'
|
||||
}
|
||||
console.info(redirect_uri);
|
||||
|
||||
console_out.innerHTML += `corpId: ${kagent.dingtalk.corpid}<br>`;
|
||||
|
||||
console_out.innerHTML += `client_id: ${kagent.dingtalk.client_id}<br>`;
|
||||
|
||||
|
||||
//钉钉登录
|
||||
dd.runtime.permission.requestAuthCode({
|
||||
corpId: kagent.dingtalk.corpid,
|
||||
clientId: kagent.dingtalk.client_id,
|
||||
onSuccess: function (result) {
|
||||
/*{
|
||||
code: 'hYLK98jkf0m' //string authCode
|
||||
}*/
|
||||
console_out.innerHTML += `钉钉code: ${result.code}<br>`;
|
||||
|
||||
//认证请求
|
||||
axios.get(redirect_uri+"?code="+result.code+"&state="+Agent_Kasn).then(response => {
|
||||
var url = response.data.url;
|
||||
|
||||
// 创建一个新的 iframe 元素
|
||||
const iframe = document.createElement('iframe');
|
||||
|
||||
// 设置 iframe 属性
|
||||
iframe.src = url; // 替换为你需要嵌入的地址
|
||||
iframe.title = '全屏嵌入页面';
|
||||
iframe.frameBorder = '0'; // 去掉边框
|
||||
iframe.style.width = '100%';
|
||||
iframe.style.height = '100%';
|
||||
iframe.style.border = 'none';
|
||||
iframe.style.display = 'block';
|
||||
|
||||
// 清空 body 内容(可选)
|
||||
document.body.innerHTML = '';
|
||||
|
||||
// 将 iframe 添加到 body 中
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
onFail: function (err) {
|
||||
console_out.innerHTML += `授权码获取失败: ${JSON.stringify(err)}<br>`;
|
||||
},
|
||||
});
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error('Error fetching data:', error);
|
||||
console_out.innerHTML += `错误: ${error}<br>`;
|
||||
throw error; // 重新抛出错误以便调用者可以处理
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user