config.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
  2. // for details on configuring this project to bundle and minify static web assets.
  3. // Write your JavaScript code.
  4. let httpUrl = 'http://127.0.0.1:6688';
  5. let mqttUrl = 'ws://localhost:8384/mqtt';
  6. let basicUrl = 'http://localhost:8384';
  7. let url = '/Config/';
  8. let containerDiv = 'configcontainer';
  9. let contentDiv = 'content';
  10. let defaultFnav = 'FuelConfigFnav';
  11. let defaultPageDic = new Array();
  12. defaultPageDic['FuelConfigFnav'] = 'PriceChangeRnav';
  13. defaultPageDic['TankConfigFnav'] = 'ProbeConfigRnav';
  14. defaultPageDic['FairbanksFnav'] = 'FairbanksRnav';
  15. let options = {
  16. clientId: 'mqttjs_' + (Math.random() * 1000000).toString(),
  17. timeout: 5000,
  18. useSSL: false
  19. };
  20. let client = mqtt.connect(mqttUrl, options);
  21. client.on('connect',
  22. function (res) {
  23. console.log(res);
  24. client.subscribe('/sys/atg_classic_App/Application.ATG_Classic_App.App/thing/service/GetConfigAsync_reply',
  25. function (err) {
  26. if (err) {
  27. console.log(err);
  28. }
  29. });
  30. client.subscribe('/sys/atg_classic_App/Application.ATG_Classic_App.App/thing/service/UpsertConfigAsync_reply',
  31. function (err) {
  32. if (err) {
  33. console.log(err);
  34. }
  35. });
  36. client.subscribe('/sys/fairbanksRealTimeDataApp/Dfs.WayneChina.FairbanksRTData.FairbanksRealTimeDataApp/thing/service/GetAppConfigAsync_reply',
  37. function (err) {
  38. if (err) {
  39. console.log(err);
  40. }
  41. });
  42. client.subscribe('/sys/fairbanksRealTimeDataApp/Dfs.WayneChina.FairbanksRTData.FairbanksRealTimeDataApp/thing/service/PutConfigAsync_reply',
  43. function (err) {
  44. if (err) {
  45. console.log(err);
  46. }
  47. });
  48. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync_reply',
  49. function (err) {
  50. if (err) {
  51. console.log(err);
  52. }
  53. });
  54. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/PutConfigAsync_reply',
  55. function (err) {
  56. if (err) {
  57. console.log(err);
  58. }
  59. });
  60. });
  61. client.on('error',
  62. function (err) {
  63. console.log(err);
  64. client.end();
  65. });
  66. client.on('message',
  67. function (topic, message) {
  68. //console.log(topic, message.toString());
  69. OnReply(JSON.parse(message.toString()));
  70. });
  71. function Publish1(path) {
  72. client.publish(path, '[]');
  73. }
  74. function Publish(name, value, path) {
  75. let parameters = '{"Parameters": [{"Name": "';
  76. parameters += name;
  77. parameters += '", "Value": "';
  78. parameters += value.replace(new RegExp('"', 'gm'), '\\"') + '"}]}';
  79. console.log(parameters);
  80. client.publish(path, parameters);
  81. }
  82. function OnloadConfig() {
  83. RenderDiv(url + defaultFnav, containerDiv, url + defaultPageDic[defaultFnav], contentDiv);
  84. }
  85. function RenderDiv(containerUrl, containerDiv, contentUrl, contentDiv) {
  86. $.ajax({
  87. url: containerUrl,
  88. success: function (result) {
  89. $('#' + containerDiv).html(result);
  90. if (contentUrl) {
  91. RenderDiv(contentUrl, contentDiv, null, null);
  92. }
  93. },
  94. error: function (msg) {
  95. console.log(msg);
  96. }
  97. })
  98. }
  99. function RenderContainer(currentId, fnav) {
  100. RenderDiv(url + currentId, containerDiv, url + defaultPageDic[currentId], contentDiv);
  101. ToggleClass(currentId, fnav);
  102. }
  103. function RenderContent(currentId, rnav) {
  104. RenderDiv(url + currentId, contentDiv, null, null);
  105. ToggleClass(currentId, rnav);
  106. }
  107. function OnChangeLanguage(locale, array) {
  108. for (let i = 0; i < array.length; i++) {
  109. if ('en-US' === locale) {
  110. array[i].style.fontSize = '1.1rem'
  111. } else {
  112. array[i].style.fontSize = ''
  113. }
  114. }
  115. }
  116. function ToggleClass(currentId, array) {
  117. for (let i = 0; i < array.length; i++) {
  118. let classNames = array[i].className;
  119. let classImage = classNames.split(' ')[0] + '-image';
  120. let id = array[i].id;
  121. if (classNames.length > 1) {
  122. $('#' + id).removeClass(classImage);
  123. }
  124. if (currentId == id) {
  125. $('#' + id).addClass(classImage);
  126. }
  127. }
  128. }
  129. function InvokeHttpGet(apiUrl, callback) {
  130. $.ajax({
  131. url: httpUrl + apiUrl,
  132. contentType: 'application/json',
  133. success: function (res) {
  134. callback(res);
  135. },
  136. error: function (msg) {
  137. console.log(msg)
  138. }
  139. })
  140. }
  141. function InvokeHttpPost(apiUrl, reqdata, callback) {
  142. $.ajax({
  143. url: httpUrl + apiUrl,
  144. contentType: 'application/json',
  145. data: JSON.stringify(reqdata),
  146. type: 'post',
  147. success: function (res) {
  148. callback(res);
  149. },
  150. error: function (msg) {
  151. console.log(msg);
  152. }
  153. })
  154. }
  155. var apis = new Map();
  156. function ShowMeAPIS(parameter,callBack) {
  157. var serviceUrl = basicUrl +"/u/?apitype=service&an=ShowMeApi&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
  158. $.ajax({
  159. url: serviceUrl,
  160. datatype: "application/json",
  161. type: 'post',
  162. contentType: "application/json;charset=utf-8;",
  163. data: JSON.stringify(parameter),
  164. beforeSend: function () {
  165. },
  166. success: function (data) {
  167. console.log(data);
  168. data.forEach(function (d) {
  169. if (d.Path === null) return;
  170. if (apis.has(d.ApiName)) {
  171. apis.delete(d.ApiName);
  172. }
  173. apis.set(d.ApiName, d.Path.slice(d.Path.length - 1) === "+" ? d.Path.slice(0, d.Path.length - 1) : d.Path);
  174. });
  175. // subscribeEvents();
  176. if (callBack !== null) callBack();
  177. },
  178. error: function (err) {
  179. console.log(err);
  180. if (callBack !== null) callBack();
  181. }
  182. });
  183. }
  184. function GetDataByAPIS(apiName, parameter,method,callBack) {
  185. if (apis.size === 0 || !apis.has(apiName)) return;
  186. $.ajax({
  187. url: basicUrl+apis.get(apiName),
  188. datatype: "application/json",
  189. type: method,
  190. contentType: "application/json;charset=utf-8;",
  191. data: JSON.stringify(parameter),
  192. beforeSend: function () {
  193. },
  194. success: function (data) {
  195. console.log(data);
  196. if (callBack !== null) callBack(data);
  197. },
  198. error: function (err) {
  199. console.log(err);
  200. if (callBack !== null) callBack(err);
  201. }
  202. });
  203. }