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
//