ble-pop.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view>
  3. <u-popup
  4. :show="show"
  5. mode="center"
  6. @open="handleOpen"
  7. :round="10"
  8. :closeable="false"
  9. :closeOnClickOverlay="false"
  10. >
  11. <view class="pop-content">
  12. <view class="top-box">
  13. <view class="flex-box flex-justify-sb flex-row-center">
  14. <view class="pop-name">选择设备</view>
  15. <image
  16. src="@/static/image/refresh-icon.png"
  17. class="refresh-btn"
  18. @click="handleRefresh"
  19. ></image>
  20. </view>
  21. <u-icon
  22. name="close"
  23. color="#666"
  24. size="20"
  25. @click="handleClose"
  26. ></u-icon>
  27. </view>
  28. <view class="ble-box">
  29. <scroll-view
  30. scroll-y
  31. :style="{
  32. height: '100%',
  33. }"
  34. >
  35. <block v-for="(item, index) in list" :key="index">
  36. <view class="ble-item">
  37. <image
  38. src="@/static/image/shebei-icon.png"
  39. class="shebei-icon"
  40. ></image>
  41. <view class="ble-name">{{ item.name }}</view>
  42. <view class="action-btn" @click="clickItem(item)">选择</view>
  43. </view>
  44. </block>
  45. </scroll-view>
  46. </view>
  47. </view>
  48. </u-popup>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. props: {
  54. show: {
  55. type: Boolean,
  56. default: false,
  57. },
  58. },
  59. computed: {
  60. list() {
  61. return this.$store.state.ble.discoveredDevices;
  62. },
  63. },
  64. data() {
  65. return {};
  66. },
  67. methods: {
  68. handleClose() {
  69. this.$emit("update:show", false);
  70. this.$emit("close");
  71. },
  72. handleOpen() {
  73. this.$emit("open");
  74. },
  75. handleRefresh() {
  76. this.$emit("refresh");
  77. },
  78. clickItem(item) {
  79. this.$emit("selectItem", item);
  80. },
  81. },
  82. };
  83. </script>
  84. <style lang="scss" scoped>
  85. .pop-content {
  86. width: 590rpx;
  87. padding: 30rpx;
  88. background: #fff;
  89. border-radius: 10rpx;
  90. .pop-name {
  91. font-family: PingFang SC;
  92. font-weight: 500;
  93. font-size: 32rpx;
  94. line-height: 1;
  95. color: rgba(29, 33, 42, 1);
  96. }
  97. .ble-box {
  98. height: 600rpx;
  99. }
  100. }
  101. .flex-box {
  102. display: flex;
  103. }
  104. .flex-justify-sb {
  105. justify-content: space-between;
  106. }
  107. .flex-row-center {
  108. align-items: center;
  109. }
  110. .top-box {
  111. display: flex;
  112. justify-content: space-between;
  113. align-items: center;
  114. margin-bottom: 30rpx;
  115. .refresh-btn {
  116. width: 40rpx;
  117. height: 40rpx;
  118. margin-left: 10rpx;
  119. }
  120. .shebei-icon {
  121. width: 80rpx;
  122. height: 80rpx;
  123. margin-right: 20rpx;
  124. }
  125. }
  126. .ble-item {
  127. display: grid;
  128. grid-template-columns: 100rpx 1fr 120rpx;
  129. align-items: center;
  130. margin-bottom: 20rpx;
  131. width: 100%;
  132. .shebei-icon {
  133. width: 80rpx;
  134. height: 80rpx;
  135. margin-right: 20rpx;
  136. }
  137. .action-btn {
  138. font-family: PingFang SC;
  139. font-weight: 400;
  140. font-size: 22rpx;
  141. width: 120rpx;
  142. height: 44rpx;
  143. border-radius: 40rpx;
  144. text-align: center;
  145. line-height: 44rpx;
  146. background-color: rgba(2, 86, 255, 0.1);
  147. color: rgba(2, 86, 255, 1);
  148. margin-left: 20rpx;
  149. }
  150. .ble-name {
  151. overflow: hidden;
  152. white-space: no-wrap;
  153. text-overflow: ellipsis;
  154. }
  155. }
  156. </style>