123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- //js点击添加html
- // var is_pc = $(".is_pc").html();
- var oldContent = $("#head").attr("content");
- var content = "width=device-width, initial-scale=1,maximum-scale=10,minimum-scale=0.1,user-scalable=no";
- var is_not_set = $(".is_not_set").html();
- var report_info = $(".report_info").html();
- /*获取 密码设置*/
- function getReportPasswordInfo() {
- return $(".report_info").html();
- }
- //js添加html
- var table = document.getElementById("table");
- if (table !== null && table !== undefined) {
- var rows = table.rows.length;
- if (rows > 0) {
- var num = table.rows[0].cells.length;
- if (num > 3) {
- var html = '<div class="title-menu none"> ' + '<div class="title-content">' + ' </div>' +
- '<div class="save-box" id="save-box"><button class="cancel btn">重置</button> <button class="save btn">保存</button></div>'
- + ' </div>';
- $("body").append(html);
- for (i = 0; i < num; i++) {
- var value = table.rows[0].cells[i].innerHTML;
- var valueclass = table.rows[0].cells[i].getAttribute("class");
- // alert(valueclass);
- var len = strlen(value);
- var btn_font = "btn-font";
- if (len > 10) {
- btn_font = "btn-font-10";
- } else if (len >= 6) {
- btn_font = "btn-font-" + len;
- }
- // alert(btn_font);
- $(".title-content").append('<button id="' + valueclass + '" class="btn checked ' + valueclass + ' ' + btn_font + ' ">' + value + '</button>');
- }
- var yu = 4 - num % 4;
- if (yu > 0) {
- for (x = 0; x < yu; x++) $(".title-content").append('<button class="btn visibility-hidden"></button>');
- }
- }
- }
- } else {
- is_not_set = "1";
- }
- //选择选项
- $(".title-content .btn").click(function () {
- if ($(this).hasClass("checked")) {
- $(this).removeClass("checked");
- } else {
- $(this).addClass("checked");
- }
- });
- //点击重置
- $(".cancel").click(function () {
- $(".title-content .btn").each(function (i, o) {
- if (!$(o).hasClass("checked")) {
- $(o).addClass("checked");
- }
- });
- var columnValueStr = ColumnSave();
- $(".condition-box").removeClass("none");
- $(".title-menu").addClass("none");
- });
- function JumpColumn() {
- if (is_not_set === "1") {
- alert("当前界面无法设置");
- return;
- }
- SetColumn();
- $("#head").attr("content", content);
- $(".condition-box").addClass("none");
- $(".title-menu").removeClass("none");
- }
- function SetColumn(columns) {
- if (columns !== null && columns !== undefined) {
- ColumnSave(columns.split(","));
- }
- return columns;
- }
- function ColumnSave(columns) {
- var colspans = [];
- var columnValues = [];
- var colspan_total = 0;
- $(".title-content .btn").each(function (i, o) {
- var columnValue = $(o).html();
- if (columns !== null && columns !== undefined) {
- if (columns.indexOf(columnValue) !== -1) {
- $(o).removeClass("checked");
- }
- }
- var valueclass = $(o).attr("class");
- var useclass = valueclass.split(" ");
- var is_checked = $(o).hasClass("checked");
- for (i = 0; i < useclass.length; i++) {
- if (useclass[i].indexOf("reportFormTableColumn_") == 0) {
- if (is_checked) {
- $(".condition-box ." + useclass[i] + " ").removeClass("none");
- var colspan_item = $(".condition-box ." + useclass[i] + " ").attr("colspan");
- if (colspan_item != undefined && colspan_item != null) {
- colspan_total = colspan_total + parseInt(colspan_item);
- }
- } else {
- $(".condition-box ." + useclass[i] + " ").addClass("none");
- columnValues.push(columnValue);
- }
- } else if (useclass[i].indexOf("reportFormTableColumnMany_") == 0) {
- var useManyclass = useclass[i].split("@");
- if (useManyclass.length > 1) {
- if (!colspans.hasOwnProperty(useManyclass[0])) {
- colspans[useManyclass[0]] = 0;
- }
- if (is_checked) {
- var colspan = parseInt(useManyclass[1]);
- colspans[useManyclass[0]] = colspans[useManyclass[0]] + colspan;
- }
- }
- }
- }
- });
- for (var key in colspans) {
- if (colspans[key] == 0) {
- $(".condition-box ." + key + " ").addClass("none");
- } else {
- $(".condition-box ." + key + " ").attr("colspan", colspans[key]);
- $(".condition-box ." + key + " ").removeClass("none");
- }
- }
- var colspan_with = $(".colspan_with").html();
- if (colspan_with !== undefined && colspan_with.length > 0) {
- var documentWidth = parseInt(colspan_total) * parseFloat(colspan_with);
- if (documentWidth > 100) {
- $("#table-box").width(documentWidth + "%");
- } else {
- $("#table-box").width("100%");
- }
- }
- $("#head").attr("content", oldContent);
- return "ColumnSave@" + columnValues.join(',');
- }
- //点击保存显示
- $(".save").click(function () {
- //判断button里面哪个含有checked;
- var columnValueStr = ColumnSave();
- $(".condition-box").removeClass("none");
- $(".title-menu").addClass("none");
- alert(columnValueStr);
- });
- //长按事件
- // $.fn.longPress = function(fn) {
- // var timeout = undefined;
- // var $this = this;
- // for(var i = 0; i < $this.length; i++) {
- // (function(target) {
- // var timeout;
- // target.addEventListener('touchstart', function(event) {
- // timeout = setTimeout(function() {
- // //fn.apply(target);
- // fn(event);
- // }, 500);
- // }, false);
- // target.addEventListener('touchend', function(event) {
- // clearTimeout(timeout);
- // }, false);
- // })($this[i]);
- // }
- // };
- //长按
- // $("#condition,#title").longPress(function(e){
- // JumpColumn();
- // });
- //双击头部显示
- // $("#condition,#title").dblclick(function () {
- // JumpColumn();
- // });
- //获取中文 长度
- function strlen(str) {
- var len = 0;
- for (var i = 0; i < str.length; i++) {
- var c = str.charCodeAt(i);
- //单字节加1
- if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
- len += 0.5;
- } else {
- len++;
- }
- }
- if (len > parseInt(len)) {
- len++;
- }
- return len;
- }
- $(document).ready(function () {
- if (is_not_set === "1") {
- return;
- }
- if (report_info !== null && report_info !== undefined && report_info !== '') {
- var report_info_obj = eval("(" + report_info + ")");
- if (report_info_obj.hide_columns !== undefined && report_info_obj.hide_columns !== null && report_info_obj.hide_columns !== '') {
- ColumnSave(report_info_obj.hide_columns.split(","));
- }
- }
- });
|