header.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!-- BluetoothHeader.vue -->
  2. <template>
  3. <view class="header">
  4. <u-row>
  5. <u-col span="2">
  6. <view class="status-btn" :class="{ active_btn: linkStatus }">Link</view>
  7. </u-col>
  8. <u-col span="2">
  9. <view class="status-btn" :class="{ active_btn: bleConnected }">blue</view>
  10. </u-col>
  11. <u-col span="4" textAlign="left">
  12. <text class="title">长沙亿旭智能</text>
  13. </u-col>
  14. <u-col span="4">
  15. <view class="text-lable">2025.12.02 V1.0</view>
  16. <view class="typeSelect" @click="toggleAgreementType">
  17. {{ agreementTypeName }}
  18. <u-icon name="arrow-down-fill" color="#fff" size="16"></u-icon>
  19. </view>
  20. </u-col>
  21. </u-row>
  22. <u-action-sheet
  23. :show="showAgreementType"
  24. :actions="typeOptions"
  25. title="请选择协议类型"
  26. @close="closeAgreementType"
  27. @select="selectAgreementType"
  28. >
  29. </u-action-sheet>
  30. </view>
  31. </template>
  32. <script>
  33. import {setAgreement,getAgreement} from '@/utils/modbus.js';
  34. export default {
  35. data() {
  36. return {
  37. communicationTimer: null,
  38. linkStatus:false,
  39. showAgreementType: false,
  40. agreementTypeName: "",
  41. typeOptions: [
  42. {name: 'Lora', value: 'Lora'},
  43. {name: 'zigbee', value: 'zigbee'}
  44. ],
  45. }
  46. },
  47. computed: {
  48. bleConnected() {
  49. return this.$store.getters['ble/connected']
  50. },
  51. bleData() {
  52. return this.$store.getters['ble/data']
  53. }
  54. },
  55. watch: {
  56. bleData: {
  57. handler(newData, oldData) {
  58. if (newData) {
  59. console.log('接收到蓝牙数据:------------------')
  60. // 清除之前的定时器
  61. if (this.communicationTimer) {
  62. clearTimeout(this.communicationTimer)
  63. this.communicationTimer = null
  64. }
  65. if (newData.device !== '255' && newData.device !== ''){
  66. // 设置通信链接状态为 true
  67. this.linkStatus = true
  68. }
  69. // 将数据传递给父组件
  70. this.$emit('ble-data-received', newData);
  71. this.communicationTimer = setTimeout(() => {
  72. this.linkStatus = false
  73. this.communicationTimer = null
  74. }, 5000)
  75. }
  76. },
  77. deep: true, // 深度监听,确保嵌套对象变化时也能触发
  78. immediate: true // 立即执行一次
  79. }
  80. },
  81. mounted() {
  82. this.agreementTypeName = getAgreement()
  83. },
  84. methods: {
  85. toggleAgreementType() {
  86. this.showAgreementType = true;
  87. },
  88. closeAgreementType() {
  89. this.showAgreementType = false;
  90. },
  91. selectAgreementType(e) {
  92. setAgreement(e.name);
  93. this.agreementTypeName = getAgreement()
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. // 头部样式
  100. .header {
  101. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  102. padding: 20rpx;
  103. .status-btn {
  104. background-color: #ff4757;
  105. border: none;
  106. margin-left: 0px;
  107. padding: 0px;
  108. width: 40px;
  109. text-align: center;
  110. color: white;
  111. border-radius: 4px;
  112. height: 20px;
  113. line-height: 20px;
  114. }
  115. .active_btn {
  116. background-color: yellowgreen !important;
  117. }
  118. .title {
  119. color: #fff;
  120. font-size: 36rpx;
  121. font-weight: bold;
  122. }
  123. }
  124. .typeSelect{
  125. font-size: 16px;
  126. color: #fff;
  127. font-weight: 600;
  128. display: flex;
  129. justify-content: flex-end;
  130. }
  131. .text-lable{
  132. color: #fff;
  133. font-size: 12px;
  134. text-align: right;
  135. }
  136. </style>