该宏示例在 V10.5上 验证通过
本文档的示例代码仅适用于本文档中的示例报表/场景。若实际报表/场景与示例代码无法完全适配(如使用功能不一致,或多个宏代码冲突等),需根据实际需求开发代码。
1. 示例效果
需求场景: 在文本框内选择函数当前日志,并设置定时刷新,这种方式会不断请求服务器,造成资源占用。客户希望请求客户端进行定时刷新。
预期效果:通过js请求获取当前客户端时间。
Image Modified
2. 操作步骤
步骤一:选中筛选器,进入宏管理
Image Modified
步骤二:在界面新建宏,弹出的新建模块对话框中输入名称,勾选对象为组件,事件为“onBeforeRender(组件渲染前)”
Image Modified
步骤三:编写宏代码实现效果
function main(page: IPage, portlet: IStaticTextPortlet) { setInterval(function() { portlet.setContentHandler(function (rawHtmlContent, processedHtmlContent) { let time2 = new Date().Format("yyyy-MM-dd hh:mm:ss"); let html = '<span style="color: |
whitered">' +time2+'</span>' return html }) }, 1000 * 1) }
Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }
|
Image Modified
步骤四:点击 保存。重新访问报表,可看到效果已实现