showHardware.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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: "devTypeName",
  23. text: "硬件类型",
  24. },
  25. {
  26. key: "name",
  27. text: "设备名称",
  28. },
  29. {
  30. key: "status",
  31. text: "设备状态",
  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].examine(player)//.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": userId
  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(!params.url){
  342. video.src = ''; video.pause();
  343. return;
  344. }
  345. if (Hls.isSupported()) {
  346. var hls = new Hls();
  347. hls.loadSource(url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8');
  348. hls.attachMedia(video);
  349. hls.on(Hls.Events.MEDIA_ATTACHED, function () {
  350. video.play();
  351. });
  352. }
  353. // hls.js is not supported on platforms that do not have Media Source Extensions (MSE) enabled.
  354. // 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.
  355. // This is using the built-in support of the plain video element, without using hls.js.
  356. else if (video.canPlayType('application/vnd.apple.mpegurl')) {
  357. video.src = url||'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8';
  358. video.addEventListener('canplay', function () {
  359. video.play();
  360. });
  361. }
  362. }
  363. window.loadCalendar = function(params = {}){
  364. let { data,cellCb=()=>{},yearSelect=()=>{},monthCb=()=>{} } = params
  365. //日历方法
  366. let ret = $("#calendar").calendar({
  367. data: data, //记录数据
  368. work: [],//上班时间
  369. mode: "month",
  370. shwoLunar:false,
  371. width: 400,
  372. cellClick: function (data) {
  373. let item = data[0]
  374. cellCb(item)
  375. },
  376. yearSelect: function (yearText) {
  377. yearSelect(yearText)
  378. },
  379. monthClick: function (e, nextMonth, opts, me) {
  380. monthCb(nextMonth)
  381. }
  382. });
  383. return ret
  384. }
  385. window.loadHistoryList = function (params={}) {
  386. let {data=[],clickItem=()=>{}} = params
  387. if (!data||data.length<=0) {
  388. return $('.histcon').hide()
  389. }else{
  390. $('.histcon').show()
  391. }
  392. let html = ''
  393. for (let i = 0; i < data.length; i++) {
  394. const element = data[i];
  395. html += `<li data-val=${i}>${element.startTime.split(" ")[1]} ~ ${element.endTime.split(" ")[1]}</li>`
  396. }
  397. $('#hislist').html(html)
  398. $('#hislist').off('click','li').on('click','li',function(e){
  399. let i = $(e.target).data('val')
  400. $(e.target).addClass('active').siblings().removeClass('active')
  401. clickItem(data[i])
  402. })
  403. }
  404. /* let ret = window.loadCalendar({
  405. data:[{
  406. 'startDate': "2021-05-18",//有监控的日期
  407. id:'传对应的id'
  408. }],
  409. //点击日期时间
  410. cellCb: (item)=> {
  411. console.log(item);
  412. console.log(ret.options.currentDate);
  413. },
  414. yearSelect: (yearText)=> {
  415. console.log(yearText);
  416. },
  417. monthCb: (nextMonth)=> {
  418. console.log(nextMonth);
  419. }
  420. }) */
  421. /* window.loadHistoryList({
  422. data:[{
  423. startTime:'2021-05-13 11:00:08',
  424. endTime:'2021-05-13 11:00:08'
  425. },{
  426. startTime:'2021-05-13 11:00:0811',
  427. endTime:'2021-05-13 11:00:08'
  428. },{
  429. startTime:'2021-05-13 11:00:082',
  430. endTime:'2021-05-13 11:00:082'
  431. }],
  432. //点击时间
  433. clickItem:(data)=>{
  434. console.log(data);
  435. }
  436. })
  437. */
  438. /*loadMonitor({
  439. id:"monitor",
  440. url:'http://14.215.216.123:18080/rtp/00A153DF/hls.m3u8'
  441. })
  442. loadAirConditioner({
  443. id:"air-conditioner",
  444. val:50,
  445. type:'冷风'
  446. }) */
  447. // loadAirConditioner({
  448. // name:'二楼-大会议室-04-空调',
  449. // val:50,
  450. // id:"air-conditioner",
  451. // type:'冷风',
  452. // ifOn:true,//开关机
  453. // windSpeed : "低风",//风速
  454. // fanPos : "上",//摆叶位置
  455. // fanState: true//摆叶状态
  456. // })
  457. });