⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 highquery.js

📁 在很多项目中
💻 JS
📖 第 1 页 / 共 4 页
字号:

	 /********************************************
	 * 文件名称:highquery.js
	 * 功能描述:高级组合查询控件
	 * 创建日期:2008-07-22
	 * @author:codeslave
	 *********************************************/

// 配置
function HQConfig()
{
	this.dialect = "oracle"; // 方言
	this.basePath = "highquery/"; // 基础路径(如果目录改变这里要相应改变)
	this.version = "0.5"; // 版本
}

var HQConfig = new HQConfig();

// 加载js
var $import = function(s)
{   
	var script = document.createElement("script");
	script.setAttribute("type", "text/javascript");
	script.setAttribute("src", s);
	try   
	{
		document.getElementsByTagName("head")[0].appendChild(script);   
	}
	catch(e)   
	{
	}
};

$import(HQConfig.basePath + "calendar.js");
$import(HQConfig.basePath + "check.js");
$import(HQConfig.basePath + HQConfig.dialect + ".js");

/******************************以下为初始化部分******************************/

var autoId = 0; // 自增变量

// 存放字段实体的容器
function FieldList()
{
	this.fields = [];
}

// 添加实体方法
FieldList.prototype.add = function(field)
{
	this.fields[this.fields.length] = field;
};

var FieldList = new FieldList();

// 字段实体
function Field(name, alias, type, length, dictCode, event)
{
	this.name = name; // 字段名
	this.alias = alias; // 别名
	this.type = type; // 类型
	this.length = length; // 长度
	this.dictCode = dictCode; // 业务字典代码
	this.event = event; // 事件(主要用于选择外键表数据)
}

// 存放业务字典实体的容器
function DictList()
{
	this.dicts = [];
}

// 添加实体方法
DictList.prototype.add = function(dict)
{
	this.dicts[this.dicts.length] = dict;
};

var DictList = new DictList();

// 业务字典实体
function Dict(code, name, text, value)
{
	this.code = code; // 代码
	this.name = name; // 名称
	this.text = text; // 文本
	this.value = value; // 值
}

// 保存当前操作对象的一些信息(用于业务字典)
function CurrModel(contentId, hibContentId, flag)
{
	this.contentId = contentId; // 内容文本控件的id
	this.hibContentId = hibContentId; // 内容文本控件的id(隐藏的)
	this.flag = flag; // 标记
}

var CurrModel = new CurrModel("", "", "");

// 取得一般查询条件的html文件(日期)。
function getDateHtml(contentId)
{
	var strHtml = "<input type='button' class='HQ_BUTTON' onClick=selDate('" + contentId + "') value='选择'>";
	strHtml += "<input type='button' class='HQ_BUTTON' onClick=clearContent('" + contentId + "') value='清除'>";
	return strHtml;
}

// 取得in或not in查询条件的html文件(日期)。
function getDateInHtml(contentId)
{
	var strHtml = "<input type='button' class='HQ_BUTTON' onClick=selDateIn('" + contentId + "') value='选择'>";
	strHtml += "<input type='button' class='HQ_BUTTON' onClick=clearContent('" + contentId + "') value='清除'>";
	return strHtml;
}

// 取得一般查询条件的html文件(日期时间)。
function getDateTimeHtml(contentId)
{
	var strHtml = "<input type='button' class='HQ_BUTTON' onClick=selDateTime('" + contentId + "') value='选择'>";
	strHtml += "<input type='button' class='HQ_BUTTON' onClick=clearContent('" + contentId + "') value='清除'>";
	return strHtml;
}

// 取得in或not in查询条件的html文件(日期时间)。
function getDateTimeInHtml(contentId)
{
	var strHtml = "<input type='button' class='HQ_BUTTON' onClick=selDateTimeIn('" + contentId + "') value='选择'>";
	strHtml += "<input type='button' class='HQ_BUTTON' onClick=clearContent('" + contentId + "') value='清除'>";
	return strHtml;
}

// 取得like查询条件的html文本。
function getLikeHtml(id) 
{
	var strHtml = "<select id='darkSign_" + id + "'><option value='0'>%</option><option value='1'>_</option></select>";
	strHtml += "&nbsp;<span id='darkB_" + id + "' onClick=addDarkSign('b') style='font-weight: bold;cursor: hand'>←→</span>" + 
		"&nbsp;<span id='darkL_" + id + "' onClick=addDarkSign('l') style='font-weight: bold;cursor: hand'>←</span>" + 
		"&nbsp;<span id='darkR_" + id + "' onClick=addDarkSign('r') style='font-weight: bold;cursor: hand'>→</span>";
	return strHtml;
}

// 取得is查询条件的html文本。
function getIsHtml(id) 
{
	var strHtml = "<span id='null_" + id + "' onClick=document.getElementById('bContent_" + id + "').value='null'" + 
		" style='font-weight: bold;cursor: hand'>○</span>" + 
		"&nbsp;<span id='notNull_" + id + "' onClick=document.getElementById('bContent_" + id + "').value='not&nbsp;null'" + 
		" style='font-weight: bold;cursor: hand'>●</span>";
	return strHtml;
}

// 取得带字典查询条件的html文本。
function getDictHtml(contentId, hibContentId, dictCode)
{
	var strHtml = "<input type='button' class='HQ_BUTTON' onClick=showDictPanel('" + contentId + "','" + hibContentId + "','" + dictCode + "') value='选择'>";
	strHtml += "<input type='button' class='HQ_BUTTON' onClick=\"clearContent('" + contentId + "');clearContent('" + hibContentId + "');\"" + 
		"value='清除'>";
	return strHtml;
}

// 取得带字典查询条件的html文本(用于in或not in查询)。
function getDictInHtml(contentId, hibContentId, dictCode) 
{
	var strHtml = "<input type='button' class='HQ_BUTTON' onClick=showDictPanelIn('" + contentId + "','" + hibContentId + "','" + dictCode + "') value='选择'>";
	strHtml += "<input type='button' class='HQ_BUTTON' onClick=\"clearContent('" + contentId + "');clearContent('" + hibContentId + "');\"" + 
		"value='清除'>";
	return strHtml;
}

// 取得带事件查询条件的html文本。
function getEventHtml(contentId, hibContentId, event)
{
	var strHtml = "<input type='button' class='HQ_BUTTON' onClick=executeEvent('" + contentId + "','" + hibContentId + "','" + event + "') value='选择'>";
	strHtml += "<input type='button' class='HQ_BUTTON' onClick=\"clearContent('" + contentId + "');clearContent('" + hibContentId + "');\"" + 
		"value='清除'>";
	return strHtml;
}

// 取得带事件查询条件的html文本(用于in或not in查询)。
function getEventInHtml(contentId, hibContentId, event) 
{
	var strHtml = "<input type='button' class='HQ_BUTTON' onClick=executeEventIn('" + contentId + "','" + hibContentId + "','" + event + "') value='选择'>";
	strHtml += "<input type='button' class='HQ_BUTTON' onClick=\"clearContent('" + contentId + "');clearContent('" + hibContentId + "');\"" + 
		"value='清除'>";
	return strHtml;
}

// 初始化字段列表。
function initField(id)
{
	var strField = "<select onChange='changeField()' id='field_" + id + "'>";
	var arrField = FieldList.fields;
	for(var i = 0; i < arrField.length; i++)
	{
		strField += "<option value='" + arrField[i].name + "'>" + arrField[i].alias + "</option>"
	}
	strField += '</select>';
	return strField;
}

// 初始化条件相连的运算符。
function initJoin(id)
{
	var strJoin = "<select id='join_" + id + "'><option value='and'>AND</option><option value='or'>OR</option></select>";
	return strJoin;
}

// 初始化条件运算符。
function initCondition(id)
{
	var strCondition = "<select onChange='changeCondition()' id='condition_" + id + "'>";
	if (id != 0) // 第一个条件必须查询
		strCondition += "<option value=''>不查询</option>";
	strCondition += "<option value='='>=</option><option value='<'><</option>" + 
		"<option value='<='><=</option><option value='>'>></option>" +
		"<option value='>='>>=</option><option value='<>'><></option>" +
		"<option value='in'>IN</option><option value='not_in'>NOT IN</option>" + 
		"<option value='between'>BETWEEN</option><option value='is'>IS</option>" +
		"<option value='like'>LIKE</option></select>";
	strCondition += "<span id='signPanel_" + id + "'></span>" // 存放查询符号,主要用于like和is查询
	return strCondition;
}

// 初始化条件内容。
function initContent(id)
{
	var strContent = "<input class='HQ_TEXT' id='bContent_" + id + "' maxLength=" + FieldList.fields[FieldList.fields.length - 1].length + ">";
	strContent += "<input type='hidden' class='HQ_TEXT' id='hibBContent_" + id + "'>";
	strContent += "<span id='bChoicePanel_" + id + "'></span>"; // 存放第一个文本控件的"选择"和"清除"按钮
	strContent += "<span id='eContentPanel_" + id + "'></span>"; // 存放第二个文本控件、以及eChoicePanel面板和他内部的"选择"和"清除"按钮
	return strContent;
}

// 初始化左括号面板
function initLParenthesisPanel(id)
{
	var strPanel = "<span id='lAdd_" + id + "' class='HQ_ADD_P' onClick=addParenthesis('" + id + "','l')>+</span>";
	strPanel += "&nbsp;<span id='lRemove_" + id + "' class='HQ_REMOVE_P' onClick=removeParenthesis('" + id + "','l')>-</span>";
	strPanel += "&nbsp;<span id='lParenthesisPanel_" + id + "' class='HQ_P'></span>";
	return strPanel;
}

// 初始化右括号面板
function initRParenthesisPanel(id)
{
	var strPanel = "<span id='rAdd_" + id + "' class='HQ_ADD_P' onClick=addParenthesis('" + id + "','r')>+</span>";
	strPanel += "&nbsp;<span id='rRemove_" + id + "' class='HQ_REMOVE_P' onClick=removeParenthesis('" + id + "','r')>-</span>";
	strPanel += "&nbsp;<span id='rParenthesisPanel_" + id + "' class='HQ_P'></span>";
	return strPanel;
}

// 初始化排序
function initSort(id)
{
	var strSort = "<select id='sort_" + id + "'>" +
		"<option value=''>不排序</option><option value='asc'>升序</option><option value='desc'>降序</option>" +
		"</select>";
	return strSort;
}

// 初始化业务字典面板
function initDictPanel(dictCode)
{
	var dicts = DictList.dicts;
	var strDict = "<table id='dictChoice' cellspacing='0' class='HQ_DICT_TABLE'>";
	strDict += "<th class='HQ_DICT_TH'>数值</th>";
	strDict += "<th class='HQ_DICT_TH'>描述</th>";
	for(var i = 0; i < dicts.length; i++)
	{
		if(dicts[i].code == dictCode)
		{
			strDict += "<tr class='HQ_DICT_TR' onClick=\"backfillDict('" + dicts[i].value + "','" + dicts[i].text + "')\" >" +
				"<td class='HQ_TD'>" + dicts[i].value + "</td>" +
				"<td class='HQ_TD'>" + dicts[i].text + "</td></tr>";
		}
	}
	strDict += "<tr><td colspan='2'><span style='cursor: hand;' onClick='closeDictPanel()'>关闭</span></td></tr>";
	strDict += "</table>";
	return strDict;
}

// 初始化控件
function initHighQuery()
{
	var strHtml = "<div id='dictPanel' style='display:none; position:absolute'></div>";
	strHtml += "<table id='highQuery' class='HQ_TABLE'>" + 
		"<th class='HQ_TH'>连接</th>" +
		"<th class='HQ_TH'>左括号</th>" +
		"<th class='HQ_TH'>字段</th>" +
		"<th class='HQ_TH'>运算符</th>" +
		"<th class='HQ_TH'>内容</th>" +
		"<th class='HQ_TH'>右括号</th>" +
		"<th class='HQ_TH'>排序</th>" +
		"<th class='HQ_TH'>操作</th>" +
		"</table>";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -