indexRouter.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <!-- 底部tab导航 -->
  3. <view class="card_bar">
  4. <view class="top_card">
  5. <view class="barboxs" :style="{paddingTop:height + 'px'}">
  6. <x-navbar :nowchos='nowchos' @botomchos="botomchos" @reconnection="getDevices"></x-navbar>
  7. </view>
  8. </view>
  9. <scroll-view scroll-y="true" class="const_card" @scrolltolower="scrolltolower">
  10. <realTime v-show="nowchos == 0"></realTime>
  11. <historical :headHeight="headHeight" v-show="nowchos == 1"></historical>
  12. <alarm v-show="nowchos == 2"></alarm>
  13. <basicSetup v-show="nowchos == 3"></basicSetup>
  14. <!-- <text class="title">读取到的内容: {{cardnumber}}</text> -->
  15. </scroll-view>
  16. <view class="bottom_card">
  17. <view class="bottomboxs">
  18. <x-navbottom></x-navbottom>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. const serialPort = uni.requireNativePlugin('Fvv-UniSerialPort')
  25. import realTime from './realTime/index.vue' // 实时数据
  26. import historical from './historical/index.vue' // 历史数据
  27. import alarm from './alarm/index.vue' // 报警查询
  28. import basicSetup from './basicSetup/index.vue' // 报警查询
  29. export default {
  30. components: { //在这里注册相应的组件
  31. realTime,
  32. historical,
  33. alarm,
  34. basicSetup
  35. },
  36. data() {
  37. return {
  38. nowchos: 0, //当前选择了那个底部菜单
  39. rebootingShow: false,
  40. height: 0,
  41. headHeight: 0,
  42. cardnumber: '',
  43. }
  44. },
  45. onLoad() {
  46. },
  47. onShow() {},
  48. mounted() {
  49. this.$nextTick(() => {
  50. const navbar = uni.createSelectorQuery().select('.top_card')
  51. navbar.boundingClientRect(data => {
  52. this.headHeight = data.height
  53. }).exec()
  54. })
  55. const arr = uni.getSystemInfoSync().statusBarHeight
  56. this.height = arr
  57. this.$nextTick(() => {
  58. this.getContentHeight()
  59. })
  60. this.getDevices()
  61. },
  62. methods: {
  63. //获取所有设备路径
  64. getDevices() {
  65. serialPort.getAllDevicePath(res => {
  66. console.log('//路径列表', res)
  67. }),
  68. setTimeout(() => {
  69. serialPort.setPath('/dev/ttyS9')
  70. serialPort.setBaudRate(9600)
  71. serialPort.open(res => {
  72. console.log(res, '111111')
  73. if (!res.status) {
  74. uni.showToast({
  75. title: res.msg,
  76. duration: 2000,
  77. icon: "none"
  78. });
  79. return
  80. }
  81. uni.showToast({
  82. title: "已打开",
  83. duration: 2000,
  84. });
  85. serialPort.onMessageHex(rec => {
  86. console.log(rec, '222222')
  87. this.cardnumber += rec + "\r\n"
  88. }, send => {
  89. console.log(send)
  90. })
  91. })
  92. }, 100)
  93. },
  94. // 触底事件
  95. scrolltolower() {
  96. // console.log(324)
  97. },
  98. // 获取内容区域高度
  99. getContentHeight() {
  100. const screenHeight = uni.getSystemInfoSync().windowHeight
  101. // 获取头部高度
  102. let headHeight = 0
  103. let bottomHeight = 0
  104. const navbar = uni.createSelectorQuery().select('.barboxs')
  105. navbar.boundingClientRect(data => {
  106. headHeight = data.height
  107. }).exec()
  108. // console.log(headHeight, 254)
  109. const bottomNavbar = uni.createSelectorQuery().select('.bottomboxs')
  110. bottomNavbar.boundingClientRect(data => {
  111. bottomHeight = data.height
  112. }).exec()
  113. let arrHeight = screenHeight - headHeight - bottomHeight
  114. this.heightfield = arrHeight
  115. this.$forceUpdate()
  116. },
  117. bottomHeightil() {
  118. this.$nextTick(() => {
  119. let num = 0
  120. const bottomNavbar = uni.createSelectorQuery().select('.bottomboxs')
  121. bottomNavbar.boundingClientRect(data => {
  122. num = data.height
  123. }).exec()
  124. return num
  125. })
  126. },
  127. // tab
  128. botomchos(e) {
  129. this.getContentHeight()
  130. uni.setStorageSync('nowchos', e);
  131. this.nowchos = e
  132. },
  133. // 确定重启
  134. confirm() {
  135. this.rebootingShow = false
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss">
  141. .card_bar {
  142. display: flex;
  143. flex-direction: column;
  144. height: 100vh;
  145. box-sizing: border-box;
  146. }
  147. .scroll-Y {
  148. overflow-y: auto;
  149. }
  150. .const_card {
  151. overflow-y: hidden;
  152. flex: 1;
  153. }
  154. .top_card {
  155. padding-bottom: 3px;
  156. }
  157. .barboxs {
  158. background-color: #ffffff;
  159. box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
  160. }
  161. .bottomboxs {
  162. height: 24rpx;
  163. }
  164. .circle_card {
  165. font-size: 36rpx;
  166. margin-left: 20rpx;
  167. }
  168. </style>