deviceData.vue 19 KB

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