list.nvue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="page">
  3. <image class="content-bg" src="/static/device/devicebg.png" mode="scaleToFill"></image>
  4. <view class="status-bar" :style="{height: statusBarHeight + 'px'}"></view>
  5. <view class="custom-head">
  6. <text class="head-placeholder"> </text>
  7. <text class="head-title">我的设备</text>
  8. <text class="head-add" @click="goAddDevice">+</text>
  9. </view>
  10. <text class="section-title">已添加设备</text>
  11. <view class="device-list">
  12. <!-- 设备卡片 -->
  13. <view class="device-card" v-for="(item, index) in list" :key="index" @click="goDeviceInfo(item)">
  14. <image class="device-icon" src="/static/device/device1.png" mode="heightFix"></image>
  15. <text class="device-name">{{item.name}}</text>
  16. <text class="device-status"></text>
  17. </view>
  18. <!-- 添加设备卡片 -->
  19. <view class="device-card add-card" @click="goAddDevice">
  20. <text class="add-title">添加设备</text>
  21. <view class="add-icon-wrap">
  22. <view class="add-icon-circle">
  23. <text class="add-icon-text">+</text>
  24. </view>
  25. <text class="add-tip">去添加</text>
  26. </view>
  27. </view>
  28. </view>
  29. <ay-toast ref="ayToast" />
  30. </view>
  31. </template>
  32. <script>
  33. import ayToast from '@/components/ay-toast/ay-toast.nvue'
  34. export default {
  35. components: {
  36. ayToast
  37. },
  38. data() {
  39. return {
  40. statusBarHeight: 44,
  41. list: []
  42. }
  43. },
  44. onShow() {
  45. const sysInfo = uni.getSystemInfoSync()
  46. this.statusBarHeight = sysInfo.statusBarHeight || 44
  47. this.init()
  48. },
  49. onPullDownRefresh() {
  50. uni.stopPullDownRefresh()
  51. this.init()
  52. },
  53. methods: {
  54. init() {
  55. // 从本地存储读取设备列表
  56. try {
  57. const data = uni.getStorageSync('deviceList')
  58. if (data && data.length > 0) {
  59. this.list = data
  60. } else {
  61. this.list = []
  62. }
  63. } catch (e) {
  64. this.list = []
  65. }
  66. },
  67. goAddDevice() {
  68. uni.navigateTo({
  69. url: '/pages/device/search/search'
  70. })
  71. },
  72. goDeviceInfo(item) {
  73. uni.navigateTo({
  74. url: '/pages/device/deviceInfo/deviceInfo?name=' + encodeURIComponent(item.name || '') + '&deviceId=' + encodeURIComponent(item.deviceId || '') + '&rssi=' + encodeURIComponent(item.RSSI || '')
  75. })
  76. }
  77. }
  78. }
  79. </script>
  80. <style>
  81. .page {
  82. flex: 1;
  83. position: relative;
  84. }
  85. .content-bg {
  86. position: absolute;
  87. left: 0;
  88. top: 0;
  89. width: 750rpx;
  90. height: 2000px;
  91. }
  92. .status-bar {
  93. background-color: rgba(0,0,0,0);
  94. }
  95. .custom-head {
  96. flex-direction: row;
  97. justify-content: space-between;
  98. align-items: center;
  99. height: 88rpx;
  100. padding-left: 54rpx;
  101. padding-right: 54rpx;
  102. }
  103. .head-placeholder {
  104. width: 36rpx;
  105. }
  106. .head-title {
  107. font-weight: bold;
  108. font-size: 32rpx;
  109. color: #545F71;
  110. }
  111. .head-add {
  112. width: 20px;
  113. height: 20px;
  114. border-width: 2px;
  115. border-style: solid;
  116. border-color: #545F71;
  117. border-radius: 20px;
  118. text-align: center;
  119. line-height: 16px;
  120. font-size: 20px;
  121. font-weight: bold;
  122. color: #545F71;
  123. }
  124. .section-title {
  125. font-size: 32rpx;
  126. color: #545F71;
  127. margin-left: 38rpx;
  128. margin-bottom: 38rpx;
  129. margin-top: 20rpx;
  130. }
  131. .device-list {
  132. flex-direction: row;
  133. flex-wrap: wrap;
  134. justify-content: space-between;
  135. padding-left: 38rpx;
  136. padding-right: 38rpx;
  137. }
  138. .device-card {
  139. width: 324rpx;
  140. height: 300rpx;
  141. background-color: #FFFFFF;
  142. border-radius: 24rpx;
  143. margin-bottom: 26rpx;
  144. align-items: center;
  145. padding-top: 40rpx;
  146. }
  147. .device-icon {
  148. width: 156rpx;
  149. height: 156rpx;
  150. }
  151. .device-name {
  152. margin-top: 36rpx;
  153. font-weight: bold;
  154. font-size: 28rpx;
  155. color: #545F71;
  156. }
  157. .device-status {
  158. font-size: 24rpx;
  159. color: #999999;
  160. margin-top: 10rpx;
  161. }
  162. .add-card {
  163. align-items: flex-start;
  164. padding-left: 40rpx;
  165. padding-top: 40rpx;
  166. }
  167. .add-title {
  168. font-weight: bold;
  169. font-size: 28rpx;
  170. color: #545F71;
  171. margin-bottom: 48rpx;
  172. }
  173. .add-icon-wrap {
  174. align-items: center;
  175. width: 244rpx;
  176. }
  177. .add-icon-circle {
  178. width: 60rpx;
  179. height: 60rpx;
  180. background-color: #C3DFDB;
  181. border-radius: 60rpx;
  182. justify-content: center;
  183. align-items: center;
  184. }
  185. .add-icon-text {
  186. font-size: 42rpx;
  187. color: #389588;
  188. font-weight: bold;
  189. margin-top: -4rpx;
  190. }
  191. .add-tip {
  192. text-align: center;
  193. margin-top: 8rpx;
  194. font-size: 24rpx;
  195. color: #999999;
  196. }
  197. </style>