index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <div class="rooms" v-if="show">
  3. <div class="eq-top">
  4. <img src="/static/img/backIcon.jpg" alt="" @click="back">
  5. <span>空间详情 / </span>
  6. <strong>{{RoomName}}-{{objectId}}报警详情</strong>
  7. </div>
  8. <div class="eq-head" v-if="false">
  9. <div class="f-left"></div>
  10. <div class="f-right">
  11. <p class="f-salarm">近期多次出现以下报警:“电流谐波畸变率过高”、“室温温度传感器出错”、“电压过压”。可能存在设备或零件老化,请多加关注!</p>
  12. <Icon type="md-close" class="close-btn" @click="closeBox"/>
  13. </div>
  14. </div>
  15. <div class="eq-bottom">
  16. <div class="alarm-top">
  17. <span @click="onClickTab(0)" :class="{active: activeIndex== 0}">当前未恢复</span>
  18. <span @click="onClickTab(1)" :class="{active: activeIndex== 1}">近期报警记录</span>
  19. <span @click="onClickTab(2)" :class="{active: activeIndex== 2}">手动处理备注</span>
  20. <span @click="onClickTab(3)" :class="{active: activeIndex== 3}">空间内报警的设备</span>
  21. </div>
  22. <div v-if="activeIndex==0">
  23. <table-alarm :tableData="tableData" @setSort='setSort'></table-alarm>
  24. </div>
  25. <div v-if="activeIndex==1">
  26. <div class="my-select-type">
  27. <my-select :dateLimitDays='dateLimitDays' @setSelectParams="setSelectParams" @setChangeAlarm='setChangeAlarm' :datePickerKey='datePickerKey' :changeAlarm='changeAlarm' :alarmNameList='alarmNameList'></my-select>
  28. </div>
  29. <history-table :historyTableData='historyTableData' :total='total' :Current='pageCurrent'
  30. :pageSize='pageSize' @changeCurrentPage='changeCurrentPage' @setSort='setSort'></history-table>
  31. </div>
  32. <div v-if="activeIndex==2 && show">
  33. <my-handle :objectId='objectId'></my-handle>
  34. </div>
  35. <div v-if="activeIndex==3 && show">
  36. <room-eq></room-eq>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import tableAlarm from '../main/TableAlarm.vue'
  43. import mySelect from '../equipment/EqSelect.vue'
  44. import myHandle from '../equipment/Handle.vue'
  45. import historyTable from '../main/HistoryTable'
  46. import roomEq from './RoomEq.vue'
  47. import {formatTime, secondsToDay} from '../../tools/formatTime.js'
  48. import dataPickerConfig from '../../tools/dataPickerConfig.js'
  49. // import {mapActions, mapMutations, mapGetters, mapState} from 'vuex'
  50. import axios from 'axios'
  51. export default {
  52. components: {
  53. tableAlarm,
  54. mySelect,
  55. myHandle,
  56. roomEq,
  57. historyTable
  58. },
  59. mixins: [],
  60. props: {
  61. },
  62. data () {
  63. return {
  64. show: false,
  65. datePickerKey: 'oneMonth',
  66. dateLimitDays: Number.MAX_SAFE_INTEGER,
  67. activeIndex: 0,
  68. pageSize: 15,
  69. historyTableData: [],
  70. tableData: [],
  71. total: null,
  72. pageCurrent: 1,
  73. status: 'alarm', // 区分3个tab的状态
  74. autoHandle: null, // 区分3个tab的手动自动
  75. order: { // 选填,没有order字段时按照默认顺序排序
  76. column: '', // 要排序的列名,只支持level,duration,ctime
  77. asc: true // true升序,false降序
  78. },
  79. selectParams: { // 所有下拉框的默认值
  80. selectedLevel: [], // 级别
  81. selectedType: [], // 类型
  82. selectedCode: [],
  83. selectedPosition: {
  84. buildingId: [],
  85. floorId: [],
  86. spaceId: []
  87. }, // 位置
  88. selectedDurationTime: '', // 持续时间
  89. selectedStartTime: { // 开始时间
  90. dStart: '',
  91. dEnd: ''
  92. },
  93. alarmName: []
  94. },
  95. alarmNameList: [],
  96. objectId: 'Sp1101080002001000007',
  97. RoomName: "",
  98. changeAlarm: 0
  99. }
  100. },
  101. computed: {
  102. },
  103. mounted () {
  104. // this.getDataList()
  105. // this.saveAlarmName()
  106. this.getEqNameAndId()
  107. },
  108. methods: {
  109. getEqNameAndId () {
  110. let hostUrl = location.search
  111. let pid = hostUrl.split('&')[0].toString().split('=')[1]
  112. this.$store.commit('setProId', pid)
  113. this.$store.commit(`setSecret`, '')
  114. this.RoomName = decodeURI(hostUrl.split('&')[2])
  115. this.objectId = hostUrl.split('&')[1]
  116. console.log(pid, this.RoomName, this.objectId)
  117. this.getDataList(this.objectId)
  118. this.saveAlarmName(this.objectId)
  119. this.show = true
  120. },
  121. // 监控到如果时间改变,重新触发请求报警条目的函数
  122. setChangeAlarm () {
  123. this.saveAlarmName(this.objectId)
  124. },
  125. // 存储条目数
  126. saveAlarmName (objectId) {
  127. let ctime = {}
  128. if (Object.values(this.selectParams.selectedStartTime).some(i => i.length)) {
  129. ctime = {
  130. $gte: this.selectParams.selectedStartTime.dStart,
  131. $lte: this.selectParams.selectedStartTime.dEnd
  132. }
  133. } else {
  134. ctime = null
  135. }
  136. let params = {
  137. objectId: objectId,
  138. ctime: ctime
  139. }
  140. axios.post(`/alarm-system/alarm-system/alarm/alarmName/list?projectId=${this.$store.state.projId}&secret=${this.$store.state.secret}`, params).then(res => {
  141. let data = res.data
  142. if (data.Result == 'success') {
  143. this.alarmNameList = data.Content
  144. this.alarmNameList = this.alarmNameList.map(el => {
  145. return {value: el, text: el}
  146. })
  147. }
  148. })
  149. },
  150. back () {
  151. history.go(-1)
  152. },
  153. closeBox () {
  154. document.querySelector('.eq-head').style.display = 'none'
  155. },
  156. // 触发排序函数
  157. setSort (col) {
  158. this.order.column = col.key
  159. this.order.asc = col.order == 'asc'
  160. this.getDataList(this.objectId)
  161. },
  162. // 每个下拉框值变化触发表格数据的返回值
  163. setSelectParams (obj) {
  164. this.selectParams = obj
  165. if (this.change == 1) {
  166. this.saveAlarmName(this.objectId)
  167. }
  168. if (this.activeIndex == 0) {
  169. this.status = 'alarm'
  170. this.autoHandle = null
  171. } else if (this.activeIndex == 2) {
  172. this.status = 'alarm'
  173. this.autoHandle = false
  174. } else {
  175. this.status = null
  176. this.autoHandle = null
  177. }
  178. this.getDataList(this.objectId)
  179. },
  180. // 3个按钮的点击传参数
  181. onClickTab (status) {
  182. this.activeIndex = status
  183. if (status == 0) {
  184. this.status = 'alarm'
  185. this.autoHandle = null
  186. this.dateLimitDays = Number.MAX_SAFE_INTEGER
  187. this.getDataList(this.objectId)
  188. } else if (status == 2) {
  189. this.status = 'alarm'
  190. this.autoHandle = false
  191. this.dateLimitDays = Number.MAX_SAFE_INTEGER
  192. } else if (status == 1) {
  193. this.status = null
  194. this.autoHandle = null
  195. this.dateLimitDays = 30
  196. this.selectParams.selectedStartTime.dStart = dataPickerConfig[this.datePickerKey].dStart // 20181215000000
  197. this.selectParams.selectedStartTime.dEnd = dataPickerConfig[this.datePickerKey].dEnd
  198. this.getDataList(this.objectId)
  199. this.saveAlarmName(this.objectId)
  200. }
  201. },
  202. // 默认未恢复的请求函数
  203. getDataList (objectId) {
  204. // 得到项目id和secret
  205. let params
  206. // 持续时间的转换
  207. let duration = {}
  208. if (Object.values(this.selectParams.selectedDurationTime).some(i => i.length)) {
  209. if (this.selectParams.selectedDurationTime == '5m') {
  210. duration.$lt = 5 * 60
  211. } else if (this.selectParams.selectedDurationTime == '2h') {
  212. duration.$gte = 300
  213. duration.$lte = 2 * 60 * 60
  214. } else if (this.selectParams.selectedDurationTime == '24h') {
  215. duration.$gte = 2 * 60 * 60
  216. duration.$lte = 24 * 60 * 60
  217. } else if (this.selectParams.selectedDurationTime == '1d') {
  218. duration.$gt = 24 * 60 * 60
  219. }
  220. } else {
  221. duration = null
  222. }
  223. // 开始时间的转换
  224. let ctime = {}
  225. if (Object.values(this.selectParams.selectedStartTime).some(i => i.length)) {
  226. ctime = {
  227. $gte: this.selectParams.selectedStartTime.dStart,
  228. $lte: this.selectParams.selectedStartTime.dEnd
  229. }
  230. } else {
  231. ctime = null
  232. }
  233. let order = null
  234. if (Object.values(this.order).some(i => i.length)) {
  235. order = this.order
  236. }
  237. // 参数的添加
  238. if (this.activeIndex == 0) {
  239. params = {
  240. criteria: {
  241. objectId: objectId,
  242. status: this.status
  243. },
  244. order: order
  245. }
  246. } if (this.activeIndex == 1) {
  247. params = {
  248. criteria: {
  249. levels: this.selectParams.selectedLevel.length > 0 ? this.selectParams.selectedLevel : null, // 选填,报警等级
  250. objectId: objectId,
  251. ctime: ctime,
  252. duration: duration,
  253. alarmName: this.selectParams.alarmName.length > 0 ? this.selectParams.alarmName : null, // 报警条目
  254. status: this.status,
  255. autoHandle: this.autoHandle
  256. },
  257. order: order
  258. }
  259. }
  260. // 请求表格数据
  261. axios.post(`/alarm-system/alarm-system/alarm/list?projectId=${this.$store.state.projId}&secret=${this.$store.state.secret}`, params)
  262. .then(res => {
  263. let data = res.data
  264. if (data.Result == 'success') {
  265. this.tableData = data.Content
  266. this.total = data.Count
  267. this.tableData.forEach(el => {
  268. el.cTime = formatTime(el.ctime)
  269. el.durationT = secondsToDay(el.duration)
  270. el.alarmName = el.alarmName ? el.alarmName : ''
  271. el.location = el.source ? el.source : ''
  272. el.content = el.alarmName + '/' + el.location
  273. if (!el.autoHandle) {
  274. el.deal = 0
  275. } else {
  276. if (el.event.type == 1) {
  277. el.deal = 1
  278. } else if (el.event.type == 2) {
  279. el.deal = 2
  280. } else {
  281. el.deal = 3
  282. }
  283. }
  284. })
  285. // 自己分页
  286. if (this.activeIndex == 1) {
  287. this.changeCurrentPage(this.pageCurrent)
  288. }
  289. }
  290. })
  291. },
  292. // 分页 点击的是哪页
  293. changeCurrentPage (index) {
  294. this.historyTableData = []
  295. // 需要显示开始数据的index,(因为数据是从0开始的,页码是从1开始的,需要-1)
  296. let _start = (index - 1) * this.pageSize
  297. // 需要显示结束数据的index
  298. let _end = index * this.pageSize
  299. // 截取需要显示的数据
  300. this.historyTableData = this.tableData.slice(_start, _end)
  301. this.pageCurrent = index
  302. }
  303. }
  304. }
  305. </script>
  306. <style scoped lang="less" >
  307. .rooms {
  308. .eq-top {
  309. margin-bottom: 20px;
  310. >img {
  311. vertical-align: middle;
  312. cursor: pointer;
  313. border: 1px solid #CACACA;
  314. border-radius: 2px;
  315. }
  316. >span {
  317. font-size: 16px;
  318. color: #728DEE;
  319. }
  320. }
  321. .eq-head {
  322. width: 100%;
  323. background: #FFF6F5;
  324. border-radius: 2px;
  325. font-size: 14px;
  326. display: flex;
  327. margin:10px 0 20px 0;
  328. //height: 60px;
  329. position: relative;
  330. .f-left {
  331. width: 8px;
  332. background: #F08378;
  333. display: inline-block;
  334. }
  335. .f-right {
  336. padding: 20px 0 20px 38px;
  337. display: inline-block;
  338. .close-btn {
  339. position: absolute;
  340. right: 12px;
  341. top: 22px;
  342. }
  343. .f-salarm {
  344. font-size: 16px;
  345. color: #F08378;
  346. font-weight: bold;
  347. }
  348. }
  349. }
  350. .eq-bottom {
  351. background: #FFFFFF;
  352. box-shadow: 0 2px 10px 0 rgba(44,48,62,0.06);
  353. border-radius: 2px;
  354. padding-top:30px;
  355. .alarm-top {
  356. margin-bottom: 40px;
  357. display: flex;
  358. justify-content: center;
  359. span {
  360. text-align: center;
  361. padding: 6px 20px;
  362. color: #62697b;
  363. cursor: pointer;
  364. border: 1px solid #cacaca;
  365. border-right: none;
  366. &:last-child {
  367. border-right: 1px solid #cacaca;
  368. border-top-right-radius: 3px;
  369. border-bottom-right-radius: 3px;
  370. }
  371. &:first-child {
  372. border-top-left-radius: 3px;
  373. border-bottom-left-radius: 3px;
  374. }
  375. &:hover,
  376. &.active {
  377. background: #728DEE;
  378. color: #fff;
  379. }
  380. }
  381. }
  382. .my-select-type {
  383. padding-left: 30px;
  384. padding-right: 20px;
  385. }
  386. }
  387. }
  388. </style>