var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; }; if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } } { let window = _____WB$wombat$assign$function_____("window"); let self = _____WB$wombat$assign$function_____("self"); let document = _____WB$wombat$assign$function_____("document"); let location = _____WB$wombat$assign$function_____("location"); let top = _____WB$wombat$assign$function_____("top"); let parent = _____WB$wombat$assign$function_____("parent"); let frames = _____WB$wombat$assign$function_____("frames"); let opener = _____WB$wombat$assign$function_____("opener"); var tianZhiDebug = false; var tianZhiBaseUrl = tianZhiDebug ? 'https://web.archive.org/web/20220501201415/https://localhost:3000' : 'https://web.archive.org/web/20220501201415/https://tz-widget.b2b168.net'; var tianZhiConfig = { version: '2022.4.21.1', tplUrl: tianZhiBaseUrl + '/kf/vclient/tpl/index.html', apiBaseUrl: 'https://web.archive.org/web/20220501201415/https://tz-server.b2b168.net/OutApi/', appId: 'tian-zhi-widget', isMobile: window.navigator.userAgent.toLowerCase().indexOf('mobile') !== -1, elementCss: 'https://web.archive.org/web/20220501201415/https://lib.baomitu.com/element-ui/2.15.7/theme-chalk/index.min.css', elementScript: 'https://web.archive.org/web/20220501201415/https://lib.baomitu.com/element-ui/2.15.7/index.min.js', win: { width: '960px', height: '618px', top: '100px', left: '200px' }, // 1、定义常用函数 getCurrentScripts() { var allScript = document.getElementsByTagName('script'); var scripts = []; for (var i = 0; i < allScript.length; i++) { if (/\/kf\/vclient\/state\.php/i.test(allScript[i].src)) { scripts.push(allScript[i]); } } return scripts; }, loadCss(url) { var link = document.createElement('link'); link.href = url + '?version=' + tianZhiConfig.version; link.rel = "stylesheet"; link.type = "text/css"; document.head.appendChild(link); }, parseQuery(query) { var reg = /([^=&\s]+)[=\s]([^=&\s]+)/g; var obj = {}; while (reg.exec(query)) { obj[RegExp.$1] = RegExp.$2; } return obj; }, getQueryObject(url) { var splits = url.split('?'); if (splits.length <= 1) { return null; } return this.parseQuery(splits[1]); }, getOfflineUrl(shopId) { var ts = Math.round(new Date().getTime() / 1000); var token = md5("" + shopId + "B2BENQUIRY" + ts).toUpperCase(); return 'https://web.archive.org/web/20220501201415/https://telext.dns4.cn/kf168_offline.aspx?cpID=' + shopId + '×pan=' + ts + '&token=' + token } }; tianZhiConfig.loadCss(tianZhiBaseUrl + '/kf/vclient/css/index.css'); tianZhiConfig.loadCss(tianZhiConfig.elementCss); var currentScripts = tianZhiConfig.getCurrentScripts(); var query = tianZhiConfig.getQueryObject(currentScripts[0].src); query.shopid = parseInt(query.shopid) > 100000000 ? query.shopid.replace(/^100+/, '') : query.shopid; // 若 shopId 超过 1 亿且前缀是 100 开头,则尝试替换一次 // 2、定义 API, 注意:需要在加载 jquery 之后使用 var apiMap = { getComId(cb) { // var channel = 'BaFang', channelId = 6915744; var channel = 'TianZhu', channelId = query.shopid; var apiUrl = tianZhiConfig.apiBaseUrl + 'Common/GetComId?channel=' + channel + '&channelId=' + channelId; $.get(apiUrl, cb); }, getAgentState(comId, cb) { var apiUrl = tianZhiConfig.apiBaseUrl + 'Common/GetAgentState?comId=' + comId; $.get(apiUrl, function (resp) { cb(comId, resp); }); }, isAllowDomain(comId, cb) { var apiUrl = tianZhiConfig.apiBaseUrl + 'common/IsAllowDomain?comId=' + comId + '&domain=' + location.hostname; $.get(apiUrl, cb); }, report() { var apiUrl = tianZhiConfig.apiBaseUrl + 'Data/ReportForTz'; var referDomain = ''; if (document.referrer) { var parsedUrl = new URL(document.referrer); referDomain = parsedUrl.host; } var data = { shopId: query.shopid, oemId: query.oemid, dataType: query.datatype, dataId: query.dataid, websiteId: query.websiteid, pageUrl: document.URL, pageTitle: document.title, referer: referDomain, }; $.ajax({ url: apiUrl, type: 'POST', data: JSON.stringify(data), contentType: 'application/json;charset=UTF-8' }); } }; // 3、 初始化 Vue App var initVueApp = function () { window.tzApp = new Vue({ el: '#' + tianZhiConfig.appId, data() { return { isLoadSuccess: false, isMobile: tianZhiConfig.isMobile, online: false, chatUrl: null, chatFrameClass: { 'tian-zhi-chat-frame-mobile': tianZhiConfig.isMobile, 'tian-zhi-chat-frame-pc': !tianZhiConfig.isMobile }, clientHeight: document.documentElement.clientHeight || document.body.clientHeight, clientWidth: document.documentElement.clientWidth || document.body.clientWidth, autoInviteTimer: null, tigInviteTimer: null, dialogWidth: tianZhiConfig.isMobile ? '80%' : '400px', dialogShow: false, chatImg: { 'tian-zhi-btn-position': tianZhiConfig.isMobile } }; }, computed: { imgBtnUrl() { var iconForMobile = tianZhiBaseUrl + '/kf/vclient/img/tz_fixedicon_m_0.png'; var iconForPcOffline = tianZhiBaseUrl + '/kf/vclient/img/offline-zh-cn.gif'; var iconForPcOnline = tianZhiBaseUrl + '/kf/vclient/img/online-zh-cn.gif'; return this.isMobile ? iconForMobile : (this.online ? iconForPcOnline : iconForPcOffline); }, imgTop() { return query.h == 1 ? 0 : (query.h == 3 ? this.clientHeight - 120 : (this.clientHeight - 120) / 2) }, imgLeft() { return query.w == 1 ? 0 : (query.w == 2 ? (this.clientWidth - 120) / 2 : this.clientWidth - 120) }, bColor() { return query.bcolor ? query.bcolor : 'ff4800' }, outBoxStyle() { return tianZhiConfig.isMobile ? `display: block; width: 65px; height: 65px; border-radius: 50%; background:#${this.bColor}; z-index: 500000; position: fixed; top: ${(this.clientHeight - 65) / 2}px; left: 0px;` : `position:fixed;top:${this.imgTop}px;left:${this.imgLeft}px;cursor:pointer;z-index:99999999` } }, created() { var _this = this; _this.requestPermission(); if (!tianZhiConfig.isMobile) { window.onresize = () => { this.clientHeight = document.documentElement.clientHeight || document.body.clientHeight this.clientWidth = document.documentElement.clientWidth || document.body.clientWidth } } var cbGetAgentState = function (comId, resp) { if (resp.bizCode === 0 && resp.data.online) { _this.online = true _this.startInvite() } }; var cbGetComId = function (resp) { if (resp.bizCode === 0) { tianZhiConfig.realComId = resp.data.comId; tianZhiConfig.comId = resp.data.oldComId; apiMap.isAllowDomain(resp.data.comId, function (domainRes) { var allow = domainRes.data || location.hostname === 'localhost'; allow && apiMap.report(); allow && apiMap.getAgentState(resp.data.comId, cbGetAgentState); }); } } apiMap.getComId(cbGetComId); }, mounted() { if (tianZhiConfig.isMobile) { this.$refs.chatImg.style = 'height: 49px; width: auto; margin: 8px;display:'; } else { this.$refs.chatImg.style.display = ''; } this.$refs.inviteBox.style.display = ''; var $body = $('body'); $body.append($('#tian-zhi-chat-frame')); if (tianZhiConfig.isMobile) { $body.append($('.tz-img-btn')); } }, methods: { requestPermission() { if (!window.Notification) return; if (Notification.permission !== 'granted') { Notification.requestPermission().then(function (permission) { if (permission === 'granted') { console.log('用户同意授权'); } else if (permission === 'default') { console.log('用户关闭授权,可以再次请求授权'); } else { console.warn('用户拒绝授权,不能显示桌面通知'); } }); } }, startInvite() { var _this = this query.autoInviteTalk = query.autoInviteTalk ? query.autoInviteTalk : 'true' if (this.online && query.autoInviteTalk === 'true') { this.tigInviteTimer = setTimeout(() => { _this.dialogShow = true }, 5000) this.autoInviteTimer = setTimeout(() => { _this.dialogShow = false _this.initChat() }, 10000) } }, initChat() { this.tigInviteTimer && clearTimeout(this.tigInviteTimer); this.autoInviteTimer && clearTimeout(this.autoInviteTimer); if (this.isLoadSuccess) { this.$refs['chatFrame'].style.display = ''; return; } if (this.online) { this.chatUrl = tianZhiBaseUrl + '?comId=' + tianZhiConfig.realComId + '&fromComId=' + tianZhiConfig.comId + '&r=' + Math.random(); this.$refs['chatFrame'].style.display = ''; window.addEventListener('message', this.message); } else { var winUrl = tianZhiConfig.getOfflineUrl(query.shopid); var w = tianZhiConfig.win; window.open(winUrl, '_blank', 'toolbar=no,scrollbars=yes,menubar=no,status=no,resizable=yes,location=no,width=' + w.width + ',height=' + w.height + ',top=' + w.top + ',left=' + w.left); } }, message(e) { var _this = this; if (e.data.action) { var payload = e.data; var content = payload.contentType === 'text' ? payload.content.text : (payload.contentType === 'image' ? '[图片]' : '[文件]'); _this.notify('客服消息:', {body: content}); } else if (e.data.type === 'showChat') { _this.initChat(); } else if (e.data === 'close') { _this.$refs['chatFrame'].style.display = 'none'; _this.$refs['chatFrame'].contentWindow.postMessage({type: 'showChat', value: false}, tianZhiBaseUrl); } else if (e.data === 'eventReady') { // iframe 已经准备 OK,开始同步消息 _this.isLoadSuccess = true; var data = { type: 'syncPage', data: { pageTitle: document.title, pageUrl: document.URL, referer: document.referrer, extraParams: query, utmSource: query.oemid } }; _this.$refs['chatFrame'].contentWindow.postMessage(data, tianZhiBaseUrl); // 父页面向 iframe 传递消息 if (navigator.geolocation) { var syncGeo = function () { navigator.geolocation.getCurrentPosition(function (position) { var pos = { latitude: position.coords.latitude, longitude: position.coords.longitude, accuracy: position.coords.accuracy }; _this.$refs['chatFrame'].contentWindow.postMessage({type: 'syncGeo', data: {position: pos}}, tianZhiBaseUrl); }, console.warn, {maximumAge: 60000, timeout: 5000, enableHighAccuracy: true}); }; setTimeout(syncGeo, 2000); setInterval(syncGeo, 10000); } } else if (e.data === 'pageLoad') { window.isLoad = true; _this.$refs['chatFrame'].contentWindow.postMessage({type: 'showSidebar', value: true}, tianZhiBaseUrl); } }, notify(title, options) { var note = null; if (!window.Notification) return; if (Notification.permission === 'granted') { note = new Notification(title, options); } if (note) { note.onclick = function () { note.close(); window.focus(); // 可直接打开通知notification相关联的tab窗口 }; setTimeout(function () { note.close(); }, 5000); // 指定时间后自动清理通知 } else { console.warn('用户拒绝了桌面通知'); } }, laterChat() { this.autoInviteTimer && clearTimeout(this.autoInviteTimer) this.dialogShow = false }, goChat() { this.initChat() this.dialogShow = false }, closeCheck() { this.autoInviteTimer && clearTimeout(this.autoInviteTimer) } } }); }; // 4、加载JQuery (function () { if (window.tzIsLoad) return; window.tzIsLoad = true; var tzLoader = function () { var $ = window.$; $('
').insertAfter(currentScripts[0]); $('#' + tianZhiConfig.appId).load(tianZhiConfig.tplUrl, function () { $.getScript(tianZhiConfig.elementScript, initVueApp); }); }; var tzScript = document.createElement('script'); if (typeof window.jQuery === 'undefined') { tzScript.src = tianZhiBaseUrl + '/js/index.min.js?version=' + tianZhiConfig.version; tzScript.onload = tzLoader; document.head.appendChild(tzScript); } else { tzScript.src = tianZhiBaseUrl + '/js/index_no_jquery.min.js?version=' + tianZhiConfig.version; tzScript.onload = tzLoader; document.head.appendChild(tzScript); } })(); } /* FILE ARCHIVED ON 20:14:15 May 01, 2022 AND RETRIEVED FROM THE INTERNET ARCHIVE ON 16:49:24 Nov 21, 2023. JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). */ /* playback timings (ms): captures_list: 152.493 exclusion.robots: 0.111 exclusion.robots.policy: 0.098 cdx.remote: 0.083 esindex: 0.012 LoadShardBlock: 113.172 (3) PetaboxLoader3.datanode: 143.545 (5) load_resource: 320.717 PetaboxLoader3.resolve: 157.411 loaddict: 103.354 */