You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
516 lines
15 KiB
516 lines
15 KiB
var AddWindowTitle = "Add";
|
|
var UpdateWindowTitle = "Update";
|
|
var ChangeWindowTitle = "Change";
|
|
var HistoryWindowTitle = "History";
|
|
var MsgNormalTitle = "Info";
|
|
var MsgErrTitle = "Error";
|
|
var NothingSelectTitle = "Please select record.";
|
|
var OnlyOneTitle = "Each can only handle a record.";
|
|
var AtLeastOneTitle= "Select at least one record!";
|
|
var FixDeleteTitle = "Delete record?";
|
|
var PleaseSelectTitle = "Please select";
|
|
|
|
//消息提示框
|
|
function MSIFade(title, message) {
|
|
$.messager.show({
|
|
title: title,
|
|
msg: message,
|
|
showType: 'fade'
|
|
});
|
|
}
|
|
|
|
function MS(title, message) {
|
|
$.messager.alert(title, message);
|
|
}
|
|
function MSE(title, message) {
|
|
$.messager.alert(title, message, 'error');
|
|
}
|
|
function MSI(title, message) {
|
|
//alert(message);
|
|
$.messager.alert(title, message, 'info');
|
|
}
|
|
|
|
function MSW(title, message) {
|
|
$.messager.alert(title, message, 'warning');
|
|
}
|
|
|
|
function MSQ(title, message, OKfun) {
|
|
$.messager.confirm(title, message, function (r) {
|
|
if (r) {
|
|
OKfun();
|
|
}
|
|
});
|
|
}
|
|
|
|
function MSE(title, message, OKfun) {
|
|
$.messager.prompt(title, message, function (r) {
|
|
if (r) {
|
|
OKfun(r);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function isValidate() {
|
|
return $("#Mainform").form('validate');
|
|
|
|
}
|
|
|
|
//自定义验证
|
|
$.extend($.fn.validatebox.defaults.rules, {
|
|
NOCHS: {
|
|
validator: function (value, param) {
|
|
if (param == null) {
|
|
if (escape(value).indexOf("%u") == -1) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
else {
|
|
var len = $.trim(value).length;
|
|
if (escape(value).indexOf("%u") == -1 && (len >= param[0] && len <= param[1])) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
},
|
|
message: ('{0}' != '') ? '请输入内容长度不大于{1}的非汉字字符' : '请输入汉字非汉字字符'
|
|
},
|
|
WORKSTATION: {
|
|
validator: function (value) {
|
|
var len = $.trim(value).length;
|
|
if (len != 5) {
|
|
return false;
|
|
}
|
|
else if (value.substring(4, 5).toUpperCase() != "L" & value.substring(4, 5).toUpperCase() != "R" & value.substring(4, 5).toUpperCase() != "A") {
|
|
return false;
|
|
}
|
|
else {
|
|
return true;
|
|
}
|
|
|
|
},
|
|
message: '工位编号不符合规则(最大5位,且最后一位为R或L或A)'
|
|
},
|
|
DATE: {
|
|
validator: function (value) {
|
|
return isDate(value);
|
|
},
|
|
message: '请输入合法日期'
|
|
},
|
|
CHS: {
|
|
validator: function (value, param) {
|
|
if (param == null) {
|
|
return /^[\u0391-\uFFE5]+$/.test(value);
|
|
}
|
|
else {
|
|
var len = $.trim(value).length;
|
|
return /^[\u0391-\uFFE5]+$/.test(value) && (len >= param[0] && len <= param[1]);
|
|
}
|
|
},
|
|
message: ('{0}' != '') ? '请输入内容长度不大于{1}的汉字' : '请输入汉字'
|
|
},
|
|
ENG: {
|
|
validator: function (value, param) {
|
|
return /^[A-Za-z]+$/.test(value);
|
|
},
|
|
message: '请输入英文'
|
|
},
|
|
ZIP: {
|
|
validator: function (value, param) {
|
|
return /^[1-9]\d{5}$/.test(value);
|
|
},
|
|
message: '邮政编码不存在'
|
|
},
|
|
QQ: {
|
|
validator: function (value, param) {
|
|
return /^[1-9]\d{4,10}$/.test(value);
|
|
},
|
|
message: 'QQ号码不正确'
|
|
},
|
|
mobile: {
|
|
validator: function (value, param) {
|
|
return /^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/.test(value);
|
|
},
|
|
message: '手机号码不正确'
|
|
},
|
|
loginName: {
|
|
validator: function (value, param) {
|
|
return /^[\u0391-\uFFE5\w]+$/.test(value);
|
|
},
|
|
message: '登录名称只允许汉字、英文字母、数字及下划线。'
|
|
},
|
|
safepass: {
|
|
validator: function (value, param) {
|
|
return safePassword(value);
|
|
},
|
|
message: '密码由字母和数字组成,至少6位'
|
|
},
|
|
equalTo: {
|
|
validator: function (value, param) {
|
|
return value == $(param[0]).val();
|
|
},
|
|
message: '两次输入的字符不一至'
|
|
},
|
|
number: {
|
|
validator: function (value, param) {
|
|
if (param == null) {
|
|
return /^\d+$/.test(value);
|
|
}
|
|
else {
|
|
var len = $.trim(value).length;
|
|
return /^\d+$/.test(value) && (len >= param[0] && len <= param[1]);
|
|
}
|
|
|
|
},
|
|
message: ('{0}' != '') ? '请输入内容长度不大于{1}的数字' : '请输入数字'
|
|
},
|
|
idcard: {
|
|
validator: function (value, param) {
|
|
return idCard(value);
|
|
},
|
|
message: '请输入正确的身份证号码'
|
|
}
|
|
});
|
|
|
|
/* 密码由字母和数字组成,至少6位 */
|
|
var safePassword = function (value) {
|
|
return !(/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/.test(value));
|
|
}
|
|
|
|
var idCard = function (value) {
|
|
if (value.length == 18 && 18 != value.length) return false;
|
|
var number = value.toLowerCase();
|
|
var d, sum = 0, v = '10x98765432', w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2], a = '11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91';
|
|
var re = number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/);
|
|
if (re == null || a.indexOf(re[1]) < 0) return false;
|
|
if (re[2].length == 9) {
|
|
number = number.substr(0, 6) + '19' + number.substr(6);
|
|
d = ['19' + re[4], re[5], re[6]].join('-');
|
|
} else d = [re[9], re[10], re[11]].join('-');
|
|
if (!isDateTime.call(d, 'yyyy-MM-dd')) return false;
|
|
for (var i = 0; i < 17; i++) sum += number.charAt(i) * w[i];
|
|
return (re[2].length == 9 || number.charAt(17) == v.charAt(sum % 11));
|
|
}
|
|
|
|
//获取表格选中行
|
|
function getGVRows() {
|
|
var Rows = $('#QDateGrid').datagrid('getRows');
|
|
if (Rows) {
|
|
return Rows;
|
|
}
|
|
}
|
|
|
|
//action提交
|
|
function submitByButton(url) {
|
|
var myform = $('form');
|
|
|
|
if (myform) {
|
|
myform.attr("action", url);
|
|
//alert(myform.attr("action"));
|
|
myform.submit();
|
|
}
|
|
|
|
}
|
|
|
|
//获取表格选中主键
|
|
function GetSelectID() {
|
|
var ids = [];
|
|
var rows = $('#QDateGrid').datagrid('getSelections');
|
|
for (var i = 0; i < rows.length; i++) {
|
|
ids.push(rows[i].code);
|
|
}
|
|
return rows;
|
|
}
|
|
|
|
//判断json集合项是否存在
|
|
function existsJsonItem(list, keyName, key) {
|
|
var r = false;
|
|
for (var i = 0; i < list.length; i++) {
|
|
if (list[i][keyName] == key) {
|
|
r = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
//查找json集合项
|
|
function findJsonItem(list, keyName, key) {
|
|
var item = null;
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
|
|
if (list[i][keyName] == key) {
|
|
item = list[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
return item;
|
|
}
|
|
|
|
//删除json集合项
|
|
function deleteJsonItem(list, keyName, key) {
|
|
|
|
for (var i = 0; i < list.length; i++) {
|
|
if (list[i][keyName] == key) {
|
|
list.splice(i, 1);
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
//随机数 单雨春
|
|
function numRand(x, y) {
|
|
var rand = parseInt(Math.random() * (x - y + 1) + y);
|
|
return rand;
|
|
}
|
|
|
|
//删除数组 单雨春
|
|
Array.prototype.remove = function (dx) {
|
|
if (isNaN(dx) || dx > this.length) { return false; }
|
|
for (var i = 0, n = 0; i < this.length; i++) {
|
|
if (this[i] != this[dx]) {
|
|
this[n++] = this[i]
|
|
}
|
|
}
|
|
this.length -= 1
|
|
}
|
|
|
|
|
|
// Trim
|
|
String.prototype.trim = function () {
|
|
return this.replace(/(^\s*)|(\s*$)/g, '');
|
|
}
|
|
|
|
//取消事件
|
|
function cancelEvent() {
|
|
if (event) {
|
|
event.returnValue = false; // 取消点击事件
|
|
}
|
|
}
|
|
|
|
function _isFormChanged() {
|
|
var isChanged = false;
|
|
var form = document.forms[0];
|
|
for (var i = 0; i < form.elements.length; i++) {
|
|
var element = form.elements[i];
|
|
var type = element.type;
|
|
if (type == "text" || type == "hidden" || type == "textarea" || type == "button") {
|
|
//无视只读的,因为有的只读项目为CODE名称,是在画显示后用脚本赋值上去的。可能和默认值不一致。
|
|
if (element.readOnly) {
|
|
continue;
|
|
}
|
|
if (element.value != element.defaultValue) {
|
|
isChanged = true;
|
|
break;
|
|
}
|
|
} else if (type == "radio" || type == "checkbox") {
|
|
if (element.checked != element.defaultChecked) {
|
|
isChanged = true;
|
|
break;
|
|
}
|
|
} else if (type == "select-one" || type == "select-multiple") {
|
|
for (var j = 0; j < element.options.length; j++) {
|
|
if (element.options[j].selected != element.options[j].defaultSelected) {
|
|
//如果默认没有选择,但是选择了第一项,则也认为是没有修改
|
|
if (element.options[j].defaultSelected == false && element.selectedIndex == 0) {
|
|
} else {
|
|
isChanged = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
// etc...
|
|
}
|
|
}
|
|
return isChanged;
|
|
}
|
|
|
|
function _doReturn(url) {
|
|
cancelEvent();
|
|
if (_isFormChanged()) {
|
|
if (!confirm('表单已被修改,是否放弃修改?')) {
|
|
return;
|
|
}
|
|
}
|
|
window.location.href = url;
|
|
}
|
|
|
|
function _doReturn(url, isChange) {
|
|
cancelEvent();
|
|
if (isChange) {
|
|
if (!confirm('表单已被修改,是否放弃修改?')) {
|
|
return;
|
|
}
|
|
}
|
|
window.location.href = url;
|
|
}
|
|
|
|
|
|
/* 查询模板开始 */
|
|
|
|
//查询模板
|
|
function ListQueryTL(programName) {
|
|
openAppWindow1('查询模板', '/QueryTL/QueryTLList?programName=' + programName, '600', '480');
|
|
}
|
|
|
|
//添加查询模板
|
|
function AddQueryTL(programName) {
|
|
openAppWindow1('添加模板', '/QueryTL/QueryTLEdit?programName=' + programName, '600', '480');
|
|
}
|
|
|
|
//修改查询模板
|
|
function UpdateQueryTL(programName, id) {
|
|
openAppWindow1('修改模板', '/QueryTL/QueryTLEdit?programName=' + programName + "&id=" + id, '600', '480');
|
|
}
|
|
|
|
/* 查询模板结束 */
|
|
|
|
//打开窗口
|
|
function openAppWindow1(title, url, width, height) {
|
|
document.getElementById("appWindow1_Frm").src = url;
|
|
|
|
var left = (document.documentElement.clientWidth - width) / 2
|
|
var top = (document.documentElement.clientHeight - height) / 2
|
|
|
|
$('#appWindow1').window({
|
|
title: title,
|
|
left: left,
|
|
top: 10,
|
|
width: width,
|
|
modal: true,
|
|
shadow: false,
|
|
collapsible: false,
|
|
closed: false,
|
|
closable: false,
|
|
minimizable: false,
|
|
maximizable: false,
|
|
height: height,
|
|
onClose: function () { document.getElementById("appWindow1_Frm").src = ""; },
|
|
onMove: function (left, top) {
|
|
var parentObj = $(this).window('window').parent();
|
|
;
|
|
if (left > 0 && top > 0) {
|
|
return;
|
|
}
|
|
if (left < 0) {
|
|
$(this).window('move', {
|
|
left: 1
|
|
});
|
|
}
|
|
if (top < 0) {
|
|
$(this).window('move', {
|
|
top: 1
|
|
});
|
|
}
|
|
var width = $(this).panel('options').width;
|
|
var height = $(this).panel('options').height;
|
|
var right = left + width;
|
|
var buttom = top + height;
|
|
var parentWidth = parentObj.width();
|
|
var parentHeight = parentObj.height();
|
|
if (parentObj.css("overflow") == "hidden") {
|
|
if (left > parentWidth - width) {
|
|
$(this).window('move', {
|
|
"left": parentWidth - width
|
|
});
|
|
}
|
|
if (top > parentHeight - $(this).parent().height()) {
|
|
$(this).window('move', {
|
|
"top": parentHeight - $(this).parent().height()
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
$('#appWindow1').window('open');
|
|
|
|
}
|
|
|
|
//关闭窗口
|
|
function closeAppWindow1() {
|
|
document.getElementById("appWindow1_Frm").src = "";
|
|
$('#appWindow1').window('close');
|
|
}
|
|
|
|
function showTitle(message) {
|
|
MSI("提示", message);
|
|
}
|
|
|
|
|
|
//禁止刷新,回退
|
|
//处理键盘事件 禁止后退键(Backspace)密码或单行、多行文本框除外
|
|
function keyHandler(e) {
|
|
|
|
//回车=》tab
|
|
if (event.keyCode == 13) {
|
|
if (event.srcElement.tagName == 'TEXTAREA') {
|
|
return;
|
|
}
|
|
if (event.srcElement.submitFnc) {
|
|
if (event.srcElement.submitFnc != "") {
|
|
eval(event.srcElement.submitFnc);
|
|
return;
|
|
}
|
|
}
|
|
event.keyCode = 9;
|
|
|
|
} else {
|
|
|
|
var ev = e || window.event; //获取event对象
|
|
var obj = ev.target || ev.srcElement; //获取事件源
|
|
|
|
var t = obj.type || obj.getAttribute('type'); //获取事件源类型
|
|
|
|
//获取作为判断条件的事件类型
|
|
var vReadOnly = obj.getAttribute('readonly');
|
|
var vEnabled = obj.getAttribute('enabled');
|
|
//处理null值情况
|
|
vReadOnly = (vReadOnly == null || vReadOnly == "") ? false : true;
|
|
vEnabled = (vEnabled == null || vEnabled == "") ? true : vEnabled;
|
|
|
|
//当敲Backspace键时,事件源类型为密码或单行、多行文本的,
|
|
//并且readonly属性为true或enabled属性为false的,则退格键失效
|
|
var flag1 = (ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vEnabled != true)) ? true : false;
|
|
|
|
//当敲Backspace键时,事件源类型非密码或单行、多行文本的,则退格键失效
|
|
var flag2 = (ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea") ? true : false;
|
|
|
|
//判断
|
|
if (flag2) {
|
|
return false;
|
|
}
|
|
if (flag1) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//禁止后退键 作用于IE、Chrome
|
|
document.onkeydown = keyHandler;
|
|
|
|
$(document).ready(function () {
|
|
//所有输入框,焦点离开后小写转大写
|
|
$.each($("input[type=text]"), function (i, n) {
|
|
if ($(this).prop("id") != "Email") {
|
|
$(this).bind("blur", function () {
|
|
$(this).val($(this).val().toUpperCase());
|
|
});
|
|
}
|
|
});
|
|
$.each($("textarea"), function (i, n) {
|
|
$(this).bind("blur", function () {
|
|
$(this).val($(this).val().toUpperCase());
|
|
});
|
|
});
|
|
});
|