showHardware.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. $(".waiting").addClass('showloading')
  111. let tmp = item.infoAttribute.hardware
  112. $.ajax({
  113. method: "GET",
  114. headers: {
  115. "Content-Type": "application/json",
  116. },
  117. dataType: "json",
  118. contentType: "application/json",
  119. url: url + `/api/device/control/${tmp.id}/${paramCode}/${paramValue}/03`,
  120. success: function (data) {
  121. console.log(data.msg)
  122. $(".waiting").removeClass('showloading')
  123. if (data.code === 0) {
  124. success && success()
  125. } else {
  126. fail && fail()
  127. }
  128. },error:function(){
  129. $(".waiting").removeClass('showloading')
  130. fail && fail()
  131. }
  132. });
  133. }
  134. window.loadTemperature = function (params={}) {
  135. let {id="temperature",val} = params
  136. //加载温度计
  137. var chartDom = document.getElementById(id);
  138. var myChart = echarts.init(chartDom);
  139. let option = {
  140. series: [
  141. {
  142. name: "Indicator",
  143. type: "gauge",
  144. data: [{
  145. value: val,
  146. name:'温度',
  147. itemStyle:{
  148. color: "#23EACF",
  149. fontSize:14
  150. },
  151. detail: {
  152. formatter: "{value}℃",
  153. color: "#23EACF",
  154. fontSize:24,
  155. offsetCenter: ['0%', '28%'],
  156. },
  157. title: {
  158. offsetCenter: ['0%', '80%'],
  159. color: "#fff",
  160. fontSize:20
  161. }
  162. }],
  163. radius: "100%",
  164. startAngle: 240,
  165. endAngle: -60,
  166. axisLine: {
  167. show: false
  168. },
  169. axisTick:{
  170. show: true,
  171. length:12,
  172. lineStyle:{
  173. color:'#339ED3'
  174. }
  175. },
  176. splitLine: {
  177. show: true,
  178. length:15,
  179. lineStyle:{
  180. color: "rgba(255, 255, 255, 1)",
  181. }
  182. },
  183. axisLabel: {
  184. color: "#23EACF"
  185. },
  186. pointer: {
  187. show: true,
  188. itemStyle:{
  189. color: "#23EACF"
  190. },
  191. width: 4.5,
  192. length: "46%"
  193. }
  194. },
  195. {
  196. name: "Indicator1",
  197. type: "gauge",
  198. data: [{
  199. value: val,
  200. detail:{
  201. show:false
  202. }
  203. }],
  204. radius: "50%",
  205. startAngle: 240,
  206. endAngle: -60,
  207. axisLine: {
  208. show: true,
  209. lineStyle:{
  210. width:5
  211. }
  212. },
  213. progress: {
  214. show: true,
  215. width:5,
  216. itemStyle:{
  217. color: "#23EACF"
  218. }
  219. },
  220. axisTick:{
  221. show: false,
  222. },
  223. splitLine: {
  224. show: false,
  225. },
  226. axisLabel: {
  227. show: false,
  228. },
  229. pointer: {
  230. show: false,
  231. }
  232. }
  233. ]
  234. }
  235. option && myChart.setOption(option, true);
  236. }
  237. window.loadAirConditioner = function (params={}) {
  238. let {id="air-conditioner",
  239. val='unset',
  240. type='unset',
  241. ifOn='unset',
  242. windSpeed='unset',
  243. fanPos='unset',
  244. name='unset',
  245. fanState='unset'} = params
  246. //开关
  247. if (ifOn!='unset') {
  248. if (ifOn) {
  249. $('.ac-body').show()
  250. $('.ac-switch').hide()
  251. }else{
  252. $('.ac-body').hide()
  253. $('.ac-switch').show()
  254. }
  255. }
  256. //名字
  257. if (name!='unset') {
  258. $('.ac-title').text(name)
  259. }
  260. //风向
  261. if (fanPos!='unset') {
  262. $('#fxDom').text('风向' + fanPos)
  263. }
  264. //风速
  265. if (windSpeed!='unset') {
  266. $('#fsDom').text(windSpeed)
  267. $(`.ac-left li[data-name='${windSpeed}']`).addClass("active").siblings().removeClass("active");
  268. }
  269. //模式
  270. if (type!='unset') {
  271. $(`#airmode span[data-name='${type}']`).addClass("activeTxt").siblings().removeClass("activeTxt");
  272. }
  273. if (val=='unset') {
  274. return
  275. }
  276. //加载温度计
  277. var chartDom = document.getElementById(id);
  278. var myChart = echarts.init(chartDom);
  279. let option = {
  280. series: [
  281. {
  282. name: "Indicator",
  283. type: "gauge",
  284. data: [{
  285. value: val,
  286. name:type,
  287. itemStyle:{
  288. color: "#23EACF",
  289. fontSize:14
  290. },
  291. detail: {
  292. offsetCenter: ['0%', '0'],
  293. formatter: "{value}℃",
  294. color: "#fff",
  295. fontSize:22
  296. },
  297. title: {
  298. offsetCenter: ['0%', '26%'],
  299. color: "#fff",
  300. fontSize:16
  301. }
  302. }],
  303. radius: "100%",
  304. startAngle: 220,
  305. endAngle: -40,
  306. progress: {
  307. show: true,
  308. roundCap:true,
  309. itemStyle:{
  310. color: "#23EACF"
  311. }
  312. },
  313. axisLine: {
  314. show: true,
  315. roundCap:true,
  316. lineStyle:{
  317. color: [[1, '#ffffff']]
  318. }
  319. },
  320. axisTick:{
  321. show: false
  322. },
  323. splitLine: {
  324. show: false
  325. },
  326. axisLabel: {
  327. show: false,
  328. },
  329. pointer: {
  330. show: false,
  331. }
  332. }
  333. ]
  334. }
  335. option && myChart.setOption(option, true);
  336. }
  337. window.loadMonitor = function (params={}) {
  338. let {id,url} = params
  339. console.log(id,url);
  340. var video = document.getElementById(id);
  341. if (Hls.isSupported()) {
  342. var hls = new Hls();
  343. hls.loadSource(url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8');
  344. hls.attachMedia(video);
  345. hls.on(Hls.Events.MEDIA_ATTACHED, function () {
  346. video.play();
  347. });
  348. }
  349. // hls.js is not supported on platforms that do not have Media Source Extensions (MSE) enabled.
  350. // 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.
  351. // This is using the built-in support of the plain video element, without using hls.js.
  352. else if (video.canPlayType('application/vnd.apple.mpegurl')) {
  353. video.src = url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8';
  354. video.addEventListener('canplay', function () {
  355. video.play();
  356. });
  357. }
  358. }
  359. window.loadCalendar = function(params = {}){
  360. let { data,cellCb=()=>{},monthCb=()=>{} } = params
  361. //日历方法
  362. $("#calendar").calendar({
  363. data: data, //记录数据
  364. work: [],//上班时间
  365. mode: "month",
  366. shwoLunar:false,
  367. width: 400,
  368. cellClick: function (data) {
  369. let item = data[0]
  370. cellCb(item)
  371. },
  372. monthClick: function (e, nextMonth, opts, me) {
  373. monthCb(e)
  374. }
  375. });
  376. }
  377. window.loadCalendar({
  378. data:[{
  379. 'startDate': "2021-5-18",//有监控的日期
  380. id:'传对应的id'
  381. }],
  382. //点击日期时间
  383. cellCb: (item)=> {
  384. console.log(item);
  385. }
  386. })
  387. /*loadMonitor({
  388. id:"monitor",
  389. url:'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8'
  390. })
  391. loadAirConditioner({
  392. id:"air-conditioner",
  393. val:50,
  394. type:'冷风'
  395. }) */
  396. // loadAirConditioner({
  397. // name:'二楼-大会议室-04-空调',
  398. // val:50,
  399. // id:"air-conditioner",
  400. // type:'冷风',
  401. // ifOn:true,//开关机
  402. // windSpeed : "低风",//风速
  403. // fanPos : "上",//摆叶位置
  404. // fanState: true//摆叶状态
  405. // })
  406. });