index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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. <text class="stat-label">总数:</text>
  12. <text class="stat-value">{{ totalDevices }}</text>
  13. </view>
  14. <view class="stat-item">
  15. <text class="stat-label online-icon">●</text>
  16. <text class="stat-label">在线:</text>
  17. <text class="stat-value online">{{ onlineDevices }}</text>
  18. </view>
  19. <view class="stat-item">
  20. <text class="stat-label offline-icon">●</text>
  21. <text class="stat-label">离线:</text>
  22. <text class="stat-value offline">{{ offlineDevices }}</text>
  23. </view>
  24. <view class="stat-item">
  25. <image src="/static/icons/alert.png" class="alert-icon" mode="aspectFit"></image>
  26. <text class="stat-label">告警:</text>
  27. <text class="stat-value alert">{{ alertDevices }}</text>
  28. </view>
  29. </view>
  30. <!-- 设备网格布局 -->
  31. <view class="device-grid">
  32. <view
  33. class="device-card"
  34. v-for="(item, index) in deviceList"
  35. :key="index"
  36. @click="navigateToDeviceList(item.type)"
  37. :class="{'has-alert': item.alerts > 0}"
  38. >
  39. <!-- 卡片内容区 -->
  40. <view class="card-content-area">
  41. <!-- 图标和环形进度 -->
  42. <view class="icon-progress-wrapper">
  43. <view class="icon-container">
  44. <image :src="item.icon" mode="aspectFit" class="icon-image"></image>
  45. </view>
  46. <view class="progress-ring-container">
  47. <svg class="progress-ring" viewBox="0 0 36 36">
  48. <defs>
  49. <linearGradient id="greenGradient" x1="0%" y1="0%" x2="100%" y2="100%">
  50. <stop offset="0%" stop-color="#7FD982" />
  51. <stop offset="100%" stop-color="#3BB44A" />
  52. </linearGradient>
  53. </defs>
  54. <circle class="progress-ring-circle" cx="18" cy="18" r="16" />
  55. <circle
  56. class="progress-ring-value"
  57. cx="18"
  58. cy="18"
  59. r="16"
  60. :stroke-dasharray="100.53"
  61. :stroke-dashoffset="100.53 - (100.53 * item.onlineRate / 100)"
  62. transform="rotate(-90, 18, 18)"
  63. />
  64. </svg>
  65. <view class="progress-center">
  66. <text class="progress-text">{{ item.onlineRate }}%</text>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 设备信息 -->
  71. <view class="device-info">
  72. <view class="card-title">{{ item.name }}</view>
  73. <view class="status-row">
  74. <view class="status-item">
  75. <view class="status-dot online-dot"></view>
  76. <text>在线: </text>
  77. <text class="status-num online-num">{{ item.online }}</text>
  78. </view>
  79. <view class="status-item">
  80. <view class="status-dot offline-dot"></view>
  81. <text>离线: </text>
  82. <text class="status-num offline-num">{{ item.offline }}</text>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. <!-- 告警信息条 -->
  88. <view v-if="item.alerts > 0" class="alert-bar">
  89. <view class="alert-icon">⚠️</view>
  90. <text class="alert-text">{{ item.alerts }} 条告警</text>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. export default {
  98. data() {
  99. return {
  100. deviceList: [
  101. {
  102. name: '监控设备',
  103. online: 8,
  104. offline: 2,
  105. type: 'monitor',
  106. icon: '/static/icons/camera.png',
  107. alerts: 1,
  108. onlineRate: 80
  109. },
  110. {
  111. name: '采集设备',
  112. online: 14,
  113. offline: 1,
  114. type: 'sensor',
  115. icon: '/static/icons/sensor.png',
  116. alerts: 2,
  117. onlineRate: 93
  118. },
  119. {
  120. name: '控制设备',
  121. online: 10,
  122. offline: 1,
  123. type: 'control',
  124. icon: '/static/icons/control.png',
  125. alerts: 0,
  126. onlineRate: 91
  127. },
  128. {
  129. name: '灌溉设备',
  130. online: 6,
  131. offline: 0,
  132. type: 'irrigation',
  133. icon: '/static/icons/water.png',
  134. alerts: 0,
  135. onlineRate: 100
  136. },
  137. {
  138. name: '农机设备',
  139. online: 3,
  140. offline: 1,
  141. type: 'tractor',
  142. icon: '/static/icons/tractor.png',
  143. alerts: 0,
  144. onlineRate: 75
  145. }
  146. ],
  147. currentPlot: '东区智慧农场'
  148. }
  149. },
  150. computed: {
  151. totalDevices() {
  152. return this.deviceList.reduce((sum, device) => sum + device.online + device.offline, 0)
  153. },
  154. onlineDevices() {
  155. return this.deviceList.reduce((sum, device) => sum + device.online, 0)
  156. },
  157. offlineDevices() {
  158. return this.deviceList.reduce((sum, device) => sum + device.offline, 0)
  159. },
  160. alertDevices() {
  161. return this.deviceList.reduce((sum, device) => sum + device.alerts, 0)
  162. }
  163. },
  164. onLoad() {
  165. // 页面加载时获取设备数据
  166. this.fetchDeviceData()
  167. },
  168. methods: {
  169. // 获取设备数据
  170. fetchDeviceData() {
  171. // 实际开发中替换为API请求
  172. // 模拟异步请求
  173. setTimeout(() => {
  174. // 这里只是示例,实际开发中应从API获取数据
  175. console.log('设备数据加载完成')
  176. this.calculateOnlineRates()
  177. }, 500)
  178. },
  179. // 计算在线率
  180. calculateOnlineRates() {
  181. this.deviceList.forEach(item => {
  182. const total = item.online + item.offline
  183. if (total > 0) {
  184. item.onlineRate = Math.round((item.online / total) * 100)
  185. } else {
  186. item.onlineRate = 0
  187. }
  188. })
  189. },
  190. // 跳转到对应设备列表页面
  191. navigateToDeviceList(type) {
  192. uni.navigateTo({
  193. url: `/pages/device-list?type=${type}`
  194. })
  195. },
  196. // 切换地块
  197. changePlot() {
  198. // 暂时仅展示UI,后续实现地块切换逻辑
  199. uni.showToast({
  200. title: '地块切换功能开发中',
  201. icon: 'none'
  202. })
  203. }
  204. },
  205. // 页面导航配置
  206. onShow() {
  207. uni.setNavigationBarTitle({
  208. title: '设备中心'
  209. })
  210. }
  211. }
  212. </script>
  213. <style scoped>
  214. .container {
  215. padding: 24rpx;
  216. background-color: #F9FCFA;
  217. min-height: 100vh;
  218. box-sizing: border-box;
  219. }
  220. /* 地块选择区域 */
  221. .plot-section {
  222. background-color: #FFFFFF;
  223. border-radius: 16rpx;
  224. padding: 24rpx 30rpx;
  225. margin-bottom: 24rpx;
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. box-shadow: 0 4rpx 12rpx rgba(59, 180, 74, 0.06);
  230. }
  231. .plot-text {
  232. font-size: 26rpx;
  233. color: #666666;
  234. }
  235. .plot-name {
  236. font-size: 30rpx;
  237. color: #333333;
  238. font-weight: 600;
  239. margin: 0 12rpx;
  240. }
  241. /* 顶部概览统计区域 */
  242. .overview-section {
  243. background-color: #FFFFFF;
  244. border-radius: 16rpx;
  245. padding: 28rpx 30rpx;
  246. margin-bottom: 24rpx;
  247. display: flex;
  248. justify-content: space-between;
  249. box-shadow: 0 4rpx 12rpx rgba(59, 180, 74, 0.06);
  250. }
  251. .stat-item {
  252. display: flex;
  253. align-items: center;
  254. position: relative;
  255. }
  256. .stat-item::after {
  257. content: '';
  258. position: absolute;
  259. right: -20rpx;
  260. top: 10rpx;
  261. height: 40rpx;
  262. width: 1px;
  263. background-color: #EBEEF5;
  264. display: block;
  265. }
  266. .stat-item:last-child::after {
  267. display: none;
  268. }
  269. .stat-label {
  270. font-size: 26rpx;
  271. color: #666666;
  272. margin-right: 8rpx;
  273. }
  274. .online-icon {
  275. color: #66CC6A;
  276. font-size: 16rpx;
  277. margin-right: 8rpx;
  278. transform: translateY(-2rpx);
  279. }
  280. .offline-icon {
  281. color: #F56C6C;
  282. font-size: 16rpx;
  283. margin-right: 8rpx;
  284. transform: translateY(-2rpx);
  285. }
  286. .alert-icon {
  287. width: 32rpx;
  288. height: 32rpx;
  289. margin-right: 8rpx;
  290. }
  291. .stat-value {
  292. font-size: 30rpx;
  293. color: #333333;
  294. font-weight: 600;
  295. }
  296. .stat-value.online {
  297. color: #3BB44A;
  298. }
  299. .stat-value.offline {
  300. color: #F56C6C;
  301. }
  302. .stat-value.alert {
  303. color: #F56C6C;
  304. }
  305. /* 设备网格区域 */
  306. .device-grid {
  307. display: flex;
  308. flex-wrap: wrap;
  309. justify-content: space-between;
  310. }
  311. .device-card {
  312. width: 48%;
  313. border-radius: 16rpx;
  314. margin-bottom: 24rpx;
  315. background-color: #FFFFFF;
  316. box-shadow: 0 4rpx 16rpx rgba(59, 180, 74, 0.05);
  317. overflow: hidden;
  318. position: relative;
  319. border: 1rpx solid rgba(59, 180, 74, 0.1);
  320. }
  321. .device-card.has-alert .card-content-area {
  322. padding-bottom: 60rpx;
  323. }
  324. /* 卡片内容区 */
  325. .card-content-area {
  326. padding: 24rpx;
  327. display: flex;
  328. flex-direction: column;
  329. padding-bottom: 24rpx;
  330. }
  331. /* 图标和环形进度 */
  332. .icon-progress-wrapper {
  333. position: relative;
  334. width: 100%;
  335. height: 130rpx;
  336. display: flex;
  337. justify-content: center;
  338. align-items: center;
  339. margin-bottom: 16rpx;
  340. }
  341. .icon-container {
  342. width: 76rpx;
  343. height: 76rpx;
  344. background: linear-gradient(135deg, #66CC6A 0%, #3BB44A 100%);
  345. border-radius: 50%;
  346. display: flex;
  347. align-items: center;
  348. justify-content: center;
  349. z-index: 2;
  350. box-shadow: 0 4rpx 12rpx rgba(59, 180, 74, 0.2);
  351. }
  352. .icon-image {
  353. width: 42rpx;
  354. height: 42rpx;
  355. filter: brightness(0) invert(1);
  356. }
  357. /* 恢复采集设备和灌溉设备的特殊图标尺寸 */
  358. .device-card:nth-child(2) .icon-image, /* 采集设备 */
  359. .device-card:nth-child(4) .icon-image { /* 灌溉设备 */
  360. width: 50rpx;
  361. height: 50rpx;
  362. }
  363. .progress-ring-container {
  364. position: absolute;
  365. top: 0;
  366. left: 50%;
  367. transform: translateX(-50%);
  368. width: 130rpx;
  369. height: 130rpx;
  370. z-index: 1;
  371. }
  372. .progress-ring {
  373. transform: rotate(0deg);
  374. width: 130rpx;
  375. height: 130rpx;
  376. }
  377. .progress-ring-circle {
  378. stroke: rgba(59, 180, 74, 0.1);
  379. fill: transparent;
  380. stroke-width: 3;
  381. }
  382. .progress-ring-value {
  383. stroke: url(#greenGradient);
  384. fill: transparent;
  385. stroke-width: 2.5;
  386. stroke-linecap: round;
  387. transition: stroke-dashoffset 0.3s;
  388. }
  389. .progress-center {
  390. position: absolute;
  391. top: 50%;
  392. left: 50%;
  393. transform: translate(-50%, -50%);
  394. width: 76rpx;
  395. height: 76rpx;
  396. display: flex;
  397. align-items: center;
  398. justify-content: center;
  399. background: transparent;
  400. border-radius: 50%;
  401. }
  402. .progress-text {
  403. position: absolute;
  404. bottom: 10rpx;
  405. right: 10rpx;
  406. font-size: 20rpx;
  407. font-weight: 600;
  408. color: #3BB44A;
  409. background-color: rgba(255, 255, 255, 0.9);
  410. padding: 2rpx 8rpx;
  411. border-radius: 10rpx;
  412. }
  413. /* 设备信息 */
  414. .device-info {
  415. text-align: center;
  416. }
  417. .card-title {
  418. font-size: 28rpx;
  419. color: #333333;
  420. font-weight: 600;
  421. margin-bottom: 12rpx;
  422. white-space: nowrap;
  423. overflow: hidden;
  424. text-overflow: ellipsis;
  425. }
  426. .status-row {
  427. display: flex;
  428. justify-content: space-between;
  429. padding: 0 8rpx;
  430. margin: 0 -8rpx;
  431. }
  432. .status-item {
  433. display: flex;
  434. align-items: baseline;
  435. }
  436. .status-dot {
  437. width: 8rpx;
  438. height: 8rpx;
  439. border-radius: 50%;
  440. margin-right: 6rpx;
  441. display: inline-block;
  442. }
  443. .online-dot {
  444. background-color: #3BB44A;
  445. }
  446. .offline-dot {
  447. background-color: #F56C6C;
  448. }
  449. .status-item text {
  450. font-size: 24rpx;
  451. color: #666666;
  452. }
  453. .status-num {
  454. font-weight: 500;
  455. }
  456. .online-num {
  457. color: #3BB44A;
  458. }
  459. .offline-num {
  460. color: #F56C6C;
  461. }
  462. /* 告警信息条 */
  463. .alert-bar {
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. padding: 14rpx 0;
  468. background-color: rgba(245, 108, 108, 0.1);
  469. font-size: 22rpx;
  470. border-top: 1px solid #FFD5D5;
  471. box-shadow: 0 -2rpx 4rpx rgba(245, 108, 108, 0.1);
  472. position: absolute;
  473. bottom: 0;
  474. left: 0;
  475. right: 0;
  476. }
  477. .alert-icon {
  478. margin-right: 6rpx;
  479. font-size: 22rpx;
  480. }
  481. .alert-text {
  482. color: #F56C6C;
  483. font-weight: 500;
  484. }
  485. </style>