HistoryLine.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="history-line">
  3. <!-- 控制设备下拉选择 -->
  4. <div class="device-select-row">
  5. <!-- <span class="select-label">控制设备</span> -->
  6. <a-select v-model:value="currentDevice" class="device-select" :options="deviceOptions" placeholder="请选择设备"
  7. :get-popup-container="(trigger) => trigger.parentNode" @change="onDeviceChange" />
  8. </div>
  9. <div class="device-row-line">
  10. <CustomChart :chart-config="chartConfig" :chart-data="chartData"></CustomChart>
  11. </div>
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import { ref, watch, type PropType } from 'vue';
  16. import CustomChart from './CustomChart.vue';
  17. import { chartConfig } from '../hsqHome.data'
  18. import { listdays } from '../hsqHome.api'
  19. import dayjs from 'dayjs';
  20. const DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss'
  21. let props = defineProps({
  22. deviceOptions: {
  23. type: Array as PropType<any[]>,
  24. default: () => []
  25. }
  26. })
  27. /** 当前选中的设备 value */
  28. const currentDevice = ref('')
  29. /** 当前选中的设备类型 */
  30. const deviceType = ref('')
  31. /** 实时温度曲线图表数据 */
  32. let chartData = ref<any[]>([])
  33. /** 时间范围:[开始时间, 结束时间],默认近 7 天至当前时间 */
  34. /** 时间范围:[开始时间, 结束时间],默认当天 0 点至当前时间 */
  35. const timeRange = ref<[string, string]>([
  36. dayjs().startOf('day').format(DATE_FORMAT),
  37. dayjs().format(DATE_FORMAT),
  38. ])
  39. /** 选择设备,触发 deviceChange 事件 */
  40. function onDeviceChange(value: string) {
  41. const item = props.deviceOptions.find((d) => d.value === value)
  42. currentDevice.value = value
  43. deviceType.value = item?.devicetype
  44. getChartData()
  45. // if (item) {
  46. // // emit('deviceChange', item)
  47. // }
  48. }
  49. /** 获取历史温度曲线数据 */
  50. async function getChartData() {
  51. let res = await listdays({ ttime_begin: timeRange.value?.[0], ttime_end: timeRange.value?.[1],skip: '8',gdeviceids: currentDevice.value,pageNo: 1, pageSize: 1000, strtype: deviceType.value, })
  52. console.log(res, '历史温度曲线数据')
  53. if (res.datalist.records.length) {
  54. chartData.value = res.datalist.records.map((v,index) => ({
  55. pos: v.ttime,
  56. value:parseFloat(v.readData.avg)
  57. }))
  58. }
  59. }
  60. watch(() => props.deviceOptions, (newVal) => {
  61. if (newVal.length > 0) {
  62. currentDevice.value = newVal[0].value
  63. deviceType.value = newVal[0].devicetype
  64. getChartData()
  65. }
  66. }, { immediate: true })
  67. </script>
  68. <style lang="less" scoped>
  69. @import '/@/design/theme.less';
  70. .history-line {
  71. position: relative;
  72. width: 100%;
  73. height: 100%;
  74. padding: 10px;
  75. box-sizing: border-box;
  76. .device-select-row {
  77. display: flex;
  78. align-items: center;
  79. gap: 5px;
  80. margin-bottom: 5px;
  81. flex-shrink: 0;
  82. .select-label {
  83. white-space: nowrap;
  84. color: #fff;
  85. }
  86. .device-select {
  87. flex: 1;
  88. min-width: 0;
  89. }
  90. }
  91. .device-row-line {
  92. width: 100%;
  93. height: calc(100% - 35px);
  94. }
  95. :deep(.zxm-select) {
  96. width: 100%;
  97. height: 28px;
  98. }
  99. :deep(.zxm-select-selector) {
  100. height: 28px !important;
  101. padding: 0 24px 0 11px !important;
  102. border: 1px solid #3ae1ff !important;
  103. background-color: rgba(16, 64, 100, 0.85) !important;
  104. box-shadow: 0 0 6px rgba(58, 225, 255, 0.25);
  105. color: #fff !important;
  106. }
  107. :deep(.zxm-select-selection-search) {
  108. inset-inline-start: 11px !important;
  109. }
  110. :deep(.zxm-select-selection-item),
  111. :deep(.zxm-select-selection-placeholder) {
  112. line-height: 26px !important;
  113. font-size: 14px;
  114. color: #fff !important;
  115. }
  116. :deep(.zxm-select-selection-placeholder) {
  117. color: rgba(200, 236, 255, 0.45) !important;
  118. }
  119. :deep(.zxm-select-arrow) {
  120. color: #3ae1ff !important;
  121. }
  122. :deep(.zxm-select-dropdown) {
  123. padding: 4px 0;
  124. background: rgba(16, 64, 100, 0.98);
  125. border: 1px solid #3ae1ff;
  126. box-shadow: 0 0 6px rgba(58, 225, 255, 0.25);
  127. }
  128. :deep(.zxm-select-item) {
  129. padding: 6px 10px;
  130. font-size: 14px;
  131. color: #fff;
  132. }
  133. :deep(.zxm-select-item-option-active),
  134. :deep(.zxm-select-item-option-selected) {
  135. background: rgba(58, 225, 255, 0.2) !important;
  136. color: #fff !important;
  137. }
  138. }
  139. </style>