var linkauthEnv='production'; // var linkauthEnv = null // 实例对象 var laAseem = null // 实例对象 if (typeof linkAuthEnabled === 'undefined') { window.linkAuthEnabled = true; // 是否启用权限控制 } if (typeof buyPromptDialogEnabled === 'undefined') { window.buyPromptDialogEnabled = true; // 是否启用 购买提示弹窗 } if (typeof loginDisplayBarEnabled === 'undefined') { window.loginDisplayBarEnabled = true; // 是否启用 登录显示栏 } if (typeof linkauthEnv === 'undefined') { window.linkauthEnv = 'production'; // 默认环境 } // 设置环境主机名 var linkauthHost = ''; if (linkauthEnv == 'production') { linkauthHost = 'https://spacemapper.cn'; } else { linkauthHost = 'https://dev.spacemapper.cn'; } // 回调标记 var linkauthLastCallback = 1; // 购买提示弹窗的弹窗间隔 // 设置初始时间为六分钟 var AuthCountDownTime = 6 * 60 * 1000; // 单位毫秒 // var AuthCountDownTime = 1 * 60 * 1000; // 单位毫秒 // 设置授权续期时间 // 默认为十分钟 var linkAuthTokenUpdateTime = 10 * 60 * 1000; // 单位毫秒 // 允许通过参数传递进行调试 if (typeof URLSearchParams !== 'undefined') { const params = new URLSearchParams(window.location.search); if (params.has('updateTime')) { linkAuthTokenUpdateTime = params.get('updateTime'); if (linkAuthTokenUpdateTime < 5) { linkAuthTokenUpdateTime = 5; } console.log("debug: set upateTime to " + linkAuthTokenUpdateTime + 's'); linkAuthTokenUpdateTime = linkAuthTokenUpdateTime * 1000; } } /* **************************** LINK AUTH 部份开始 ***************************** */ // 加载全局 CSS (function () { var cssLink = document.createElement('link'); cssLink.rel = 'stylesheet'; cssLink.href = 'https://spacemapper.cn/link/info.css'; // 替换为你的全局 CSS 文件路径 //cssLink.href = 'http://192.168.2.118:23321/link/info.css'; // 本地调试的css // 将 link 元素添加到 head 元素中 document.head.appendChild(cssLink); // 获取当前路由参数是否存在d 当d为1时关闭权限控制 var d = new URLSearchParams(window.location.search).get('d'); if (d === '1') { window.linkAuthEnabled = false; // 是否启用权限控制 window.buyPromptDialogEnabled = false; // 是否启用 购买提示弹窗 window.loginDisplayBarEnabled = false; // 是否启用 登录显示栏 } })(); // 使用方法 // if(window.laAseem) { // // 已初始化 // // 调用一次用户资料获取 // laAseem.check(document.body) // // 获取当前项目名称 // var pn = laAseem.projectName // // 获取当前请求的主机(可用于环境判定) // var host = laAseem.host // // 获取当前是否已授权 // laAseem.isAuth() // // 获取当前请求到的用户信息 // var ui = laAseem.userInfo // } // if(!window.laAseem) { // // 未初始化,初始化 // newLinkauth("EXAMPLE_SSA") // } // // 为应用定义一个自定义回调处理函数 // 只要需要处理自有逻辑时才需要在应用中定义该函数 // 多数应用应都不需要 // window.linkAuthCustomCallback = function (u) { // // 自定义处理逻辑 // } // 初始化获取用户信息 function newLinkauth(projectName, callbackFunc) { if (laAseem) { // 已初始化,直接返回 return; } // 加载全局 CSS laAseem = new linkauth(); // if (!window.linkAuthEnabled) { // 关闭权限控制,直接返回 return; } // 设置当前请求项目名称 laAseem.projectName = projectName; // 更改请求主机, 可选 // laAseem.host = 'https://spacemapper.cn'; // 设置完成回调函数名, 可选 laAseem.func = 'linkAuthCallback'; // 设置默认的cookie存储路径,可选,通常设置为当前应用程序名称 laAseem.path = '/'; // TOKEN 过期时间,默认:当前会话 laAseem.timeout = 1800; // 动态回调列表 laAseem.dynamicCallbacks = []; // 设置回调 if (callbackFunc) { laAseem.customCallback = callbackFunc; } // 定时,每10分钟续期1次 setInterval(function () { laAseem.check(document.body); }, linkAuthTokenUpdateTime); // 延迟 600 毫秒调用授权检查 setTimeout(function () { laAseem.check(document.body); }, 600); } // 请求接口获取信息 function linkauth() { // var referrer = document.referrer.toLowerCase(); // if (referrer === 'https://spacemapper.cn/'){ // this.host = 'https://spacemapper.cn' // }else{ // this.host = 'http://36.103.232.201:23320' // } // this.host = 'https://spacemapper.cn' // this.host = linkauthEnv == 'production' ? 'https://spacemapper.cn' : 'http://36.103.232.201:23320'; this.host = linkauthHost; this.func = null; this.path = null; this.timeout = null; this.projectName = null; this.userInfo = null; this.getQueryStringParameter = function (name) { var queryString = window.location.search.substring(1); var params = queryString.split('&'); for (let i = 0; i < params.length; i++) { var pair = params[i].split('='); if (pair[0] == name) { return pair[1]; } } return null; }; this.saveToken = function (token) { // link auth token sessionStorage.setItem("LINK_AT", token); }; this.removeToken = function () { sessionStorage.removeItem("LINK_AT"); sessionStorage.removeItem("LINK_UT"); } this.loadToken = function () { // 当传入地址发生变化 var utoken1 = this.getQueryStringParameter('TOKEN'); var utoken2 = sessionStorage.getItem("LINK_UT"); if (utoken1 && utoken1 != utoken2) { sessionStorage.setItem("LINK_UT", utoken1); return utoken1; } // 取授权TOKEN var stoken = sessionStorage.getItem("LINK_AT"); if (stoken && stoken.length > 0) { return stoken; } // 无 AUTH TOKEN,使用 URL TOKEN return utoken1; }; this.isAuth = function () { return this.userInfo && this.userInfo.id > 0; }; // ele: DOM element this.send = function (ele, token) { var url = this.host; url += "/cgi/link/auth"; url += "?t=" // if (this.func) { url += "&func=" + this.func; } if (this.timeout) { url += "&timeout=" + this.timeout; } if (this.path) { url += "&path=" + this.path; } // if (token) { url += '&TOKEN=' + token; } else { url += '&TOKEN=' + this.loadToken(); } // var s = document.createElement('script'); s.setAttribute('type', 'text/javascript'); s.setAttribute('src', url); ele.appendChild(s); }; this.check = function (ele) { this.send(ele || document.body); }; } // 接口获取用户信息回调函数 function linkAuthCallback(u) { // 注意:保存到全局变量(需要复核有那些系统用到,后期应考虑删除,并在应用中使用 laAseem.userInfo) window._user = u; // 标记:最后回调时间 window.linkauthLastCallback = new Date().getTime(); // 设置用户信息到LINK AUTH对象 if (window.laAseem) { window.laAseem.userInfo = u; if (u.token && u.token.length > 0) { window.laAseem.saveToken(u.token) } // 调用传入的回调 if (window.laAseem.customCallback) { window.laAseem.customCallback(u); } // 调用动态回调 while (window.laAseem.dynamicCallbacks && window.laAseem.dynamicCallbacks.length > 0) { window.laAseem.dynamicCallbacks.shift()(u); } } // 调用应用可以定义了的自定义处理回调 if (window.linkAuthCustomCallback) { window.linkAuthCustomCallback(u); } } /* **************************** LINK AUTH 部份结束 ***************************** */ // createTips(u) // // 自定义处理逻辑 // window.userObj = u // if (window.laAseem && window.userObj && window.userObj.r_list && window.userObj.r_list.length) { // let r_list = window.userObj.r_list // r_list.map(item => { // if (item.resourceId == window.laAseem.projectName) { // // 显示提示框 // resetPrompt(item); // } // }) // } else { // resetPrompt(); // } /* **************************** 采购提示框部分开始 ***************************** */ // 定义授权提示框 var buyPromptDialog = {}; // 最后验证时间 buyPromptDialog.lastTime = new Date(); buyPromptDialog.isExpired = function (d,sd) { // 将目标日期字符串转换为 Date 对象 var targetDate = new Date(d); // 获取当前时间 var currentDate = (sd) ? new Date(sd) : new Date(); // 比较当前时间是否大于目标时间 if (currentDate > targetDate) { return true; // 已过期 } else { return false; // 未过期 } } // 退出登录信息 buyPromptDialog.logout = function () { if (window.laAseem) { window.laAseem.removeToken(); // 清除token } try { var url = new URL(window.location.href); // 移除查询参数 "TOKEN"(如果存在) url.searchParams.delete("TOKEN"); // 添加或更新 "t=timestamp" url.searchParams.set("t", Date.now()); // 跳转到新的 URL window.location.href = url.toString(); } catch (error) { // 如果出错,刷新当前页面 window.location.reload(); } } // 关闭提示信息 buyPromptDialog.close = function () { // 重置最后验证时间 buyPromptDialog.lastTime = new Date(); // 移除提示框 var element = document.getElementById('buyPromptDialogElement'); if (element) { element.parentNode.removeChild(element); } }; // 打开提示信息 buyPromptDialog.open = function () { // https://dev.spacemapper.cn/account/dialog/login if (!window.laAseem) { // alert('系统未加载授权模块,请刷新系统后重试。'); console.log('系统未加载授权模块,请刷新系统后重试。'); return; } // 变量赋值 var userId = 0; var token = ''; if (window.laAseem.userInfo) { if (window.laAseem.userInfo.id) { userId = window.laAseem.userInfo.id; } if (window.laAseem.userInfo.token) token = window.laAseem.userInfo.token; } // var element = document.getElementById('buyPromptDialogElement'); if (element) { element.parentNode.removeChild(element); } // 创建窗口元素 var element = document.createElement('div'); element.id = 'buyPromptDialogElement'; var url = linkauthHost; var iframeWidth = "900"; var iframeHeight = "440"; // 弹出登录窗 if (userId < 1) { iframeWidth = "900" iframeHeight = "440" element.setAttribute("style", "width:" + iframeWidth + "px; height:" + iframeHeight + "px;") url += "/account/dialog/login?msgOrigin=" + encodeURIComponent(location.origin) + '&msgNext=buy'; } // 弹出购买窗 else { iframeWidth = "940" iframeHeight = "560" element.setAttribute("style", "width:" + iframeWidth + "px; height:" + iframeHeight + "px;") url += "/account/dialog/menu?TOKEN=" + token + "&system=" + encodeURIComponent(window.laAseem.projectName) + "&msgOrigin=" + encodeURIComponent(location.origin); } element.innerHTML = ''; // 使用模板字符串创建结构并添加到 element 中 // element.innerHTML = ` //
注意!
//
//
//

// 未有权限 // 您当前属于限免权限,如果您需要继续使用此应用请购买权限。联系电话:010-5774-2838 //

//
//
//
// 关闭 //
// `; // 获取权限 document.body.appendChild(element); }; // 验证定时器 setInterval(function () { if (!window.buyPromptDialogEnabled) { // 已禁用,退出 return; } if (document.getElementById('buyPromptDialogElement')) { // 当前为弹窗打开状态,退出 return; } // var isLogin = false; var isBuy = false; // if (window.laAseem) { // 已登录 isLogin = window.laAseem.isAuth(); var userInfo = window.laAseem.userInfo; // 有服务期 if (isLogin) { // 遍历用户资源列表,判断是否已购买 for (var i = 0; i < userInfo.r_list.length; i++) { var item = userInfo.r_list[i]; if (item.resourceId == window.laAseem.projectName) { if (item.lastExpireTime && !buyPromptDialog.isExpired(item.lastExpireTime,userInfo.s_time)) { // 已购买且有服务期 isBuy = true; } else { isBuy = false; } break; } } } } // 已登录,已购买, if (isLogin && isBuy) { // 退出 return; } // 是否已达时间隔,已达则弹窗 if (new Date().getTime() - buyPromptDialog.lastTime.getTime() > AuthCountDownTime) { buyPromptDialog.open(); } }, 5000); // 每5秒验证一次 /* **************************** 采购提示框部分结束 ***************************** */ /* **************************** 登录状态栏开始 ***************************** */ // 整体包含在函数中,防止同界面出现元素冲突 (function () { if (!window.loginDisplayBarEnabled) { // 禁止显示 return; } // 时间更新计时器 var linkAuthTipsInterval = null; // 当前用户项目资源 var resourceItem = null; // 当前用户信息 var userInfo = null; // 日期格式化函数 function dateFormat(date, fmt = 'yyyy-MM-dd hh:mm:ss') { if (!date) return date = new Date(date) var o = { 'M+': date.getMonth() + 1, //月份 'd+': date.getDate(), //日 'h+': date.getHours(), //小时 'm+': date.getMinutes(), //分 's+': date.getSeconds(), //秒 'q+': Math.floor((date.getMonth() + 3) / 3), //季度 S: date.getMilliseconds(), //毫秒 } if (/(y+)/.test(fmt)) { fmt = fmt.replace( RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length) ) } for (var k in o) { if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace( RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length) ) } } return fmt } // 电话掩码函数 function middleDigits(phoneNumber) { // 使用正则表达式匹配手机号中的数字,并替换中间四位为星号 return phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'); } // 返回购买提示弹窗剩余时间 function getBuyRemainTime() { return AuthCountDownTime - (new Date().getTime() - buyPromptDialog.lastTime.getTime()); } function createTips() { // 删除现有计时器 if (linkAuthTipsInterval) { window.clearInterval(linkAuthTipsInterval); } // 删除现有元素 var element = document.getElementById('link_auth_tips'); if (element) { element.parentNode.removeChild(element); } // var isShowTime = false; var userName = '访客'; var remainingTime = '未知'; var isTrialVersion = true; var detailsText = ', 你正在使用体验版, 购买'; var logoutText = '' // 获取资源信息 if (window.laAseem) { userInfo = window.laAseem.userInfo; for (var i = 0; i < userInfo?.r_list?.length; i++) { var item = userInfo.r_list[i]; if (item.resourceId == window.laAseem.projectName) { resourceItem = item; break; } } } else { userInfo = null; resourceItem = null; } // if (userInfo && userInfo.id > 0) { // if (resourceItem && resourceItem.lastExpireTime && resourceItem.lastExpireTime.length > 1) { // 登录已购买 userName = userInfo.name; remainingTime = '服务截止至: ' + dateFormat(resourceItem.lastExpireTime); isTrialVersion = false; detailsText = ', 续期'; logoutText = ' | 退出'; } else { // 登录未购买 userName = userInfo.name; if (/^1[3-9]\d{9}$/.test(userName)) { userName = middleDigits(userName); } remainingTime = '提醒倒计时: ' + Math.floor(getBuyRemainTime() / 1000 / 60) + '分钟'; isShowTime = true; logoutText = ' | 退出'; } } else { // 未登录 remainingTime = '提醒倒计时: ' + Math.floor(getBuyRemainTime() / 1000 / 60) + '分钟'; isShowTime = true; logoutText = '' } var message = userName + ' 你好' + detailsText + logoutText; var secondMsg = isTrialVersion ? '购买服务请联系客服 010-5774-2838' : '如需帮助请联系客服 010-5774-2838'; // 创建提示框 element = document.createElement('div'); element.id = 'link_auth_tips'; element.innerHTML = `
➤ ${message}
`; element.style.cssText = ` position: absolute; top: 50px; right: 0.26rem; z-index: 9999999; width:500px; display: flex; font-size: 12px; color: #fff; `; // 添加定时器,每分钟更新剩余时间 document.body.appendChild(element); // 启动更新计时器 if (isShowTime) { linkAuthTipsInterval = setInterval(() => { var element = document.getElementById('link_auth_tips_remain'); var time = getBuyRemainTime() if (element) { if (time < 1) { element.innerHTML = '0分0秒'; } else { element.innerHTML = Math.floor(time / 1000 / 60) + '分' + Math.floor(time / 1000 % 60) + '秒'; } } }, 1000); } } // 首次加载,延迟2秒后创建登录提示栏 // setTimeout(createTips, 2000); // 监控token是否已发生变化,若已发生变化 则重新创建 tips // 每2秒 检测一次 var lastUpdateFlag = -1; setInterval(() => { if (window.linkauthLastCallback) { // userInfo = window.laAseem.userInfo; // if (userInfo && userInfo.token != window.laAseem.userInfo.token) { // // token 发生变化, 重建 tips // setTimeout(createTips, 2000); // } var lcb = window.linkauthLastCallback; if (lastUpdateFlag != lcb) { // 当发生回调时,更新tips createTips(); // 重置标记 lastUpdateFlag = lcb; } } }, 2 * 1000); })(); /* **************************** 登录状态栏 结束 ***************************** */ // use // new linkauth().check(document.body, callbackName) // var laAseem = new linkauth() // laAseem.host = 'http://127.0.0.1:23323'; // this.func = 'callbackFunc'; // this.path = '/'; // this.timeout = '2000'; /** userInfo 用户信息 * { "name": "马佳男", "id": 285, "token_expires": 86400, "r_list": [ { "resourceId": "SYSTEM_COLLISION", "resourceName": "碰撞预警系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "SYSTEM_TSSY", "resourceName": "态势溯源系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "PICTURE", "resourceName": "观测图像", "balance": 0.0, "lastExpireTime": null }, { "resourceId": "SYSTEM_SP", "resourceName": "星下点分析系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "SYSTEM_DEDUCE", "resourceName": "轨迹溯源系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "TLE", "resourceName": "两行根数", "balance": 0.0, "lastExpireTime": null }, { "resourceId": "SYSTEM_HEAT", "resourceName": "碰撞热力系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "SYSTEM_SEA", "resourceName": "星地链接系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "SYSTEM_SITUATION", "resourceName": "太空资产态势系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "POSITION", "resourceName": "定位数据", "balance": 0.0, "lastExpireTime": null }, { "resourceId": "SYSTEM_ORBIT", "resourceName": "轨道仿真系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "OBSERVATION", "resourceName": "观测数据", "balance": 0.0, "lastExpireTime": null }, { "resourceId": "SYSTEM_BEAM", "resourceName": "波束演示系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "CATALOG", "resourceName": "编目数据", "balance": 0.0, "lastExpireTime": null }, { "resourceId": "VIEWER", "resourceName": "VIEWER", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "ORBIT", "resourceName": "定轨数据", "balance": 0.0, "lastExpireTime": null }, { "resourceId": "SYSTEM_TRANSIT", "resourceName": "过境预报系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "SYSTEM_CATALOG", "resourceName": "太空编目系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" }, { "resourceId": "SYSTEM_SSA", "resourceName": "太空态势系统", "balance": 100.0, "lastExpireTime": "2024-08-20T10:15:27+0800" } ], "token": "xPL56JMza3-Y9WQ9MR2VGMayiu-pUdnNM2U8Dl24t9G4kh7rZcMtNkhpVE3Tv7wxRMbgG_nzl9vF_TB0gwE", "c_path": "/" } */ /* **************************** 页面通信 ***************************** */ // 父页面监听消息 if (window.addEventListener) { window.addEventListener('message', (event) => { // 校验消息来源 const allowedOrigins = [ 'https://spacemapper.cn', 'https://dev.spacemapper.cn', 'https://aseem.cn', 'https://dev.aseem.cn', 'https://ads.aseem.cn', 'https://aos.aseem.cn', 'https://ssa.aseem.cn' ]; // 验证消息来源是否可信 if (allowedOrigins.includes(event.origin)) { const message = event.data; // 根据 type 字段区分不同的业务 if (message.type === 'userLogin') { console.log('User Login:', message.data); // { "token":"", "type": "userLogin", "next": "浏览器传入的msgNext" } // 登录成功 if (window.laAseem) { // 存储新token window.laAseem.saveToken(message.data.token); // 弹出购买窗 if (message.data.next && message.data.next == 'buy') { // 添加检查后回调, 关闭登录窗 & 弹出购买窗 window.laAseem.dynamicCallbacks.push(function (userInfo) { var isBuy = false; if (userInfo && userInfo.r_list) { for(var i=0;i