index.vue 14 KB

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