showHardware.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. $("#moshi").click(function () {
  68. $(".air-con").hide();
  69. $(".oper-con").fadeToggle();
  70. }
  71. )
  72. $("#fengxiang").click(function () {
  73. $(".oper-con").hide();
  74. $(".air-con").fadeToggle();
  75. }
  76. )
  77. let getList = function (params) {
  78. return new Promise((resolve, reject) => {
  79. $.ajax({
  80. method: "POST",
  81. data : JSON.stringify({
  82. "devTypeId": "",
  83. "name": "",
  84. "pageNum": params.cPage,
  85. "pageSize": params.pSize,
  86. "searchKey": "",
  87. "userId": "77547f7af360c5d8e14932866b844d53"
  88. }),
  89. headers: {
  90. "Content-Type": "application/json",
  91. },
  92. dataType: "json",
  93. contentType: "application/json",
  94. url: url + "/api/device/listPage",
  95. success: function (data) {
  96. if (data.code == 0) {
  97. resolve({
  98. data:data.data.records,
  99. totals: data.data.total,
  100. });
  101. } else {
  102. reject(data);
  103. }
  104. },
  105. });
  106. });
  107. };
  108. window.changeDeviceStatus = function (item, paramCode, paramValue, success, fail) {//设置设备
  109. console.log(item);
  110. let tmp = item.infoAttribute.hardware
  111. $.ajax({
  112. method: "GET",
  113. headers: {
  114. "Content-Type": "application/json",
  115. },
  116. dataType: "json",
  117. contentType: "application/json",
  118. url: url + `/api/device/control/${tmp.id}/${paramCode}/${paramValue}/03`,
  119. success: function (data) {
  120. console.log(data.msg)
  121. if (data.code === 0) {
  122. success && success()
  123. } else {
  124. fail && fail()
  125. }
  126. },error:function(){
  127. fail && fail()
  128. }
  129. });
  130. }
  131. window.loadTemperature = function (params={}) {
  132. let {id="temperature",val} = params
  133. //加载温度计
  134. var chartDom = document.getElementById(id);
  135. var myChart = echarts.init(chartDom);
  136. let option = {
  137. series: [
  138. {
  139. name: "Indicator",
  140. type: "gauge",
  141. data: [{
  142. value: val,
  143. name:'温度',
  144. itemStyle:{
  145. color: "#23EACF",
  146. fontSize:14
  147. },
  148. detail: {
  149. formatter: "{value}℃",
  150. color: "#23EACF",
  151. fontSize:24,
  152. offsetCenter: ['0%', '28%'],
  153. },
  154. title: {
  155. offsetCenter: ['0%', '80%'],
  156. color: "#fff",
  157. fontSize:20
  158. }
  159. }],
  160. radius: "100%",
  161. startAngle: 240,
  162. endAngle: -60,
  163. axisLine: {
  164. show: false
  165. },
  166. axisTick:{
  167. show: true,
  168. length:12,
  169. lineStyle:{
  170. color:'#339ED3'
  171. }
  172. },
  173. splitLine: {
  174. show: true,
  175. length:15,
  176. lineStyle:{
  177. color: "rgba(255, 255, 255, 1)",
  178. }
  179. },
  180. axisLabel: {
  181. color: "#23EACF"
  182. },
  183. pointer: {
  184. show: true,
  185. itemStyle:{
  186. color: "#23EACF"
  187. },
  188. width: 4.5,
  189. length: "46%"
  190. }
  191. },
  192. {
  193. name: "Indicator1",
  194. type: "gauge",
  195. data: [{
  196. value: val,
  197. detail:{
  198. show:false
  199. }
  200. }],
  201. radius: "50%",
  202. startAngle: 240,
  203. endAngle: -60,
  204. axisLine: {
  205. show: true,
  206. lineStyle:{
  207. width:5
  208. }
  209. },
  210. progress: {
  211. show: true,
  212. width:5,
  213. itemStyle:{
  214. color: "#23EACF"
  215. }
  216. },
  217. axisTick:{
  218. show: false,
  219. },
  220. splitLine: {
  221. show: false,
  222. },
  223. axisLabel: {
  224. show: false,
  225. },
  226. pointer: {
  227. show: false,
  228. }
  229. }
  230. ]
  231. }
  232. option && myChart.setOption(option, true);
  233. }
  234. window.loadAirConditioner = function (params={}) {
  235. let {id="air-conditioner",val,type,ifOn,windSpeed,fanPos,name,fanState} = params
  236. //开关
  237. $('.ac-close').text(ifOn?'开':'关')
  238. $('.ac-close').addClass('activeTxt')
  239. //名字
  240. $('.ac-title').text(name)
  241. //风向
  242. $('#fxDom').text('风向' + fanPos)
  243. //风速
  244. $('#fsDom').text(windSpeed)
  245. $(`.ac-left li[data-name='${windSpeed}']`).addClass("active").siblings().removeClass("active");
  246. //模式
  247. $(`#airmode span[data-name='${type}']`).addClass("activeTxt").siblings().removeClass("activeTxt");
  248. //加载温度计
  249. var chartDom = document.getElementById(id);
  250. var myChart = echarts.init(chartDom);
  251. let option = {
  252. series: [
  253. {
  254. name: "Indicator",
  255. type: "gauge",
  256. data: [{
  257. value: val,
  258. name:type,
  259. itemStyle:{
  260. color: "#23EACF",
  261. fontSize:14
  262. },
  263. detail: {
  264. offsetCenter: ['0%', '0'],
  265. formatter: "{value}℃",
  266. color: "#fff",
  267. fontSize:22
  268. },
  269. title: {
  270. offsetCenter: ['0%', '26%'],
  271. color: "#fff",
  272. fontSize:16
  273. }
  274. }],
  275. radius: "100%",
  276. startAngle: 220,
  277. endAngle: -40,
  278. progress: {
  279. show: true,
  280. roundCap:true,
  281. itemStyle:{
  282. color: "#23EACF"
  283. }
  284. },
  285. axisLine: {
  286. show: true,
  287. roundCap:true,
  288. lineStyle:{
  289. color: [[1, '#ffffff']]
  290. }
  291. },
  292. axisTick:{
  293. show: false
  294. },
  295. splitLine: {
  296. show: false
  297. },
  298. axisLabel: {
  299. show: false,
  300. },
  301. pointer: {
  302. show: false,
  303. }
  304. }
  305. ]
  306. }
  307. option && myChart.setOption(option, true);
  308. }
  309. window.loadMonitor = function (params={}) {
  310. let {id,url} = params
  311. console.log(id,url);
  312. var video = document.getElementById(id);
  313. if (Hls.isSupported()) {
  314. var hls = new Hls();
  315. hls.loadSource(url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8');
  316. hls.attachMedia(video);
  317. hls.on(Hls.Events.MEDIA_ATTACHED, function () {
  318. video.play();
  319. });
  320. }
  321. // hls.js is not supported on platforms that do not have Media Source Extensions (MSE) enabled.
  322. // 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.
  323. // This is using the built-in support of the plain video element, without using hls.js.
  324. else if (video.canPlayType('application/vnd.apple.mpegurl')) {
  325. video.src = url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8';
  326. video.addEventListener('canplay', function () {
  327. video.play();
  328. });
  329. }
  330. }
  331. /*loadMonitor({
  332. id:"monitor",
  333. url:'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8'
  334. })
  335. loadAirConditioner({
  336. id:"air-conditioner",
  337. val:50,
  338. type:'冷风'
  339. }) */
  340. loadAirConditioner({
  341. name:'二楼-大会议室-04-空调',
  342. val:50,
  343. id:"air-conditioner",
  344. type:'冷风',
  345. ifOn:true,//开关机
  346. windSpeed : "低风",//风速
  347. fanPos : "上",//摆叶位置
  348. fanState: true//摆叶状态
  349. })
  350. });