📄 common.js
字号:
/**
* 应用上下文路径,如果定义了控制台路径,则包含控制台路径。
*/
//var __CONTEXT_PATH = "/e4/admin";
/**
* 基本应用上下文路径,不包含控制台路径,是纯应用上下文路径。
*/
//var __BASE_CONTEXT_PATH = "/e4";
/**
* 获得应用上下文路径。
*/
function getContextPath(){
return getContextPath(true);
}
/**
* 获得应用上下文路径。
* @param includeConsolePath 如果为true表示返回路径包含控制台路径;如果为false表示返回路径不包含控制台路径。
* @return 返回应用上下文路径
*/
function getContextPath(includeConsolePath){
if(includeConsolePath == null || includeConsolePath){
if(typeof(__CONTEXT_PATH) == "undefined"){
alert('未定义请求路径!');
return "";
}
return __CONTEXT_PATH;
}else{
if(typeof(__BASE_CONTEXT_PATH) == "undefined"){
alert('未定义基本请求路径!');
return "";
}
return __BASE_CONTEXT_PATH;
}
}
function doSubmit(){
document.forms[0].submit();
}
//----------------------------------------------------
function doAction(action,arg){
if(!check()) return;
setValue("_action",action);
if(arg!=null){
//附加参数
document.forms[0].target="";
document.forms[0].action=document.forms[0].action+"?"+arg;
}
document.forms[0].submit();
if( getEvent() != null ) {
var e = getEventElement();
e.disabled=true;
}
}
//查找
function doFind(){
document.forms[0].target="";
document.forms[0].action=document.forms[0].action+"?_pageFirst=true";
document.forms[0].submit();
}
function doDialogAction(action,arg,features){
if(!check()) return;
setValue("_action",action);
if(arg!=null && arg.trim()!=""){
//附加参数
document.forms[0].target="";
var orgAction = document.forms[0].action;
document.forms[0].action=document.forms[0].action+"?"+arg;
}
if(features==null || features.trim()==""){
var dHeight = 400;
var dWidth = 400;
var left = (window.screen.width - dWidth)/2;
var top = (window.screen.height - dHeight)/2;
features = 'dialogHeight:'+dHeight+'px;dialogWidth:'+dWidth+'px;dialogLeft:'+left+'px;dialogTop:'+top+'px;';
}
window.showModalDialog(getContextPath() + "/epod/page/common/proxyDialog.html",window,features);
//还原action的值,否则可能造成action值被不断累加得到不期望的结果
document.forms[0].action = orgAction;
}
function doLink(link){
if(link != null && link.indexOf("/")==0){
link = getContextPath() + link;
}
window.location=link;
}
//在dialog窗口中设置原来窗口的元素。
function setSrcWindowTextValue(objName , value){
if(objName != null ) {
//var obj = window.dialogArguments.document.all(objName);
var obj = window.dialogArguments.document.getElementsByName(objName);
if(obj != null ) obj[0].value = value;
}
}
//在dialog窗口中设置原来窗口的CheckBox元素。
function setSrcWindowCheckBox( objName , value ) {
if(objName != null ) {
//var obj = window.dialogArguments.document.all(objName);
var obj = window.dialogArguments.document.getElementsByName(objName);
if(obj != null ) obj[0].checked = value;
}
}
//返回当前单元得单选和多选按钮用户选中的值,只能支持单主键得情况。
//返回值是选中1,选中2。。。最后没有逗号。没有选中,提示noSelectHint,并返回空。
function getCheckSingleValue(){
//var unitid = getUnitId(event.srcElement);
var unitid = getUnitId(getEventElement());
var head = unitid+"._check";
//var checks = document.all(head);
var checks = getAllElements(head);
if( checks == null ) return null;
var flag = false ;
var returnValue = "";
var thisValue ="";
/*
if( checks.length == null ) {
if (checks.checked) {
thisValue = checks.value;
returnValue += thisValue.substring(thisValue.indexOf(",")+1);
flag = true;
}
} else {
*/
for(var ii=0 ; ii < checks.length ; ii++) {
if (checks[ii].checked) {
thisValue = checks[ii].value;
if( flag ) returnValue += ",";
returnValue += thisValue.substring(thisValue.indexOf(",")+1);
flag = true;
}
}
/*
}
*/
if( !flag ) {
return null;
}
return returnValue;
}
function disableF5(){
//with (event){
var e = getEvent();
if(!e) return;
with (e){
// F5 and Ctrl+R
if ((keyCode==116 || (ctrlKey && keyCode==82)) && e.repeat){
alert('不要重复刷新页面,这将导致系统资源耗尽.');
e.keyCode = 0;
e.cancelBubble = true;
return false;
}
}
}
document.onkeydown = disableF5;
function doDelete(action,unitId){
//判断是否需要做删除动作
var needDelete = false
var unitid = unitId;
if(unitid == null){
//unitid = getUnitId(event.srcElement);
unitid = getUnitId(getEventElement());
}
//alert("unitid="+unitid);
var head = unitid+"._check";
//var checks = document.all(head);
var checks = getAllElements(head);
if(!checks) return ;
/*
if(!checks.length){
if(checks.checked){
needDelete = true;
}
}else{
*/
for(var i=0;i<checks.length;i++){
if(checks[i].checked){
needDelete = true;
}
}
/*
}
*/
if(!needDelete) return ;
//做删除操作
if (confirm("删除操作不可恢复,你确认吗?")){
deleteRow();
doAction(action);
}
}
function doConfirm(msg,action,arg){
if(confirm(msg)){
if(arg != null){
doAction(action,arg);
}else{
doAction(action);
}
}
}
function onTableSelected(obj,tableName){
if(obj.checked==true) setCheckBoxByTable(tableName,true);
else setCheckBoxByTable(tableName,false);
}
function setCheckBoxByTable(tableName,flag){
var obj = document.forms[0].all("check");
for (var i=0;i<obj.length;i++){
if (obj[i].name.indexOf(tableName+"._check")!=-1){
obj[i].checked=flag;
obj[i].parentElement.parentElement.style.display=(flag==false?"none":"block");
}
}
}
//此方法供列表单元使用
function deleteRow(){
//取单元编号
//var unitid = getUnitId(event.srcElement);
var unitid = getUnitId(getEventElement());
var head = unitid+".";
//var checks = document.all(head+"_check");
//var table = document.all("_u_"+unitid);
var checks = getAllElements(head+"_check");
var table = getAllElements("_u_"+unitid);
if(!checks) return ;
/*
if(checks.length == undefined){
if(checks.checked){
//定位checkbox所在的若干row
var rows = table.all(getRow(checks).id);
var operator = findOperator(head,rows);
//4种状态中,只处理'修改'、'浏览'、'新增',不理会'删除'
//alert("operator="+operator.value);
if(operator.value=="u" || operator.value=="s" || operator.value=="q"){
hiddenRows(rows);
operator.value = "d";
}else if(operator.value=="i"){
removeRows(rows);
i--;
}
}
}else{
*/
for(var i=0;i<checks.length;i++){
if(checks[i].checked){
//定位checkbox所在的若干row
//var rows = table[0].all(getRow(checks[i]).id);
var rows = getAllElements(getRow(checks[i]).id,table[0]);
var operator = findOperator(head,rows);
//4种状态中,只处理'修改'、'浏览'、'新增',不理会'删除'
if(operator.value=="u" || operator.value=="s" || operator.value=="q"){
hiddenRows(rows);
operator.value = "d";
}else if(operator.value=="i"){
removeRows(rows);
//i--;
}
}
}//for end
/*
}
*/
//reset
//table.parentElement.innerHTML = table.parentElement.innerHTML ;
table[0].parentNode.innerHTML = table[0].parentNode.innerHTML;
//重新排序
order(unitid);
}
function hiddenRows(rows){
if(rows.length){
for(var i=0;i<rows.length;i++){
rows[i].style.display="none";
}
}else{
rows.style.display="none";
}
}
function removeRows(rows){
if(rows.length){
for(var i=0;i<rows.length;i++){
//rows[i].removeNode(true);
var parent = rows[i].parentNode;
parent.removeChild(rows[i]);
//i--;
}
}else{
//rows.removeNode(true);
var parent = rows.parentNode;
parent.removeChild(rows);
}
}
function findOperator(head,rows){
if(rows.length){
//return rows[rows.length-1].all(head+"d");
for(var i=0;i<rows.length;i++){
//var ope = rows[i].all(head+"d");
var ope = getAllElements(head+"d",rows[i]);
if(ope.length){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -