index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="page">
  3. <view ref="header" class="detail-header">
  4. <uni-row>
  5. <uni-col :span="12" class="flex-row align-center">
  6. <view class="detail-label">{{ $t('realTimeData.detail.assetCode') }}</view>
  7. <view>{{ info.deviceCode }}</view>
  8. </uni-col>
  9. <uni-col :span="12" class="flex-row align-center">
  10. <view class="detail-label">{{ $t('realTimeData.detail.isOnline') }}</view>
  11. <view v-if="info.ifInline === 3" class="flex-row align-center" style="color: #9CFFE6">
  12. <view class="dot-green" />
  13. {{ $t('realTimeData.status.online') }}
  14. </view>
  15. <view v-else class="flex-row align-center" style="margin-left: 10px; color: #FB0000">
  16. <view class="dot-red" />
  17. {{ $t('realTimeData.status.offline') }}
  18. </view>
  19. </uni-col>
  20. </uni-row>
  21. <uni-row style="margin-top: 10px">
  22. <uni-col :span="24" class="flex-row">
  23. <view class="detail-label">{{ $t('realTimeData.detail.deviceType') }}</view>
  24. <view style="flex: 1">{{ info.deviceName }}</view>
  25. </uni-col>
  26. <!-- <uni-col :span="12" class="flex-row align-center">-->
  27. <!-- <view class="detail-label">{{ $t('realTimeData.detail.lastUpdateTime') }}</view>-->
  28. <!-- <view>{{ dayjs(info.lastInlineTime).format('HH:mm:ss') }}</view>-->
  29. <!-- </uni-col>-->
  30. </uni-row>
  31. <uni-row style="margin-top: 10px">
  32. <uni-col :span="24" class="flex-row">
  33. <view class="detail-label">{{ $t('realTimeData.detail.lastUpdateTime') }}</view>
  34. <view>{{ info.lastInlineTime ? dayjs(info.lastInlineTime).format('YYYY-MM-DD HH:mm:ss') : '--' }}</view>
  35. </uni-col>
  36. </uni-row>
  37. </view>
  38. <scroll-view scroll-y="true" style="margin-top: 10px; height: calc(100% - 150px)">
  39. <view
  40. v-for="item of list"
  41. class="item"
  42. :class="clickItem.identifier === item.identifier ? 'selected' : undefined"
  43. :key="item.id"
  44. @click="loadChartData(item)"
  45. >
  46. <view>{{ item.modelName }}</view>
  47. <view>{{ item.value }}</view>
  48. </view>
  49. <uni-card>
  50. <uni-section :title="(clickItem?.modelName || '') + $t('realTimeData.detail.chartTitle')" @click="viewChart">
  51. <template #right>
  52. <image src="~@/static/realTimeData/expand.svg" style="width: 16px; height: 16px" />
  53. </template>
  54. </uni-section>
  55. <view class="charts-box">
  56. <qiun-data-charts
  57. type="area"
  58. :ontouch="true"
  59. :opts="opts"
  60. :chartData="chartData"
  61. />
  62. </view>
  63. </uni-card>
  64. </scroll-view>
  65. </view>
  66. </template>
  67. <script setup>
  68. import { onLoad } from '@dcloudio/uni-app'
  69. import { getDeviceRealTimeChartData, getDeviceRealTimeDataDetail } from "@/api/realTimeData"
  70. import { onMounted, reactive, ref } from "vue"
  71. import dayjs from "dayjs";
  72. const info = ref()
  73. const list = ref([])
  74. const clickItem = ref()
  75. const opts = reactive({
  76. color: ['#0876C3'],
  77. padding: [15, 0, 0, 0],
  78. legend: {
  79. show: false,
  80. },
  81. enableScroll: true,
  82. xAxis: {
  83. disableGrid: true,
  84. rotateLabel: true, // 旋转x轴文字
  85. rotateAngle: 90, // x轴文字旋转角度
  86. enableScroll: true,
  87. itemCount: 10,
  88. marginTop: 5,
  89. fontColor: '#666666',
  90. fontSize: 12,
  91. },
  92. yAxis: {
  93. gridColor: '#BABABA',
  94. gridType: "dash",
  95. dashLength: 10,
  96. data: [{
  97. fontSize: 12,
  98. fontColor: '#666666',
  99. }]
  100. },
  101. extra: {
  102. area: {
  103. type: "curve",
  104. opacity: 0.8, // 区域图透明度
  105. addLine: true,
  106. width: 2,
  107. gradient: true,
  108. activeType: "hollow"
  109. }
  110. }
  111. })
  112. const chartData = reactive({
  113. categories: [],
  114. series: [],
  115. })
  116. // 跳转查看横版图表
  117. const viewChart = () => {
  118. uni.navigateTo({ url: `/pages/realTimeData/chart/index?deviceCode=${info.value.deviceCode}&type=${clickItem.value.identifier}&name=${clickItem.value.modelName}` })
  119. }
  120. // 加载图表数据,并转换格式
  121. const loadChartData = async (item) => {
  122. clickItem.value = item
  123. const source = (await getDeviceRealTimeChartData(info.value.deviceCode, item.identifier, {
  124. // beginTime: dayjs().add(-10, 'minute').format('YYYY-MM-DD HH:mm:ss'),
  125. beginTime: dayjs().add(-1, 'day').format('YYYY-MM-DD HH:mm:ss'), // 获取过去一天的数据 08/04修改
  126. endTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  127. })).data
  128. // 1. 提取x轴时间
  129. const categories = source
  130. .map(item => dayjs(item.timestamp).format('YYYY-MM-DD HH:mm:ss'))
  131. // .sort((a, b) => new Date(a) - new Date(b)); // 按时间升序排列
  132. // console.log("🚀 ~ loadChartData ~ categories:", categories)
  133. // 2. 提取y轴数据
  134. const seriesData = source.map(item => item?.value ? item.value.toFixed(2) : 0); // 确保数值为数字,避免 NaN
  135. // console.log("🚀 ~ loadChartData ~ seriesData:", seriesData)
  136. chartData.categories = categories
  137. chartData.series = [{
  138. name: item.modelName,
  139. data: seriesData,
  140. textColor: '#333333',
  141. textSize: 10,
  142. }]
  143. }
  144. onLoad(async (params) => {
  145. // 根据导航传递的id加载设备详情
  146. info.value = JSON.parse(params.info)
  147. const id = info.value.id
  148. const data = (await getDeviceRealTimeDataDetail(id)).data
  149. // 按 modelOrder 降序排序
  150. data.sort((a, b) => b.modelOrder - a.modelOrder)
  151. // 提取“累计运行时间”和其余项
  152. //const cumulativeItem = data.filter(item => item.modelName === '累计运行时间')
  153. // const otherItems = data.filter(item => item.modelName !== '累计运行时间')
  154. // 合并:累计运行时间在前
  155. // list.value = [...cumulativeItem, ...otherItems]
  156. list.value = data
  157. if (list.value.length > 0) {
  158. await loadChartData(list.value[0])
  159. }
  160. })
  161. // 当顶部内容超过一行时,缩小滚动部分的高度
  162. const style = ref({
  163. transform: 'translateY(92px)',
  164. height: 'calc(100% - 102px)'
  165. })
  166. const header = ref()
  167. onMounted(() => {
  168. if (header.value.$el.offsetHeight > 130) {
  169. style.value = {
  170. transform: 'translateY(112px)',
  171. height: 'calc(100% - 122px)'
  172. }
  173. }
  174. })
  175. </script>
  176. <style scoped lang="scss">
  177. .page {
  178. width: 100%;
  179. height: 100%;
  180. padding: 0;
  181. }
  182. .detail-header {
  183. width: 100%;
  184. padding: 20px;
  185. background-color: #004098;
  186. color: white;
  187. font-size: 16px;
  188. font-weight: 500;
  189. // position: fixed;
  190. }
  191. .item {
  192. display: flex;
  193. flex-direction: row;
  194. justify-content: space-between;
  195. align-items: center;
  196. background: white;
  197. border-radius: 5px;
  198. padding: 12px 20px;
  199. font-size: 14px;
  200. color: #333333;
  201. margin: 0 10px 10px 10px;
  202. }
  203. .dot-red {
  204. width: 6px;
  205. height: 6px;
  206. background: #FB0000;
  207. border-radius: 3px;
  208. margin-right: 5px;
  209. }
  210. .dot-green {
  211. width: 6px;
  212. height: 6px;
  213. background: #9CFFE6;
  214. border-radius: 3px;
  215. margin-right: 5px;
  216. }
  217. :deep(.uni-card) {
  218. padding: 0 !important;
  219. .uni-section-header {
  220. padding-right: 30px;
  221. }
  222. .uni-section__content-title {
  223. font-size: 16px !important;
  224. color: #333333 !important;
  225. font-weight: 600;
  226. }
  227. }
  228. .charts-box {
  229. width: 100%;
  230. height: 300px;
  231. }
  232. .detail-label {
  233. width: 80px !important;
  234. }
  235. .selected {
  236. border: 2px solid #0087D3;
  237. border-radius: 5px;
  238. padding: 10px 18px;
  239. }
  240. </style>