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. SetColumn();
  70. $("#head").attr("content", content);
  71. $(".condition-box").addClass("none");
  72. $(".title-menu").removeClass("none");
  73. }
  74. function SetColumn(columns) {
  75. if (columns !== null && columns !== undefined) {
  76. ColumnSave(columns.split(","));
  77. }
  78. return columns;
  79. }
  80. function ColumnSave(columns) {
  81. var colspans = [];
  82. var columnValues = [];
  83. var colspan_total = 0;
  84. $(".title-content .btn").each(function (i, o) {
  85. var columnValue = $(o).html();
  86. if (columns !== null && columns !== undefined) {
  87. if (columns.indexOf(columnValue) !== -1) {
  88. $(o).removeClass("checked");
  89. }
  90. }
  91. var valueclass = $(o).attr("class");
  92. var useclass = valueclass.split(" ");
  93. var is_checked = $(o).hasClass("checked");
  94. for (i = 0; i < useclass.length; i++) {
  95. if (useclass[i].indexOf("reportFormTableColumn_") == 0) {
  96. if (is_checked) {
  97. $(".condition-box ." + useclass[i] + " ").removeClass("none");
  98. var colspan_item = $(".condition-box ." + useclass[i] + " ").attr("colspan");
  99. if (colspan_item != undefined && colspan_item != null) {
  100. colspan_total = colspan_total + parseInt(colspan_item);
  101. }
  102. } else {
  103. $(".condition-box ." + useclass[i] + " ").addClass("none");
  104. columnValues.push(columnValue);
  105. }
  106. } else if (useclass[i].indexOf("reportFormTableColumnMany_") == 0) {
  107. var useManyclass = useclass[i].split("@");
  108. if (useManyclass.length > 1) {
  109. if (!colspans.hasOwnProperty(useManyclass[0])) {
  110. colspans[useManyclass[0]] = 0;
  111. }
  112. if (is_checked) {
  113. var colspan = parseInt(useManyclass[1]);
  114. colspans[useManyclass[0]] = colspans[useManyclass[0]] + colspan;
  115. }
  116. }
  117. }
  118. }
  119. });
  120. for (var key in colspans) {
  121. if (colspans[key] == 0) {
  122. $(".condition-box ." + key + " ").addClass("none");
  123. } else {
  124. $(".condition-box ." + key + " ").attr("colspan", colspans[key]);
  125. $(".condition-box ." + key + " ").removeClass("none");
  126. }
  127. }
  128. var colspan_with = $(".colspan_with").html();
  129. if (colspan_with !== undefined && colspan_with.length > 0) {
  130. var documentWidth = parseInt(colspan_total) * parseFloat(colspan_with);
  131. if (documentWidth > 100) {
  132. $("#table-box").width(documentWidth + "%");
  133. } else {
  134. $("#table-box").width("100%");
  135. }
  136. }
  137. $("#head").attr("content", oldContent);
  138. return "ColumnSave@" + columnValues.join(',');
  139. }
  140. //点击保存显示
  141. $(".save").click(function () {
  142. //判断button里面哪个含有checked;
  143. var columnValueStr = ColumnSave();
  144. $(".condition-box").removeClass("none");
  145. $(".title-menu").addClass("none");
  146. alert(columnValueStr);
  147. });
  148. //长按事件
  149. // $.fn.longPress = function(fn) {
  150. // var timeout = undefined;
  151. // var $this = this;
  152. // for(var i = 0; i < $this.length; i++) {
  153. // (function(target) {
  154. // var timeout;
  155. // target.addEventListener('touchstart', function(event) {
  156. // timeout = setTimeout(function() {
  157. // //fn.apply(target);
  158. // fn(event);
  159. // }, 500);
  160. // }, false);
  161. // target.addEventListener('touchend', function(event) {
  162. // clearTimeout(timeout);
  163. // }, false);
  164. // })($this[i]);
  165. // }
  166. // };
  167. //长按
  168. // $("#condition,#title").longPress(function(e){
  169. // JumpColumn();
  170. // });
  171. //双击头部显示
  172. // $("#condition,#title").dblclick(function () {
  173. // JumpColumn();
  174. // });
  175. //获取中文 长度
  176. function strlen(str) {
  177. var len = 0;
  178. for (var i = 0; i < str.length; i++) {
  179. var c = str.charCodeAt(i);
  180. //单字节加1
  181. if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
  182. len += 0.5;
  183. } else {
  184. len++;
  185. }
  186. }
  187. if (len > parseInt(len)) {
  188. len++;
  189. }
  190. return len;
  191. }
  192. $(document).ready(function () {
  193. if (is_not_set === "1") {
  194. return;
  195. }
  196. if (report_info !== null && report_info !== undefined && report_info !== '') {
  197. var report_info_obj = eval("(" + report_info + ")");
  198. if (report_info_obj.hide_columns !== undefined && report_info_obj.hide_columns !== null && report_info_obj.hide_columns !== '') {
  199. ColumnSave(report_info_obj.hide_columns.split(","));
  200. }
  201. }
  202. });