GoldenOwnerDesignReportSet.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. //创建自定义报表配置控件
  2. function CreateOwnDesignReportSet(x,y,width,height,pageHeight,paneStyle)
  3. {
  4. //列表控件
  5. var listView = new ht.widget.ListView();
  6. var SelectReportName="";
  7. for(var i=0;i<20;i++)
  8. {
  9. AddListViewElem(listView,"xxxx");
  10. }
  11. //获得列表控件中文字颜色
  12. listView.getLabelColor = function(data)
  13. {
  14. return this.isSelected(data) ? paneStyle.ListSelTextColor : paneStyle.DialogTitleFontColor ;
  15. };
  16. var listView_View = listView.getView();
  17. listView_View.style.backgroundColor = paneStyle.paneBackColor;
  18. //各行的颜色
  19. listView.drawRowBackground = function(g, data, selected, xx, yy, widthb, heightb)
  20. {
  21. if (this.isSelected(data)) {
  22. g.fillStyle = paneStyle.ListSelBackColor;
  23. } else if (this.getRowIndex(data) % 2 === 0) {
  24. g.fillStyle = paneStyle.paneBackColor;
  25. } else {
  26. g.fillStyle = paneStyle.paneBackColor;
  27. }
  28. g.beginPath();
  29. g.rect(xx, yy, widthb, heightb);
  30. g.fill();
  31. };
  32. listView.getLabel = function(data){
  33. return data.a('Name');
  34. };
  35. //列表选择某条数据
  36. listView.onDataClicked=function(data)
  37. {
  38. if(!data)
  39. return;
  40. SelectReportName=data.a('Name');
  41. }
  42. //布局控件
  43. var borderPaneDayReport = new ht.widget.BorderPane();
  44. borderPaneDayReport.setCenterView(listView);
  45. //工具栏
  46. var toolbar = new ht.widget.Toolbar();
  47. toolbar.getView().style.background = paneStyle.paneBackColor;
  48. borderPaneDayReport.setTopView(toolbar);
  49. toolbar.getSelectBackground = function(item){ return '#3D97D0'; };
  50. //建立一个websocket链接
  51. //var socket = new WebSocket('ws://192.168.0.141:10087/Command');
  52. var socket = new WebSocket('ws://'+webServiceIP+':10087/Command');
  53. // 打开Socket
  54. socket.onopen = function(event)
  55. {
  56. console.log('web socket connceted!',event);
  57. //请求自定义列表
  58. socket.send("{\"method\":\"GetOwnReportXlsxList\"}");
  59. };
  60. socket.onmessage = function(event)
  61. {
  62. console.log('Client received a message',event);
  63. if (event.data instanceof Blob) //接收的模板文件
  64. {
  65. var a = document.createElement('a');
  66. var url = window.URL.createObjectURL(event.data);
  67. var filename = SelectReportName;
  68. a.href = url;
  69. a.download = filename;
  70. a.click();
  71. window.URL.revokeObjectURL(url);
  72. return;
  73. }
  74. var receiveObj=JSON.parse(event.data);
  75. if(receiveObj.method=="GetOwnReportXlsxList")
  76. {
  77. var dayList=JSON.parse(receiveObj.obj);
  78. listView.dm().clear();
  79. dayList.forEach(function(val,index,arr)
  80. {
  81. AddListViewElem(listView,val);
  82. });
  83. //listView.setSortFunc(sortFunc);
  84. }
  85. }
  86. //上传模板按钮
  87. var upReportBtn=new ht.widget.Button();
  88. upReportBtn.setWidth(80);
  89. upReportBtn.setLabel("上传模板");
  90. upReportBtn.setBorderColor("#4682B4");
  91. upReportBtn.setBackground("#4682B4");
  92. upReportBtn.setLabelColor("#FFFAF0");
  93. upReportBtn.setBorderColor(typeof (paneStyle) == "undefined" ? "#4682B4" : "#000000");
  94. upReportBtn.setBackground(typeof (paneStyle) == "undefined" ? "#4682B4" : paneStyle.btnBackColor);
  95. upReportBtn.setLabelColor(typeof (paneStyle) == "undefined" ? "#FFFAF0" : paneStyle.btnFontColor);
  96. upReportBtn.onClicked= function(e)
  97. {
  98. var inputObj=document.createElement('input')
  99. inputObj.setAttribute('id','_ef');
  100. inputObj.setAttribute('type','file');
  101. inputObj.setAttribute("style",'visibility:hidden');
  102. document.body.appendChild(inputObj);
  103. inputObj.click();
  104. inputObj.onchange=function()
  105. {
  106. var reader = new FileReader();
  107. var fileobj=inputObj.files[0] ;
  108. if(fileobj.name.indexOf(".js")>0)
  109. reader.readAsText( inputObj.files[0]);
  110. else
  111. //以二进制形式读取文件
  112. reader.readAsArrayBuffer( inputObj.files[0]);
  113. //文件读取完毕后该函数响应
  114. reader.onload = function loaded(evt)
  115. {
  116. var binaryString = evt.target.result;
  117. var obj=new CommandObj();
  118. obj.method="SendOwnReportXlsxFile";
  119. if(fileobj.name.indexOf(".js")>0)
  120. obj.parm1=binaryString;
  121. else
  122. obj.parm1="";
  123. obj.parm2=inputObj.files[0].name;
  124. var objStr=JSON.stringify(obj);
  125. socket.send(objStr);
  126. socket.send(binaryString);
  127. }
  128. }
  129. }
  130. //下载模板按钮
  131. var downReportBtn=new ht.widget.Button();
  132. downReportBtn.setWidth(80);
  133. downReportBtn.setLabel("下载模板");
  134. //downReportBtn.setBorderColor("#4682B4");
  135. //downReportBtn.setBackground("#4682B4");
  136. //downReportBtn.setLabelColor("#FFFAF0");
  137. downReportBtn.setBorderColor(typeof (paneStyle) == "undefined" ? "#4682B4" : "#000000");
  138. downReportBtn.setBackground(typeof (paneStyle) == "undefined" ? "#4682B4" : paneStyle.btnBackColor);
  139. downReportBtn.setLabelColor(typeof (paneStyle) == "undefined" ? "#FFFAF0" : paneStyle.btnFontColor);
  140. downReportBtn.onClicked= function(e)
  141. {
  142. var obj=new CommandObj();
  143. obj.method="GetReportXlsxFile";
  144. obj.parm1=SelectReportName;
  145. obj.parm2="";
  146. var objStr=JSON.stringify(obj);
  147. socket.send(objStr);
  148. }
  149. //删除模板按钮
  150. var deleteReportBtn=new ht.widget.Button();
  151. deleteReportBtn.setWidth(80);
  152. deleteReportBtn.setLabel("删除模板");
  153. //deleteReportBtn.setBorderColor("#4682B4");
  154. //deleteReportBtn.setBackground("#4682B4");
  155. //deleteReportBtn.setLabelColor("#FFFAF0");
  156. deleteReportBtn.setBorderColor(typeof (paneStyle) == "undefined" ? "#4682B4" : "#000000");
  157. deleteReportBtn.setBackground(typeof (paneStyle) == "undefined" ? "#4682B4" : paneStyle.btnBackColor);
  158. deleteReportBtn.setLabelColor(typeof (paneStyle) == "undefined" ? "#FFFAF0" : paneStyle.btnFontColor);
  159. deleteReportBtn.onClicked= function(e)
  160. {
  161. var obj=new CommandObj();
  162. obj.method="DeleteOwnReportXlsxFile";
  163. obj.parm1=SelectReportName;
  164. var objStr=JSON.stringify(obj);
  165. socket.send(objStr);
  166. }
  167. //设置工具栏元素
  168. toolbar.setItems([
  169. {
  170. label: '',
  171. element:upReportBtn
  172. },
  173. {
  174. label: '',
  175. element:downReportBtn
  176. },
  177. {
  178. label: '',
  179. element:deleteReportBtn
  180. },
  181. ]);
  182. //节点控件
  183. var borderPaneRealNode = new ht.HtmlNode();
  184. borderPaneRealNode.a('borderPaneRealNode.background', 'rgba(255,0,0,1)');
  185. borderPaneRealNode.setScalable(false);
  186. borderPaneRealNode.s({
  187. '2d.selectable': true,
  188. '2d.movable': false
  189. });
  190. borderPaneRealNode.setHtml(borderPaneDayReport);
  191. borderPaneRealNode.setPosition({
  192. x: x,
  193. y: y
  194. });
  195. borderPaneRealNode.setWidth(width);
  196. borderPaneRealNode.setHeight(height);
  197. borderPaneRealNode.setPadding(0);
  198. /*startSubscribe();*/
  199. /*getSnapshotCallback();*/
  200. return borderPaneRealNode;
  201. }
  202. //添加列表控件的数据
  203. function AddListViewElem(listView,obj)
  204. {
  205. var data = new ht.Data();
  206. data.a(obj);
  207. listView.dm().add(data);
  208. }
  209. function CommandObj()
  210. {
  211. var method="";
  212. var parm1="";
  213. var parm2="";
  214. }
  215. // 对Date的扩展,将 Date 转化为指定格式的String
  216. // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  217. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  218. // 例子:
  219. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  220. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  221. Date.prototype.Format = function (fmt) { //author: meizz
  222. var o = {
  223. "M+": this.getMonth() + 1, //月份
  224. "d+": this.getDate(), //日
  225. "h+": this.getHours(), //小时
  226. "m+": this.getMinutes(), //分
  227. "s+": this.getSeconds(), //秒
  228. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  229. "S": this.getMilliseconds() //毫秒
  230. };
  231. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  232. for (var k in o)
  233. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  234. return fmt;
  235. }