var smsFlag=false; var smsShowFun=null; var hasScroll=false; var isWeixin = function(){ var ua = navigator.userAgent.toLowerCase(); return ua.match(/MicroMessenger/i) == "micromessenger" } $(function(){ //首页执行,灰色主题 if(window.pageObj && window.pageObj.isHomePage==1){ gray() } if(tenant.unittype!='portal-saas-mall'){ //节日挂件 festival() //智慧客服 smartServiceInit() } //防钓鱼 if(tenant.tenantId!=268516 && tenant.unittype!='portal-saas-mall'){ preventFish() } if(isWeixin() && tenant.unittype!='portal-saas-mall'){ wxShare() } //微信小程序 if(window.__wxjs_environment === 'miniprogram'){ $require(['/npublic/commonjs/jweixin/jweixin.js','pl_util'],function(){ wx.miniProgram.postMessage({ data: { shareTitle:encodeURIComponent(document.title), shareDesc:getmeta("description"), shareUrl:encodeURIComponent(location.href) } }) }) } //限制访问 accessLimit() }) //限制访问 function accessLimit(){ if(!isFrontEnv() || location.hostname != tenant.domain){ return } let xskey = tenant.XSKey let noAccess = localStorage.getItem("kt"+tenant.tenantId) let time = +new Date() if(!isNaN(Number(noAccess)) && (time - Number(noAccess)) > 3600000){ localStorage.removeItem("kt"+tenant.tenantId); } if(xskey && !noAccess){ let domestic = xskey[9] let foreign = xskey[10] if(domestic=="1" || foreign=="1"){ $require(['cmsAjax',"/npublic/commonjs/jsencrypt.js"],function(c,rsa){ let url = "/fwebapi/visitor/lowcode/designToken/getToken" let p = $.nrsa(`designVue&${+new Date()}`,'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCdBbSMUKBY3wW8C/RFFwFoTHyO8xM67xBtgERb/4z6dqUq2ZeTagHUT6tbnuvhug0FNU9t/bzBc6KOivkzPToYYJG/RDzvdAJTjdvvvu3WQUpKOa0s0V3ehkKRoZPIFw3YnahtUrIe9es0V0LlTkOyFlH2M6rpceC7K0XgEs7lZwIDAQAB') c.cmsAjax.get(url,{},{headers:{authCode:p}}).then(function(res){ try{ let iurl = "/fwebapi/visitor/lowcode/designToken/getI" c.cmsAjax.get(iurl,{},{headers:{token:res.data.token}}).then(function(res){ if((res.data.status=="1" && domestic=="1") || (res.data.status=="2" && foreign=="1")){ location.href = "/npublic/plugins/accessLimit/index.html" } }) }catch(e){} }) }) } } } //通过name获取对应meta的content值 function getmeta(name) { var _metas = document.getElementsByTagName("meta") for (var i = 0, _item; (_item = _metas[i++]); ) { if (_item.getAttribute("name") && _item.getAttribute("name").toLowerCase() === name) { return encodeURIComponent(_item.content) } } } //灰色主题 function gray(){ $require(['cmsAjax'],function(c){ let url = window.location.origin + "/ndesigner/api/gray" c.cmsAjax.postJson(url).then(function(res){ if(res.code == 200){ $("html")[0].style="filter:progid:DXImageTransform.Microsoft.Basiclmage\(grayscale=1\);-webkit-filter\:grayscale\(100%\)\;" } }) }) } //节日挂件 function festival(){ if(!isFrontEnv()){ return } $require(['cmsAjax'],function(c){ let url = "/fwebapi/cms/lowcode/festivalPendant/getSettings" c.cmsAjax.get(url).then(function(resp){ if(resp.data && resp.data.code == 200 && resp.data.settings){ let res = resp.data.settings if(res.location==1 && window.pageObj && window.pageObj.isHomePage!=1){ return } let canTime = (res.showTime && res.showTime.length==2 && res.nowTime>=res.showTime[0] && res.nowTime<=res.showTime[1]) || !res.showTime || res.showTime.length==0 if(res.isOpen && canTime){ $require(['/npublic/commonjs/restival.js'],function(r){ r.init(res) }) } } }) }) } //智慧客服 function smartServiceInit(){ if(!isFrontEnv()){ return } $(window).on('mousemove scroll touchmove tap click keydown',function(){ if(!hasScroll){ hasScroll = true $require(['cmsAjax','pl_util'],function(c){ let search = $.getSearch() let domain = __ce.smartServiceUrl || 'https://web-visitor.yun300.cn' let url = `${domain}/visitormanager/intelligent/front/checkAndRegister?tenantId=${tenant.tenantId}&instance=${tenant.bossProductInstance}` let data = { account:localStorage.getItem(`account_${tenant.tenantId}`) } if(search.previewFlow){ data.account = search.previewFlow } c.cmsAjax.postJson(url,data).then(function(res){ if(res.status==200 && res.data){ if(noServicePage(res.data.setting)){ return } if(!search.previewFlow){ localStorage.setItem(`account_${tenant.tenantId}`,res.data.account) } $require([`css!/npublic/commonjs/smartService/t.css`,'/npublic/commonjs/smartService/smartService.js'],function(r,smartService){ res.data.domain = domain let sms = new smartService(res.data) }) } }) function noServicePage(obj){ let flag = false let set = JSON.parse(obj.colorLayout).linkObj let pageId = window.pageObj ? pageObj.pageId : "" if(pageId && set){ let arr = set.P if(isMo() && (tenant.mobileStatus==1 || tenant.mobileStatus==6 || tenant.mobileStatus==11)){ arr = set.M } let page = arr.findIndex(n=>n.pageId==pageId) if(page>-1){ flag = true } } return flag } }) } }) } //防钓鱼 function preventFish(){ var req = location.hostname var rel = getCookie('realhost') || "" if(rel && rel != req){ var url = "/repository/cheat?req="+req+"&rel="+rel $.ajax({ url:url }) } } //自定义微信分享 function wxShare(){ $require(['cmsAjax','/npublic/commonjs/jweixin/jweixin.js','pl_util'],function(c){ let url = "/fwebapi/cms/api/tdk/getWxShareInfo" let data = { pageUrl:location.href, appCode:pageObj.appId, tid:pageObj.contentType, pageType:pageObj.pageType, isHomePage:pageObj.isHomePage, pageId:pageObj.pageId, contentId:pageObj._detailId, pageName:pageObj.name } function imgxaf(src,v){ var imgParam = src.indexOf('?')>-1 ? src.split('?')[1] : ""; var imgSrc = src.split('?')[0] var paramStr = imgParam ? "?" + imgParam : ""; return imgSrc + "_" + v + "xaf" + imgSrc.substr(imgSrc.lastIndexOf('.')) + paramStr } c.cmsAjax.postJson(url,data).then(function(resp){ let data = resp.data if(data.data){ data = data.data } if(data.wxJsConfig){ let obj = data.wxJsConfig let content = data.wxShareContent let sharObj = { title: content.title, // 分享标题 desc: content.desc, // 分享描述 link: location.href, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: imgxaf($.handleDataImg(content.imgUrl),104) } console.log("分享数据:",sharObj) wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: obj.appId, // 必填,公众号的唯一标识 timestamp: obj.timestamp, // 必填,生成签名的时间戳 nonceStr: obj.nonceStr, // 必填,生成签名的随机串 signature: obj.signature,// 必填,签名 jsApiList: ['updateAppMessageShareData','updateTimelineShareData'] // 必填,需要使用的JS接口列表 }); wx.ready(function () { //需在用户可能点击分享按钮前就先调用 wx.updateAppMessageShareData(sharObj) wx.updateTimelineShareData(sharObj) }); } }) }) }