config.js 7.0 KB

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