showHardware.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. $(function () {
  2. let url = ``;
  3. // let url = `http://192.168.0.135:8004`;
  4. let gName = "Gridtable";
  5. let grtable = document.querySelector("#gridtb");
  6. grtable.GM({
  7. gridManagerName: gName,
  8. height: "300px",
  9. ajaxData: function (setting) {
  10. console.log(setting.pageData,setting.sortData);
  11. // 传入分页及排序的配置项
  12. return getList(Object.assign({}, setting.pageData, setting.sortData));
  13. },
  14. ajaxType: "POST",
  15. supportCheckbox: false,
  16. supportAjaxPage: true,
  17. useNoTotalsMode: true,
  18. pageSize:10,
  19. columnData: [
  20. {
  21. key: "code",
  22. text: "硬件编号",
  23. },
  24. {
  25. key: "devTypeName",
  26. text: "硬件状态",
  27. },
  28. {
  29. key: "name",
  30. text: "热点名字",
  31. },
  32. ,
  33. {
  34. key: "id",
  35. width: "100px",
  36. align: "center",
  37. text: "查看",
  38. template: function (username) {
  39. var titleNode = document.createElement("div");
  40. // titleNode.attr('href', `https://www.lovejavascript.com/#!zone/blog/content.html?id=${rowObject.id}`);
  41. titleNode.setAttribute("title", username);
  42. titleNode.classList.add("plugin-action");
  43. titleNode.innerHTML = `<img src="./images/jiantou2.png" alt="">`;
  44. return titleNode;
  45. },
  46. },
  47. ],
  48. });
  49. // 阻止冒泡
  50. $(".hardware-list").on("click keydown keyup keypress", function (event) {
  51. event.stopPropagation();
  52. });
  53. //点击前往查看
  54. $(grtable).on("click", ".plugin-action", function (e) {
  55. const row = GridManager.getRowData(
  56. gName,
  57. e.currentTarget.parentElement.parentElement
  58. );
  59. console.log(row);
  60. window.hardwareHotList[row.id] &&
  61. window.hardwareHotList[row.id].showPannel({ focus: true });
  62. });
  63. $(".hard-header").click(function () {
  64. $(".hard-body").toggle();
  65. }
  66. )
  67. let getList = function (params) {
  68. return new Promise((resolve, reject) => {
  69. $.ajax({
  70. method: "POST",
  71. data : JSON.stringify({
  72. "devTypeId": "",
  73. "name": "",
  74. "pageNum": params.cPage,
  75. "pageSize": params.pSize,
  76. "searchKey": "",
  77. "userId": "77547f7af360c5d8e14932866b844d53"
  78. }),
  79. headers: {
  80. "Content-Type": "application/json",
  81. },
  82. dataType: "json",
  83. contentType: "application/json",
  84. url: url + "/api/device/listPage",
  85. success: function (data) {
  86. if (data.code == 0) {
  87. resolve({
  88. data:data.data.records,
  89. totals: data.data.total,
  90. });
  91. } else {
  92. reject(data);
  93. }
  94. },
  95. });
  96. });
  97. };
  98. window.changeDeviceStatus = function (item, on) {
  99. console.log(item);
  100. var paramValue = on?1:0
  101. let tmp = item.infoAttribute.hardware
  102. $.ajax({
  103. method: "GET",
  104. headers: {
  105. "Content-Type": "application/json",
  106. },
  107. dataType: "json",
  108. contentType: "application/json",
  109. url: url + `/api/device/control/${tmp.id}/${tmp.code}/${paramValue}/03`,
  110. success: function (data) {
  111. if (data.code === 0) {
  112. resolve({
  113. ...data,
  114. totals: data.data.length,
  115. });
  116. } else {
  117. reject(data);
  118. }
  119. },
  120. });
  121. }
  122. window.loadTemperature = function (params={}) {
  123. let {id="temperature",val} = params
  124. //加载温度计
  125. var chartDom = document.getElementById(id);
  126. var myChart = echarts.init(chartDom);
  127. let option = {
  128. series: [
  129. {
  130. name: "Indicator",
  131. type: "gauge",
  132. data: [{
  133. value: val,
  134. name:'温度',
  135. itemStyle:{
  136. color: "#23EACF",
  137. fontSize:14
  138. },
  139. detail: {
  140. formatter: "{value}℃",
  141. color: "#23EACF",
  142. fontSize:24,
  143. offsetCenter: ['0%', '28%'],
  144. },
  145. title: {
  146. offsetCenter: ['0%', '80%'],
  147. color: "#fff",
  148. fontSize:20
  149. }
  150. }],
  151. radius: "100%",
  152. startAngle: 240,
  153. endAngle: -60,
  154. axisLine: {
  155. show: false
  156. },
  157. axisTick:{
  158. show: true,
  159. length:12,
  160. lineStyle:{
  161. color:'#339ED3'
  162. }
  163. },
  164. splitLine: {
  165. show: true,
  166. length:15,
  167. lineStyle:{
  168. color: "rgba(255, 255, 255, 1)",
  169. }
  170. },
  171. axisLabel: {
  172. color: "#23EACF"
  173. },
  174. pointer: {
  175. show: true,
  176. itemStyle:{
  177. color: "#23EACF"
  178. },
  179. width: 4.5,
  180. length: "46%"
  181. }
  182. },
  183. {
  184. name: "Indicator1",
  185. type: "gauge",
  186. data: [{
  187. value: val,
  188. detail:{
  189. show:false
  190. }
  191. }],
  192. radius: "50%",
  193. startAngle: 240,
  194. endAngle: -60,
  195. axisLine: {
  196. show: true,
  197. lineStyle:{
  198. width:5
  199. }
  200. },
  201. progress: {
  202. show: true,
  203. width:5,
  204. itemStyle:{
  205. color: "#23EACF"
  206. }
  207. },
  208. axisTick:{
  209. show: false,
  210. },
  211. splitLine: {
  212. show: false,
  213. },
  214. axisLabel: {
  215. show: false,
  216. },
  217. pointer: {
  218. show: false,
  219. }
  220. }
  221. ]
  222. }
  223. option && myChart.setOption(option, true);
  224. }
  225. window.loadAirConditioner = function (params={}) {
  226. let {id="air-conditioner",val,type} = params
  227. //加载温度计
  228. var chartDom = document.getElementById(id);
  229. var myChart = echarts.init(chartDom);
  230. let option = {
  231. series: [
  232. {
  233. name: "Indicator",
  234. type: "gauge",
  235. data: [{
  236. value: val,
  237. name:type,
  238. itemStyle:{
  239. color: "#23EACF",
  240. fontSize:14
  241. },
  242. detail: {
  243. offsetCenter: ['0%', '0'],
  244. formatter: "{value}℃",
  245. color: "#fff",
  246. fontSize:22
  247. },
  248. title: {
  249. offsetCenter: ['0%', '26%'],
  250. color: "#fff",
  251. fontSize:16
  252. }
  253. }],
  254. radius: "100%",
  255. startAngle: 220,
  256. endAngle: -40,
  257. progress: {
  258. show: true,
  259. roundCap:true,
  260. itemStyle:{
  261. color: "#23EACF"
  262. }
  263. },
  264. axisLine: {
  265. show: true,
  266. roundCap:true,
  267. lineStyle:{
  268. color: [[1, '#ffffff']]
  269. }
  270. },
  271. axisTick:{
  272. show: false
  273. },
  274. splitLine: {
  275. show: false
  276. },
  277. axisLabel: {
  278. show: false,
  279. },
  280. pointer: {
  281. show: false,
  282. }
  283. }
  284. ]
  285. }
  286. option && myChart.setOption(option, true);
  287. }
  288. window.loadMonitor = function (params={}) {
  289. let {id,url} = params
  290. console.log(id,url);
  291. var video = document.getElementById(id);
  292. if (Hls.isSupported()) {
  293. var hls = new Hls();
  294. hls.loadSource(url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8');
  295. hls.attachMedia(video);
  296. hls.on(Hls.Events.MEDIA_ATTACHED, function () {
  297. video.play();
  298. });
  299. }
  300. // hls.js is not supported on platforms that do not have Media Source Extensions (MSE) enabled.
  301. // When the browser has built-in HLS support (check using `canPlayType`), we can provide an HLS manifest (i.e. .m3u8 URL) directly to the video element throught the `src` property.
  302. // This is using the built-in support of the plain video element, without using hls.js.
  303. else if (video.canPlayType('application/vnd.apple.mpegurl')) {
  304. video.src = url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8';
  305. video.addEventListener('canplay', function () {
  306. video.play();
  307. });
  308. }
  309. }
  310. loadMonitor({
  311. id:"monitor",
  312. url:'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8'
  313. })
  314. loadAirConditioner({
  315. id:"air-conditioner",
  316. val:50,
  317. type:'冷风'
  318. })
  319. });