Index: ssts-web/src/main/webapp/js/common.js =================================================================== diff -u -r16613 -r16644 --- ssts-web/src/main/webapp/js/common.js (.../common.js) (revision 16613) +++ ssts-web/src/main/webapp/js/common.js (.../common.js) (revision 16644) @@ -1,4 +1,3 @@ -$refreshStartDateHandle = null; //定时器的句柄(陈家儒改) var bPageModified=false; var wheight=window.screen.height-60; var wwidth=window.screen.width; @@ -7,15 +6,13 @@ /** - * 设置"开始时间"的方法,以服务器的时间为准(cjr) + * 取服务器的当前时间(异步请求,目的只要减少总体的请求时间,如果想用同步的方法请用synchronizationSetDateField方法) * @param extObject: ext对象,top.Ext或者top.Ext4或者Ext - * @param format: 时间的格式(如果时间控件的xtype为'datefieldWithMin'就要传yyyy/MM/dd HH:mm:ss的格式前台显示的格式为'yyyy-MM-dd HH:mm:ss',其他的你传什么格式就是什么格式) - * @param datefieldWithMinId: 时间选项框的id - * @param refreshFrequency: 时间刷新的频率(可选) - * @param refresh: 是否需要刷新(可选) + * @param format 时间的格式(注意:如果时间控件的xtype为datefieldWithMin,要得到'yyyy-MM-dd HH:mm:ss'格式,就必须要传yyyy/MM/dd HH:mm:ss的格式) + * @param datefieldId 时间选项框的id * */ -function setStartDate(extObject, format, datefieldWithMinId, refreshFrequency, refresh) { +function setStartDate(extObject, format, datefieldId) { extObject.Ajax.request({ url : WWWROOT + '/system/serverTimeAction!getServerDateTime.do', @@ -24,33 +21,56 @@ var result = extObject.decode(response.responseText); if(result.success){ var serverTime = result.serverTime; - extObject.getCmp(datefieldWithMinId).setValue(new Date(serverTime)); - lastTime = extObject.getCmp(datefieldWithMinId).getValue().getTime(); - if (refresh) { - $refreshStartDateHandle = setInterval(function() { - var time = extObject.getCmp(datefieldWithMinId).getValue().getTime(); - if (time == lastTime) { - lastTime = time + refreshFrequency; - extObject.getCmp(datefieldWithMinId).setValue(new Date(lastTime)); - } else { //如果上一秒或者分钟和下一秒或者分钟的时间戳不一样,清除定时器 - clearInterval($refreshStartDateHandle); - } - }, refreshFrequency); - } + extObject.getCmp(datefieldId).setValue(new Date(serverTime)); } }, - failure : function(response, options) { - alert('获取服务器时间失败'); - } + failure : function(response, options) { + alert('获取服务器时间失败'); + } }); } +/** + * 设置时间控件的值,如果datefieldValue没值,则取服务器的当前时间(注意如果是取服务器的当前时间,则该请求为同步请求,此时调用此方法的页面需要有dwr环境,和ServerTimeTableManager类) + * @param extObject ext对象,top.Ext或者top.Ext4或者Ext + * @param format 时间的格式(注意:如果时间控件的xtype为datefieldWithMin,你要得到'yyyy-MM-dd HH:mm:ss'格式,就必须要传yyyy/MM/dd HH:mm:ss的格式) + * @param datefieldId 时间选项框的id + * @param datefieldValue 时间的值 + * @param refreshFrequency 时间刷新的频率(可选,如果需要定时刷新,则会返回一个定时器的句柄,调用者可以控制此定时器的生命周期) + * + */ +function synchronizationSetDateField(extObject, format, datefieldId, datefieldValue, refreshFrequency) { + + if (!datefieldValue) { //如果没传时间的值,就取服务器的当前时间 + DWREngine.setAsync(false); + ServerTimeTableManager.getServerDateTime(format, function(config) { + datefieldValue = config; + }); + DWREngine.setAsync(true); + } + + extObject.getCmp(datefieldId).setValue(new Date(datefieldValue)); + + if (refreshFrequency && !isNaN(refreshFrequency)) { //需要定时刷新时间 + var lastTime = extObject.getCmp(datefieldId).getValue().getTime(); + var timerHandle = setInterval(function() { + var time = extObject.getCmp(datefieldId).getValue().getTime(); + if (time == lastTime) { + lastTime = time + refreshFrequency; + extObject.getCmp(datefieldId).setValue(new Date(lastTime)); + } else { //如果上一秒或者分钟和下一秒或者分钟的时间戳不一样,清除定时器 + clearInterval(timerHandle); + } + }, refreshFrequency); + return timerHandle; + } + +} - /** * 获取服务器时间 * @param format 时间格式