function deleteUrlParam(targetUrl, targetKey) {
if (typeof targetUrl !== 'string') {
return targetUrl
}
if(!targetUrl.includes('?')) {
return targetUrl
}
const queries = targetUrl.split('?')
let resultUrl = ''
if (queries.length > 1) {
const search = queries[1].split('&');
if (search.length > 0) {
resultUrl += queries[0] + '?';
for (const kvStr of search) {
const [key, val] = kvStr.split('=')
if (targetKey === key) continue;
else resultUrl += `${key}=${val}&`
}
return resultUrl.substring(0, resultUrl.length - 1);
}
}
return '';
}
// 从指定字符串中获取参数
function getQueryFromTargetStr(targetStr, targetKey) {
if (typeof targetStr !== 'string') {
return null
}
const queries = targetStr.split('?')
if (queries.length > 1) {
const search = queries[1].split('&');
for (const kvStr of search) {
const [key, val] = kvStr.split('=')
if (targetKey === key) return val
}
}
return null
}
// script 标签过滤
function filterXSS(str) {
if (typeof str !== 'string') {
return str
}
str = str.trim()
return str.replace(/<\/?[^>]+>/gi, '')
.replace(/[(]/g, '')
.replace(/->/g, '_')
}
function promptGener(msg, defVal) {
var val = window.prompt(msg, defVal);
return val;
}
function Reload() {
window.location.reload();
}
function GetHrefUrl() {
return window.location.href;
//return GetHrefUrl();
}
function SetHref(url) {
window.location.href = filterXSS(url);
}
/**
* 把表达式计算或者转化为json对象.
*
* @param {表达式} exp
*/
function cceval(exp) {
if (/^[\d\-\+]*$/.test(exp))
return eval(exp);
else {
var a = 1;
var b = 2;
if (a + a == b)
return eval(exp);
}
// alert("非法的表达式:" + exp);
}
/**
* 处理文本,方式被污染,用于安全检查
* @param {any} text
*/
function DealText(text) {
//if (text.toUpperCase().indexOf('SCRIPT') ==-1 )
// return text;
if (/^[\d\-\+]*$/.test(text))
return text;
var a = 12;
var b = 24;
if (a + a == b || b == a * 2 || /^[\d\-\+]*$/.test(text))
return text;
}
function setTimeoutGener(callback, time) {
if (typeof callback != "function")
return;
else
setTimeout(callback, time);
}
//检查字段,从表名,附件ID,输入是否合法.
function CheckID(val) {
//首位可以是字母以及下划线。
//首位之后可以是字母,数字以及下划线。下划线后不能接下划线
var flag = false; //用来判断
var reg = /(^_([a-zA-Z0-9]_?)*$)|(^[a-zA-Z](_?[a-zA-Z0-9])*_?$)/;
flag = reg.test(val);
return flag;
}
//去左空格;
function ltrim(s) {
return s.replace(/(^\s*)/g, "");
}
//去右空格;
function rtrim(s) {
return s.replace(/(\s*$)/g, "");
}
//去左右空格;
function trim(s) {
return s.replace(/(^\s*)|(\s*$)/g, "");
}
/* 把一个 @XB=1@Age=25 转化成一个js对象. */
function AtParaToJson(json) {
var jsObj = {};
if (json) {
var atParamArr = json.split('@');
$.each(atParamArr, function (i, atParam) {
if (atParam != '') {
var atParamKeyValue = atParam.split('=');
if (atParamKeyValue.length == 2) {
jsObj[atParamKeyValue[0]] = atParamKeyValue[1];
}
}
});
}
return jsObj;
}
function GetPKVal() {
var val = this.GetQueryString("OID");
if (val == undefined || val == "")
val = GetQueryString("No");
if (val == undefined || val == "")
val = GetQueryString("WorkID");
if (val == undefined || val == "")
val = GetQueryString("NodeID");
if (val == undefined || val == "")
val = GetQueryString("MyPK");
if (val == undefined || val == "")
val = GetQueryString("PKVal");
if (val == undefined || val == "")
val = GetQueryString("PK");
if (val == "null" || val == "" || val == undefined)
return null;
return val;
}
//处理url,删除无效的参数.
function DearUrlParas(urlParam) {
//如何获得全部的参数? &FK_Node=120&FK_Flow=222 放入到url里面去?
//var href = GetHrefUrl();
//var urlParam = href.substring(href.indexOf('?') + 1, href.length);
if (urlParam == null || urlParam == undefined)
urlParam = window.location.search.substring(1);
var params = {};
if (urlParam == "" && urlParam.length == 0) {
urlParam = "1=1"
} else {
$.each(urlParam.split("&"), function (i, o) {
if (o) {
var param = o.split("=");
if (param.length == 2) {
var key = param[0];
var value = param[1];
if (key == "DoType" || key == "DoMethod" || key == "HttpHandlerName")
return true;
if (value == "null" || typeof value == "undefined")
return true;
if (value != null && typeof value != "undefined"
&& value != "null"
&& value != "undefined") {
// value = value.trim();
if (value != "" && value.length > 0) {
if (typeof params[key] == "undefined") {
params[key] = value;
}
}
}
}
}
});
}
urlParam = "";
$.each(params, function (i, o) {
urlParam += i + "=" + o + "&";
});
urlParam = urlParam.replace("&&", "&");
urlParam = urlParam.replace("&&", "&");
urlParam = urlParam.replace("&&", "&");
return urlParam;
}
function GetRadioValue(groupName) {
var obj;
obj = document.getElementsByName(groupName);
if (obj != null) {
var i;
for (i = 0; i < obj.length; i++) {
if (obj[i].checked) {
return obj[i].value;
}
}
}
return null;
}
//获得所有的checkbox 的id组成一个string用逗号分开, 以方便后台接受的值保存.
function GenerCheckIDs() {
var checkBoxIDs = "";
var arrObj = document.all;
for (var i = 0; i < arrObj.length; i++) {
if (arrObj[i].type != 'checkbox')
continue;
var cid = arrObj[i].name;
if (cid == null || cid == "" || cid == '')
continue;
checkBoxIDs += arrObj[i].id + ',';
}
return checkBoxIDs;
}
function GenerCheckNames() {
var checkBoxIDs = "";
var arrObj = document.all;
for (var i = 0; i < arrObj.length; i++) {
if (arrObj[i].type != 'checkbox')
continue;
var cid = arrObj[i].name;
if (cid == null || cid == "" || cid == '')
continue;
if (checkBoxIDs.indexOf(arrObj[i].name) == -1)
checkBoxIDs += arrObj[i].name + ',';
}
return checkBoxIDs;
}
//填充下拉框.
function GenerBindDDL(ddlCtrlID, data, noCol, nameCol, selectVal, filterKey1, filterVal1) {
if (noCol == null)
noCol = "No";
if (nameCol == null)
nameCol = "Name";
//判断data是否是一个数组,如果是一个数组,就取第1个对象.
var json = data;
// 清空默认值, 写一个循环把数据给值.
$("#" + ddlCtrlID).empty();
$("#" + ddlCtrlID).append("");
//如果他的数量==0,就return.
if (json.length == 0)
return;
if (data[0].length == 1)
json = data[0];
if (json[0][noCol] == undefined) {
alert('@在绑定[' + ddlCtrlID + ']错误,No列名' + noCol + '不存在,无法行程期望的下拉框value . ');
return;
}
if (json[0][nameCol] == undefined) {
alert('@在绑定[' + ddlCtrlID + ']错误,Name列名' + nameCol + '不存在,无法行程期望的下拉框value. ');
return;
}
for (var i = 0; i < json.length; i++) {
if (filterKey1 != undefined) {
if (json[i][filterKey1] != filterVal1)
continue;
}
if (json[i][noCol] == undefined)
$("#" + ddlCtrlID).append("");
else
$("#" + ddlCtrlID).append("");
}
//设置选中的值.
if (selectVal != undefined) {
var v = $("#" + ddlCtrlID)[0].options.length;
if (v == 0)
return;
$("#" + ddlCtrlID).val(selectVal);
var v = $("#" + ddlCtrlID).val();
if (v == null) {
$("#" + ddlCtrlID)[0].options[0].selected = true;
}
}
}
/*绑定枚举值.*/
function GenerBindEnumKey(ctrlDDLId, enumKey, selectVal) {
if (dynamicHandler == "")
return;
$.ajax({
type: 'post',
async: false,
xhrFields: {
withCredentials: true
},
crossDomain: true,
url: dynamicHandler + "?DoType=EnumList&EnumKey=" + enumKey + "&m=" + Math.random(),
dataType: 'html',
success: function (data) {
data = JSON.parse(data);
if (data.length == 0) {
alert('没有找到枚举值:' + enumKey);
return;
}
//绑定枚举值.
GenerBindDDL(ctrlDDLId, data, "IntKey", "Lab", selectVal);
return;
}
});
}
/* 绑定枚举值外键表.*/
function GenerBindEntities(ctrlDDLId, ensName, selectVal, filter) {
if (dynamicHandler == "")
return;
$.ajax({
type: 'post',
async: true,
xhrFields: {
withCredentials: true
},
crossDomain: true,
url: dynamicHandler + "?DoType=EnsData&EnsName=" + ensName + "&Filter=" + filter + "&m=" + Math.random(),
dataType: 'html',
success: function (data) {
data = JSON.parse(data);
//绑定枚举值.
GenerBindDDL(ctrlDDLId, data, "No", "Name", selectVal);
return;
},
error: function (jqXHR, textStatus, errorThrown) {
/*错误信息处理*/
alert("GenerBindEntities,错误:参数:EnsName" + ensName + " , 异常信息 responseText:" + jqXHR.responseText + "; status:" + jqXHR.status + "; statusText:" + jqXHR.statusText + "; \t\n textStatus=" + textStatus + ";errorThrown=" + errorThrown);
}
});
}
/*
绑定外键表.
*/
function GenerBindSFTable(ctrlDDLId, sfTable, selectVal) {
if (dynamicHandler == "")
return;
$.ajax({
type: 'post',
async: true,
xhrFields: {
withCredentials: true
},
crossDomain: true,
url: dynamicHandler + "?DoType=SFTable&SFTable=" + sfTable + "&m=" + Math.random(),
dataType: 'html',
success: function (data) {
data = JSON.parse(data);
//绑定枚举值.
GenerBindDDL(ctrlDDLId, data, "No", "Name", selectVal);
return;
},
error: function (jqXHR, textStatus, errorThrown) {
/*错误信息处理*/
alert("GenerBindSFTable,错误:参数:EnsName" + ensName + " , 异常信息 responseText:" + jqXHR.responseText + "; status:" + jqXHR.status + "; statusText:" + jqXHR.statusText + "; \t\n textStatus=" + textStatus + ";errorThrown=" + errorThrown);
}
});
}
/* 绑定SQL.
1. 调用这个方法,需要在 SQLList.xml 配置一个SQL , sqlKey 就是该sql的标记.
2, paras 就是向这个sql传递的参数, 比如: @FK_Mapdata=BAC@KeyOfEn=MyFild .
*/
function GenerBindSQL(ctrlDDLId, sqlKey, paras, colNo, colName, selectVal) {
if (dynamicHandler == "")
return;
if (colNo == null)
colNo = "NO";
if (colName == null)
colName = "NAME";
$.ajax({
type: 'post',
async: true,
xhrFields: {
withCredentials: true
},
crossDomain: true,
url: dynamicHandler + "?DoType=SQLList&SQLKey=" + sqlKey + "&Paras=" + paras + "&m=" + Math.random(),
dataType: 'html',
success: function (data) {
if (data.indexOf('err@') == 0) {
alert(data);
}
data = JSON.parse(data);
//绑定枚举值.
GenerBindDDL(ctrlDDLId, data, colNo, colName, selectVal);
return;
}
});
}
/*为页面的所有字段属性赋值. */
function GenerChangeParentValue(data) {
//判断data是否是一个数组,如果是一个数组,就取第1个对象.
var json = data;
if (data.length == 1)
json = data[0];
var unSetCtrl = "";
for (var attr in json) {
var val = json[attr]; //值
var div = window.parent.document.getElementById(attr);
if (div != null) {
div.innerHTML = val;
continue;
}
}
}
/*为页面的所有字段属性赋值. */
function GenerFullAllCtrlsVal(data) {
if (data == null)
return;
//判断data是否是一个数组,如果是一个数组,就取第1个对象.
var json = data;
if ($.isArray(data) && data.length > 0)
json = data[0];
var unSetCtrl = "";
for (var attr in json) {
var val = json[attr]; //值
var div = document.getElementById(attr);
if (div != null) {
div.innerHTML = val;
continue;
}
// textbox
var tb = document.getElementById('TB_' + attr);
if (tb != null) {
if (val != null && '' != val && !isNaN(val) && !(/^\+?[1-9][0-9]*$/.test(val + '')))
val = val.replace(new RegExp("~", "gm"), "'");
//val = val.replace( /~/g, "'"); //替换掉特殊字符,设置的sql语句的引号.
if (tb.tagName.toLowerCase() != "input") {
tb.innerHTML = val;
}
else {
tb.value = val;
}
continue;
}
//checkbox.
var cb = document.getElementById('CB_' + attr);
if (cb != null) {
if (val == "1")
cb.checked = true;
else
cb.checked = false;
continue;
}
//下拉框.
var ddl = document.getElementById('DDL_' + attr);
if (ddl != null) {
if (ddl.options.length == 0)
continue;
$("#DDL_" + attr).val(val); // 操作权限.
continue;
}
// RadioButton. 单选按钮.
var rb = document.getElementById('RB_' + attr + "_" + val);
if (rb != null) {
rb.checked = true;
continue;
}
// 处理参数字段.....................
if (attr == "AtPara") {
//val=@Title=1@SelectType=0@SearchTip=2@RootTreeNo=0
$.each(val.split("@"), function (i, o) {
if (o == "") {
return true;
}
var kv = o.split("=");
if (kv.length == 2) {
json[kv[0]] = kv[1];
var suffix = kv[0];
var val = kv[1];
// textbox
tb = document.getElementById('TBPara_' + suffix);
if (tb != null) {
val = val.replace(new RegExp("~", "gm"), "'");
tb.value = val;
return true;
}
//下拉框.
ddl = document.getElementById('DDLPara_' + suffix);
if (ddl != null) {
if (ddl.options.length == 0)
return true;
// console.log(suffix + "_before_" + val);
//$("#DDLPara_" + suffix).val(""); // 操作权限.
$("#DDLPara_" + suffix).val(val); // 操作权限.
// window.setTimeout(function () { $("#DDLPara_" + suffix).val(row.districtCode); }, 1200);
// json[kv[0]] = kv[1];
// $("#DDLPara_" + suffix).val("2"); // 操作权限.
//console.log(suffix + "_" + val);
return true;
}
//checkbox.
cb = document.getElementById('CBPara_' + suffix);
if (cb != null) {
if (val == "1")
cb.checked = true;
else
cb.checked = false;
return true;
}
// RadioButton. 单选按钮.
rb = document.getElementById('RBPara_' + suffix + "_" + val);
if (rb != null) {
rb.checked = true;
return true;
}
}
});
}
unSetCtrl += "@" + attr + " = " + val;
}
}
/*为页面的所有 div 属性赋值. */
function GenerFullAllDivVal(data) {
//判断data是否是一个数组,如果是一个数组,就取第1个对象.
var json = data;
if (data.length == 1)
json = data[0];
var unSetCtrl = "";
for (var attr in json) {
var val = json[attr]; //值
var div = document.getElementById(attr);
if (div != null) {
div.innerHTML = val;
continue;
}
}
// alert('没有找到的控件类型:' + unSetCtrl);
}
function DoCheckboxValue(frmData, cbId) {
if (frmData.indexOf(cbId + "=") == -1) {
frmData += "&" + cbId + "=0";
}
else {
frmData.replace(cbId + '=on', cbId + '=1');
}
return frmData;
}
/*隐藏与显示.*/
function ShowHidden(ctrlID) {
var ctrl = document.getElementById(ctrlID);
if (ctrl.style.display == "block") {
ctrl.style.display = 'none';
} else {
ctrl.style.display = 'block';
}
}
function OpenDialogAndCloseRefresh(url, dlgTitle, dlgWidth, dlgHeight, dlgIcon, fnClosed) {
///使用EasyUiDialog打开一个页面,页面中嵌入iframe【id="eudlgframe"】
///页面链接
///Dialog标题
///Dialog宽度
///Dialog高度
///Dialog图标,必须是一个样式class
///窗体关闭调用的方法(注意:此方法中可以调用dialog中页面的内容;如此方法启用,则关闭窗体时的自动刷新功能会失效)
var dlg = $('#eudlg');
var iframeId = "eudlgframe";
if (dlg.length == 0) {
var divDom = document.createElement('div');
divDom.setAttribute('id', 'eudlg');
document.body.appendChild(divDom);
dlg = $('#eudlg');
dlg.append("");
}
dlg.dialog({
title: dlgTitle,
left: document.body.clientWidth > dlgWidth ? (document.body.clientWidth - dlgWidth) / 2 : 0,
top: document.body.clientHeight > dlgHeight ? (document.body.clientHeight - dlgHeight) / 2 : 0,
width: dlgWidth,
height: dlgHeight,
iconCls: dlgIcon,
resizable: true,
modal: true,
onClose: function () {
if (fnClosed) {
fnClosed();
return;
}
Reload();
},
cache: false
});
dlg.dialog('open');
$('#' + iframeId).attr('src', url);
}
function Reload() {
///重新加载当前页面
var newurl = "";
var urls = GetHrefUrl().split('?');
var params;
if (urls.length == 1) {
SetHref(GetHrefUrl() + "?t=" + Math.random());
}
newurl = urls[0] + '?1=1';
params = urls[1].split('&');
for (var i = 0; i < params.length; i++) {
if (params[i].indexOf("1=1") != -1 || params[i].toLowerCase().indexOf("t=") != -1) {
continue;
}
newurl += "&" + params[i];
}
SetHref(newurl + "&t=" + Math.random());
}
function ConvertDataTableFieldCase(dt, isLower) {
///转换datatable的json对象中的属性名称的大小写形式
///datatable json化后的[]数组
///是否转换成小写模式,默认转换成大写
if (!dt || !IsArray(dt)) {
return dt;
}
if (dt.length == 0 || IsObject(dt[0]) == false) {
return dt;
}
var newArr = [];
var obj;
for (var i = 0; i < dt.length; i++) {
obj = {};
for (var field in dt[i]) {
obj[isLower ? field.toLowerCase() : field.toUpperCase()] = dt[i][field];
}
newArr.push(obj);
}
return newArr;
}
//通用的aj访问与处理工具.
function AjaxServiceGener(param, myUrl, callback, scope) {
$.ajax({
type: "GET", //使用GET或POST方法访问后台
dataType: "html", //返回json格式的数据
contentType: "text/plain; charset=utf-8",
url: Handler + myUrl, //要访问的后台地址
data: param, //要发送的数据
async: true,
cache: false,
xhrFields: {
withCredentials: true
},
crossDomain: true,
complete: function () { }, //AJAX请求完成时隐藏loading提示
error: function (XMLHttpRequest, errorThrown) {
callback(XMLHttpRequest);
},
success: function (data) { //msg为返回的数据,在这里做数据绑定
callback(data, scope);
}
});
}
function IsArray(obj) {
///判断是否是数组
///要判断的对象
return Object.prototype.toString.call(obj) == "[object Array]";
}
function IsObject(obj) {
///判断是否是Object对象
///要判断的对象
return typeof obj != "undefined" && obj.constructor == Object;
}
function To(url) {
//window.location.href = filterXSS(url);
window.name = "dialogPage"; window.open(url, "dialogPage")
}
function WinOpen(url, winName) {
var newWindow = window.open(url, winName, 'width=700,height=400,top=100,left=300,scrollbars=yes,resizable=yes,toolbar=false,location=false,center=yes,center: yes;');
newWindow.focus();
return;
}
function WinOpenFull(url, winName) {
var newWindow = window.open(url, winName, 'width=' + window.screen.availWidth + ',height=' + window.screen.availHeight + ',scrollbars=yes,resizable=yes,toolbar=false,location=false,center=yes,center: yes;');
newWindow.focus();
return;
}
// document绑定esc键的keyup事件, 关闭弹出窗
function closeWhileEscUp() {
$(document).bind("keyup", function (e) {
e = e || window.event;
var key = e.keyCode || e.which || e.charCode;
if (key == 27) {
// 可能需要调整if判断的顺序
if (parent && typeof parent.doCloseDialog === 'function') {
parent.doCloseDialog.call();
} else if (typeof doCloseDialog === 'function') {
doCloseDialog.call();
} else if (parent && parent.parent && typeof parent.parent.doCloseDialog === "function") {
parent.parent.doCloseDialog.call();
} else {
window.close();
}
}
});
}
function DBAccess() {
var url = Handler + "?SQL=select * from sss";
$.ajax({
type: "GET", //使用GET或POST方法访问后台
dataType: "json", //返回json格式的数据
contentType: "text/plain; charset=utf-8",
url: url, //要访问的后台地址
async: true,
cache: false,
xhrFields: {
withCredentials: true
},
crossDomain: true,
complete: function () { }, //AJAX请求完成时隐藏loading提示
error: function (XMLHttpRequest, errorThrown) {
callback(XMLHttpRequest);
},
success: function (data) { //msg为返回的数据,在这里做数据绑定
callback(data, scope);
}
});
}
/* 关于实体的类
GEEntity_Init
var pkval="Demo_DtlExpImpDtl1";
var EnName="BP.WF.Template.Frm.MapDtlExt";
GEntity en=new GEEntity(EnName,pkval);
var strs= en.ImpSQLNames;
// var strss=en.GetValByKey('ImpSQLNames');
en.ImpSQLNames=aaa;
en.Updata();
*/
var Entity = (function () {
var jsonString;
var Entity = function (enName, pkval) {
if (enName == null || enName == "" || enName == undefined) {
alert('enName不能为空');
throw Error('enName不能为空');
return;
}
this.enName = enName;
if (pkval != null && typeof pkval === "object") {
jsonString = {};
this.CopyJSON(pkval);
} else {
this.pkval = pkval || "";
this.loadData();
}
};
function setData(self) {
if (typeof jsonString !== "undefined") {
$.each(jsonString, function (n, o) {
// 需要判断属性名与当前对象属性名是否相同
if (typeof self[n] !== "function") {
self[n] = o;
}
});
}
}
function getParams(self) {
var params = {};
$.each(jsonString, function (n, o) {
if (typeof self[n] !== "function") {
params[n] = self[n];
}
});
return params;
}
function getParams1(self) {
var params = ["t=" + new Date().getTime()];
$.each(jsonString, function (n, o) {
if (typeof self[n] !== "function" && (self[n] != o || true)) {
if (self[n] != undefined && self[n].toString().indexOf('