deviceData.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. <template>
  2. <view class="device-data-container">
  3. <!-- 顶部时间戳和图标区域 -->
  4. <view class="device-data-wraper">
  5. <view class="top-bar">
  6. <text class="timestamp">2025-12-28 08:00:00
  7. <u-icon name="reload" color="#0BBC58" style="margin-left: 12rpx"></u-icon>
  8. </text>
  9. <view class="icon-group">
  10. <view class="icon-item refresh-icon" @click="refreshData">
  11. <text class="iconfont">&#xe6aa;</text>
  12. </view>
  13. <view class="icon-item settings-icon" @click="openSettings">
  14. <text class="iconfont">&#xe634;</text>
  15. </view>
  16. <view class="icon-item info-icon">
  17. <text class="iconfont">&#xe604;</text>
  18. </view>
  19. </view>
  20. </view>
  21. <!-- 主要数据面板 -->
  22. <view class="main-data-panel">
  23. <view class="data-column-left">
  24. <view class="data-item">
  25. <text class="data-value">84%</text>
  26. <text class="data-label">电量</text>
  27. </view>
  28. <view class="data-item">
  29. <text class="data-value">时控</text>
  30. <text class="data-label">电压</text>
  31. </view>
  32. <view class="data-item">
  33. <text class="data-value temp-value">25°C</text>
  34. <text class="data-label">环境湿度</text>
  35. </view>
  36. <view class="data-item">
  37. <text class="data-value">70min</text>
  38. <text class="data-label">数据上传间隔</text>
  39. </view>
  40. </view>
  41. <view class="data-column-left">
  42. <view class="data-item">
  43. <text class="data-value">时控</text>
  44. <text class="data-label">定时模式</text>
  45. </view>
  46. <view class="data-item">
  47. <text class="data-value">220V</text>
  48. <text class="data-label">信号强度</text>
  49. </view>
  50. <view class="data-item">
  51. <text class="data-value">70%RH</text>
  52. <text class="data-label">环境湿度</text>
  53. </view>
  54. <view class="data-item">
  55. <text class="data-value">1.54.40(2000W)-2.11.1</text>
  56. <text class="data-label">设备版本</text>
  57. </view>
  58. </view>
  59. <view class="data-column-right">
  60. <view class="device-image-container">
  61. <view class="device-glow"></view>
  62. <image class="device-image" src="../assets/online.png" mode="aspectFit"></image>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 图表区域 -->
  68. <view class="chart-section">
  69. <view class="chart-header">
  70. <view class="chart-tabs">
  71. <view
  72. v-for="(tab, index) in chartTabs"
  73. :key="index"
  74. class="chart-tab-item"
  75. :class="{ active: activeChartTab === index }"
  76. @click="switchChartTab(index)"
  77. >
  78. {{ tab.name }}
  79. </view>
  80. </view>
  81. <view class="chart-dropdown">
  82. <text class="iconfont dropdown-icon">&#xe606;</text>
  83. </view>
  84. </view>
  85. <view class="chart-content">
  86. <view class="chart-canvas-container">
  87. <canvas
  88. canvas-id="tempChart"
  89. id="tempChart"
  90. class="chart-canvas"
  91. @touchstart="chartTouchStart"
  92. @touchmove="chartTouchMove"
  93. @touchend="chartTouchEnd"
  94. />
  95. </view>
  96. </view>
  97. </view>
  98. <!-- 历史数据表格 -->
  99. <view class="history-section">
  100. <view class="history-header">
  101. <text class="history-title">历史数据</text>
  102. </view>
  103. <view class="history-table">
  104. <view class="table-container">
  105. <!-- 固定列 -->
  106. <view class="fixed-column">
  107. <view class="fixed-header">
  108. <text class="header-cell fixed">上报时间</text>
  109. </view>
  110. <view class="fixed-body">
  111. <view
  112. v-for="(item, index) in historyData"
  113. :key="index"
  114. class="fixed-row"
  115. :class="{ even: index % 2 === 0 }"
  116. >
  117. <text class="body-cell fixed">{{ item.time }}</text>
  118. </view>
  119. </view>
  120. </view>
  121. <!-- 可滑动列 -->
  122. <view class="scrollable-column">
  123. <view class="scrollable-header">
  124. <text class="header-cell">环境温度(°C)</text>
  125. <text class="header-cell">环境湿度(%)</text>
  126. <text class="header-cell">环境湿度(%)</text>
  127. <text class="header-cell">环境湿度(%)</text>
  128. <text class="header-cell">环境湿度(%)</text>
  129. <text class="header-cell">环境湿度(%)</text>
  130. </view>
  131. <view class="scrollable-body">
  132. <view
  133. v-for="(item, index) in historyData"
  134. :key="index"
  135. class="scrollable-row"
  136. :class="{ even: index % 2 === 0 }"
  137. >
  138. <text class="body-cell">{{ item.temp }}</text>
  139. <text class="body-cell">{{ item.humidity }}</text>
  140. <text class="body-cell">{{ item.humidity }}</text>
  141. <text class="body-cell">{{ item.humidity }}</text>
  142. <text class="body-cell">{{ item.humidity }}</text>
  143. <text class="body-cell">{{ item.humidity }}</text>
  144. <text class="body-cell">{{ item.humidity }}</text>
  145. </view>
  146. </view>
  147. </view>
  148. </view>
  149. </view>
  150. <view class="pagination">
  151. <text class="pagination-btn prev-btn">上一页</text>
  152. <text class="pagination-info">1/6</text>
  153. <text class="pagination-btn next-btn">下一页</text>
  154. </view>
  155. </view>
  156. </view>
  157. </template>
  158. <script>
  159. import uCharts from '@/components/js_sdk/u-charts/u-charts/u-charts.js';
  160. let chartInstance = null;
  161. export default {
  162. name: 'DeviceData',
  163. data() {
  164. return {
  165. chartTabs: [
  166. { name: '温度', id: 'temp' },
  167. { name: '湿度', id: 'humidity' },
  168. { name: '加热仓温度', id: 'heatingTemp' },
  169. { name: '雨量累计', id: 'rainfall' }
  170. ],
  171. activeChartTab: 0,
  172. chartData: {
  173. categories: ['05-29/00:00', '05-29/00:00', '05-29/00:00', '05-29/00:00', '05-29/00:00', '05-29/00:00'],
  174. series: [
  175. {
  176. name: '大气温度',
  177. data: [2, 4, 6, 8, 10, 8]
  178. }
  179. ]
  180. },
  181. cWidth: 320,
  182. cHeight: 180,
  183. historyData: [
  184. { time: '2025-12-28 08:00', temp: '25', humidity: '70' },
  185. { time: '2025-12-28 07:00', temp: '24', humidity: '68' },
  186. { time: '2025-12-28 06:00', temp: '23', humidity: '65' },
  187. { time: '2025-12-28 05:00', temp: '22', humidity: '63' },
  188. { time: '2025-12-28 04:00', temp: '21', humidity: '60' },
  189. { time: '2025-12-28 03:00', temp: '20', humidity: '58' },
  190. { time: '2025-12-28 02:00', temp: '19', humidity: '55' }
  191. ],
  192. currentPage: 1,
  193. totalPages: 6
  194. };
  195. },
  196. mounted() {
  197. this.initChart();
  198. },
  199. methods: {
  200. openSettings(){
  201. this.$router.push({
  202. path: '/pages/cbd/deviceControl',
  203. query: {
  204. deviceId: this.deviceId
  205. }
  206. });
  207. },
  208. initChart() {
  209. this.cWidth = uni.upx2px(640);
  210. this.cHeight = uni.upx2px(360);
  211. this.$nextTick(() => {
  212. this.drawChart();
  213. });
  214. },
  215. drawChart() {
  216. const ctx = uni.createCanvasContext('tempChart', this);
  217. chartInstance = new uCharts({
  218. type: 'area',
  219. context: ctx,
  220. width: this.cWidth,
  221. height: this.cHeight,
  222. categories: this.chartData.categories,
  223. series: this.chartData.series,
  224. animation: true,
  225. background: '#FFFFFF',
  226. color: ['#0BBC58'],
  227. padding: [20, 10, 10, 0],
  228. dataLabel: false,
  229. dataPointShape: true,
  230. enableScroll: false,
  231. legend: {
  232. show: false
  233. },
  234. xAxis: {
  235. disableGrid: true,
  236. boundaryGap: 'center',
  237. fontSize: 10,
  238. fontColor: '#999999',
  239. scrollShow: false
  240. },
  241. yAxis: {
  242. gridType: 'dash',
  243. splitNumber: 4,
  244. min: 0,
  245. max: 12,
  246. fontSize: 10,
  247. fontColor: '#999999'
  248. },
  249. extra: {
  250. area: {
  251. type: 'curve',
  252. width: 2,
  253. addLine: true,
  254. gradient: true,
  255. activeType: 'hollow',
  256. linearType: 'custom',
  257. shadowColor: 'rgba(11, 188, 88, 0.3)',
  258. tension: 0.4
  259. }
  260. }
  261. });
  262. },
  263. switchChartTab(index) {
  264. this.activeChartTab = index;
  265. // 根据不同标签切换数据
  266. this.$nextTick(() => {
  267. this.drawChart();
  268. });
  269. },
  270. chartTouchStart(e) {
  271. if (chartInstance) {
  272. chartInstance.scrollStart(e);
  273. }
  274. },
  275. chartTouchMove(e) {
  276. if (chartInstance) {
  277. chartInstance.scroll(e);
  278. }
  279. },
  280. chartTouchEnd(e) {
  281. if (chartInstance) {
  282. chartInstance.scrollEnd(e);
  283. chartInstance.showToolTip(e);
  284. }
  285. }
  286. }
  287. };
  288. </script>
  289. <style lang="scss" scoped>
  290. .device-data-container {
  291. width: 100%;
  292. min-height: 100vh;
  293. }
  294. .device-data-wraper{
  295. padding: 16rpx;
  296. background: #ffffff;
  297. border-radius: 16rpx;
  298. }
  299. /* 顶部时间戳和图标区域 */
  300. .top-bar {
  301. display: flex;
  302. justify-content: space-between;
  303. align-items: center;
  304. padding: 16rpx 0;
  305. .timestamp {
  306. font-size: 28rpx;
  307. font-family: 'Source Han Sans CN VF', sans-serif;
  308. font-weight: 400;
  309. color: #999999;
  310. }
  311. .icon-group {
  312. display: flex;
  313. gap: 24rpx;
  314. .icon-item {
  315. width: 48rpx;
  316. height: 48rpx;
  317. display: flex;
  318. align-items: center;
  319. justify-content: center;
  320. border-radius: 50%;
  321. .iconfont {
  322. font-size: 36rpx;
  323. }
  324. &.refresh-icon .iconfont {
  325. color: #0BBC58;
  326. }
  327. &.settings-icon .iconfont {
  328. color: #999999;
  329. }
  330. &.info-icon .iconfont {
  331. color: #999999;
  332. }
  333. }
  334. }
  335. }
  336. /* 主要数据面板 */
  337. .main-data-panel {
  338. display: flex;
  339. background: #FFFFFF;
  340. border-radius: 16rpx;
  341. margin-bottom: 16rpx;
  342. .data-column-left {
  343. flex: 1;
  344. display: flex;
  345. flex-direction: column;
  346. gap: 24rpx;
  347. .data-item {
  348. display: flex;
  349. flex-direction: column;
  350. gap: 8rpx;
  351. .data-label {
  352. font-size: 24rpx;
  353. font-family: 'Source Han Sans CN VF', sans-serif;
  354. font-weight: 400;
  355. color: #999999;
  356. }
  357. .data-value {
  358. font-size: 24rpx;
  359. font-family: 'Source Han Sans CN VF', sans-serif;
  360. font-weight: 700;
  361. color: #042118;
  362. &.temp-value {
  363. color: #FF6B6B;
  364. }
  365. }
  366. .data-unit {
  367. font-size: 24rpx;
  368. font-family: 'Source Han Sans CN VF', sans-serif;
  369. font-weight: 400;
  370. color: #999999;
  371. }
  372. }
  373. }
  374. .data-column-right {
  375. flex: 1;
  376. display: flex;
  377. flex-direction: column;
  378. align-items: center;
  379. gap: 16rpx;
  380. .device-image-container {
  381. position: relative;
  382. width: 200rpx;
  383. height: 200rpx;
  384. display: flex;
  385. align-items: center;
  386. justify-content: center;
  387. .device-glow {
  388. position: absolute;
  389. width: 180rpx;
  390. height: 180rpx;
  391. background: radial-gradient(circle, rgba(11, 188, 88, 0.3) 0%, rgba(11, 188, 88, 0) 70%);
  392. border-radius: 50%;
  393. }
  394. .device-image {
  395. position: relative;
  396. width: 160rpx;
  397. height: 160rpx;
  398. z-index: 1;
  399. }
  400. }
  401. .device-info {
  402. display: flex;
  403. flex-direction: column;
  404. gap: 12rpx;
  405. width: 100%;
  406. .info-row {
  407. display: flex;
  408. justify-content: space-between;
  409. align-items: center;
  410. .info-label {
  411. font-size: 24rpx;
  412. font-family: 'Source Han Sans CN VF', sans-serif;
  413. font-weight: 400;
  414. color: #999999;
  415. }
  416. .info-value {
  417. font-size: 36rpx;
  418. font-family: 'Source Han Sans CN VF', sans-serif;
  419. font-weight: 700;
  420. color: #042118;
  421. }
  422. .info-version {
  423. font-size: 24rpx;
  424. font-family: 'Source Han Sans CN VF', sans-serif;
  425. font-weight: 400;
  426. color: #999999;
  427. }
  428. .info-label-small {
  429. font-size: 24rpx;
  430. font-family: 'Source Han Sans CN VF', sans-serif;
  431. font-weight: 400;
  432. color: #999999;
  433. }
  434. }
  435. }
  436. }
  437. }
  438. /* 图表区域 */
  439. .chart-section {
  440. background: #FFFFFF;
  441. border-radius: 16rpx;
  442. padding: 24rpx 32rpx 32rpx;
  443. margin: 24rpx 0;
  444. .chart-header {
  445. display: flex;
  446. justify-content: space-between;
  447. align-items: center;
  448. margin-bottom: 24rpx;
  449. .chart-tabs {
  450. display: flex;
  451. gap: 32rpx;
  452. overflow-x: auto;
  453. white-space: nowrap;
  454. .chart-tab-item {
  455. font-size: 28rpx;
  456. font-family: 'Source Han Sans CN VF', sans-serif;
  457. font-weight: 500;
  458. color: #999999;
  459. position: relative;
  460. padding-bottom: 8rpx;
  461. transition: all 0.3s;
  462. &.active {
  463. color: #0BBC58;
  464. font-weight: 700;
  465. &::after {
  466. content: '';
  467. position: absolute;
  468. bottom: 0;
  469. left: 0;
  470. right: 0;
  471. height: 4rpx;
  472. background: #0BBC58;
  473. border-radius: 2rpx;
  474. }
  475. }
  476. }
  477. }
  478. .chart-dropdown {
  479. .dropdown-icon {
  480. font-size: 28rpx;
  481. color: #999999;
  482. }
  483. }
  484. }
  485. .chart-content {
  486. .chart-legend {
  487. display: flex;
  488. justify-content: space-between;
  489. align-items: center;
  490. margin-bottom: 16rpx;
  491. .legend-item {
  492. display: flex;
  493. align-items: center;
  494. gap: 8rpx;
  495. .legend-dot {
  496. width: 16rpx;
  497. height: 16rpx;
  498. background: #0BBC58;
  499. border-radius: 50%;
  500. }
  501. .legend-text {
  502. font-size: 24rpx;
  503. font-family: 'Source Han Sans CN VF', sans-serif;
  504. font-weight: 400;
  505. color: #042118;
  506. }
  507. }
  508. .legend-average {
  509. .average-text {
  510. font-size: 24rpx;
  511. font-family: 'Source Han Sans CN VF', sans-serif;
  512. font-weight: 400;
  513. color: #999999;
  514. }
  515. }
  516. }
  517. .chart-canvas-container {
  518. width: 100%;
  519. height: 360rpx;
  520. .chart-canvas {
  521. width: 100%;
  522. height: 100%;
  523. }
  524. }
  525. }
  526. }
  527. /* 历史数据表格 */
  528. .history-section {
  529. background: #FFFFFF;
  530. border-radius: 16rpx;
  531. padding: 24rpx 32rpx 32rpx;
  532. .history-header {
  533. margin-bottom: 24rpx;
  534. .history-title {
  535. font-size: 32rpx;
  536. font-family: 'Source Han Sans CN VF', sans-serif;
  537. font-weight: 700;
  538. color: #042118;
  539. }
  540. }
  541. .history-table {
  542. margin-bottom: 24rpx;
  543. .table-container {
  544. display: flex;
  545. position: relative;
  546. /* 固定列 */
  547. .fixed-column {
  548. width: 180rpx;
  549. position: relative;
  550. z-index: 2;
  551. background: #FFFFFF;
  552. .fixed-header {
  553. border-bottom: 2rpx solid #F0F0F0;
  554. padding: 16rpx 0;
  555. .header-cell.fixed {
  556. font-size: 24rpx;
  557. font-family: 'Source Han Sans CN VF', sans-serif;
  558. font-weight: 500;
  559. color: #666666;
  560. text-align: left;
  561. padding-left: 0;
  562. }
  563. }
  564. .fixed-body {
  565. .fixed-row {
  566. padding: 16rpx 0;
  567. border-bottom: 1rpx solid #F5F5F5;
  568. height: 80rpx;
  569. display: flex;
  570. align-items: center;
  571. &.even {
  572. background: #FAFAFA;
  573. }
  574. .body-cell.fixed {
  575. font-size: 24rpx;
  576. font-family: 'Source Han Sans CN VF', sans-serif;
  577. font-weight: 400;
  578. color: #042118;
  579. text-align: left;
  580. padding-left: 0;
  581. }
  582. }
  583. }
  584. }
  585. /* 可滑动列 */
  586. .scrollable-column {
  587. flex: 1;
  588. overflow-x: auto;
  589. white-space: nowrap;
  590. /* 隐藏滚动条 */
  591. &::-webkit-scrollbar {
  592. display: none;
  593. }
  594. scrollbar-width: none;
  595. .scrollable-header {
  596. display: flex;
  597. border-bottom: 2rpx solid #F0F0F0;
  598. padding: 20rpx 0;
  599. .header-cell {
  600. min-width: 140rpx;
  601. font-size: 24rpx;
  602. font-family: 'Source Han Sans CN VF', sans-serif;
  603. font-weight: 500;
  604. color: #666666;
  605. text-align: center;
  606. // 超出隐藏
  607. overflow: hidden;
  608. text-overflow: ellipsis;
  609. white-space: nowrap;
  610. }
  611. }
  612. .scrollable-body {
  613. .scrollable-row {
  614. display: flex;
  615. padding: 16rpx 0;
  616. border-bottom: 1rpx solid #F5F5F5;
  617. height: 80rpx;
  618. align-items: center;
  619. &.even {
  620. background: #FAFAFA;
  621. }
  622. .body-cell {
  623. min-width: 120rpx;
  624. font-size: 24rpx;
  625. font-family: 'Source Han Sans CN VF', sans-serif;
  626. font-weight: 400;
  627. color: #042118;
  628. text-align: center;
  629. }
  630. }
  631. }
  632. }
  633. }
  634. }
  635. .pagination {
  636. display: flex;
  637. justify-content: space-between;
  638. align-items: center;
  639. .pagination-btn {
  640. font-size: 24rpx;
  641. font-family: 'Source Han Sans CN VF', sans-serif;
  642. font-weight: 400;
  643. padding: 6rpx 18rpx;
  644. border-radius: 8rpx;
  645. transition: all 0.3s;
  646. &.prev-btn {
  647. color: #656565;
  648. border: 1px solid #E4E7ED;
  649. }
  650. &.next-btn {
  651. color: #0BBC58;
  652. border: 1px solid #0BBC58;
  653. }
  654. }
  655. .pagination-info {
  656. font-size: 28rpx;
  657. font-family: 'Source Han Sans CN VF', sans-serif;
  658. font-weight: 400;
  659. color: #999999;
  660. }
  661. }
  662. }
  663. </style>