index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <template>
  2. <view class="content">
  3. <view class="Dataview">
  4. <SubTitle title="数据概览" titleEng="DATA OVERVIEW"></SubTitle>
  5. <view class="datalist">
  6. <view class="datablcok">
  7. <view>今日换电次数</view>
  8. <view class="icon-data">
  9. <view>
  10. <image src="/static/index/icon1.png"></image>
  11. </view>
  12. <view class="number">{{dataView.todaySwap ||'0'}}</view>
  13. </view>
  14. <view class="positon p-left"></view>
  15. </view>
  16. <view class="datablcok">
  17. <view>累计换电次数</view>
  18. <view class="icon-data">
  19. <view>
  20. <image src="/static/index/icon2.png"></image>
  21. </view>
  22. <view class="number">{{dataView.totalSwap ||'0'}}</view>
  23. </view>
  24. <view class="positon p-left"></view>
  25. </view>
  26. <view class="datablcok">
  27. <view>今日告警次数</view>
  28. <view class="icon-data">
  29. <view>
  30. <image src="/static/index/icon3.png"></image>
  31. </view>
  32. <view class="number">{{dataView.todayAlarm ||'0'}}</view>
  33. </view>
  34. <view class="positon p-left"></view>
  35. </view>
  36. <view class="datablcok">
  37. <view>告警总数(次)</view>
  38. <view class="icon-data">
  39. <view>
  40. <image src="/static/index/icon4.png"></image>
  41. </view>
  42. <view class="number">{{dataView.totalAlarm ||'0'}}</view>
  43. </view>
  44. <view class="positon p-left"></view>
  45. </view>
  46. <view class="datablcok">
  47. <view>消防告警(次)</view>
  48. <view class="icon-data">
  49. <view>
  50. <image src="/static/index/icon5.png"></image>
  51. </view>
  52. <view class="number">{{dataView.fireAlarm ||'0'}}</view>
  53. </view>
  54. <view class="positon p-left"></view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="equipment">
  59. <SubTitle title="设备状态" titleEng="DEVICE STATUS"></SubTitle>
  60. <view class="statusShow">
  61. <view class="positon p-left"></view>
  62. <view class="positon p-right"></view>
  63. <view class="positon p-b-left"></view>
  64. <view class="positon p-b-right"></view>
  65. <view class="title">
  66. <view class="first">
  67. <image src="/static/index/title-left.png"></image>
  68. </view>
  69. <view class="second">智能换电站</view>
  70. <view class="last">
  71. <image src="/static/index/title-right.png">
  72. </view>
  73. </view>
  74. <view class="line">
  75. <image src="/static/index/line.png"></image>
  76. </view>
  77. <view class="changeList">
  78. <view>
  79. <image :src="robotResult"></image>
  80. </view>
  81. <ChargerState v-for="item in stateList" :key="item.code" :chargerState="item.chargerState"></ChargerState>
  82. </view>
  83. <view class="borderList">
  84. <view></view>
  85. <view v-for="item in 8"></view>
  86. </view>
  87. <view class="batteryList">
  88. <view></view>
  89. <BatteryState v-for="item in stateList" :key="item.code" :batteryState="item.batteryState"></BatteryState>
  90. </view>
  91. </view>
  92. <view class="status-description">
  93. <view class="positon p-left"></view>
  94. <view class="positon p-right"></view>
  95. <view class="positon p-b-left"></view>
  96. <view class="positon p-b-right"></view>
  97. <view class="status-list">
  98. <view class="plc-row">
  99. <view class="plc-status">
  100. <view>
  101. <image src="/static/index/status1.png"></image>
  102. </view>
  103. <view>机器人状态</view>
  104. </view>
  105. <IndexStatus text="未就绪" color="default"></IndexStatus>
  106. <IndexStatus text="就绪" color="green"></IndexStatus>
  107. <IndexStatus text="运行中" color="orange"></IndexStatus>
  108. <IndexStatus text="完成" color="orange"></IndexStatus>
  109. <IndexStatus text="故障" color="yellow"></IndexStatus>
  110. <IndexStatus text="中止" color="pink"></IndexStatus>
  111. <IndexStatus text="离线" color="default"></IndexStatus>
  112. </view>
  113. <view class="plc-row">
  114. <view class="plc-status">
  115. <view>
  116. <image src="/static/index/status2.png"></image>
  117. </view>
  118. <view>充电机状态</view>
  119. </view>
  120. <IndexStatus text="空闲" color="green"></IndexStatus>
  121. <IndexStatus text="准备充电" color="orange"></IndexStatus>
  122. <IndexStatus text="充电中" color="orange"></IndexStatus>
  123. <IndexStatus text="充电结束" color="green"></IndexStatus>
  124. <IndexStatus text="充电失败" color="yellow"></IndexStatus>
  125. <IndexStatus text="故障" color="yellow"></IndexStatus>
  126. <IndexStatus text="离线" color="default"></IndexStatus>
  127. </view>
  128. <view class="plc-row">
  129. <view class="plc-status">
  130. <view>
  131. <image src="/static/index/status1.png"></image>
  132. </view>
  133. <view>电池状态</view>
  134. </view>
  135. <IndexStatus text="故障" color="yellow"></IndexStatus>
  136. <IndexStatus text="有电池" color="green"></IndexStatus>
  137. <IndexStatus text="无电池" color="default"></IndexStatus>
  138. </view>
  139. </view>
  140. <view class="status-img">
  141. <image src="/static/index/status-bg.png"></image>
  142. </view>
  143. </view>
  144. </view>
  145. </view>
  146. </template>
  147. <script>
  148. import ChargerState from './components/ChargerState'
  149. import BatteryState from './components/BatteryState'
  150. export default {
  151. components:{ChargerState,BatteryState},
  152. data() {
  153. return {
  154. dataView: {},
  155. robotState: 0,
  156. stateList: [],
  157. heartbeatTimer:null,
  158. onMessageTime:null,
  159. }
  160. },
  161. mounted() {
  162. this.onMessageTime = new Date();
  163. this.InitWs()
  164. this.heartbeatTimer = setInterval(()=>{
  165. let newDate = new Date();
  166. if(newDate-this.onMessageTime>3000){
  167. if(this.ws!=null){
  168. this.ws.close()
  169. this.ws=null
  170. }
  171. }
  172. },3000)
  173. this.getDataView()
  174. },
  175. computed: {
  176. robotResult() {
  177. switch (this.robotState) {
  178. case 0:
  179. return '/static/index/plc-null.png'
  180. case 1:
  181. return '/static/index/plc-has.png'
  182. case 2:
  183. return '/static/index/plc-doing.png'
  184. case 3:
  185. return '/static/index/plc-doing.png'
  186. case 4:
  187. return '/static/index/plc-warn.png'
  188. case 5:
  189. return '/static/index/plc-over.png'
  190. }
  191. }
  192. },
  193. methods: {
  194. //数据概览
  195. getDataView() {
  196. this.$http.getoverview().then(res => {
  197. this.dataView = res.data
  198. })
  199. },
  200. InitWs() {
  201. if (this.ws != null) {
  202. this.ws.close()
  203. this.ws = null
  204. }
  205. if (this.timer != null) {
  206. clearInterval(this.timer)
  207. this.timer = null
  208. }
  209. let token = this.$storage.getJson('token');
  210. if (token == null) {
  211. uni.navigateTo({
  212. url: '/pages/login/index'
  213. })
  214. return false;
  215. }
  216. this.ws = uni.connectSocket({
  217. url: this.$config.web_socket_url + token,
  218. header: {
  219. 'content-type': 'application/json'
  220. },
  221. complete: () => {}
  222. })
  223. this.ws.onOpen(() => {
  224. // let msg = {
  225. // type: "subscribeExchange",
  226. // payLoad: {
  227. // exchangeNo: exchangeNo
  228. // }
  229. // }
  230. // this.ws.send({
  231. // data: JSON.stringify(msg)
  232. // })
  233. // uni.showLoading({
  234. // title: '数据加载中...'
  235. // });
  236. console.log('websocket连接成功')
  237. const wsMessage = {
  238. type: 'page',
  239. payload: 'PageIndex'
  240. }
  241. this.ws.send({
  242. data: JSON.stringify(wsMessage)
  243. })
  244. })
  245. this.ws.onMessage((res) => {
  246. this.onMessageTime = new Date();
  247. let d = JSON.parse(res.data)
  248. // console.log(d)
  249. this.stateList = d.stateList
  250. this.robotState = d.robotState
  251. // uni.hideLoading()
  252. })
  253. // 监听WebSocket关闭事件
  254. this.ws.onClose(() => {
  255. console.log('WebSocket连接已关闭!');
  256. })
  257. this.ws.onError(() => {
  258. console.log("WebSocket连接错误")
  259. })
  260. if(this.timer == null){
  261. //检查断开重连
  262. this.timer = setInterval(() => {
  263. if(this.ws==null){
  264. console.log('ws为null,检查断开重连')
  265. this.InitWs()
  266. }else if(this.ws.readyState != 1){
  267. this.ws.close()
  268. this.ws = null
  269. console.log('未连接成功,检查断开重连')
  270. this.InitWs()
  271. }
  272. }, 2000)
  273. }
  274. },
  275. },
  276. onUnload() {
  277. console.log('onUnload')
  278. if(this.timer!=null){
  279. clearInterval(this.timer)
  280. this.timer = null
  281. }
  282. if(this.ws!=null){
  283. this.ws.close()
  284. this.ws=null
  285. }
  286. if(this.heartbeatTimer!=null){
  287. this.heartbeatTimer.close()
  288. this.heartbeatTimer=null
  289. }
  290. },
  291. }
  292. </script>
  293. <style lang="scss" scoped>
  294. .positon {
  295. position: absolute;
  296. width: 1px;
  297. height: 1px;
  298. background: #FFFFFF;
  299. }
  300. .p-left {
  301. left: -1px;
  302. top: -1px;
  303. }
  304. .p-right {
  305. right: -1px;
  306. top: -1px;
  307. }
  308. .p-b-left {
  309. left: -1px;
  310. bottom: -1px;
  311. }
  312. .p-b-right {
  313. right: -1px;
  314. bottom: -1px;
  315. }
  316. .content {
  317. width: 100%;
  318. display: flex;
  319. flex-direction: column;
  320. .Dataview {
  321. background-color: #111827;
  322. height: 129px;
  323. .datalist {
  324. margin: 20px;
  325. display: flex;
  326. justify-content: space-between;
  327. .datablcok {
  328. width: 180px;
  329. height: 60px;
  330. border: 1px solid #334568;
  331. color: rgba(153, 174, 197, 0.65);
  332. font-size: 12px;
  333. font-weight: 400;
  334. padding: 8px 12px;
  335. box-sizing: border-box;
  336. display: flex;
  337. flex-direction: column;
  338. position: relative;
  339. .icon-data {
  340. display: flex;
  341. margin-top: 6px;
  342. .number {
  343. font-size: 18px;
  344. font-weight: 600;
  345. color: #C7D2DF;
  346. line-height: 20px;
  347. text-indent: 5px;
  348. }
  349. image {
  350. width: 20px;
  351. height: 20px;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. .equipment {
  358. display: flex;
  359. flex-direction: column;
  360. margin-top: 16px;
  361. height: 567px;
  362. overflow: hidden;
  363. background-color: #111827;
  364. .statusShow {
  365. margin: 16px 20px;
  366. height: 386px;
  367. border: 1px solid #334568;
  368. box-sizing: border-box;
  369. padding: 20px;
  370. position: relative;
  371. .title {
  372. display: flex;
  373. justify-content: space-between;
  374. align-items: center;
  375. .first {
  376. image {
  377. width: 304px;
  378. height: 70px;
  379. }
  380. }
  381. .second {
  382. width: 320px;
  383. height: 70px;
  384. background-image: url('/static/index/title.png');
  385. background-position: bottom;
  386. background-size: 100% 68px;
  387. font-weight: 600;
  388. color: #C7D2DF;
  389. font-size: 32px;
  390. letter-spacing: 1px;
  391. text-align: center;
  392. line-height: 70px;
  393. }
  394. .last {
  395. image {
  396. width: 305px;
  397. height: 70px;
  398. }
  399. }
  400. }
  401. .line {
  402. text-align: center;
  403. width: 100%;
  404. image {
  405. width: 889px;
  406. height: 56px;
  407. }
  408. }
  409. .changeList {
  410. display: flex;
  411. justify-content: space-between;
  412. margin-top: 8px;
  413. image {
  414. width: 70px;
  415. height: 70px;
  416. }
  417. }
  418. .batteryList {
  419. display: flex;
  420. justify-content: space-between;
  421. image {
  422. width: 70px;
  423. height: 70px;
  424. }
  425. view {
  426. width: 70px;
  427. height: 70px;
  428. }
  429. view:first-child {
  430. visibility: hidden;
  431. }
  432. }
  433. .borderList {
  434. margin: 16px 0px;
  435. display: flex;
  436. justify-content: space-between;
  437. view {
  438. width: 70px;
  439. height: 28px;
  440. position: relative;
  441. }
  442. view:before {
  443. content: "";
  444. width: 0px;
  445. height: 28px;
  446. opacity: 1;
  447. border: 1px solid #334568;
  448. position: absolute;
  449. left: 50%;
  450. }
  451. view:first-child {
  452. visibility: hidden;
  453. }
  454. }
  455. }
  456. .status-description {
  457. border: 1px solid #334568;
  458. box-sizing: border-box;
  459. text-align: center;
  460. margin: 0px 20px;
  461. padding: 12px 16px;
  462. display: flex;
  463. justify-content: space-between;
  464. position: relative;
  465. .status-list {
  466. flex: 1;
  467. font-size: 12px;
  468. font-weight: 400;
  469. color: #7681AD;
  470. display: flex;
  471. height: 75px;
  472. justify-content: space-between;
  473. flex-direction: column;
  474. image {
  475. width: 12px;
  476. height: 12px;
  477. }
  478. .plc-row {
  479. flex: 1;
  480. display: flex;
  481. }
  482. .plc-status {
  483. display: flex;
  484. height: 20px;
  485. line-height: 16px;
  486. align-items: center;
  487. width: 80px;
  488. image {
  489. margin-right: 4px;
  490. margin-top: 4px;
  491. }
  492. margin-right: 15px;
  493. }
  494. }
  495. .status-img {
  496. margin-top: 9px;
  497. image {
  498. width: 245px;
  499. height: 56px;
  500. }
  501. }
  502. }
  503. }
  504. }
  505. </style>