index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <view class="container">
  3. <!-- 地块信息 -->
  4. <view class="plot-section">
  5. <text class="plot-text">当前查看地块:</text>
  6. <text class="plot-name">{{ currentPlot }}</text>
  7. </view>
  8. <!-- 顶部区域:概览统计 -->
  9. <view class="overview-section">
  10. <view class="stat-item">
  11. <view class="stat-icon-wrapper">
  12. <image src="/static/icons/device_num.png" mode="aspectFit" class="stat-icon-img"></image>
  13. </view>
  14. <text class="stat-value">{{ totalDevices }}</text>
  15. <text class="stat-label">总数</text>
  16. </view>
  17. <view class="stat-item">
  18. <view class="stat-icon-wrapper online">
  19. <image src="/static/icons/device_online.png" mode="aspectFit" class="stat-icon-img"></image>
  20. </view>
  21. <text class="stat-value online">{{ onlineDevices }}</text>
  22. <text class="stat-label">在线</text>
  23. </view>
  24. <view class="stat-item">
  25. <view class="stat-icon-wrapper offline">
  26. <image src="/static/icons/device_offline.png" mode="aspectFit" class="stat-icon-img"></image>
  27. </view>
  28. <text class="stat-value offline">{{ offlineDevices }}</text>
  29. <text class="stat-label">离线</text>
  30. </view>
  31. <view class="stat-item">
  32. <view class="stat-icon-wrapper alert">
  33. <image src="/static/icons/device_alert.png" mode="aspectFit" class="stat-icon-img"></image>
  34. </view>
  35. <text class="stat-value alert">{{ alertDevices }}</text>
  36. <text class="stat-label">告警</text>
  37. </view>
  38. </view>
  39. <!-- 设备网格布局 -->
  40. <view class="device-grid">
  41. <view
  42. v-for="(item, index) in deviceList"
  43. :key="index"
  44. @click="navigateToDeviceList(item.type)"
  45. class="device-card"
  46. :class="{'has-alert': item.alerts > 0}"
  47. hover-class="device-card-hover"
  48. >
  49. <!-- 告警角标 -->
  50. <view v-if="item.alerts > 0" class="alert-badge">{{ item.alerts }}</view>
  51. <!-- 设备图标 -->
  52. <view class="device-icon-container">
  53. <image :src="item.icon" mode="aspectFit" class="device-icon"></image>
  54. </view>
  55. <!-- 设备名称 -->
  56. <text class="device-name">{{ item.name }}</text>
  57. <!-- 设备状态信息区域 -->
  58. <view class="device-status-container">
  59. <!-- 在线状态 -->
  60. <view class="status-info">
  61. <view class="status-dot online-dot"></view>
  62. <text class="status-text">在线</text>
  63. <text class="status-num online-num">{{ item.online }}</text>
  64. </view>
  65. <!-- 离线状态 -->
  66. <view class="status-info">
  67. <view class="status-dot offline-dot"></view>
  68. <text class="status-text">离线</text>
  69. <text class="status-num offline-num">{{ item.offline }}</text>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. export default {
  78. data() {
  79. return {
  80. deviceList: [
  81. {
  82. name: '监控设备',
  83. online: 8,
  84. offline: 2,
  85. type: 'monitor',
  86. icon: '/static/icons/camera.png',
  87. alerts: 1,
  88. onlineRate: 80
  89. },
  90. {
  91. name: '采集设备',
  92. online: 14,
  93. offline: 1,
  94. type: 'sensor',
  95. icon: '/static/icons/sensor.png',
  96. alerts: 2,
  97. onlineRate: 93
  98. },
  99. {
  100. name: '控制设备',
  101. online: 10,
  102. offline: 1,
  103. type: 'control',
  104. icon: '/static/icons/control.png',
  105. alerts: 0,
  106. onlineRate: 91
  107. },
  108. {
  109. name: '灌溉设备',
  110. online: 6,
  111. offline: 0,
  112. type: 'irrigation',
  113. icon: '/static/icons/water.png',
  114. alerts: 0,
  115. onlineRate: 100
  116. },
  117. {
  118. name: '农机设备',
  119. online: 3,
  120. offline: 1,
  121. type: 'tractor',
  122. icon: '/static/icons/tractor.png',
  123. alerts: 0,
  124. onlineRate: 75
  125. }
  126. ],
  127. currentPlot: '东区智慧农场'
  128. }
  129. },
  130. computed: {
  131. totalDevices() {
  132. return this.deviceList.reduce((sum, device) => sum + device.online + device.offline, 0)
  133. },
  134. onlineDevices() {
  135. return this.deviceList.reduce((sum, device) => sum + device.online, 0)
  136. },
  137. offlineDevices() {
  138. return this.deviceList.reduce((sum, device) => sum + device.offline, 0)
  139. },
  140. alertDevices() {
  141. return this.deviceList.reduce((sum, device) => sum + device.alerts, 0)
  142. }
  143. },
  144. onLoad() {
  145. // 页面加载时获取设备数据
  146. this.fetchDeviceData()
  147. },
  148. methods: {
  149. // 获取设备数据
  150. fetchDeviceData() {
  151. // 实际开发中替换为API请求
  152. // 模拟异步请求
  153. setTimeout(() => {
  154. // 这里只是示例,实际开发中应从API获取数据
  155. console.log('设备数据加载完成')
  156. this.calculateOnlineRates()
  157. }, 500)
  158. },
  159. // 计算在线率
  160. calculateOnlineRates() {
  161. this.deviceList.forEach(item => {
  162. const total = item.online + item.offline
  163. if (total > 0) {
  164. item.onlineRate = Math.round((item.online / total) * 100)
  165. } else {
  166. item.onlineRate = 0
  167. }
  168. })
  169. },
  170. // 跳转到对应设备列表页面
  171. navigateToDeviceList(type) {
  172. uni.navigateTo({
  173. url: '/pages/device-list/index?type=' + type
  174. })
  175. },
  176. // 切换地块
  177. changePlot() {
  178. // 暂时仅展示UI,后续实现地块切换逻辑
  179. uni.showToast({
  180. title: '地块切换功能开发中',
  181. icon: 'none'
  182. })
  183. }
  184. },
  185. // 页面导航配置
  186. onShow() {
  187. uni.setNavigationBarTitle({
  188. title: '设备中心'
  189. })
  190. }
  191. }
  192. </script>
  193. <style scoped>
  194. .container {
  195. padding: 30rpx;
  196. background-color: #F9FCFA;
  197. min-height: 100vh;
  198. box-sizing: border-box;
  199. }
  200. /* 地块选择区域 */
  201. .plot-section {
  202. background-color: #FFFFFF;
  203. border-radius: 20rpx;
  204. padding: 26rpx 30rpx;
  205. margin-bottom: 30rpx;
  206. display: flex;
  207. align-items: center;
  208. justify-content: center;
  209. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.04);
  210. }
  211. .plot-text {
  212. font-size: 28rpx;
  213. color: #606060;
  214. }
  215. .plot-name {
  216. font-size: 32rpx;
  217. color: #333333;
  218. font-weight: 600;
  219. margin: 0 12rpx;
  220. }
  221. /* 顶部概览统计区域 */
  222. .overview-section {
  223. background-color: #F2F7F3;
  224. border-radius: 20rpx;
  225. padding: 36rpx 40rpx;
  226. margin-bottom: 34rpx;
  227. display: flex;
  228. justify-content: space-between;
  229. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.03);
  230. }
  231. .stat-item {
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. position: relative;
  236. }
  237. .stat-icon-wrapper {
  238. width: 90rpx;
  239. height: 90rpx;
  240. border-radius: 50%;
  241. background-color: #F0F0F0;
  242. display: flex;
  243. justify-content: center;
  244. align-items: center;
  245. margin-bottom: 14rpx;
  246. box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.04);
  247. }
  248. .stat-icon-wrapper.online {
  249. background: linear-gradient(135deg, #E8F5EA, #D6ECD8);
  250. }
  251. .stat-icon-wrapper.offline {
  252. background: linear-gradient(135deg, #FDEAEA, #FDDCDC);
  253. }
  254. .stat-icon-wrapper.alert {
  255. background: linear-gradient(135deg, #FFF6E5, #FFEFD0);
  256. }
  257. .stat-icon-img {
  258. width: 48rpx;
  259. height: 48rpx;
  260. display: block;
  261. }
  262. .stat-value {
  263. font-size: 38rpx;
  264. color: #333333;
  265. font-weight: 600;
  266. margin: 8rpx 0;
  267. line-height: 1.2;
  268. }
  269. .stat-value.online {
  270. color: #4CAF50;
  271. }
  272. .stat-value.offline {
  273. color: #F44336;
  274. }
  275. .stat-value.alert {
  276. color: #FF9800;
  277. }
  278. .stat-label {
  279. font-size: 24rpx;
  280. color: #888888;
  281. font-weight: 400;
  282. }
  283. /* 设备网格区域 */
  284. .device-grid {
  285. display: flex;
  286. flex-wrap: wrap;
  287. justify-content: space-between;
  288. width: 100%;
  289. }
  290. .device-card {
  291. width: 48%;
  292. border-radius: 24rpx; /* 加大卡片圆角 */
  293. background-color: #FFFFFF;
  294. box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05); /* 柔和阴影 */
  295. padding: 30rpx 0 24rpx 0;
  296. margin-bottom: 30rpx; /* 增加卡片间距 */
  297. position: relative;
  298. display: flex;
  299. flex-direction: column;
  300. align-items: center;
  301. transition: all 0.25s ease;
  302. }
  303. .device-card-hover {
  304. background-color: #f2fef6;
  305. box-shadow: 0 12rpx 32rpx rgba(59, 180, 74, 0.1);
  306. transform: translateY(-3rpx);
  307. }
  308. .device-card.has-alert {
  309. box-shadow: 0 10rpx 30rpx rgba(245, 108, 108, 0.08);
  310. }
  311. /* 告警角标 */
  312. .alert-badge {
  313. position: absolute;
  314. top: 16rpx; /* 6px */
  315. right: 16rpx; /* 6px */
  316. width: 40rpx; /* 20px */
  317. height: 40rpx; /* 20px */
  318. border-radius: 50%;
  319. background-color: #F56C6C;
  320. color: white;
  321. font-size: 24rpx; /* 12px */
  322. font-weight: 600;
  323. display: flex;
  324. align-items: center;
  325. justify-content: center;
  326. box-shadow: 0 4rpx 8rpx rgba(245, 108, 108, 0.3);
  327. z-index: 2;
  328. }
  329. /* 设备图标 */
  330. .device-icon-container {
  331. width: 72rpx; /* 36px */
  332. height: 72rpx; /* 36px */
  333. border-radius: 50%;
  334. background: linear-gradient(135deg, #66CC6A 0%, #3BB44A 100%);
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. margin-bottom: 18rpx;
  339. box-shadow: 0 6rpx 12rpx rgba(59, 180, 74, 0.15);
  340. }
  341. .device-icon {
  342. width: 40rpx;
  343. height: 40rpx;
  344. filter: brightness(0) invert(1);
  345. }
  346. /* 设备名称 */
  347. .device-name {
  348. font-size: 32rpx; /* 16px */
  349. color: #333333;
  350. font-weight: 600;
  351. text-align: center;
  352. margin-bottom: 24rpx;
  353. padding: 0 20rpx;
  354. }
  355. /* 设备状态信息区域 */
  356. .device-status-container {
  357. width: 100%;
  358. display: flex;
  359. flex-direction: row;
  360. justify-content: center;
  361. padding: 16rpx 0;
  362. border-top: 1rpx solid #EEEEEE;
  363. }
  364. /* 状态信息项 */
  365. .status-info {
  366. display: flex;
  367. align-items: center;
  368. margin: 0 16rpx;
  369. }
  370. /* 状态指示点 */
  371. .status-dot {
  372. width: 8rpx;
  373. height: 8rpx;
  374. border-radius: 50%;
  375. margin-right: 6rpx;
  376. }
  377. .online-dot {
  378. background-color: #4CAF50;
  379. }
  380. .offline-dot {
  381. background-color: #F56C6C;
  382. }
  383. /* 状态文本 */
  384. .status-text {
  385. font-size: 26rpx;
  386. color: #999999;
  387. margin-right: 6rpx;
  388. }
  389. /* 状态数字 */
  390. .status-num {
  391. font-size: 26rpx;
  392. font-weight: 600;
  393. }
  394. .online-num {
  395. color: #4CAF50;
  396. }
  397. .offline-num {
  398. color: #F56C6C;
  399. }
  400. </style>