'use strict'; /** * * * @author Zhong * @date 2018/11/30 * @version */ //header相关的公共操作接口 const CommonHeader = (function () { //帮助-联系客服 const csDom = $('#customerService'); //获取办事处客服列表 //@param {Number}category @return {void} function getCategoryList(category = -1, titile = '') { if (titile) { $('#upgrade-title').text(titile); } $.ajax({ type: 'get', url: '/cld/getCategoryStaff?category=' + category, dataType: 'json', timeout: 5000, success: function (response) { if (response.error !== 0) { alert('获取CLD人员信息失败!'); } else { let staffList = response.data; let staffhtml = ''; $.each(staffList, function (key, staff) { staffhtml += '
'; }); $('#staffList').html(staffhtml); $('#activ').modal('show'); } }, error: function () { console.log('请求超时'); } }) } // 推荐给朋友 const copyDom = $('#copy_link'); //绑定事件 //@return {void} function addEventListener(){ csDom.click(function () { getCategoryList(-1, '联系客服'); }); copyDom.click(function () { copy('大司空市政云计价,正版软件永久免费\r\nhttps://yun.smartcost.com.cn'); $('#show_share_msg').show(); }) } //取消浏览器自带右键 //@return {void} function banNavigatorContextMenu() { document.oncontextmenu = function(event) { if (window.event) { event = window.event; } try { var the = event.srcElement; if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) { return false; } return true; } catch (e) { return false; } } } /** * 复制字符串到剪贴板的函数 * @param {String} value 需要被复制的字符串 * @returns {Boolean} 操作结果 */ function copy(value){ var currentFocus = document.activeElement;// 保存当前活动节点 let input = document.createElement('textarea');// 创建一个texterea标签 document.body.appendChild(input);// 把标签添加给body input.style.opacity = 0;//设置input标签设置为透明(不可见) input.value = value;// 把需要复制的值放到input上 // 记录当前滚动位置, 因为添加节点并选中的时候回影响页面滚动 let scrollY = window.scrollY; input.focus();// input节点获取焦点 input.setSelectionRange(0, input.value.length);// 选中input框中的所有文字 var res = document.execCommand('copy');// 复制文字并获取结果 currentFocus.focus();// 之前活动节点获得焦点 document.body.removeChild(input);// 删除添加的input节点 // 页面滚动到之前位置 window.scrollTo(0, scrollY); return res;// 返回操作结果 } return {getCategoryList, addEventListener, banNavigatorContextMenu}; })(); CommonHeader.banNavigatorContextMenu(); $(document).ready(function(){ CommonHeader.addEventListener(); });