FloatingButton.js 5.3 KB

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