equipment-data.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <hc-drawer v-model="isShow" to-id="hc-main-box">
  3. <div class="hc-tentative-acquisition-humidity-equipment-info">
  4. <div class="data-statistics">
  5. <hc-body>
  6. <div class="equipment-list-data-item temperature hc-flex">
  7. <div class="icon-box">
  8. <hc-icon name="temp-hot" />
  9. </div>
  10. <div class="content">
  11. <div class="name">温度</div>
  12. <div class="num">{{ deviceDataInfo.temperature }}</div>
  13. <div class="time">记录时间:{{ deviceDataInfo.time }}</div>
  14. </div>
  15. </div>
  16. <div class="equipment-list-data-item humidity hc-flex">
  17. <div class="icon-box">
  18. <hc-icon name="water-percent" />
  19. </div>
  20. <div class="content">
  21. <div class="name">湿度</div>
  22. <div class="num">{{ deviceDataInfo.humidity }}</div>
  23. <div class="time">记录时间:{{ deviceDataInfo.time }}</div>
  24. </div>
  25. </div>
  26. <div class="equipment-list-data-echart">
  27. <hc-charts :option="setChartsOption" />
  28. </div>
  29. </hc-body>
  30. </div>
  31. <div class="data-table">
  32. <hc-card>
  33. <template #header>
  34. <div class="mr-14px w-410px">
  35. <el-date-picker
  36. v-model="dateTimeArr" type="datetimerange" :shortcuts="shortcuts" class="w-full!"
  37. value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
  38. range-separator="至" start-placeholder="开始日期时间" end-placeholder="结束日期时间"
  39. />
  40. </div>
  41. <el-button type="primary" @click="searchClick">搜索</el-button>
  42. </template>
  43. <template #extra>
  44. <el-button @click="toBackClick">
  45. <hc-icon name="arrow-go-back" />
  46. <span>返回</span>
  47. </el-button>
  48. </template>
  49. <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" :is-index="false" :is-current-row="false" />
  50. <template #action>
  51. <hc-pages :pages="searchForm" @change="pageChange" />
  52. </template>
  53. </hc-card>
  54. </div>
  55. </div>
  56. </hc-drawer>
  57. </template>
  58. <script setup>
  59. import { ref, watch } from 'vue'
  60. import { getArrValue, getObjValue, isNullES } from 'js-fast-way'
  61. import { useClick } from 'hc-vue3-ui'
  62. import dayjs from 'dayjs'
  63. import mainApi from '~api/tentative/acquisition/humidity'
  64. const props = defineProps({
  65. data: {
  66. type: Object,
  67. default: () => ({}),
  68. },
  69. })
  70. //双向绑定
  71. const isShow = defineModel('modelValue', {
  72. default: false,
  73. })
  74. //监听可否编辑
  75. const dataInfo = ref(props.data)
  76. watch(() => props.data, (data) => {
  77. dataInfo.value = getObjValue(data)
  78. }, { immediate: true, deep: true })
  79. //监听显示
  80. watch(isShow, (val) => {
  81. if (val) getInfoData()
  82. })
  83. //获取数据详情
  84. const getInfoData = async () => {
  85. await getDeviceList()
  86. setChartsData()
  87. }
  88. //获取设备列表
  89. const deviceDataInfo = ref({})
  90. const getDeviceList = async () => {
  91. const { token, deviceAddr } = getObjValue(dataInfo.value)
  92. if (isNullES(token) || isNullES(deviceAddr)) {
  93. deviceDataInfo.value = {}
  94. return
  95. }
  96. let temperature = '0℃', humidity = '0%'
  97. const { data } = await mainApi.getRealTimeDataByDeviceAddr(token, deviceAddr)
  98. //数据是否存在
  99. const arr = getArrValue(data)
  100. if (arr.length <= 0) {
  101. setDeviceData({ temperature, humidity })
  102. return
  103. }
  104. //子级数据是否存在
  105. const dataItem = getArrValue(arr[0].dataItem)
  106. if (dataItem.length <= 0) {
  107. setDeviceData({ temperature, humidity })
  108. return
  109. }
  110. //最子级数据判断
  111. const registerItem = getArrValue(dataItem[0].registerItem)
  112. if (registerItem.length <= 0) {
  113. setDeviceData({ temperature, humidity })
  114. return
  115. }
  116. //最子级数据
  117. for (let i = 0; i < registerItem.length; i++) {
  118. if (registerItem[i].registerName === '温度') {
  119. temperature = registerItem[i].data + registerItem[i].unit
  120. }
  121. if (registerItem[i].registerName === '湿度') {
  122. humidity = registerItem[i].data + registerItem[i].unit
  123. }
  124. }
  125. //设置数据
  126. setDeviceData({ temperature, humidity })
  127. }
  128. //设置空数据
  129. const setDeviceData = ({ temperature, humidity }) => {
  130. const currentDateTime = new dayjs().format('YYYY年MM月DD日 HH:mm:ss')
  131. deviceDataInfo.value = {
  132. temperature: temperature,
  133. humidity: humidity,
  134. time: currentDateTime,
  135. }
  136. }
  137. //搜索表单
  138. const searchForm = ref({ nodeId: -1, startTime: '', endTime: '', deviceAddr: null, current: 1, size: 20, total: 0 })
  139. const searchClick = () => {
  140. console.log(searchForm.value)
  141. console.log(dateTimeArr.value)
  142. }
  143. //分页被点击
  144. const pageChange = ({ current, size }) => {
  145. searchForm.value.current = current
  146. searchForm.value.size = size
  147. getTableData()
  148. }
  149. //历史记录表格
  150. const tableColumn = [
  151. { key: 'name', name: '设备地址' },
  152. { key: 'text', name: '温度' },
  153. { key: 'color', name: '湿度' },
  154. { key: 'time', name: '记录时间' },
  155. ]
  156. const tableData = ref([])
  157. //获取历史记录数据
  158. const tableLoading = ref(false)
  159. const getTableData = async () => {
  160. }
  161. //日期时间选择
  162. const dateTimeArr = ref('')
  163. const shortcuts = [
  164. {
  165. text: '最近1小时',
  166. value: () => {
  167. const end = new Date()
  168. const start = new Date(end - 3600 * 1000) // 1小时前
  169. return [start, end]
  170. },
  171. },
  172. {
  173. text: '今天',
  174. value: () => {
  175. const end = new Date()
  176. const start = new Date(end.setHours(0, 0, 0, 0))
  177. return [start, new Date()]
  178. },
  179. },
  180. {
  181. text: '昨天',
  182. value: () => {
  183. const end = new Date()
  184. end.setDate(end.getDate() - 1)
  185. const start = new Date(end.setHours(0, 0, 0, 0))
  186. return [start, new Date(start.getTime() + 24 * 3600 * 1000 - 1)]
  187. },
  188. },
  189. {
  190. text: '最近7天',
  191. value: () => {
  192. const end = new Date()
  193. const start = new Date(end - 7 * 24 * 3600 * 1000)
  194. return [start, end]
  195. },
  196. },
  197. {
  198. text: '最近30天',
  199. value: () => {
  200. const end = new Date()
  201. const start = new Date(end - 30 * 24 * 3600 * 1000)
  202. return [start, end]
  203. },
  204. },
  205. {
  206. text: '本月',
  207. value: () => {
  208. const end = new Date()
  209. const start = new Date(end.getFullYear(), end.getMonth(), 1)
  210. return [start, end]
  211. },
  212. },
  213. {
  214. text: '上个月',
  215. value: () => {
  216. const end = new Date()
  217. const start = new Date(end.getFullYear(), end.getMonth() - 1, 1)
  218. const lastDayOfLastMonth = new Date(end.getFullYear(), end.getMonth(), 0)
  219. return [start, lastDayOfLastMonth]
  220. },
  221. },
  222. ]
  223. //图表数据
  224. const setChartsOption = ref({})
  225. const setChartsData = () => {
  226. const data = [
  227. { time: '00:00:00', temperature: 27, humidity: 50 },
  228. { time: '00:30:00', temperature: 28.5, humidity: 41 },
  229. { time: '01:00:00', temperature: 32, humidity: 60 },
  230. { time: '01:30:00', temperature: 27, humidity: 48 },
  231. { time: '02:00:00', temperature: 28, humidity: 40 },
  232. { time: '02:30:00', temperature: 29.5, humidity: 55 },
  233. { time: '03:00:00', temperature: 30.5, humidity: 48 },
  234. { time: '03:30:00', temperature: 30, humidity: 61 },
  235. { time: '04:00:00', temperature: 27.2, humidity: 54 },
  236. ]
  237. setChartsOption.value = {
  238. tooltip: {
  239. trigger: 'axis',
  240. axisPointer: {
  241. type: 'cross',
  242. },
  243. formatter: function (params) {
  244. let result = params[0].axisValue + '<br/>'
  245. params.forEach(function (item) {
  246. let unit = item.seriesName === '温度' ? '°C' : '%'
  247. result += item.marker + ' ' + item.seriesName + ': ' + item.value + unit + '<br/>'
  248. })
  249. return result
  250. },
  251. },
  252. legend: {
  253. data: ['温度', '湿度'],
  254. },
  255. xAxis: {
  256. type: 'category',
  257. data: data.map(item => item.time),
  258. axisLine: {
  259. onZero: false,
  260. },
  261. },
  262. yAxis: [
  263. {
  264. type: 'value',
  265. name: '温度(°C)',
  266. min: 23,
  267. max: 33,
  268. interval: 2,
  269. position: 'left',
  270. axisLabel: {
  271. formatter: '{value}°C',
  272. },
  273. },
  274. {
  275. type: 'value',
  276. name: '湿度(%)',
  277. min: 20,
  278. max: 70,
  279. interval: 10,
  280. position: 'right',
  281. axisLabel: {
  282. formatter: '{value}%',
  283. },
  284. },
  285. ],
  286. series: [
  287. {
  288. name: '温度',
  289. type: 'line',
  290. yAxisIndex: 0,
  291. data: data.map(item => item.temperature),
  292. smooth: true,
  293. lineStyle: {
  294. color: '#1D4590',
  295. },
  296. itemStyle: {
  297. color: '#1D4590',
  298. },
  299. },
  300. {
  301. name: '湿度',
  302. type: 'line',
  303. yAxisIndex: 1,
  304. data: data.map(item => item.humidity),
  305. smooth: true,
  306. lineStyle: {
  307. color: '#91CC75',
  308. },
  309. itemStyle: {
  310. color: '#91CC75',
  311. },
  312. },
  313. ],
  314. grid: {
  315. left: '3%',
  316. right: '4%',
  317. bottom: '3%',
  318. containLabel: true,
  319. },
  320. }
  321. }
  322. //返回
  323. const toBackClick = () => {
  324. isShow.value = false
  325. tableData.value = []
  326. dateTimeArr.value = ''
  327. setChartsOption.value = {}
  328. }
  329. </script>
  330. <style lang="scss">
  331. @import "~src/styles/tentative/acquisition/equipment";
  332. </style>