common.js 7.8 KB

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