index.vue 14 KB

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