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) } }) }) } }) //通过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 getsmsvs(function(resp){ $require([`css!/npublic/commonjs/smartservice/t.css`,'/npublic/commonjs/smartservice.js'],function(r,smartservice){ let set = {} try{ set = json.parse(resp.setting.colorlayout) }catch(e){} if(set.entrancelocation==1){ let dom = ` ` $("body").append(dom) $(".smarticon").hover(function(){ $(this).css({ "background-color": set.windowcolor, "color": "#fff" }) },function(){ $(this).css({ "background-color": "#fff", "color": set.windowcolor }) }) } $(document).on("click","[smartservice]",showandinit) //主动关闭标识 let smartserviceclose = sessionstorage.getitem('smartserviceclose') if(set.showflag==1 && resp && smartserviceclose!='true'){ showandinit() } function showandinit(){ if(smsshowfun){ if($(".smartservice.show").length>0){ smsshowfun.closedialog() return } if(smsflag){ smsshowfun.showfun() }else{ smsshowfun() } return } smsflag = true smsshowfun = new smartservice(resp) if(window.zqsensorsobj){ let obj = { tenantid: tenant.tenantid, ibusinesscode : "01", ibusinessname : "智慧客服业务线", ibusinesscustid : localstorage.getitem(`account_${tenant.tenantid}`) } zqsensorsobj.track('smartservicewakeup',obj); } } }) }) } }) //请求接口数据 function getsmsvs(callback){ $require(['cmsajax'],function(c){ 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}`) } c.cmsajax.postjson(url,data).then(function(res){ if(res.status==200 && res.data){ localstorage.setitem(`account_${tenant.tenantid}`,res.data.account) callback(res.data) } }) }) } } //防钓鱼 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) }); } }) }) }