HistoryLine.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. const timeRange = ref<[string, string]>([
  35. dayjs().subtract(30, 'day').format(DATE_FORMAT),
  36. dayjs().format(DATE_FORMAT),
  37. ])
  38. /** 选择设备,触发 deviceChange 事件 */
  39. function onDeviceChange(value: string) {
  40. const item = props.deviceOptions.find((d) => d.value === value)
  41. currentDevice.value = value
  42. deviceType.value = item?.devicetype
  43. if (item) {
  44. // emit('deviceChange', item)
  45. }
  46. }
  47. /** 获取历史温度曲线数据 */
  48. async function getChartData() {
  49. 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, })
  50. console.log(res, '历史温度曲线数据')
  51. if (res.datalist.records.length) {
  52. chartData.value = res.datalist.records.map((v,index) => ({
  53. pos: v.ttime,
  54. value:parseFloat(v.readData.avg)
  55. }))
  56. }
  57. }
  58. watch(() => props.deviceOptions, (newVal) => {
  59. if (newVal.length > 0) {
  60. currentDevice.value = newVal[0].value
  61. deviceType.value = newVal[0].devicetype
  62. getChartData()
  63. }
  64. }, { immediate: true })
  65. </script>
  66. <style lang="less" scoped>
  67. @import '/@/design/theme.less';
  68. .history-line {
  69. position: relative;
  70. width: 100%;
  71. height: 100%;
  72. padding: 10px;
  73. box-sizing: border-box;
  74. .device-select-row {
  75. display: flex;
  76. align-items: center;
  77. gap: 5px;
  78. margin-bottom: 5px;
  79. flex-shrink: 0;
  80. .select-label {
  81. white-space: nowrap;
  82. color: #fff;
  83. }
  84. .device-select {
  85. flex: 1;
  86. min-width: 0;
  87. }
  88. }
  89. .device-row-line {
  90. width: 100%;
  91. height: calc(100% - 35px);
  92. }
  93. :deep(.zxm-select) {
  94. width: 100%;
  95. height: 28px;
  96. }
  97. :deep(.zxm-select-selector) {
  98. height: 28px !important;
  99. padding: 0 24px 0 11px !important;
  100. border: 1px solid #3ae1ff !important;
  101. background-color: rgba(16, 64, 100, 0.85) !important;
  102. box-shadow: 0 0 6px rgba(58, 225, 255, 0.25);
  103. color: #fff !important;
  104. }
  105. :deep(.zxm-select-selection-search) {
  106. inset-inline-start: 11px !important;
  107. }
  108. :deep(.zxm-select-selection-item),
  109. :deep(.zxm-select-selection-placeholder) {
  110. line-height: 26px !important;
  111. font-size: 14px;
  112. color: #fff !important;
  113. }
  114. :deep(.zxm-select-selection-placeholder) {
  115. color: rgba(200, 236, 255, 0.45) !important;
  116. }
  117. :deep(.zxm-select-arrow) {
  118. color: #3ae1ff !important;
  119. }
  120. :deep(.zxm-select-dropdown) {
  121. padding: 4px 0;
  122. background: rgba(16, 64, 100, 0.98);
  123. border: 1px solid #3ae1ff;
  124. box-shadow: 0 0 6px rgba(58, 225, 255, 0.25);
  125. }
  126. :deep(.zxm-select-item) {
  127. padding: 6px 10px;
  128. font-size: 14px;
  129. color: #fff;
  130. }
  131. :deep(.zxm-select-item-option-active),
  132. :deep(.zxm-select-item-option-selected) {
  133. background: rgba(58, 225, 255, 0.2) !important;
  134. color: #fff !important;
  135. }
  136. }
  137. </style>