index.vue 12 KB

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