Upload.cshtml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. @*
  2. For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
  3. *@
  4. @{
  5. Layout = null;
  6. }
  7. @{
  8. int screenWidth = 1280;
  9. int mainviewHeight = 570;
  10. int marginLeft = 42;
  11. int marginTop = 20;
  12. int dataDescriptionWidth = (screenWidth - 2 * marginLeft) * 50 / 100;
  13. int dataDescriptionHeight = mainviewHeight - marginTop - marginTop / 2;
  14. int dataDescriptionTableHeight = dataDescriptionHeight * 95 / 100;
  15. int dataDescriptionTableHeadHeight = dataDescriptionTableHeight / 5;
  16. int dataDescriptionTableBodyRowHeight = (dataDescriptionTableHeight - dataDescriptionTableHeight / 5) / 8;
  17. int dataDescriptionTableBodyHeight = dataDescriptionTableHeight - dataDescriptionTableHeight / 5;
  18. int dataHistoryWidth = (screenWidth - 2 * marginLeft) * 50 / 100;
  19. int stationInfoHeigth = dataDescriptionHeight - dataDescriptionTableHeight;
  20. //int dataDescriptionHeaderHeight = dataDescriptionHeight - dataDescriptionTableHeight;
  21. }
  22. <style type="text/css">
  23. .table{
  24. border-collapse:collapse;
  25. }
  26. .table tr td{
  27. /*border-bottom: 1px solid#00bfff;
  28. border-left: 1px solid #00bfff;*/
  29. color: #000000;
  30. font-size: 30px;
  31. /*padding:5px 8px;*/
  32. text-align: left;
  33. font-weight: bold;
  34. }
  35. .table>thead {
  36. display: table;
  37. width: 100%;
  38. height:@(dataDescriptionTableHeadHeight)px;
  39. table-layout:fixed;
  40. }
  41. .table>tbody>tr{
  42. display: table;
  43. width: 100%;
  44. height:@(dataDescriptionTableBodyRowHeight)px;
  45. table-layout:fixed;
  46. }
  47. .table>tbody{
  48. height:@(dataDescriptionTableBodyHeight)px;
  49. overflow: hidden;
  50. display: block;
  51. overflow: hidden;
  52. overflow-y:auto;
  53. }
  54. </style>
  55. <script src="~/js/mqtt.min.js"></script>
  56. @*<script src="~/js/jquery-3.4.1.min.js"></script>*@
  57. @*@{
  58. await Html.RenderPartialAsync("OnlineMonitorHeader");
  59. }*@
  60. <div id="dataupload" style="position: relative; width:@(screenWidth-2)px; height:@(mainviewHeight-2)px;">
  61. @*<span id="testmqqt" style="position: relative">数据上传</span>
  62. <input type="button" onclick="Onmqtttest()" value="Test MQQT" />*@
  63. <div id="dataupload_description" style="position: relative;float: left;margin-left: @(marginLeft)px; margin-top: @(marginTop)px;width:@(dataDescriptionWidth)px; height:@(dataDescriptionHeight)px;">
  64. @*<span id="dataupload_description_header" style="position: relative; width: 100%; height: 40px; line-height: 40px; font-size: 22px; text-align: left; font-weight: bold;">
  65. 北京环保局上传(测试)
  66. </span>*@
  67. <table id="dataupload_description_table" class="table">
  68. <thead>
  69. <tr style="font-weight: bold; font-size: 40px;">
  70. <td style="height: @(dataDescriptionTableHeadHeight)px;">北京环保局上传(测试)</td>
  71. </tr>
  72. </thead>
  73. <tbody>
  74. @for (int i = 0; i < 4; i++)
  75. {
  76. <tr style="font-size: 30px;">
  77. <td style="text-align: left; height: @(dataDescriptionTableBodyRowHeight-2)px;">2020-04-16</td>
  78. </tr>
  79. <tr style="font-size: 30px;">
  80. <td style="padding-left: 20%; height: @(dataDescriptionTableBodyRowHeight)px;">加油数据首次上传</td>
  81. </tr>
  82. }
  83. </tbody>
  84. </table>
  85. <div id="dataupload_stationInfo" style="position: relative; float: left;width:@(dataDescriptionWidth)px; height:@(stationInfoHeigth-2)px;font-size: 22px;">站点编号:1234567890</div>
  86. </div>
  87. <div id="dataupload_history" style="position: relative;float: left;margin-top: @(marginTop)px;width:@(dataHistoryWidth)px; height:@(dataDescriptionHeight)px;">
  88. <table id="dataupload_history_table" class="table">
  89. <thead>
  90. <tr style="font-weight: bold; font-size: 30px;">
  91. <td style="height: @(dataDescriptionTableHeadHeight)px;">上传历史</td>
  92. </tr>
  93. </thead>
  94. <tbody>
  95. @for (int i = 0; i < 15; i++)
  96. {
  97. <tr style="font-size: 30px;font-weight: bold;">
  98. <td style="width: 33%;">2020-04-16</td>
  99. <td style="width: 41%;">加油数据上传</td>
  100. <td style="width: 25%;">成功</td>
  101. </tr>
  102. }
  103. </tbody>
  104. </table>
  105. </div>
  106. </div>
  107. @*<img id="dataupload_img" src="/image/online/筛选图标.png" style="position: absolute; left: @(screenWidth-63)px;top: 55px;"/>*@
  108. <script>
  109. var textSpan = document.getElementById("head_left_text");
  110. if (textSpan != null)
  111. textSpan.innerHTML = "数据上传";
  112. </script>
  113. <script type="text/javascript">
  114. var hostname = 'localhost', //'192.168.1.2',
  115. port = 8384,
  116. clientId = 'mqttjs_' + (Math.random() * 1000000).toString(),
  117. timeout = 5000,
  118. keepAlive = 100,
  119. cleanSession = false,
  120. mqttVersion = 3,
  121. ssl = false;
  122. //var client = new Paho.MQTT.Client(hostname, port, clientId);
  123. //client.onConnectionLost = onConnectionLost;//绑定连接断开事件
  124. //client.onMessageArrived = onMessageArrived;//
  125. var options = {
  126. //mqtt客户端的id,这里面应该还可以加上其他参数,具体看官方文档
  127. clientId: 'mqttjs_' + (Math.random() * 1000000).toString(),
  128. //invocationContext: {
  129. // host: hostname,
  130. // port: port,
  131. // //path: client.path,
  132. // mqttVersion:mqttVersion,
  133. // clientId: clientId
  134. //},
  135. //mqttVersion:mqttVersion,
  136. timeout: timeout,
  137. //keepAliveInterval: keepAlive,
  138. //cleanSession: cleanSession,
  139. useSSL: false
  140. //onSuccess: onConnect,
  141. //onFailure: onError
  142. }
  143. //浏览器采用websocket协议,host主机地址为192.168.0.200,端口为9001,路径为/mqtt
  144. var client = mqtt.connect("ws://localhost:8384/mqtt", options); // you add a ws:// url here
  145. //client.on('connect',
  146. // function() {
  147. // client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync_reply',
  148. // function(err) {
  149. // if (!err) {
  150. // client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync', 'Hello mqtt');
  151. // }
  152. // });
  153. // });
  154. //client.on('message',
  155. // function(topic, message) {
  156. // // message is Buffer
  157. // console.log(message.toString());
  158. // client.end();
  159. // });
  160. ////建立连接
  161. client.on('connect',
  162. function () {
  163. var a = document.getElementById("testmqqt");
  164. if (a != null) a.innerHTML = "connected";
  165. //订阅主题 presence
  166. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync_reply',
  167. function (err) {
  168. if (!err) {
  169. if (a != null) a.innerHTML = "subscribe GetConfigAsync_reply successfully";
  170. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync', 'Hello mqtt ');
  171. } else {
  172. //打印错误
  173. if (a != null) a.innerHTML = err;
  174. }
  175. });
  176. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesData_reply',
  177. function (err) {
  178. if (!err) {
  179. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesData', "Hello mqtt");
  180. };
  181. });
  182. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesFlowData_reply',
  183. function (err) {
  184. if (!err) {
  185. if (a != null) a.innerHTML = "subscribe nozzleFlowData successfully";
  186. } else {
  187. //打印错误
  188. if (a != null) a.innerHTML = err;
  189. }
  190. });
  191. });
  192. //如果连接错误,打印错误
  193. client.on('error',
  194. function (err) {
  195. var a = document.getElementById("testmqqt");
  196. if (a != null) a.innerHTML = err;
  197. client.end();
  198. });
  199. //如果client订阅主题成功,那么这里就是当接收到自己订阅主题的处理逻辑
  200. client.on('message',
  201. function (topic, message) {
  202. // message is Buffer,此处就是打印消息的具体内容
  203. //console.log('-> ' + message.toString());
  204. var a = document.getElementById("testmqqt");
  205. if (a != null) a.innerHTML = topic;
  206. if (topic === "/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync_reply") {
  207. processConfigData(JSON.parse(message.toString()));
  208. return;
  209. }
  210. if (topic === "/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesData_reply") {
  211. var nozzles = processNozzlesData(JSON.parse(message.toString()));
  212. return;
  213. }
  214. });
  215. function processConfigData(message) {
  216. var WarningValueMin = message.onlineWatchConfig.WarningValueMin;
  217. var WarningValueMax = message.onlineWatchConfig.WarningValueMax;
  218. var a = document.getElementById("testmqqt");
  219. if (a != null) a.innerHTML = WarningValueMin;
  220. }
  221. function processNozzlesData(message) {
  222. var data = message.data;
  223. var pumpMap = new Map();
  224. var currentDispenserId = 0;
  225. var nozzlesArray = new Array();
  226. data.forEach(function (d) {
  227. if (currentDispenserId === 0) {
  228. currentDispenserId = d.SiteLevelDispenserId;
  229. nozzlesArray.push(d);
  230. } else if (currentDispenserId !== d.SiteLevelDispenserId) {
  231. pumpMap.set(currentDispenserId, new Array().concat(nozzlesArray));
  232. currentDispenserId = d.SiteLevelDispenserId;
  233. nozzlesArray.splice(0, nozzlesArray.length);
  234. nozzlesArray.push(d);
  235. } else {
  236. currentDispenserId = d.SiteLevelDispenserId;
  237. //nozzlesArray.clear();
  238. nozzlesArray.push(d);
  239. }
  240. });
  241. if (nozzlesArray.length > 0) {
  242. pumpMap.set(currentDispenserId, new Array().concat(nozzlesArray));
  243. nozzlesArray.splice(0, nozzlesArray.length);
  244. }
  245. pumpMap.forEach(function (value, key) {
  246. var dispenserId = key;
  247. var nozzleCount = value.length;
  248. });
  249. }
  250. //// 用户程序点击事件
  251. function Onmqtttest() {
  252. var message = "message from browser with websocket"; // 消息内容
  253. var nozzleId = 1;
  254. var temp = { "Parameters": [{ "Name": "nozzleid", "Value": nozzleId }, { "Name": "starttime", "Value": "20200422000000" }, { "Name": "endtime", "Value": "20200422235959" }] };
  255. message = JSON.stringify(temp);
  256. //message ="{/"Parameters/": [{/"Name/": /"nozzleid/","Value": "2"}, { "Name": "starttime","Value": "20200422000000"}, {"Name": "endtime","Value": "20200422235959"}]}"
  257. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesFlowData', message);
  258. //发布主题presence,消息内容为Hello mqtt,订阅与推送一样自发自收
  259. //client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync', 'Hello mqtt ' + message);
  260. var a = document.getElementById("testmqqt");
  261. if (a != null) a.innerHTML = message;
  262. }
  263. </script>