// 判断当前环境 const isLocalHost = location.host.indexOf("127.0.0.1") !== -1 || location.host.indexOf("localhost") !== -1; const isUatHost = /^retail-uat.test/g.test(location.host) || /^isurvey-uat/g.test(location.host); const isSitHost = /^retail-sit.test/g.test(location.host) || /^isurvey-sit/g.test(location.host); const isPerf = /^wp-dfx.test/g.test(location.host) //性能环境 const isGray = /gray/g.test(location.pathname)//灰度环境 const isOverseas = /overseas/g.test(location.pathname)//海外测试环境 const isQuestionnaire = /questionnaire/g.test(location.pathname) const mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) let env; if (isLocalHost) { env = 'sit' } else if (isSitHost) { env = 'sit' } else if (isUatHost) { env = 'uat' } else if (isPerf) { env = 'perf' } else if (isGray) { env = 'gray' } else if (isOverseas) { env = 'overseas' } else { env = 'prod' } const isWelink = /huawei.cloudlink.workplace/.test(navigator.userAgent) || /com.huawei.welink/.test(navigator.userAgent); const isHonorELink = navigator?.userAgent?.includes('ChannelName/Feishu'); if (isQuestionnaire) { if (isWelink) { var script = document.createElement("script"); script.setAttribute("type", "text/javascript"); script.setAttribute('src', 'https://open-doc.welink.huaweicloud.com/docs/jsapi/2.0.11/hwh5-cloudonline.js') } if (isHonorELink) { var scriptHonorELink = document.createElement("script"); scriptHonorELink.setAttribute("type", "text/javascript"); scriptHonorELink.setAttribute('src', 'https://lf1-cdn-tos.bytegoofy.com/goofy/lark/op/h5-js-sdk-1.5.23.js') } } var text; if (isGray) { text = document.createTextNode(env + '-gray'); } else { text = document.createTextNode(env); } let body = document.getElementsByTagName("body")[0]; if (isQuestionnaire) { if (isWelink) { body.appendChild(script); } if (isHonorELink) { body.appendChild(scriptHonorELink); } } if (env !== 'prod') { let movableAreaNode = document.createElement('div') movableAreaNode.setAttribute('class', 'movableArea') movableAreaNode.setAttribute('style', 'position: fixed;top: 0;left: 0;z-index: 1001;') body.appendChild(movableAreaNode) var movableArea = document.getElementsByClassName("movableArea")[0]; //获取元素 let movableViewNode = document.createElement('div') movableViewNode.setAttribute('class', 'movableView') movableViewNode.setAttribute('style', ' pointer-events: auto;width: 70px;height: 10px;padding: 10px;background: #07c160;line-height: 10px;color: #ffffff;text-align: center;box-shadow: 0 0 0.61538462em rgb(0 0 0 / 40%);border-radius: 4px;cursor: pointer;') movableArea.appendChild(movableViewNode) var movableView = document.getElementsByClassName("movableView")[0]; //获取元素 movableView.appendChild(text) var x, y; //鼠标相对与div左边,上边的偏移 var isDrop = false; //移动状态的判断鼠标按下才能移动 if (mobile) { movableArea.ontouchstart = function (e) { var e = e || window.event; //要用event这个对象来获取鼠标的位置 x = e.changedTouches[0].clientX - movableArea.offsetLeft; y = e.changedTouches[0].clientY - movableArea.offsetTop; isDrop = true; //设为true表示可以移动 body.style.overflow = 'hidden' } movableArea.ontouchmove = function (e) { //是否为可移动状态                     if (isDrop) { var moveX = e.changedTouches[0].clientX - x; //得到距离左边移动距离    var moveY = e.changedTouches[0].clientY - y; //得到距离上边移动距离 setRemoving(moveX,moveY) } else { return; } } movableArea.ontouchend = function () { isDrop = false; //设置为false不可移动 body.style.overflow = 'auto' } } else { movableArea.onmousedown = function (e) { var e = e || window.event; //要用event这个对象来获取鼠标的位置 x = e.clientX - movableArea.offsetLeft; y = e.clientY - movableArea.offsetTop; isDrop = true; //设为true表示可以移动 } document.onmousemove = function (e) { //是否为可移动状态                     if (isDrop) { var e = e || window.event; var moveX = e.clientX - x; //得到距离左边移动距离    var moveY = e.clientY - y; //得到距离上边移动距离 setRemoving(moveX,moveY) } else { return; } } document.onmouseup = function () { isDrop = false; //设置为false不可移动 } } } function setRemoving(moveX,moveY) { //可移动最大距离 var maxX = document.documentElement.clientWidth - movableArea.offsetWidth; var maxY = document.documentElement.clientHeight - movableArea.offsetHeight; moveX = Math.min(maxX, Math.max(0, moveX)); moveY = Math.min(maxY, Math.max(0, moveY)); movableArea.style.left = moveX + "px"; movableArea.style.top = moveY + "px"; }