common.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //js点击添加html
  2. // var is_pc = $(".is_pc").html();
  3. var oldContent = $("#head").attr("content");
  4. var content = "width=device-width, initial-scale=1,maximum-scale=10,minimum-scale=0.1,user-scalable=no";
  5. var is_not_set = $(".is_not_set").html();
  6. var report_info = $(".report_info").html();
  7. /*获取 密码设置*/
  8. function getReportPasswordInfo() {
  9. return $(".report_info").html();
  10. }
  11. //js添加html
  12. var table = document.getElementById("table");
  13. if (table !== null && table !== undefined) {
  14. var rows = table.rows.length;
  15. if (rows > 0) {
  16. var num = table.rows[0].cells.length;
  17. if (num > 3) {
  18. var html = '<div class="title-menu none"> ' + '<div class="title-content">' + ' </div>' +
  19. '<div class="save-box" id="save-box"><button class="cancel btn">重置</button> <button class="save btn">保存</button></div>'
  20. + ' </div>';
  21. $("body").append(html);
  22. for (i = 0; i < num; i++) {
  23. var value = table.rows[0].cells[i].innerHTML;
  24. var valueclass = table.rows[0].cells[i].getAttribute("class");
  25. // alert(valueclass);
  26. var len = strlen(value);
  27. var btn_font = "btn-font";
  28. if (len > 10) {
  29. btn_font = "btn-font-10";
  30. } else if (len >= 6) {
  31. btn_font = "btn-font-" + len;
  32. }
  33. // alert(btn_font);
  34. $(".title-content").append('<button id="' + valueclass + '" class="btn checked ' + valueclass + ' ' + btn_font + ' ">' + value + '</button>');
  35. }
  36. var yu = 4 - num % 4;
  37. if (yu > 0) {
  38. for (x = 0; x < yu; x++) $(".title-content").append('<button class="btn visibility-hidden"></button>');
  39. }
  40. }
  41. }
  42. } else {
  43. is_not_set = "1";
  44. }
  45. //选择选项
  46. $(".title-content .btn").click(function () {
  47. if ($(this).hasClass("checked")) {
  48. $(this).removeClass("checked");
  49. } else {
  50. $(this).addClass("checked");
  51. }
  52. });
  53. //点击重置
  54. $(".cancel").click(function () {
  55. $(".title-content .btn").each(function (i, o) {
  56. if (!$(o).hasClass("checked")) {
  57. $(o).addClass("checked");
  58. }
  59. });
  60. var columnValueStr = ColumnSave();
  61. $(".condition-box").removeClass("none");
  62. $(".title-menu").addClass("none");
  63. });
  64. function JumpColumn() {
  65. if (is_not_set === "1") {
  66. alert("当前界面无法设置");
  67. return;
  68. }
  69. oldContent = $("#head").attr("content");
  70. SetColumn();
  71. $("#head").attr("content", content);
  72. $(".condition-box").addClass("none");
  73. $(".title-menu").removeClass("none");
  74. }
  75. function SetColumn(columns) {
  76. if (columns !== null && columns !== undefined) {
  77. ColumnSave(columns.split(","));
  78. }
  79. return columns;
  80. }
  81. function ColumnSave(columns) {
  82. var colspans = [];
  83. var columnValues = [];
  84. var colspan_total = 0;
  85. $(".title-content .btn").each(function (i, o) {
  86. var columnValue = $(o).html();
  87. if (columns !== null && columns !== undefined) {
  88. if (columns.indexOf(columnValue) !== -1) {
  89. $(o).removeClass("checked");
  90. }
  91. }
  92. var valueclass = $(o).attr("class");
  93. var useclass = valueclass.split(" ");
  94. var is_checked = $(o).hasClass("checked");
  95. for (i = 0; i < useclass.length; i++) {
  96. if (useclass[i].indexOf("reportFormTableColumn_") == 0) {
  97. if (is_checked) {
  98. $(".condition-box ." + useclass[i] + " ").removeClass("none");
  99. var colspan_item = $(".condition-box ." + useclass[i] + " ").attr("colspan");
  100. if (colspan_item != undefined && colspan_item != null) {
  101. colspan_total = colspan_total + parseInt(colspan_item);
  102. }
  103. } else {
  104. $(".condition-box ." + useclass[i] + " ").addClass("none");
  105. columnValues.push(columnValue);
  106. }
  107. } else if (useclass[i].indexOf("reportFormTableColumnMany_") == 0) {
  108. var useManyclass = useclass[i].split("@");
  109. if (useManyclass.length > 1) {
  110. if (!colspans.hasOwnProperty(useManyclass[0])) {
  111. colspans[useManyclass[0]] = 0;
  112. }
  113. if (is_checked) {
  114. var colspan = parseInt(useManyclass[1]);
  115. colspans[useManyclass[0]] = colspans[useManyclass[0]] + colspan;
  116. }
  117. }
  118. }
  119. }
  120. });
  121. for (var key in colspans) {
  122. if (colspans[key] == 0) {
  123. $(".condition-box ." + key + " ").addClass("none");
  124. } else {
  125. $(".condition-box ." + key + " ").attr("colspan", colspans[key]);
  126. $(".condition-box ." + key + " ").removeClass("none");
  127. }
  128. }
  129. var colspan_with = $(".colspan_with").html();
  130. if (colspan_with !== undefined && colspan_with.length > 0) {
  131. var documentWidth = parseInt(colspan_total) * parseFloat(colspan_with);
  132. if (documentWidth > 100) {
  133. $("#table-box").width(documentWidth + "%");
  134. } else {
  135. $("#table-box").width("100%");
  136. }
  137. }
  138. return "ColumnSave@" + columnValues.join(',');
  139. }
  140. //点击保存显示
  141. $(".save").click(function () {
  142. //判断button里面哪个含有checked;
  143. var columnValueStr = ColumnSave();
  144. $("#head").attr("content", oldContent);
  145. $(".condition-box").removeClass("none");
  146. $(".title-menu").addClass("none");
  147. alert(columnValueStr);
  148. });
  149. //长按事件
  150. // $.fn.longPress = function(fn) {
  151. // var timeout = undefined;
  152. // var $this = this;
  153. // for(var i = 0; i < $this.length; i++) {
  154. // (function(target) {
  155. // var timeout;
  156. // target.addEventListener('touchstart', function(event) {
  157. // timeout = setTimeout(function() {
  158. // //fn.apply(target);
  159. // fn(event);
  160. // }, 500);
  161. // }, false);
  162. // target.addEventListener('touchend', function(event) {
  163. // clearTimeout(timeout);
  164. // }, false);
  165. // })($this[i]);
  166. // }
  167. // };
  168. //长按
  169. // $("#condition,#title").longPress(function(e){
  170. // JumpColumn();
  171. // });
  172. //双击头部显示
  173. // $("#condition,#title").dblclick(function () {
  174. // JumpColumn();
  175. // });
  176. //获取中文 长度
  177. function strlen(str) {
  178. var len = 0;
  179. for (var i = 0; i < str.length; i++) {
  180. var c = str.charCodeAt(i);
  181. //单字节加1
  182. if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
  183. len += 0.5;
  184. } else {
  185. len++;
  186. }
  187. }
  188. if (len > parseInt(len)) {
  189. len++;
  190. }
  191. return len;
  192. }
  193. $(document).ready(function () {
  194. if (is_not_set === "1") {
  195. return;
  196. }
  197. if (report_info !== null && report_info !== undefined && report_info !== '') {
  198. var report_info_obj = eval("(" + report_info + ")");
  199. if (report_info_obj.hide_columns !== undefined && report_info_obj.hide_columns !== null && report_info_obj.hide_columns !== '') {
  200. ColumnSave(report_info_obj.hide_columns.split(","));
  201. }
  202. }
  203. });