showHardware.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. $(function () {
  2. let url = ``;
  3. // let url = `http://192.168.0.135:8004`;
  4. let userId = getQueryVal('userId')
  5. let gName = "Gridtable";
  6. let grtable = document.querySelector("#gridtb");
  7. grtable.GM({
  8. gridManagerName: gName,
  9. height: "300px",
  10. ajaxData: function (setting) {
  11. console.log(setting.pageData,setting.sortData);
  12. // 传入分页及排序的配置项
  13. return getList(Object.assign({}, setting.pageData, setting.sortData));
  14. },
  15. ajaxType: "POST",
  16. supportCheckbox: false,
  17. supportAjaxPage: true,
  18. useNoTotalsMode: true,
  19. pageSize:10,
  20. columnData: [
  21. {
  22. key: "code",
  23. text: "硬件编号",
  24. },
  25. {
  26. key: "devTypeName",
  27. text: "硬件状态",
  28. },
  29. {
  30. key: "name",
  31. text: "热点名字",
  32. },
  33. ,
  34. {
  35. key: "id",
  36. width: "100px",
  37. align: "center",
  38. text: "查看",
  39. template: function (username) {
  40. var titleNode = document.createElement("div");
  41. // titleNode.attr('href', `https://www.lovejavascript.com/#!zone/blog/content.html?id=${rowObject.id}`);
  42. titleNode.setAttribute("title", username);
  43. titleNode.classList.add("plugin-action");
  44. titleNode.innerHTML = `<img src="./images/jiantou2.png" alt="">`;
  45. return titleNode;
  46. },
  47. },
  48. ],
  49. });
  50. // 阻止冒泡
  51. $(".hardware-list").on("click keydown keyup keypress", function (event) {
  52. event.stopPropagation();
  53. });
  54. //点击前往查看
  55. $(grtable).on("click", ".plugin-action", function (e) {
  56. const row = GridManager.getRowData(
  57. gName,
  58. e.currentTarget.parentElement.parentElement
  59. );
  60. console.log(row);
  61. window.hardwareHotList[row.id] &&
  62. window.hardwareHotList[row.id].showPannel({ focus: true });
  63. });
  64. $(".hard-header").click(function () {
  65. $(".hard-body").toggle();
  66. }
  67. )
  68. $("#moshi").click(function () {
  69. $(".air-con").hide();
  70. $(".oper-con").fadeToggle();
  71. }
  72. )
  73. $("#fengxiang").click(function () {
  74. $(".oper-con").hide();
  75. $(".air-con").fadeToggle();
  76. }
  77. )
  78. let getList = function (params) {
  79. return new Promise((resolve, reject) => {
  80. $.ajax({
  81. method: "POST",
  82. data : JSON.stringify({
  83. "devTypeId": "",
  84. "name": "",
  85. "pageNum": params.cPage,
  86. "pageSize": params.pSize,
  87. "searchKey": "",
  88. "userId": userId
  89. }),
  90. headers: {
  91. "Content-Type": "application/json",
  92. },
  93. dataType: "json",
  94. contentType: "application/json",
  95. url: url + "/api/device/listPage",
  96. success: function (data) {
  97. if (data.code == 0) {
  98. resolve({
  99. data:data.data.records,
  100. totals: data.data.total,
  101. });
  102. } else {
  103. reject(data);
  104. }
  105. },
  106. });
  107. });
  108. };
  109. window.changeDeviceStatus = function (item, paramCode, paramValue, success, fail) {//设置设备
  110. console.log(item);
  111. $(".waiting").addClass('showloading')
  112. let tmp = item.infoAttribute.hardware
  113. $.ajax({
  114. method: "GET",
  115. headers: {
  116. "Content-Type": "application/json",
  117. },
  118. dataType: "json",
  119. contentType: "application/json",
  120. url: url + `/api/device/control/${tmp.id}/${paramCode}/${paramValue}/03`,
  121. success: function (data) {
  122. console.log(data.msg)
  123. $(".waiting").removeClass('showloading')
  124. if (data.code === 0) {
  125. success && success()
  126. } else {
  127. fail && fail()
  128. }
  129. },error:function(){
  130. $(".waiting").removeClass('showloading')
  131. fail && fail()
  132. }
  133. });
  134. }
  135. window.loadTemperature = function (params={}) {
  136. let {id="temperature",val} = params
  137. //加载温度计
  138. var chartDom = document.getElementById(id);
  139. var myChart = echarts.init(chartDom);
  140. let option = {
  141. series: [
  142. {
  143. name: "Indicator",
  144. type: "gauge",
  145. data: [{
  146. value: val,
  147. name:'温度',
  148. itemStyle:{
  149. color: "#23EACF",
  150. fontSize:14
  151. },
  152. detail: {
  153. formatter: "{value}℃",
  154. color: "#23EACF",
  155. fontSize:24,
  156. offsetCenter: ['0%', '28%'],
  157. },
  158. title: {
  159. offsetCenter: ['0%', '80%'],
  160. color: "#fff",
  161. fontSize:20
  162. }
  163. }],
  164. radius: "100%",
  165. startAngle: 240,
  166. endAngle: -60,
  167. axisLine: {
  168. show: false
  169. },
  170. axisTick:{
  171. show: true,
  172. length:12,
  173. lineStyle:{
  174. color:'#339ED3'
  175. }
  176. },
  177. splitLine: {
  178. show: true,
  179. length:15,
  180. lineStyle:{
  181. color: "rgba(255, 255, 255, 1)",
  182. }
  183. },
  184. axisLabel: {
  185. color: "#23EACF"
  186. },
  187. pointer: {
  188. show: true,
  189. itemStyle:{
  190. color: "#23EACF"
  191. },
  192. width: 4.5,
  193. length: "46%"
  194. }
  195. },
  196. {
  197. name: "Indicator1",
  198. type: "gauge",
  199. data: [{
  200. value: val,
  201. detail:{
  202. show:false
  203. }
  204. }],
  205. radius: "50%",
  206. startAngle: 240,
  207. endAngle: -60,
  208. axisLine: {
  209. show: true,
  210. lineStyle:{
  211. width:5
  212. }
  213. },
  214. progress: {
  215. show: true,
  216. width:5,
  217. itemStyle:{
  218. color: "#23EACF"
  219. }
  220. },
  221. axisTick:{
  222. show: false,
  223. },
  224. splitLine: {
  225. show: false,
  226. },
  227. axisLabel: {
  228. show: false,
  229. },
  230. pointer: {
  231. show: false,
  232. }
  233. }
  234. ]
  235. }
  236. option && myChart.setOption(option, true);
  237. }
  238. window.loadAirConditioner = function (params={}) {
  239. let {id="air-conditioner",
  240. val='unset',
  241. type='unset',
  242. ifOn='unset',
  243. windSpeed='unset',
  244. fanPos='unset',
  245. name='unset',
  246. fanState='unset'} = params
  247. //开关
  248. if (ifOn!='unset') {
  249. if (ifOn) {
  250. $('.ac-body').show()
  251. $('.ac-switch').hide()
  252. }else{
  253. $('.ac-body').hide()
  254. $('.ac-switch').show()
  255. }
  256. }
  257. //名字
  258. if (name!='unset') {
  259. $('.ac-title').text(name)
  260. }
  261. //风向
  262. if (fanPos!='unset') {
  263. $('#fxDom').text('风向' + fanPos)
  264. }
  265. //风速
  266. if (windSpeed!='unset') {
  267. $('#fsDom').text(windSpeed)
  268. $(`.ac-left li[data-name='${windSpeed}']`).addClass("active").siblings().removeClass("active");
  269. }
  270. //模式
  271. if (type!='unset') {
  272. $(`#airmode span[data-name='${type}']`).addClass("activeTxt").siblings().removeClass("activeTxt");
  273. }
  274. if (val=='unset') {
  275. return
  276. }
  277. //加载温度计
  278. var chartDom = document.getElementById(id);
  279. var myChart = echarts.init(chartDom);
  280. let option = {
  281. series: [
  282. {
  283. name: "Indicator",
  284. type: "gauge",
  285. data: [{
  286. value: val,
  287. name:type,
  288. itemStyle:{
  289. color: "#23EACF",
  290. fontSize:14
  291. },
  292. detail: {
  293. offsetCenter: ['0%', '0'],
  294. formatter: "{value}℃",
  295. color: "#fff",
  296. fontSize:22
  297. },
  298. title: {
  299. offsetCenter: ['0%', '26%'],
  300. color: "#fff",
  301. fontSize:16
  302. }
  303. }],
  304. radius: "100%",
  305. startAngle: 220,
  306. endAngle: -40,
  307. progress: {
  308. show: true,
  309. roundCap:true,
  310. itemStyle:{
  311. color: "#23EACF"
  312. }
  313. },
  314. axisLine: {
  315. show: true,
  316. roundCap:true,
  317. lineStyle:{
  318. color: [[1, '#ffffff']]
  319. }
  320. },
  321. axisTick:{
  322. show: false
  323. },
  324. splitLine: {
  325. show: false
  326. },
  327. axisLabel: {
  328. show: false,
  329. },
  330. pointer: {
  331. show: false,
  332. }
  333. }
  334. ]
  335. }
  336. option && myChart.setOption(option, true);
  337. }
  338. window.loadMonitor = function (params={}) {
  339. let {id,url} = params
  340. console.log(id,url);
  341. var video = document.getElementById(id);
  342. if(!params.url){
  343. video.src = ''; video.pause();
  344. return;
  345. }
  346. if (Hls.isSupported()) {
  347. var hls = new Hls();
  348. hls.loadSource(url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8');
  349. hls.attachMedia(video);
  350. hls.on(Hls.Events.MEDIA_ATTACHED, function () {
  351. video.play();
  352. });
  353. }
  354. // hls.js is not supported on platforms that do not have Media Source Extensions (MSE) enabled.
  355. // 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.
  356. // This is using the built-in support of the plain video element, without using hls.js.
  357. else if (video.canPlayType('application/vnd.apple.mpegurl')) {
  358. video.src = url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8';
  359. video.addEventListener('canplay', function () {
  360. video.play();
  361. });
  362. }
  363. }
  364. window.loadCalendar = function(params = {}){
  365. let { data,cellCb=()=>{},yearSelect=()=>{},monthCb=()=>{} } = params
  366. //日历方法
  367. let ret = $("#calendar").calendar({
  368. data: data, //记录数据
  369. work: [],//上班时间
  370. mode: "month",
  371. shwoLunar:false,
  372. width: 400,
  373. cellClick: function (data) {
  374. let item = data[0]
  375. cellCb(item)
  376. },
  377. yearSelect: function (yearText) {
  378. yearSelect(yearText)
  379. },
  380. monthClick: function (e, nextMonth, opts, me) {
  381. monthCb(nextMonth)
  382. }
  383. });
  384. return ret
  385. }
  386. window.loadHistoryList = function (params={}) {
  387. let {data=[],clickItem=()=>{}} = params
  388. if (!data||data.length<=0) {
  389. return $('.histcon').hide()
  390. }else{
  391. $('.histcon').show()
  392. }
  393. let html = ''
  394. for (let i = 0; i < data.length; i++) {
  395. const element = data[i];
  396. html += `<li data-val=${i}>${element.startTime.split(" ")[1]} ~ ${element.endTime.split(" ")[1]}</li>`
  397. }
  398. $('#hislist').html(html)
  399. $('#hislist').off('click','li').on('click','li',function(e){
  400. let i = $(e.target).data('val')
  401. $(e.target).addClass('active').siblings().removeClass('active')
  402. clickItem(data[i])
  403. })
  404. }
  405. /* let ret = window.loadCalendar({
  406. data:[{
  407. 'startDate': "2021-05-18",//有监控的日期
  408. id:'传对应的id'
  409. }],
  410. //点击日期时间
  411. cellCb: (item)=> {
  412. console.log(item);
  413. console.log(ret.options.currentDate);
  414. },
  415. yearSelect: (yearText)=> {
  416. console.log(yearText);
  417. },
  418. monthCb: (nextMonth)=> {
  419. console.log(nextMonth);
  420. }
  421. }) */
  422. /* window.loadHistoryList({
  423. data:[{
  424. startTime:'2021-05-13 11:00:08',
  425. endTime:'2021-05-13 11:00:08'
  426. },{
  427. startTime:'2021-05-13 11:00:0811',
  428. endTime:'2021-05-13 11:00:08'
  429. },{
  430. startTime:'2021-05-13 11:00:082',
  431. endTime:'2021-05-13 11:00:082'
  432. }],
  433. //点击时间
  434. clickItem:(data)=>{
  435. console.log(data);
  436. }
  437. })
  438. */
  439. /*loadMonitor({
  440. id:"monitor",
  441. url:'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8'
  442. })
  443. loadAirConditioner({
  444. id:"air-conditioner",
  445. val:50,
  446. type:'冷风'
  447. }) */
  448. // loadAirConditioner({
  449. // name:'二楼-大会议室-04-空调',
  450. // val:50,
  451. // id:"air-conditioner",
  452. // type:'冷风',
  453. // ifOn:true,//开关机
  454. // windSpeed : "低风",//风速
  455. // fanPos : "上",//摆叶位置
  456. // fanState: true//摆叶状态
  457. // })
  458. });