demo.html 6.5 KB

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