power-change-header - 副本.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="header">
  3. <navigator url="/pages/monitoring/index" open-type="redirect" :class="{'active':currentPage===1}">换电流程
  4. </navigator>
  5. <navigator url="/pages/carinfo/index" open-type="redirect" :class="{'active':currentPage===2}">车辆信息</navigator>
  6. <navigator url="/pages/batteryinfo/index" open-type="redirect" :class="{'active':currentPage===3}">电池信息
  7. </navigator>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. name: "power-change-header",
  13. data() {
  14. return {
  15. currentPage: 0,
  16. socketOpen: false
  17. };
  18. },
  19. mounted() {
  20. this.getRoute()
  21. this.initWs()
  22. },
  23. methods: {
  24. initWs11() {
  25. let msg = {
  26. type: "subscribeExchange",
  27. payLoad: {
  28. exchangeNo: "aaab"
  29. }
  30. }
  31. this.$ws.connect()
  32. this.$ws.onSocketOpen=()=>{
  33. this.$ws.sendmessage(msg)
  34. }
  35. this.$ws.onSocketMsg=(res)=>{
  36. console.log(res)
  37. }
  38. },
  39. initWs() {
  40. let that = this
  41. uni.connectSocket({
  42. url: 'ws://192.168.0.89:8088/ws/abbbccc/SSSSSSSS', //仅为示例,并非真实接口地址。
  43. complete: (res) => {
  44. console.log(res)
  45. }
  46. });
  47. uni.onSocketOpen(function(res) {
  48. //扫码成功之后发送订阅消息
  49. that.socketOpen = true;
  50. let msg = {
  51. type: "subscribeExchange",
  52. payLoad: {
  53. exchangeNo: "aaab"
  54. }
  55. }
  56. //确认换电发送订阅消息
  57. let msg2 = {
  58. type: "startExchange",
  59. payLoad: {
  60. exchangeNo: "aaab"
  61. }
  62. }
  63. if (that.socketOpen) {
  64. uni.sendSocketMessage({
  65. data: JSON.stringify(msg)
  66. });
  67. setTimeout(() => {
  68. uni.sendSocketMessage({
  69. data: JSON.stringify(msg2)
  70. });
  71. }, 3000)
  72. }
  73. console.log('WebSocket连接已打开!');
  74. });
  75. uni.onSocketError(function(res) {
  76. console.log('WebSocket连接打开失败,请检查!');
  77. });
  78. uni.onSocketMessage(function(res) {
  79. console.log('收到服务器内容:' + res.data);
  80. });
  81. uni.onSocketClose(function(res) {
  82. console.log('WebSocket 已关闭!');
  83. });
  84. },
  85. getRoute() {
  86. let curPage = getCurrentPages();
  87. let route = curPage[curPage.length - 1].route
  88. if (route === 'pages/monitoring/index') {
  89. this.currentPage = 1
  90. } else if (route === 'pages/carinfo/index') {
  91. this.currentPage = 2
  92. } else if (route === 'pages/batteryinfo/index') {
  93. this.currentPage = 3
  94. }
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .header {
  101. display: flex;
  102. padding: 30rpx;
  103. width: 690rpx;
  104. color: #86909c;
  105. font-size: 32rpx;
  106. justify-content: space-around;
  107. .active {
  108. color: #1d2129;
  109. font-weight: bold;
  110. position: relative;
  111. }
  112. .active::after {
  113. content: '';
  114. background-image: url('@/static/line.png');
  115. background-size: 100% 100%;
  116. width: 52rpx;
  117. height: 9rpx;
  118. position: absolute;
  119. bottom: -25rpx;
  120. left: 32%;
  121. }
  122. }
  123. </style>