Index: ssts-web/src/main/webapp/js/Ext2CompUtil.js
===================================================================
diff -u -r15833 -r16102
--- ssts-web/src/main/webapp/js/Ext2CompUtil.js (.../Ext2CompUtil.js) (revision 15833)
+++ ssts-web/src/main/webapp/js/Ext2CompUtil.js (.../Ext2CompUtil.js) (revision 16102)
@@ -10,6 +10,12 @@
this.getComboBuilder = function () {
return comboBuilder;
}
+ this.getTableBuilder = function () {
+ return tableBuilder;
+ }
+ this.getTableTips = function () {
+ return tableTips;
+ }
}
//region comboBuilder
@@ -95,6 +101,179 @@
//endregion
+ //region tableBuilder
+ //用于生成table的对象
+ var tableBuilder = {};
+
+ /**
+ * 根据头部的配置来设置table的头部内容
+ * @param tHeadConfig 头部配置(有每一列的宽和内容)
+ * @returns {string}
+ */
+ tableBuilder.setTHead = function (tHeadConfig) {
+ var tHead = "";
+ for (var prop in tHeadConfig) {
+ tHead += "
" + prop + " | ";
+ }
+ return tHead;
+ }
+
+
+ /**
+ * 创建table
+ * @param tHeadConfig table的头部配置
+ * @param tBodyContent table的正文内容
+ * @returns {string}
+ */
+ tableBuilder.createTable = function (tHeadConfig, tBodyContent) {
+ var me = this;
+ var tipTable =
+ "" +
+ "
" +
+ "" + me.setTHead(tHeadConfig) + "
" + tBodyContent +
+ "
" +
+ "
";
+ return tipTable;
+ }
+ //endregion
+
+
+ //region tableTips
+ //提示框对象
+ var tableTips = {};
+
+
+ /**
+ * 添加mouseover事件
+ * @param winConfig 弹窗提示框配置(里面有grid,url,title,tipManagerCache)
+ * @param fn 回调函数
+ */
+ tableTips.popTipWin = function (winConfig, fn) {
+ var this_ = this;
+ var grid = winConfig.grid;
+ var tipManagerCache = winConfig.tipManagerCache;
+ grid.on('mouseover', function (e, elHtml) {
+ var me = this;
+ var thisRow = grid.getView().findRowIndex(elHtml);
+ if (thisRow !== false) {
+ var record = me.getStore().getAt(thisRow);
+ var id = record.get('id');
+ //从缓存里找对应生成的html,如果存在,则不再请求服务器,直接从缓存读取并生成
+ var tipTable = tipManagerCache[id];
+ if (tipTable) {
+ this_.register({
+ text: tipTable,
+ target: elHtml,
+ title: winConfig.title
+ });
+ }
+ else {
+ //获得提示框的对象
+ var tableTips = ext2CompUtil.getTableTips();
+ //加载对应提示框需要的数据并且在页面显示
+ tableTips.loadGoodsTips(winConfig.url, id, elHtml, fn);
+ }
+ }
+ });
+ }
+ /**
+ * 加载提示信息
+ * @param url 请求的url
+ * @param id 该项对应的id
+ * @param fn 回调函数
+ * @param elHtml 渲染的地方
+ */
+ tableTips.loadGoodsTips = function (url, id, elHtml, fn) {
+ Ext.Ajax.request({
+ url: url,
+ params: {id: id},
+ timeout: 600000,
+ waitMsg: '正在加载数据,请稍候',
+ method: 'POST',
+ success: function (response, options) {
+ try {
+ var result = Ext.decode(response.responseText);
+ var items = result.data.items;
+ //传回给回调函数的参数
+ var callBackPara = {
+ items: items,
+ elHtml: elHtml,
+ id: id
+ }
+ fn(callBackPara);
+ }
+ catch (e) {
+ alert("Exception : " + e);
+ }
+ },
+ failure: function (response, options) {
+ showResult(response.responseText);
+ }
+ });
+ }
+
+ /**
+ * 生成弹窗小提示
+ * @param tipConfig 相关配置(必传text,target,title)
+ */
+ tableTips.register = function (tipConfig) {
+ new Ext.ToolTip({
+ html: tipConfig.text,
+ target: tipConfig.target,
+ // 最大宽度
+ maxWidth: tipConfig.maxWidth || 500,
+ // 最小宽度
+ minWidth: tipConfig.minWidth || 300,
+ //允许溢出
+ overflowY: 'scroll',
+ overflowX: 'scroll',
+ title: tipConfig.title,
+ trackMouse: true
+ });
+ /* Ext.QuickTips.register({
+ text: tipConfig.text,
+ target: tipConfig.target,
+ // 消失的时间
+ hideDelay: tipConfig.hideDelay || 5000,
+ // 最大宽度
+ maxWidth: tipConfig.maxWidth || 500,
+ width: tipConfig.width || 450,
+ // 最小宽度
+ minWidth: tipConfig.minWidth || 300,
+ // 显示时间
+ showDelay: tipConfig.showDelay || 2000,
+ // 提示框是否跟着鼠标一起走
+ trackMouse: tipConfig.showDelay || true,
+ title: tipConfig.title
+ });*/
+ }
+
+ /**
+ * 建立提示框
+ * @param tHeadConfig table的head设置
+ * @param tBodyContent table的正文内容
+ * @param target 要渲染到什么地方
+ * @param title 提示框的信息
+ */
+ tableTips.buildTaleTips = function (tHeadConfig, tBodyContent, target, title) {
+ var me = this;
+ var tableBuilder = ext2CompUtil.getTableBuilder();
+ //获得生成的table的html
+ var tipTable = tableBuilder.createTable(tHeadConfig, tBodyContent);
+ var tipContent = {
+ text: tipTable,
+ target: target,
+ title: title
+ };
+ me.register(tipContent);
+ //返回页面做缓存,不能用register和tipContent返回,tipContent会缓存target,所以鼠标指向的地方要和第一次生成的地方一致才能正常显示,而register会有部分生成不了
+ return tipTable;
+ }
+
+
+ //endregion
+
+
return new ExtCompUtilFactory();
})();
\ No newline at end of file