GoldenOwnerDesignReportSet.js.bak 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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.setLeftView(listView, 270);
  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. //以二进制形式读取文件
  109. reader.readAsArrayBuffer( inputObj.files[0]);
  110. //文件读取完毕后该函数响应
  111. reader.onload = function loaded(evt)
  112. {
  113. var binaryString = evt.target.result;
  114. var obj=new CommandObj();
  115. obj.method="SendOwnReportXlsxFile";
  116. obj.parm1="";
  117. obj.parm2=inputObj.files[0].name;
  118. var objStr=JSON.stringify(obj);
  119. socket.send(objStr);
  120. socket.send(binaryString);
  121. }
  122. }
  123. }
  124. //下载模板按钮
  125. var downReportBtn=new ht.widget.Button();
  126. downReportBtn.setWidth(80);
  127. downReportBtn.setLabel("下载模板");
  128. //downReportBtn.setBorderColor("#4682B4");
  129. //downReportBtn.setBackground("#4682B4");
  130. //downReportBtn.setLabelColor("#FFFAF0");
  131. downReportBtn.setBorderColor(typeof (paneStyle) == "undefined" ? "#4682B4" : "#000000");
  132. downReportBtn.setBackground(typeof (paneStyle) == "undefined" ? "#4682B4" : paneStyle.btnBackColor);
  133. downReportBtn.setLabelColor(typeof (paneStyle) == "undefined" ? "#FFFAF0" : paneStyle.btnFontColor);
  134. downReportBtn.onClicked= function(e)
  135. {
  136. var obj=new CommandObj();
  137. obj.method="GetReportXlsxFile";
  138. obj.parm1=SelectReportName;
  139. obj.parm2="";
  140. var objStr=JSON.stringify(obj);
  141. socket.send(objStr);
  142. }
  143. //删除模板按钮
  144. var deleteReportBtn=new ht.widget.Button();
  145. deleteReportBtn.setWidth(80);
  146. deleteReportBtn.setLabel("删除模板");
  147. //deleteReportBtn.setBorderColor("#4682B4");
  148. //deleteReportBtn.setBackground("#4682B4");
  149. //deleteReportBtn.setLabelColor("#FFFAF0");
  150. deleteReportBtn.setBorderColor(typeof (paneStyle) == "undefined" ? "#4682B4" : "#000000");
  151. deleteReportBtn.setBackground(typeof (paneStyle) == "undefined" ? "#4682B4" : paneStyle.btnBackColor);
  152. deleteReportBtn.setLabelColor(typeof (paneStyle) == "undefined" ? "#FFFAF0" : paneStyle.btnFontColor);
  153. deleteReportBtn.onClicked= function(e)
  154. {
  155. var obj=new CommandObj();
  156. obj.method="DeleteOwnReportXlsxFile";
  157. obj.parm1=SelectReportName;
  158. var objStr=JSON.stringify(obj);
  159. socket.send(objStr);
  160. }
  161. //设置工具栏元素
  162. toolbar.setItems([
  163. {
  164. label: '',
  165. element:upReportBtn
  166. },
  167. {
  168. label: '',
  169. element:downReportBtn
  170. },
  171. {
  172. label: '',
  173. element:deleteReportBtn
  174. },
  175. ]);
  176. //节点控件
  177. var borderPaneRealNode = new ht.HtmlNode();
  178. borderPaneRealNode.a('borderPaneRealNode.background', 'rgba(255,0,0,1)');
  179. borderPaneRealNode.setScalable(false);
  180. borderPaneRealNode.s({
  181. '2d.selectable': true,
  182. '2d.movable': false
  183. });
  184. borderPaneRealNode.setHtml(borderPaneDayReport);
  185. borderPaneRealNode.setPosition({
  186. x: x,
  187. y: y
  188. });
  189. borderPaneRealNode.setWidth(width);
  190. borderPaneRealNode.setHeight(height);
  191. borderPaneRealNode.setPadding(0);
  192. /*startSubscribe();*/
  193. /*getSnapshotCallback();*/
  194. return borderPaneRealNode;
  195. }
  196. //添加列表控件的数据
  197. function AddListViewElem(listView,obj)
  198. {
  199. var data = new ht.Data();
  200. data.a(obj);
  201. listView.dm().add(data);
  202. }
  203. function CommandObj()
  204. {
  205. var method="";
  206. var parm1="";
  207. var parm2="";
  208. }
  209. // 对Date的扩展,将 Date 转化为指定格式的String
  210. // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  211. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  212. // 例子:
  213. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  214. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  215. Date.prototype.Format = function (fmt) { //author: meizz
  216. var o = {
  217. "M+": this.getMonth() + 1, //月份
  218. "d+": this.getDate(), //日
  219. "h+": this.getHours(), //小时
  220. "m+": this.getMinutes(), //分
  221. "s+": this.getSeconds(), //秒
  222. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  223. "S": this.getMilliseconds() //毫秒
  224. };
  225. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  226. for (var k in o)
  227. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  228. return fmt;
  229. }