Widget.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. import BaseWidget = require('core/BaseWidget.class');
  2. declare var echarts;
  3. /**
  4. * 报警信息
  5. */
  6. class Warning extends BaseWidget {
  7. baseClass: string = "widget-Warning";
  8. chart: any;
  9. toast: any;
  10. popupDiv: any;
  11. /**
  12. * 启动模块
  13. */
  14. startup() {
  15. var htmlString = _.template(this.template.split("$$")[0])({title:this.config.title});
  16. this.setHtml(htmlString);
  17. this.toast = this.AppX.runtimeConfig.toast;
  18. this.ready()
  19. this.initEvent()
  20. this.initBottonPopup()
  21. this.loadChart()
  22. this.loadWarringPopup()
  23. this.loadMoreInfoEvent()
  24. }
  25. /**
  26. * 初始化事件
  27. */
  28. initEvent(){
  29. }
  30. loadChart() {
  31. (this.chart = echarts
  32. .init(document.getElementById('widget-Warning-chart')))
  33. .setOption({
  34. title: {
  35. id: 'warring', text: '报警总数', subtext: '0', left: 'center', top:'center', itemGap: 30,
  36. textStyle: { color: '#29b0e7', fontSize: 38, fontWeight: '', },
  37. subtextStyle: { color: '#eee', fontWeight: 'bold', fontFamily: 'Courier New', fontSize: 83, },
  38. },
  39. color: ['#ffe363', '#1ee2f4', '#507dff', '#c548f9'],
  40. tooltip: { trigger: 'item', formatter: "{b} <br/>共 {c} " + "条" + "<br/>占比 {d}%", padding: 10, textStyle: { fontSize: 28} },
  41. legend: { id: 'warring', orient: 'vertical', padding: 10, itemGap: 20, itemWidth: 50 ,itemHeight: 28, right: 10, bottom: 50, textStyle: { color: '#fff', fontSize: 24 }, data: [] },
  42. series: [
  43. {
  44. id: 'warring', name: '报警', type: 'pie', radius: ['55%', '85%'], center: ['50%', '50%'],
  45. itemStyle: { shadowColor: '#1ee2f4', shadowBlur: 20 }, cursor: 'default',
  46. label: { show: false }, data: []
  47. }
  48. ]
  49. })
  50. var loading = document.getElementById('Warning-chart-loading')
  51. var url = this.config.requestURL.warringChartURL
  52. var timerForLoadWarring = () => {
  53. loading.style.display = ''
  54. $.ajax({ //结果
  55. url: this.AppX.appConfig.apiRoot + url[1], type: url[0],
  56. success: (res) => {
  57. if(res.code == 1) {
  58. var sum = 0, legend = []
  59. var data = res.result.map( e => {
  60. sum += e.sum, legend.push(e.warnType || '-')
  61. return {
  62. name: e.warnType || '-',
  63. value: e.sum
  64. }
  65. })
  66. this.chart.setOption({
  67. title: { id: 'warring', subtext: sum },
  68. legend: { id: 'warring', data: legend },
  69. series: [{ id: 'warring', data: data}]
  70. })
  71. } else {
  72. this.toast.Show('获取报警数据失败:' + res.message)
  73. console.error(res)
  74. }
  75. setTimeout(timerForLoadWarring, this.AppX.appConfig.timeOut.warring)
  76. loading.style.display = 'none'
  77. },
  78. error: (e) => console.error(e)
  79. })
  80. }
  81. timerForLoadWarring()
  82. }
  83. loadWarringPopup() {
  84. (AppX.runtimeConfig.popup || { Close: () => {} }).Close()
  85. var url = this.config.requestURL.warringPopupURL
  86. $.ajax({ //结果
  87. url: this.AppX.appConfig.apiRoot + url[1], type: url[0],
  88. success: (res) => {
  89. if(res.code == 1) {
  90. if((res = res.result).length == 0) return
  91. var popup = AppX.runtimeConfig.popup
  92. popup.setSize(800, 400)
  93. popup
  94. .ShowMessage("报警提示", _.template(this.template.split("$$")[1])({ infos: res })).submitObj
  95. .off("click")
  96. .on("click", (e) => {//弹出更多信息框
  97. AppX.runtimeConfig.popup.Close();
  98. // clearInterval(this.voiceTime)
  99. // this.openPopup()
  100. })
  101. } else {
  102. this.toast.Show('获取报警失败:' + res.message)
  103. console.error(res)
  104. }
  105. },
  106. error: (e) => console.error(e)
  107. })
  108. }
  109. loadMoreInfoEvent() {
  110. var moreBotton = document.getElementById('moreWarrInfo')
  111. var url = this.config.requestURL.warringTypeURL
  112. var warringTypeList = []
  113. var warringStateList = this.config.warringStates
  114. // 请求报警type
  115. $.ajax({ //结果
  116. url: this.AppX.appConfig.apiRoot + url[1], type: url[0],
  117. success: (res) => res.code == 1 ? warringTypeList = res.result : (this.toast.Show('获取地图报警类型失败:' + res.message), console.error(res)),
  118. error: (e) => console.error(e)
  119. })
  120. moreBotton.onclick = () => {
  121. AppX.runtimeConfig.datapopup.setSize(3000, 1300);
  122. var Obj = AppX.runtimeConfig.datapopup.Show("报警信息", this.template.split("$$")[2]);
  123. var typeSelect = document.getElementById('widget-Warning-more-warringType') as HTMLSelectElement
  124. typeSelect.innerHTML = warringTypeList.map(e => '<option value="' + (e || '') + '">' + (e || '-') + '</option>').join('')
  125. var statesSelect = document.getElementById('widget-Warning-more-warringStates') as HTMLSelectElement
  126. statesSelect.innerHTML =
  127. '<option value="0">全部</option>' +
  128. warringStateList.map(e => '<option value="' + e.value + '">' + e.name + '</option>').join('')
  129. var date1 = $(document.getElementById('widget-Warning-more-dateTimeChoose1'))
  130. var date2 = $(document.getElementById('widget-Warning-more-dateTimeChoose2'))
  131. date1.datetimepicker({ language: 'zh-CN', format: 'yyyy-mm-dd hh:ii:ss' })
  132. date2.datetimepicker({ language: 'zh-CN', format: 'yyyy-mm-dd hh:ii:ss' })
  133. var queryOptions = [typeSelect.value, statesSelect.value, (date1[0] as HTMLInputElement).value, (date2[0] as HTMLInputElement).value]
  134. var url = this.config.requestURL.warringHistoryURL
  135. var loading = document.getElementById('Warning-table-loading')
  136. var tableDiv = document.getElementById('widget-Warning-more-table')
  137. var tableBody = tableDiv.querySelector('tbody.infowarn_body')
  138. var queryBotton = document.getElementById('widget-Warning-more-query');
  139. (queryBotton.onclick = this.popupDiv['TF_BottonPopup'].trueCallBack = () => {
  140. $(tableDiv).dataTable().fnDestroy()
  141. tableBody.innerHTML = ''
  142. loading.style.display = ''
  143. queryOptions = [typeSelect.value, statesSelect.value, (date1[0] as HTMLInputElement).value, (date2[0] as HTMLInputElement).value]
  144. var state = queryOptions[1]
  145. // 请求报警历史
  146. $.ajax({ //结果
  147. url: this.AppX.appConfig.apiRoot + url[1] + [
  148. '?type=' + (queryOptions[0] || ''),
  149. 'start=' + (queryOptions[2] || ''),
  150. 'end=' + (queryOptions[3] || '')
  151. ].join('&') + { 0: '', 1: '&isconfirm=0', 2: '&isclear=0'}[state] + '&size=300&current=1',
  152. type: url[0],
  153. success: (res) => {
  154. if (res.code == 1) {
  155. res = res.result.records
  156. var htmlStr = ''
  157. for(var i=0,ii=res.length;i<ii;i++){
  158. var dr = res[i]
  159. htmlStr +=
  160. '<tr>' +
  161. '<td>' + dr.rowId + '</td>' +
  162. '<td>' + (dr.warnType || '-') + '</td>' +
  163. '<td>' + 1 + '</td>' +
  164. '<td>' + (dr.address || '-') + '</td>' +
  165. '<td>' + dr.scadaTime + '</td>' +
  166. '<td>' + dr.notes + '</td>' +
  167. '<td>' + (dr.isconfirm == 0 ?
  168. '<div data="' + dr.id + '" class="trquren">确认</div>' :
  169. '<div>-</div>') +
  170. '</td>' +
  171. '</tr>'
  172. }
  173. tableBody.innerHTML = htmlStr
  174. $(tableDiv).dataTable({
  175. language: {
  176. "lengthMenu": "每页 _MENU_ 条",
  177. "zeroRecords": "未查询到任何记录",
  178. "info": "共 _TOTAL_ 条记录,当前 _START_ - _END_ ",
  179. "infoEmpty": "没有符合条件的记录",
  180. "infoFiltered": "(从总共 _MAX_ 条数据中找到)",
  181. "paginate": {
  182. "first": "首页",
  183. "last": "尾页",
  184. "next": "下页",
  185. "previous": "上页"
  186. },
  187. "search": "搜索: ",
  188. },
  189. pagingType: "simple_numbers",
  190. scrollY: "1000",
  191. pageLength: 50,
  192. bLengthChange: false,
  193. scrollCollapse: false,
  194. scrollX: true,
  195. searching: false,
  196. ordering: true,
  197. autoWidth: false,
  198. dom: '<t><lfip>',
  199. drawCallback: () => {
  200. var trueBottom = $(tableBody).find('tr td:nth-last-child(1) div.trquren')
  201. for(var i=0,ii=trueBottom.length;i<ii;i++) {
  202. trueBottom[i].onclick = function(e) { this.shotDownWarring(e) }.bind(this)
  203. }
  204. }
  205. //aoColumnDefs:[
  206. // {"sClass":"col_class","aTargets":[0]},{"sClass":"cos_class","aTargets":[1]}],
  207. // createdRow: function ( row, data, index ) {
  208. // if ( index %2 == 0 ) {
  209. // $('td', row).css("background","#c43ff6");
  210. // }
  211. // },
  212. } )
  213. } else {
  214. this.toast.Show('获取报警历史失败:' + res.message)
  215. console.error(res)
  216. }
  217. loading.style.display = 'none'
  218. },
  219. error: (e) => console.error(e)
  220. })
  221. })()
  222. }
  223. }
  224. shotDownWarring(e: Event) {
  225. var div = e.currentTarget as HTMLElement
  226. var id = div.getAttribute('data')
  227. var BottonPopup = this.popupDiv['TF_BottonPopup']
  228. BottonPopup.init(div, id, e)
  229. }
  230. initBottonPopup() {
  231. var popupDiv = this.popupDiv = document.createElement('div')
  232. popupDiv.classList.value = 'botton-popup'
  233. popupDiv.innerHTML =
  234. '<div>' +
  235. '<span style="font-size: 20px;" class="glyphicon glyphicon-question-sign" aria-hidden="true"></span>' +
  236. '<span style="color: #fff; margin-left: 10px; vertical-align: top;">是否关闭报警?</span>' +
  237. '</div>' +
  238. '<div style="margin-top:5px">' +
  239. '<span>部门</span>' +
  240. '<select class="input-sm form-control warnstatus minwidth tf-select" style="height:100%">' +
  241. '</select>' +
  242. '</div>' +
  243. '<div style="margin-top:5px">' +
  244. '<span>人员</span>' +
  245. '<select class="input-sm form-control warnstatus minwidth tf-select" style="height:100%">' +
  246. '</select>' +
  247. '</div>' +
  248. '<div style="margin-top:5px">' +
  249. '<button class="btn btn-default tf-botton" style="float:right;">确定</button>' +
  250. '<div style="clear:both;"></div>' +
  251. '</div>';
  252. (popupDiv.children[3].children[0] as HTMLElement).onclick = () => {
  253. var id = that.id
  254. if(id == 'undefined') return
  255. $.ajax({ //结果
  256. url: this.AppX.appConfig.apiRoot + '/gis/bigScreen/handleWarnHistroy?code=0&wanrIds=' + id + '&id=' + perBotton.value, type: 'GET',
  257. success: (res) => {
  258. AppX.runtimeConfig.toast.Show(res.code == 1 ? '确认成功!' : (console.error(res), '确认失败!' + res.message));
  259. that.trueCallBack()
  260. },
  261. error: (e) => console.error(e)
  262. })
  263. }
  264. var style = popupDiv.style
  265. var timeDip = undefined
  266. var that = popupDiv['TF_BottonPopup'] = {
  267. id: undefined,
  268. clickCallBack: undefined,
  269. trueCallBack: () => {},
  270. init: function (div, id, e) {
  271. if(that.id == id) return
  272. if(that.id) {
  273. that.id = undefined
  274. if(timeDip) clearTimeout(timeDip)
  275. style.display = ''
  276. style.transform = ''
  277. style.opacity = ''
  278. document.removeEventListener('click', that.clickCallBack)
  279. that.init(div, id, e)
  280. return
  281. }
  282. that.id = id
  283. div.appendChild(popupDiv)
  284. if(timeDip) clearTimeout(timeDip)
  285. style.display = 'block'
  286. window.requestAnimationFrame(_ => {
  287. style.transform = 'rotateX(0deg)'
  288. style.opacity = '1'
  289. })
  290. var clickFun = that.clickCallBack = (evt) => {
  291. for(var i=0,il=evt.path,ii=il.length;i<ii;i++) {
  292. var di = il[i]
  293. if(di == popupDiv || di == div) return evt.stopPropagation()
  294. }
  295. that.id = undefined
  296. style.opacity = ''
  297. style.transform = ''
  298. if(timeDip) clearTimeout(timeDip)
  299. timeDip = setTimeout(_ => style.display = '', 316)
  300. document.removeEventListener('click', clickFun)
  301. that.clickCallBack = undefined
  302. evt.stopPropagation()
  303. }
  304. document.addEventListener('click', clickFun)
  305. e.stopPropagation()
  306. },
  307. }
  308. var depBotton = popupDiv.children[1].children[1] as HTMLInputElement
  309. var perBotton = popupDiv.children[2].children[1] as HTMLInputElement
  310. $.ajax({ //结果
  311. url: this.AppX.appConfig.apiRoot + '/gis/bigScreen/deptAll', type: 'GET',
  312. success: (res) => {
  313. if(res.code == 1) {
  314. depBotton.innerHTML = res.result.result
  315. .filter(e => e.statusName == '启用')
  316. .map(e => '<option value="' + e.id + '">' + e.name + '</option>')
  317. .join('')
  318. depBotton.value = depBotton.children[0].getAttribute('value')
  319. depBotton.oninput(undefined)
  320. } else console.error(res)
  321. },
  322. error: (e) => console.error(e)
  323. })
  324. depBotton.oninput = () => {
  325. $.ajax({ //结果
  326. url: this.AppX.appConfig.apiRoot + '/gis/bigScreen/getUserByDepts?depts=' + depBotton.value, type: 'GET',
  327. success: (res) => {
  328. if(res.code == 1) {
  329. perBotton.innerHTML = res.result.result[0].users
  330. .map(e => '<option value="' + e.id + '">' + e.realName + '</option>')
  331. .join('')
  332. } else console.error(res)
  333. },
  334. error: (e) => console.error(e)
  335. })
  336. perBotton.innerHTML = ''
  337. }
  338. }
  339. /**
  340. * 销毁对象
  341. */
  342. destroy() {
  343. this.afterDestroy();
  344. }
  345. }
  346. export = Warning;