common.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //全选
  2. function CheckAll(event){
  3. var checked = event.checked;
  4. $(".table tbody input[type = 'checkbox']").each(function(i){
  5. if(!$(this).prop("disabled")){
  6. $(this).prop("checked",checked)
  7. }
  8. });
  9. }
  10. //快捷排序
  11. function sort(url) {
  12. $("input[name='sort']").change(function () {
  13. var param = {
  14. id : $(this).attr('id'),
  15. sort : $(this).val()
  16. }
  17. $.post(url,param,function (data) {
  18. if(data.code == 200){
  19. layer.msg(data.msg,{time: 300}, function () { window.location.reload();});
  20. }else{
  21. layer.msg(data.msg);
  22. }
  23. })
  24. });
  25. }
  26. //快捷工具栏弹窗
  27. function openwin(url){
  28. parent.layer.open({type: 2,maxmin:true,area:['60%','70%'],content: url,cancel:function (index,layero) {
  29. parent.layer.close(index);
  30. }, success: function (layero, index) {
  31. parent.layer.getChildFrame('body',index).addClass(window.name);
  32. }});
  33. }
  34. /*
  35. ** randomWord 产生任意长度随机字母数字组合
  36. ** randomFlag-是否任意长度 min-任意长度最小位[固定位数] max-任意长度最大位
  37. ** xuanfeng 2014-08-28
  38. */
  39. function randomWord(randomFlag, min, max){
  40. var str = "",range = min,arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
  41. // 随机产生
  42. if(randomFlag){
  43. range = Math.round(Math.random() * (max-min)) + min;
  44. }
  45. for(var i=0; i<range; i++){
  46. pos = Math.round(Math.random() * (arr.length-1));
  47. str += arr[pos];
  48. }
  49. return str;
  50. }
  51. //批量操作
  52. function tools_submit(obj){
  53. var ids = "";
  54. $("input:checkbox[name='ids[]']:checked").each(function() {
  55. ids += $(this).val() + ",";
  56. });
  57. parent.layer.confirm(obj.msg,{icon:3},function(index){
  58. $.post(obj.action,{ids:ids},function(data) {
  59. if (data.code == "302") {
  60. $.isEmptyObject(data.data.url) ? window.location.reload(): window.location.replace(data.data.url);
  61. }else if(data.code == "200"){
  62. parent.layer.alert(data.msg,{icon:1,closeBtn:0},function(index){
  63. $.isEmptyObject(data.data.url) ? window.location.reload(): window.location.replace(data.data.url);
  64. parent.layer.close(index);
  65. });
  66. } else {
  67. parent.layer.alert(data.msg,{icon:5});
  68. }
  69. },"json");
  70. parent.layer.close(index);
  71. });
  72. }
  73. //添加图片
  74. function setImg(show_src) {
  75. if ($("#imgbox img[src='" + show_src + "']").get(0)) {
  76. parent.layer.msg("图片已经添加,请不要重复添加!");
  77. } else {
  78. $("#imgbox").append('<div class="box-view fn-left"><input type="hidden" name="imgs[]" value="' + show_src + '" /><img src="' + show_src + '" onclick="selectImg(this)"><div class="opera"><a class="imgbox-left" href="javascript:;"><i class="iconfont icon-arrowleft"></i></a><a class="imgbox-right" href="javascript:;"><i class="iconfont icon-arrowright"></i></a><a class="imgbox-link" href="javascript:;" onclick="linkImg(this)"><i class="iconfont icon-search_icon"></i></a><a class="imgbox-close" href="javascript:;" onclick="delImg(this)"><i class="iconfont icon-close_icon"></i></a></div></div>');
  79. if ($("#img_index").val() == "") {
  80. $("#img_index").val(show_src);
  81. }
  82. bindEvent();
  83. }
  84. }
  85. //删除添加的图片
  86. function delImg(id) {
  87. $(id).parent().parent().remove();
  88. }
  89. //显示图片URL
  90. function linkImg(id) {
  91. var src = $(id).parent().parent().find('img').attr('src');
  92. layer.photos({photos:{"status":1,"title": "图片预览","id":8,"start": 0,"data":[{"alt":"layer","pid": 109,"src":src}]},anim:5});
  93. }
  94. //放大图片URL
  95. function bigImg(src) {
  96. layer.photos({photos:{"status":1,"title": "图片预览","id":8,"start": 0,"data":[{"alt":"layer","pid": 109,"src":src}]},anim:5});
  97. }
  98. //操作左右按钮事件绑定
  99. function bindEvent() {
  100. $(".imgbox-right").off();
  101. $(".imgbox-left").off();
  102. $(".imgbox-right").on("click", function () {
  103. var current_tr = $(this).parent().parent();
  104. current_tr.insertAfter(current_tr.next());
  105. });
  106. $(".imgbox-left").on("click", function () {
  107. var current_tr = $(this).parent().parent();
  108. if (current_tr.prev().html() != null) current_tr.insertBefore(current_tr.prev());
  109. });
  110. }
  111. //设置默认图片
  112. function selectImg(id) {
  113. var img = $(id).attr('src');
  114. $(".box-view").removeClass("current");
  115. $(id).parent().addClass("current");
  116. $("#img_index").val(img);
  117. }
  118. //JS图片转换成B64
  119. function imgtob64(imgurl) {
  120. var img = new Image();
  121. img.src = imgurl;
  122. var canvas = document.createElement("canvas");
  123. canvas.width = img.width;
  124. canvas.height = img.height;
  125. var ctx = canvas.getContext("2d");
  126. ctx.drawImage(img, 0, 0, img.width, img.height);
  127. var dataURL = canvas.toDataURL("image/png");
  128. return dataURL
  129. }