index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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. ws: null, //websuokit 链接器
  174. }
  175. },
  176. mounted() {
  177. this.onMessageTime = new Date();
  178. this.InitWs()
  179. // this.heartbeatTimer = setInterval(()=>{
  180. // let newDate = new Date();
  181. // if(newDate-this.onMessageTime>3000){
  182. // if(this.ws!=null){
  183. // this.ws.close()
  184. // this.ws=null
  185. // }
  186. // }
  187. // },3000)
  188. this.getDataView()
  189. },
  190. destroyed(){
  191. clearInterval(this.timer)
  192. if(this.ws){
  193. this.ws.close()
  194. }
  195. },
  196. computed: {
  197. robotResult() {
  198. switch (this.robotState) {
  199. case 0:
  200. return '/static/index/plc-null.png'
  201. case 1:
  202. return '/static/index/plc-has.png'
  203. case 2:
  204. return '/static/index/plc-doing.png'
  205. case 3:
  206. return '/static/index/plc-doing.png'
  207. case 4:
  208. return '/static/index/plc-warn.png'
  209. case 5:
  210. return '/static/index/plc-over.png'
  211. }
  212. }
  213. },
  214. methods: {
  215. //数据概览
  216. getDataView() {
  217. this.$http.getoverview().then(res => {
  218. this.dataView = res.data
  219. })
  220. },
  221. InitWs() {
  222. uni.showLoading({
  223. title:'数据加载中...'
  224. })
  225. if (this.ws != null) {
  226. this.ws.close()
  227. this.ws = null
  228. }
  229. if (this.timer != null) {
  230. clearInterval(this.timer)
  231. this.timer = null
  232. }
  233. let token = this.$storage.getJson('token');
  234. if (token == null) {
  235. uni.navigateTo({
  236. url: '/pages/login/index'
  237. })
  238. return false;
  239. }
  240. this.ws = uni.connectSocket({
  241. url: this.$config.web_socket_url + token,
  242. header: {
  243. 'content-type': 'application/json'
  244. },
  245. complete: () => {}
  246. })
  247. this.ws.onOpen(() => {
  248. // let msg = {
  249. // type: "subscribeExchange",
  250. // payLoad: {
  251. // exchangeNo: exchangeNo
  252. // }
  253. // }
  254. // this.ws.send({
  255. // data: JSON.stringify(msg)
  256. // })
  257. // uni.showLoading({
  258. // title: '数据加载中...'
  259. // });
  260. console.log('websocket连接成功')
  261. const wsMessage = {
  262. type: 'page',
  263. payload: 'PageIndex'
  264. }
  265. this.ws.send({
  266. data: JSON.stringify(wsMessage)
  267. })
  268. })
  269. this.ws.onMessage((res) => {
  270. this.onMessageTime = new Date();
  271. let d = JSON.parse(res.data)
  272. // console.log(d)
  273. this.stateList = d.stateList
  274. this.robotState = d.robotState
  275. uni.hideLoading()
  276. })
  277. // 监听WebSocket关闭事件
  278. this.ws.onClose(() => {
  279. console.log('WebSocket连接已关闭!');
  280. })
  281. this.ws.onError(() => {
  282. console.log("WebSocket连接错误")
  283. })
  284. if(this.timer == null){
  285. //检查断开重连
  286. this.timer = setInterval(() => {
  287. if(this.ws==null){
  288. console.log('ws为null,检查断开重连')
  289. this.InitWs()
  290. }else if(this.ws.readyState != 1){
  291. this.ws.close()
  292. this.ws = null
  293. console.log('未连接成功,检查断开重连')
  294. this.InitWs()
  295. }
  296. }, 2000)
  297. }
  298. },
  299. },
  300. onUnload() {
  301. console.log('onUnload')
  302. if(this.timer!=null){
  303. clearInterval(this.timer)
  304. this.timer = null
  305. }
  306. if(this.ws!=null){
  307. this.ws.close()
  308. this.ws=null
  309. }
  310. if(this.heartbeatTimer!=null){
  311. this.heartbeatTimer.close()
  312. this.heartbeatTimer=null
  313. }
  314. },
  315. }
  316. </script>
  317. <style lang="scss" scoped>
  318. .positon {
  319. position: absolute;
  320. width: 1px;
  321. height: 1px;
  322. background: #FFFFFF;
  323. }
  324. .p-left {
  325. left: -1px;
  326. top: -1px;
  327. }
  328. .p-right {
  329. right: -1px;
  330. top: -1px;
  331. }
  332. .p-b-left {
  333. left: -1px;
  334. bottom: -1px;
  335. }
  336. .p-b-right {
  337. right: -1px;
  338. bottom: -1px;
  339. }
  340. .content {
  341. width: 100%;
  342. display: flex;
  343. flex-direction: column;
  344. .Dataview {
  345. background-color: #111827;
  346. height: 129px;
  347. .datalist {
  348. margin: 20px;
  349. display: flex;
  350. justify-content: space-between;
  351. .datablcok {
  352. width: 180px;
  353. height: 60px;
  354. border: 1px solid #334568;
  355. color: rgba(153, 174, 197, 0.65);
  356. font-size: 12px;
  357. font-weight: 400;
  358. padding: 8px 12px;
  359. box-sizing: border-box;
  360. display: flex;
  361. flex-direction: column;
  362. position: relative;
  363. .icon-data {
  364. display: flex;
  365. margin-top: 6px;
  366. .number {
  367. font-size: 18px;
  368. font-weight: 600;
  369. color: #C7D2DF;
  370. line-height: 20px;
  371. text-indent: 5px;
  372. }
  373. image {
  374. width: 20px;
  375. height: 20px;
  376. }
  377. }
  378. }
  379. }
  380. }
  381. .equipment {
  382. display: flex;
  383. flex-direction: column;
  384. margin-top: 16px;
  385. height: 567px;
  386. overflow: hidden;
  387. background-color: #111827;
  388. .statusShow {
  389. margin: 16px 20px;
  390. height: 386px;
  391. border: 1px solid #334568;
  392. box-sizing: border-box;
  393. padding: 20px 0px;
  394. position: relative;
  395. .title {
  396. display: flex;
  397. justify-content: space-between;
  398. align-items: center;
  399. .first {
  400. image {
  401. width: 304px;
  402. height: 70px;
  403. }
  404. }
  405. .second {
  406. width: 320px;
  407. height: 70px;
  408. background-image: url('/static/index/title.png');
  409. background-position: bottom;
  410. background-size: 100% 68px;
  411. font-weight: 600;
  412. color: #C7D2DF;
  413. font-size: 32px;
  414. letter-spacing: 1px;
  415. text-align: center;
  416. line-height: 70px;
  417. }
  418. .last {
  419. image {
  420. width: 305px;
  421. height: 70px;
  422. }
  423. }
  424. }
  425. .line {
  426. display: flex;
  427. justify-content: center;
  428. width: 100%;
  429. .sx{
  430. width: 1px;
  431. height: 28px;
  432. background-color: #334568;
  433. }
  434. image {
  435. width: 889px;
  436. height: 56px;
  437. }
  438. }
  439. .status-top{
  440. padding: 0px 20px;
  441. }
  442. .stateList{
  443. width: 980px;
  444. display: flex;
  445. flex-direction: column;
  446. overflow: hidden;
  447. padding-left:20px;
  448. .scroll_x {
  449. width: 980px;
  450. height: 100%;
  451. // border: 1px solid red;
  452. ::v-deep .uni-scroll-view-content {
  453. display: flex;
  454. view:first-child {
  455. .battery-info {
  456. margin-left: 0px;
  457. }
  458. }
  459. }
  460. }
  461. .lineBox{
  462. height: 28px;
  463. border-left: #334568 solid 1px;
  464. display: flex;
  465. margin-left: 36px;
  466. box-sizing: border-box;
  467. .line-child{
  468. width: 110px;
  469. height: 28px;
  470. border-top:#334568 solid 1px;
  471. border-right:#334568 solid 1px;
  472. }
  473. }
  474. }
  475. .changeList {
  476. display: flex;
  477. margin-top: 8px;
  478. image {
  479. width: 70px;
  480. height: 70px;
  481. padding-right: 41px;
  482. }
  483. }
  484. .batteryList {
  485. display: flex;
  486. justify-content: space-between;
  487. image {
  488. width: 70px;
  489. height: 70px;
  490. }
  491. view {
  492. width: 70px;
  493. height: 70px;
  494. }
  495. view:first-child {
  496. visibility: hidden;
  497. }
  498. }
  499. .borderList {
  500. margin: 16px 0px;
  501. display: flex;
  502. justify-content: space-between;
  503. view {
  504. width: 70px;
  505. height: 28px;
  506. position: relative;
  507. }
  508. view:before {
  509. content: "";
  510. width: 0px;
  511. height: 28px;
  512. opacity: 1;
  513. border: 1px solid #334568;
  514. position: absolute;
  515. left: 50%;
  516. }
  517. view:first-child {
  518. visibility: hidden;
  519. }
  520. }
  521. }
  522. .status-description {
  523. border: 1px solid #334568;
  524. box-sizing: border-box;
  525. text-align: center;
  526. margin: 0px 20px;
  527. padding: 12px 16px;
  528. display: flex;
  529. justify-content: space-between;
  530. position: relative;
  531. .status-list {
  532. flex: 1;
  533. font-size: 12px;
  534. font-weight: 400;
  535. color: #7681AD;
  536. display: flex;
  537. height: 75px;
  538. justify-content: space-between;
  539. flex-direction: column;
  540. image {
  541. width: 12px;
  542. height: 12px;
  543. }
  544. .plc-row {
  545. flex: 1;
  546. display: flex;
  547. }
  548. .plc-status {
  549. display: flex;
  550. height: 20px;
  551. line-height: 16px;
  552. align-items: center;
  553. width: 80px;
  554. image {
  555. margin-right: 4px;
  556. margin-top: 4px;
  557. }
  558. margin-right: 15px;
  559. }
  560. }
  561. .status-img {
  562. margin-top: 9px;
  563. image {
  564. width: 245px;
  565. height: 56px;
  566. }
  567. }
  568. }
  569. }
  570. }
  571. </style>