/** * 通用jquery类库 v1.1 * xuwei 2020-07-28 */ //获取参数 function request(paras) { var url = location.href; var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&"); var paraObj = {}; for (i = 0; i < paraString.length; i++) { paraObj[decodeURI(paraString[i].substring(0, paraString[i].indexOf("=")).toLowerCase())] = paraString[i].substring(paraString[i].indexOf("=") + 1, paraString[i].length); } var returnValue = paraObj[decodeURI(paras.toLowerCase())]; if (typeof returnValue == "undefined") { return ""; } else { return decodeURI(returnValue); } } //替换全部 String.prototype.replaceAll = function (s1, s2) { if (s1 != null && s2 != null) return this.replace(new RegExp(s1, "gm"), s2); } //格式化日期 Date.prototype.format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } //序列化表单为Json $.fn.serializeJson = function () { var o = {}; var a = this.serializeArray(); $.each(a, function () { if (o[this.name] !== undefined) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; } //加载数据 $.fn.loadHtml = function (url, templateid, callback) { const id = '#' + $(this).attr('id'); $(id).html('数据加载中...'); $.get(url, function (data) { var json = JSON.parse(data); if (json['success'] == true) { $(id).empty(); for (var i = 0; i < json['rows'].length; i++) { var temp = $(templateid).html(); temp = temp.replaceAll('{index}', i); for (var key in json['rows'][i]) { //temp = temp.replaceAll('{' + key + '}', json['rows'][i][key]); temp = temp.replace(new RegExp('{' + key + '}', "gm"), json['rows'][i][key]) //temp = temp.replace('{' + key + '}', json['rows'][i][key]); } $(id).append(temp); } if (callback) callback(json); } else { swal({ title: '系统异常!', text: '数据获取失败!', icon: 'error', button: '确定' }).then(function () { //window.location = '../ProductCheck/login.html'; }); } }); } //复选框加载数据 $.fn.loadSelect = function (url, callback) { const id = '#' + $(this).attr('id'); $.get(url, function (data) { var json = JSON.parse(data); if (json['success'] == true) { var temp = ''; $(id).empty(); $(id).append(''); for (var i = 0; i < json['rows'].length; i++) { $(id).append(temp .replace('{key}', json['rows'][i]['ID']) .replace('{value}', json['rows'][i]['NAME']) ); } $(id).get(0).selectedIndex = 0; if (callback) callback(json); } else { swal({ title: '系统异常!', text: '数据获取失败!', icon: 'error', button: '确定' }).then(function () { //window.location = '../ProductCheck/login.html'; }); } }); } //复选框加载数据 //查返工工序专用 $.fn.loadSelectFromData = function (json, callback) { const id = '#' + $(this).attr('id'); var temp = ''; $(id).empty(); $(id).append(''); for (var i = 0; i < json.length; i++) { $(id).append(temp .replace('{key}', json[i]['REWORKPROCEDUREID']) .replace('{value}', json[i]['REWORKPROCEDURENAME']) ); } $(id).get(0).selectedIndex = 0; if (callback) callback(json); //var json = JSON.parse(data); //if (json['success'] == true) { //} //else { // swal({ // title: '系统异常!', // text: '数据获取失败!', // icon: 'error', // button: '确定' // }).then(function () { // //window.location = '../ProductCheck/login.html'; // }); //} } $.fn.loadSelectPicker = function (url, callback) { const id = '#' + $(this).attr('id'); $.get(url, function (data) { var json = JSON.parse(data); if (json['success'] == true) { var temp = ''; $(id).empty(); $(id).append(''); for (var i = 0; i < json['rows'].length; i++) { $(id).append(temp .replace('{key}', json['rows'][i]['ID']) .replace('{value}', json['rows'][i]['NAME']) ); } $(id).get(0).selectedIndex = 0; $(id).selectpicker('refresh'); if (callback) callback(json); } else { swal({ title: '系统异常!', text: '数据获取失败!', icon: 'error', button: '确定' }).then(function () { //window.location = '../ProductCheck/login.html'; }); } }); } //单选框处理 $.fn.getRadioVal = function () { var result = ''; $(this).find('input:radio').each(function () { if ($(this).prop('checked') == true) { if (result != '') result += ','; result += $(this).val(); } }); return result; } $.fn.setRadioVal = function (val) { $(this).find("input:radio").each(function (index, el) { if ($(this).val() == val) { $(this).prop('checked', true); $(this).parent("label").addClass('active'); } else { $(this).prop('checked', false); $(this).parent("label").removeClass('active'); } }); } //复选框处理 $.fn.getCheckBoxVal = function () { var result = ''; $(this).find('input:checkbox').each(function () { if ($(this).prop('checked') == true) { if (result != '') result += ','; result += $(this).val(); } }); return result; } $.fn.setCheckBoxVal = function setCheckBoxVal(val) { var vals = val.split(','); $(this).find("input:checkbox").each(function (index, el) { $(this).prop('checked', false); $(this).parent("label").removeClass('active'); for (var i = 0; i < vals.length; i++) { if ($(this).val() == vals[i]) { $(this).prop('checked', true); $(this).parent("label").addClass('active'); } } }); } //下拉选项框 $.fn.getSelectVal = function () { var result = ''; $(this).find('select option').each(function () { if ($(this).prop('selected') == true) { if (result != '') result += ','; result += $(this).val(); } }); return result; } $.fn.setSelectVal = function (val) { var vals = val.split(','); $(this).find("select").each(function (index, el) { $(this).find("option").each(function () { if ($(this).val() == vals[index]) { $(this).prop('selected', true); } else { $(this).prop('selected', false); } }); }); } //窗体显示隐藏 $.fn.animateShow = function (callback) { $(this).animate({ top: 880 }, { easing: "easeInOutBack",complete: function () { if(callback) callback(); } }); } $.fn.animateHide = function (callback) { $(this).animate({ top: -880 }, { easing: "easeInOutBack", complete: function () { if(callback) callback(); } }); } var xuwell = { //加载数据到Select控件,参数:id url data fieldKey fieldValue autoDisabled 'loadSelect': function (opt) { var id = typeof (opt.id) == 'undefined' ? null : opt.id; var url = typeof (opt.url) == 'undefined' ? null : opt.url; var data = typeof (opt.data) == 'undefined' ? null : opt.data; var fieldKey = typeof (opt.fieldKey) == 'undefined' ? null : opt.fieldKey; var fieldValue = typeof (opt.fieldValue) == 'undefined' ? null : opt.fieldValue; var autoDisabled = typeof (opt.autoDisabled) == 'undefined' ? true : false; var addTitle = typeof (opt.addTitle) == 'undefined' ? true : opt.addTitle; var onLoad = typeof (opt.onLoad) == 'undefined' ? null : opt.onLoad; var onError = typeof (opt.onError) == 'undefined' ? null : opt.onError; $.get(url, data, function (result) { var json = JSON.parse(result); if (json['success'] == true) { var temp = ''; $(id).empty(); if (addTitle) $(id).append(''); for (var i = 0; i < json['rows'].length; i++) { $(id).append(temp .replace('$key$', json['rows'][i][fieldKey]) .replace('$value$', json['rows'][i][fieldValue]) ); } if (autoDisabled) $(id).prop('disabled', json['total'] == 0 && autoDisabled); $(id).get(0).selectedIndex = 0; if (onLoad != null) onLoad(json); } else { swal({ title: '登录异常!', text: '请您先登录系统!', icon: 'error', button: '确定' }).then(function () { window.location = '/main/login/login.html'; }); } }).fail(function () { if (onError != null) onError(); }); }, 'loadSelectPicker': function (opt) { var id = typeof (opt.id) == 'undefined' ? null : opt.id; var url = typeof (opt.url) == 'undefined' ? null : opt.url; var data = typeof (opt.data) == 'undefined' ? null : opt.data; var fieldKey = typeof (opt.fieldKey) == 'undefined' ? null : opt.fieldKey; var fieldValue = typeof (opt.fieldValue) == 'undefined' ? null : opt.fieldValue; var autoDisabled = typeof (opt.autoDisabled) == 'undefined' ? true : false; var addTitle = typeof (opt.addTitle) == 'undefined' ? true : opt.addTitle; var onLoad = typeof (opt.onLoad) == 'undefined' ? null : opt.onLoad; var onError = typeof (opt.onError) == 'undefined' ? null : opt.onError; $.get(url, data, function (result) { var json = JSON.parse(result); if (json['success'] == true) { var temp = ''; $(id).empty(); if (addTitle) $(id).append(''); for (var i = 0; i < json['rows'].length; i++) { $(id).append(temp .replace('$key$', json['rows'][i][fieldKey]) .replace('$value$', json['rows'][i][fieldValue]) ); } $(id).prop('disabled', json['total'] == 0 && autoDisabled); $(id).get(0).selectedIndex = 0; $(id).selectpicker('refresh'); if (onLoad != null) onLoad(json); } else { swal({ title: '登录异常!', text: '请您先登录系统!', icon: 'error', button: '确定' }).then(function () { window.location = '/main/login/login.html'; }); } }).fail(function () { if (onError != null) onError(); }); }, //加载bootstrapTable 'loadTable': function (opt) { var id = typeof (opt.id) == 'undefined' ? '#table' : opt.id; var toolbar = typeof (opt.toolbar) == 'undefined' ? '#toolbar' : opt.toolbar; var formSearchId = typeof (opt.formSearchId) == 'undefined' ? '#formSearch' : opt.formSearchId; var pageSize = typeof (opt.pageSize) == 'undefined' ? 10 : opt.pageSize; var pageNumber = typeof (opt.pageNumber) == 'undefined' ? 1 : opt.pageNumber; var sortable = typeof (opt.sortable) == 'undefined' ? false : opt.sortable; var url = typeof (opt.url) == 'undefined' ? '' : opt.url; $(id).bootstrapTable('destroy').bootstrapTable({ toggle: "table", boolbar: toolbar, url: url, locale: "zh-CN", //showExport: true, //是否显示导出按钮 //exportdatatype: 'all',//basic', 'all', 'selected'. //exportOptions: { // ignoreColumn: [0, 1], //忽略某一列的索引 // fileName: '导出数据', //文件名称设置 // worksheetName: 'sheet1', //表格工作区名称 // tableName: '数据', // excelstyles: ['background-color', 'color', 'font-size', 'font-weight', 'border-top'] //}, //buttonsAlign: "right", //按钮位置 //exportTypes: ['csv'], //导出文件类型 sortable: sortable, sortOrder: "asc", pagination: true, pageNumber: pageNumber, pageSize: pageSize, pageList: "[10, 12, 15 , 20, 100, 500, 1000, 2000, 5000, ALL]", striped: true, sidePagination: 'server', queryParams: function (params) { var args = $.param({ pageNumber: params.offset / params.limit, pageSize: params.limit, sort: params.sort, order: params.order }) + "&" + $(formSearchId).serialize(); return args; }, responseHandler: function (res) { return res; }, onLoadSuccess: function (json) { //var json = JSON.parse(data); if (json['success'] == false) { swal({ title: '登录异常!', text: '请您先登录系统!', icon: 'error', button: '确定' }).then(function () { window.location = '/main/login/login.html'; }); } if (typeof (opt.onLoadSuccess) != 'undefined') { opt.onLoadSuccess(json); } } }); }, 'exportFile': function exportFile(tableId, fileName) { /** * 表格导出 * style="mso-number-format:'@';" * 1) 文本:'@' * 2) 日期:'yyyy/mm/dd' * 3) 数字:'#,##0.00' * 4) 货币:'¥#,##0.00' * 5) 百分比:'#0.00%' */ if (tableId == 'undefined') tableId = 'table'; if (fileName == 'undefined') fileName = '数据导出.xls'; //获取表格 var exportFileContent = document.getElementById(tableId).innerHTML; exportFileContent = '