jstmpl.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var xmlhttp=new XMLHttpRequest();
  2. var data = [];//配置信息
  3. var appip_source = '';
  4. var appuip_user = '';
  5. var isIE=!!window.ActiveXObject; //是否IE浏览器
  6. var isIE6=isIE&&!window.XMLHttpRequest; //是否IE6浏览器
  7. var isIE7=isIE&&!isIE6&&!isIE8; //是否IE7浏览器
  8. var isIE8=isIE&&!!document.documentMode; //是否IE8浏览器
  9. var availheight = screen.availHeight; //默认高度为屏幕的高度
  10. var hostname = location.protocol+'//'+location.host;
  11. var adminDomain = '{ADMIN_DOMAIN}'; //服务器域名
  12. var serverDomain = '{CUSTOMER_DOMAIN}'; //客服域名
  13. var userDomain = '{VISITOR_DOMAIN}/?pid='+escape("这就是一个编码没有什么用啊"); //用户域名
  14. if(isIE8){
  15. availheight= screen.height;
  16. }
  17. //IE11升级弹出窗口小
  18. if (!!window.ActiveXObject || "ActiveXObject" in window){
  19. availheight= screen.height;
  20. }
  21. var div = document.createElement('div');
  22. data = [];
  23. {JSDATA}
  24. //浮动按钮样式
  25. div.style = `position: fixed; right:15px; top:${data[data.length - 1].margin_top}px;width:80px;background: #867c7c00;border-radius: 10px 0 0 10px;
  26. display:flex;flex-direction: column; justify-content: space-between;z-index:1000;`;
  27. div.style.height = 80 * (data.length) + 'px';
  28. //拼接浮动按钮样式
  29. let btn_html = '';
  30. for (let i = 0; i < data.length - 1; i++) {
  31. btn_html += `<div id='set_user_info_${data[i].group_id}' style="width:80px;height:80px;background:#9a949775;display:flex;
  32. flex-direction: column;justify-content: center;align-items: center; cursor:pointer;z-index:1000; ">
  33. <img id='set_user_img_${data[i].group_id}'src='${adminDomain}${data[i].image}'></img>
  34. <span id='set_user_span_${data[i].group_id}' style="font-size:12px;font-weight:bold; color: #f0f0f0;">${data[i].name}</span> </div>`;
  35. }
  36. div.innerHTML = btn_html;
  37. //延时显示提示框
  38. setTimeout(function () {
  39. create_prompt_box();
  40. }, data[data.length - 1].stop_time * 1000);
  41. /***
  42. * 打开会话窗口
  43. */
  44. div.onclick =function(e){
  45. console.log(window.location.href)
  46. var index=e.target.id.lastIndexOf("_");
  47. // console.log(e.target,index);
  48. var group_id = e.target.id.substring(index+1,e.target.id.length);
  49. console.log(window);
  50. if(appuip_user && appip_source){
  51. openWindowCenter(userDomain+"&appid="+appip_source+"&appuid="+appuip_user+'&group_id='+group_id,700,700);
  52. }else{
  53. openWindowCenter(userDomain+"&appid="+appip_source+"&appuid="+appuip_user,700,700);
  54. }
  55. }
  56. //将浮动按钮添加到对应到网站body上
  57. setTimeout(function(){
  58. document.body.appendChild(div);
  59. }, 2000);
  60. /**
  61. * 提示框样式
  62. */
  63. function create_prompt_box(){
  64. var popupWindowBox = document.createElement('div');
  65. popupWindowBox.style = `position: fixed; top:35%; padding: 10px; left:45%;width:350px;height:160px;
  66. background:#e5e5e5;border-radius:10px;font-size:17px;display:flex; flex-direction: column;
  67. justify-content: space-between;z-index:9999;`;
  68. //拼接提示框样式
  69. popupWindowBox.innerHTML =`
  70. <div style='display:flex;flex-direction: row;justify-content: center;'>
  71. <span style="font-weight:bold; color: #666666;">${data[data.length - 1].copywriting}</span>
  72. </div>
  73. <div style='flex-direction: row;display:flex;justify-content: flex-end;'>
  74. <div id="$startSession" style='margin-right: 10px; padding: 4px;border: 1px solid #999; border-radius: 4px; color: #666666;font-weight: bold;cursor:pointer;'>开始会话</div>
  75. <div id="$cancel" style="padding: 3px;border: 1px solid #999; border-radius: 4px; color: #666666;font-weight: bold;cursor:pointer;">下次再说</div>
  76. </div>
  77. `;
  78. popupWindowBox.onclick =function(e){
  79. if(e.target.id == '$startSession'){
  80. openWindowCenter(userDomain+"&appid="+appip_source+"&appuid="+appuip_user,700,700);
  81. }else if(e.target.id == '$cancel'){
  82. popupWindowBox.style.display="none";
  83. }
  84. }
  85. //将提示框添加到对应到网站body上
  86. document.body.appendChild(popupWindowBox);
  87. }
  88. // padding: 3px;border: 1px solid #999; border-radius: 4px; color: #666666;font-weight: bold;
  89. // /***
  90. // *
  91. // */
  92. // function (){
  93. // }
  94. /**
  95. * 打开一个居中的窗口
  96. * @param pageUrl url链接
  97. * @param innerWidth 宽度,不带px,小于0表示百分比
  98. * @param innerHeight 高度,不带px,小于0表示百分比
  99. */
  100. function openWindowCenter(pageUrl, innerWidth, innerHeight){
  101. var screenWidth = screen.availWidth;
  102. var screenHeight = screen.availHeight;
  103. var width = screenWidth;
  104. var height = screenHeight;
  105. if(innerWidth < 1){
  106. width = screenWidth * innerWidth;
  107. screenWidth = (screen.availWidth - width)/2;
  108. }else{
  109. width = innerWidth;
  110. screenWidth = (screen.availWidth - innerWidth)/2;
  111. }
  112. if(innerHeight < 1){
  113. height = screenHeight * innerHeight;
  114. screenHeight = (screen.availHeight - height)/2;
  115. }else{
  116. height = innerHeight;
  117. screenHeight = (screen.availHeight - innerHeight)/2;
  118. }
  119. window.open(pageUrl, "", "left=" + screenWidth + ",top=" + screenHeight +",width=" + width + ",height=" + height + ",resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no");
  120. };
  121. //html页面调用
  122. /**
  123. * 获取数据
  124. */
  125. function set_user_info_js(a,b){
  126. appip_source = a;
  127. appuip_user=b;
  128. }
  129. //vue调用
  130. // export default {
  131. // /**
  132. // * 获取数据
  133. // */
  134. // set_user_info_vue: function (a,b){
  135. // appip_source = a;
  136. // appuip_user =b;
  137. // }
  138. // }