//创建自定义报表配置控件 function CreateOwnDesignReportSet(x,y,width,height,pageHeight,paneStyle) { //列表控件 var listView = new ht.widget.ListView(); var SelectReportName=""; for(var i=0;i<20;i++) { AddListViewElem(listView,"xxxx"); } //获得列表控件中文字颜色 listView.getLabelColor = function(data) { return this.isSelected(data) ? paneStyle.ListSelTextColor : paneStyle.DialogTitleFontColor ; }; var listView_View = listView.getView(); listView_View.style.backgroundColor = paneStyle.paneBackColor; //各行的颜色 listView.drawRowBackground = function(g, data, selected, xx, yy, widthb, heightb) { if (this.isSelected(data)) { g.fillStyle = paneStyle.ListSelBackColor; } else if (this.getRowIndex(data) % 2 === 0) { g.fillStyle = paneStyle.paneBackColor; } else { g.fillStyle = paneStyle.paneBackColor; } g.beginPath(); g.rect(xx, yy, widthb, heightb); g.fill(); }; listView.getLabel = function(data){ return data.a('Name'); }; //列表选择某条数据 listView.onDataClicked=function(data) { if(!data) return; SelectReportName=data.a('Name'); } //布局控件 var borderPaneDayReport = new ht.widget.BorderPane(); borderPaneDayReport.setLeftView(listView, 270); //工具栏 var toolbar = new ht.widget.Toolbar(); toolbar.getView().style.background = paneStyle.paneBackColor; borderPaneDayReport.setTopView(toolbar); toolbar.getSelectBackground = function(item){ return '#3D97D0'; }; //建立一个websocket链接 //var socket = new WebSocket('ws://192.168.0.141:10087/Command'); var socket = new WebSocket('ws://'+webServiceIP+':10087/Command'); // 打开Socket socket.onopen = function(event) { console.log('web socket connceted!',event); //请求自定义列表 socket.send("{\"method\":\"GetOwnReportXlsxList\"}"); }; socket.onmessage = function(event) { console.log('Client received a message',event); if (event.data instanceof Blob) //接收的模板文件 { var a = document.createElement('a'); var url = window.URL.createObjectURL(event.data); var filename = SelectReportName; a.href = url; a.download = filename; a.click(); window.URL.revokeObjectURL(url); return; } var receiveObj=JSON.parse(event.data); if(receiveObj.method=="GetOwnReportXlsxList") { var dayList=JSON.parse(receiveObj.obj); listView.dm().clear(); dayList.forEach(function(val,index,arr) { AddListViewElem(listView,val); }); //listView.setSortFunc(sortFunc); } } //上传模板按钮 var upReportBtn=new ht.widget.Button(); upReportBtn.setWidth(80); upReportBtn.setLabel("上传模板"); upReportBtn.setBorderColor("#4682B4"); upReportBtn.setBackground("#4682B4"); upReportBtn.setLabelColor("#FFFAF0"); upReportBtn.setBorderColor(typeof (paneStyle) == "undefined" ? "#4682B4" : "#000000"); upReportBtn.setBackground(typeof (paneStyle) == "undefined" ? "#4682B4" : paneStyle.btnBackColor); upReportBtn.setLabelColor(typeof (paneStyle) == "undefined" ? "#FFFAF0" : paneStyle.btnFontColor); upReportBtn.onClicked= function(e) { var inputObj=document.createElement('input') inputObj.setAttribute('id','_ef'); inputObj.setAttribute('type','file'); inputObj.setAttribute("style",'visibility:hidden'); document.body.appendChild(inputObj); inputObj.click(); inputObj.onchange=function() { var reader = new FileReader(); var fileobj=inputObj.files[0] ; //以二进制形式读取文件 reader.readAsArrayBuffer( inputObj.files[0]); //文件读取完毕后该函数响应 reader.onload = function loaded(evt) { var binaryString = evt.target.result; var obj=new CommandObj(); obj.method="SendOwnReportXlsxFile"; obj.parm1=""; obj.parm2=inputObj.files[0].name; var objStr=JSON.stringify(obj); socket.send(objStr); socket.send(binaryString); } } } //下载模板按钮 var downReportBtn=new ht.widget.Button(); downReportBtn.setWidth(80); downReportBtn.setLabel("下载模板"); //downReportBtn.setBorderColor("#4682B4"); //downReportBtn.setBackground("#4682B4"); //downReportBtn.setLabelColor("#FFFAF0"); downReportBtn.setBorderColor(typeof (paneStyle) == "undefined" ? "#4682B4" : "#000000"); downReportBtn.setBackground(typeof (paneStyle) == "undefined" ? "#4682B4" : paneStyle.btnBackColor); downReportBtn.setLabelColor(typeof (paneStyle) == "undefined" ? "#FFFAF0" : paneStyle.btnFontColor); downReportBtn.onClicked= function(e) { var obj=new CommandObj(); obj.method="GetReportXlsxFile"; obj.parm1=SelectReportName; obj.parm2=""; var objStr=JSON.stringify(obj); socket.send(objStr); } //删除模板按钮 var deleteReportBtn=new ht.widget.Button(); deleteReportBtn.setWidth(80); deleteReportBtn.setLabel("删除模板"); //deleteReportBtn.setBorderColor("#4682B4"); //deleteReportBtn.setBackground("#4682B4"); //deleteReportBtn.setLabelColor("#FFFAF0"); deleteReportBtn.setBorderColor(typeof (paneStyle) == "undefined" ? "#4682B4" : "#000000"); deleteReportBtn.setBackground(typeof (paneStyle) == "undefined" ? "#4682B4" : paneStyle.btnBackColor); deleteReportBtn.setLabelColor(typeof (paneStyle) == "undefined" ? "#FFFAF0" : paneStyle.btnFontColor); deleteReportBtn.onClicked= function(e) { var obj=new CommandObj(); obj.method="DeleteOwnReportXlsxFile"; obj.parm1=SelectReportName; var objStr=JSON.stringify(obj); socket.send(objStr); } //设置工具栏元素 toolbar.setItems([ { label: '', element:upReportBtn }, { label: '', element:downReportBtn }, { label: '', element:deleteReportBtn }, ]); //节点控件 var borderPaneRealNode = new ht.HtmlNode(); borderPaneRealNode.a('borderPaneRealNode.background', 'rgba(255,0,0,1)'); borderPaneRealNode.setScalable(false); borderPaneRealNode.s({ '2d.selectable': true, '2d.movable': false }); borderPaneRealNode.setHtml(borderPaneDayReport); borderPaneRealNode.setPosition({ x: x, y: y }); borderPaneRealNode.setWidth(width); borderPaneRealNode.setHeight(height); borderPaneRealNode.setPadding(0); /*startSubscribe();*/ /*getSnapshotCallback();*/ return borderPaneRealNode; } //添加列表控件的数据 function AddListViewElem(listView,obj) { var data = new ht.Data(); data.a(obj); listView.dm().add(data); } function CommandObj() { var method=""; var parm1=""; var parm2=""; } // 对Date的扩展,将 Date 转化为指定格式的String // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 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; }