index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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. // 导入API服务
  78. import { forEach } from "../../utils/lib/request/utils";
  79. import { fetchDeviceOverview } from "@/api/services/device.js";
  80. import storage from "@/utils/storage.js";
  81. export default {
  82. data() {
  83. return {
  84. deviceList: [],
  85. currentPlot: "加载中...",
  86. totalDevices: 0,
  87. onlineDevices: 0,
  88. offlineDevices: 0,
  89. alertDevices: 0,
  90. loading: false,
  91. currentFieldId: null, // 当前选中的地块ID
  92. typeOnline: 0,
  93. typeOffline: 0
  94. }
  95. },
  96. methods: {
  97. // 初始化地块信息
  98. initFieldInfo() {
  99. const fieldInfo = storage.getPlots();
  100. console.log("ggg ");
  101. if (fieldInfo) {
  102. const plotData = JSON.parse(fieldInfo);
  103. this.currentFieldId = plotData.id;
  104. this.currentPlot = plotData.name || "未选择地块";
  105. } else {
  106. this.currentPlot = "未选择地块";
  107. }
  108. },
  109. // 获取设备数据
  110. fetchDeviceData() {
  111. if (this.loading) return;
  112. this.loading = true;
  113. uni.showLoading({
  114. title: '加载中...'
  115. });
  116. // 调用API获取设备概览数据
  117. fetchDeviceOverview(this.currentFieldId)
  118. .then(res => {
  119. if (res.data.code === 200 && res.data.data) {
  120. const data = res.data.data;
  121. // 更新设备总览数据
  122. this.totalDevices = data.totalDevices || 0;
  123. this.onlineDevices = data.onlineDevices || 0;
  124. this.offlineDevices = data.offlineDevices || 0;
  125. this.alertDevices = data.alertDevices || 0;
  126. // 更新设备类型列表
  127. if (data.deviceList && data.deviceList.length > 0) {
  128. this.deviceList = data.deviceList;
  129. }
  130. console.log('设备概览数据加载成功');
  131. } else {
  132. this.handleApiError(res);
  133. }
  134. })
  135. .catch(error => {
  136. console.error('获取设备概览数据失败', error);
  137. uni.showToast({
  138. title: '获取设备数据失败',
  139. icon: 'none'
  140. });
  141. })
  142. .finally(() => {
  143. this.loading = false;
  144. uni.hideLoading();
  145. });
  146. },
  147. // 处理API错误
  148. handleApiError(res) {
  149. console.error('API错误', res);
  150. uni.showToast({
  151. title: res.data.msg || '获取数据失败',
  152. icon: 'none'
  153. });
  154. },
  155. // 跳转到对应设备列表页面
  156. navigateToDeviceList(type) {
  157. // 传递指定设备类型的在线、离线数量
  158. this.deviceList.forEach((item, index) => {
  159. if(item.type === type){
  160. this.typeOnline = item.online
  161. this.typeOffline = item.offline
  162. }
  163. });
  164. uni.navigateTo({
  165. url: `/pages/device/device-list/index?type=${type}&typeOnline=${this.typeOnline}&typeOffline=${this.typeOffline}`
  166. });
  167. },
  168. // 切换地块
  169. changePlot() {
  170. uni.navigateTo({
  171. url: '/pages/field-selector/index?callback=deviceCenter'
  172. });
  173. }
  174. },
  175. // 页面导航配置
  176. onShow() {
  177. this.initFieldInfo();
  178. this.fetchDeviceData();
  179. },
  180. // 下拉刷新
  181. onPullDownRefresh() {
  182. this.fetchDeviceData();
  183. setTimeout(() => {
  184. uni.stopPullDownRefresh();
  185. }, 1000);
  186. }
  187. }
  188. </script>
  189. <style scoped>
  190. .container {
  191. padding: 30rpx;
  192. background-color: #F9FCFA;
  193. min-height: 100vh;
  194. box-sizing: border-box;
  195. }
  196. /* 地块选择区域 */
  197. .plot-section {
  198. background-color: #FFFFFF;
  199. border-radius: 20rpx;
  200. padding: 26rpx 30rpx;
  201. margin-bottom: 30rpx;
  202. display: flex;
  203. align-items: center;
  204. justify-content: center;
  205. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.04);
  206. }
  207. .plot-text {
  208. font-size: 28rpx;
  209. color: #606060;
  210. }
  211. .plot-name {
  212. font-size: 32rpx;
  213. color: #333333;
  214. font-weight: 600;
  215. margin: 0 12rpx;
  216. }
  217. /* 顶部概览统计区域 */
  218. .overview-section {
  219. background-color: #F2F7F3;
  220. border-radius: 20rpx;
  221. padding: 36rpx 40rpx;
  222. margin-bottom: 34rpx;
  223. display: flex;
  224. justify-content: space-between;
  225. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.03);
  226. }
  227. .stat-item {
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. position: relative;
  232. }
  233. .stat-icon-wrapper {
  234. width: 90rpx;
  235. height: 90rpx;
  236. border-radius: 50%;
  237. background-color: #F0F0F0;
  238. display: flex;
  239. justify-content: center;
  240. align-items: center;
  241. margin-bottom: 14rpx;
  242. box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.04);
  243. }
  244. .stat-icon-wrapper.online {
  245. background: linear-gradient(135deg, #E8F5EA, #D6ECD8);
  246. }
  247. .stat-icon-wrapper.offline {
  248. background: linear-gradient(135deg, #FDEAEA, #FDDCDC);
  249. }
  250. .stat-icon-wrapper.alert {
  251. background: linear-gradient(135deg, #FFF6E5, #FFEFD0);
  252. }
  253. .stat-icon-img {
  254. width: 48rpx;
  255. height: 48rpx;
  256. display: block;
  257. }
  258. .stat-value {
  259. font-size: 38rpx;
  260. color: #333333;
  261. font-weight: 600;
  262. margin: 8rpx 0;
  263. line-height: 1.2;
  264. }
  265. .stat-value.online {
  266. color: #4CAF50;
  267. }
  268. .stat-value.offline {
  269. color: #F44336;
  270. }
  271. .stat-value.alert {
  272. color: #FF9800;
  273. }
  274. .stat-label {
  275. font-size: 24rpx;
  276. color: #888888;
  277. font-weight: 400;
  278. }
  279. /* 设备网格区域 */
  280. .device-grid {
  281. display: flex;
  282. flex-wrap: wrap;
  283. justify-content: space-between;
  284. width: 100%;
  285. }
  286. .device-card {
  287. width: 48%;
  288. border-radius: 24rpx; /* 加大卡片圆角 */
  289. background-color: #FFFFFF;
  290. box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05); /* 柔和阴影 */
  291. padding: 30rpx 0 24rpx 0;
  292. margin-bottom: 30rpx; /* 增加卡片间距 */
  293. position: relative;
  294. display: flex;
  295. flex-direction: column;
  296. align-items: center;
  297. transition: all 0.25s ease;
  298. }
  299. .device-card-hover {
  300. background-color: #f2fef6;
  301. box-shadow: 0 12rpx 32rpx rgba(59, 180, 74, 0.1);
  302. transform: translateY(-3rpx);
  303. }
  304. .device-card.has-alert {
  305. box-shadow: 0 10rpx 30rpx rgba(245, 108, 108, 0.08);
  306. }
  307. /* 告警角标 */
  308. .alert-badge {
  309. position: absolute;
  310. top: 16rpx; /* 6px */
  311. right: 16rpx; /* 6px */
  312. width: 40rpx; /* 20px */
  313. height: 40rpx; /* 20px */
  314. border-radius: 50%;
  315. background-color: #F56C6C;
  316. color: white;
  317. font-size: 24rpx; /* 12px */
  318. font-weight: 600;
  319. display: flex;
  320. align-items: center;
  321. justify-content: center;
  322. box-shadow: 0 4rpx 8rpx rgba(245, 108, 108, 0.3);
  323. z-index: 2;
  324. }
  325. /* 设备图标 */
  326. .device-icon-container {
  327. width: 72rpx; /* 36px */
  328. height: 72rpx; /* 36px */
  329. border-radius: 50%;
  330. background: linear-gradient(135deg, #66CC6A 0%, #3BB44A 100%);
  331. display: flex;
  332. align-items: center;
  333. justify-content: center;
  334. margin-bottom: 18rpx;
  335. box-shadow: 0 6rpx 12rpx rgba(59, 180, 74, 0.15);
  336. }
  337. .device-icon {
  338. width: 40rpx;
  339. height: 40rpx;
  340. filter: brightness(0) invert(1);
  341. }
  342. /* 设备名称 */
  343. .device-name {
  344. font-size: 32rpx; /* 16px */
  345. color: #333333;
  346. font-weight: 600;
  347. text-align: center;
  348. margin-bottom: 24rpx;
  349. padding: 0 20rpx;
  350. }
  351. /* 设备状态信息区域 */
  352. .device-status-container {
  353. width: 100%;
  354. display: flex;
  355. flex-direction: row;
  356. justify-content: center;
  357. padding: 16rpx 0;
  358. border-top: 1rpx solid #EEEEEE;
  359. }
  360. /* 状态信息项 */
  361. .status-info {
  362. display: flex;
  363. align-items: center;
  364. margin: 0 16rpx;
  365. }
  366. /* 状态指示点 */
  367. .status-dot {
  368. width: 8rpx;
  369. height: 8rpx;
  370. border-radius: 50%;
  371. margin-right: 6rpx;
  372. }
  373. .online-dot {
  374. background-color: #4CAF50;
  375. }
  376. .offline-dot {
  377. background-color: #F56C6C;
  378. }
  379. /* 状态文本 */
  380. .status-text {
  381. font-size: 26rpx;
  382. color: #999999;
  383. margin-right: 6rpx;
  384. }
  385. /* 状态数字 */
  386. .status-num {
  387. font-size: 26rpx;
  388. font-weight: 600;
  389. }
  390. .online-num {
  391. color: #4CAF50;
  392. }
  393. .offline-num {
  394. color: #F56C6C;
  395. }
  396. </style>