|
@@ -1,4 +1,4 @@
|
|
|
- 'use strict';
|
|
|
+'use strict';
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -51,12 +51,20 @@ const CommonHeader = (function () {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ // 推荐给朋友
|
|
|
+ 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}
|
|
@@ -76,6 +84,36 @@ const CommonHeader = (function () {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复制字符串到剪贴板的函数
|
|
|
+ * @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};
|
|
|
})();
|
|
|
|