history.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <a-card>
  3. <a-row>
  4. <a-col span="20" >
  5. <a-space>
  6. <a-select allowClear v-model:value="queryParams.modelId" placeholder="请选择产品" style="width: 170px;" >
  7. <a-select-option
  8. v-for="item in state.modelList"
  9. :key="item.id"
  10. :value="item.id"
  11. >
  12. {{item.modelLabel}}
  13. </a-select-option>
  14. </a-select>
  15. <a-select allowClear v-model:value="queryParams.deviceId" placeholder="请选择设备" style="width: 170px;" >
  16. <a-select-option
  17. v-for="item in state.deviceList"
  18. :key="item.id"
  19. :value="item.id"
  20. >
  21. {{item.deviceLabel}}
  22. </a-select-option>
  23. </a-select>
  24. <a-range-picker v-model:value="time" :format="['DD/MM/YYYY', 'DD/MM/YYYY']" />
  25. <a-button type="primary" @click="getHistoryPage">搜索</a-button>
  26. </a-space>
  27. </a-col>
  28. <a-col span="2" >
  29. <a-button @click="exportExcel" >导出</a-button>
  30. </a-col>
  31. </a-row>
  32. <a-table
  33. style="margin-top: 20px;"
  34. :columns="columns"
  35. :loading="state.loading"
  36. :data-source="state.dataSource"
  37. :pagination="queryParams"
  38. @change="changePage"
  39. >
  40. </a-table>
  41. </a-card>
  42. </template>
  43. <script lang='ts' setup >
  44. import { DeviceContriller, ModelController } from '@/controller'
  45. import { DataController } from '@/controller/iot/data'
  46. import { onMounted, reactive, ref, watch } from 'vue'
  47. import dayjs from 'dayjs'
  48. import { useExportExcel } from '@/hooks'
  49. const columns = [
  50. {
  51. title: '设备ID',
  52. dataIndex: 'deviceId'
  53. },
  54. {
  55. title: 'key',
  56. dataIndex: 'key'
  57. },
  58. {
  59. title: 'keyLabel',
  60. dataIndex: 'keyLabel'
  61. },
  62. {
  63. title: '结果',
  64. dataIndex: 'value'
  65. },
  66. {
  67. title: '单位',
  68. dataIndex: 'dataUnit'
  69. }
  70. ]
  71. const time = ref([])
  72. const queryParams = reactive({
  73. page: 1,
  74. pageSize: 10,
  75. total: 0,
  76. deviceId: null,
  77. modelId: null,
  78. attributeKey: '',
  79. startTime: '',
  80. endTime: ''
  81. })
  82. const state = reactive<{
  83. loading: boolean,
  84. dataSource: IOT.API.DATA.History[],
  85. modelList: IOT.API.MODEL.Model[]
  86. deviceList: IOT.API.DEVICE.Device[]
  87. }>({
  88. loading: false,
  89. dataSource: [],
  90. modelList: [],
  91. deviceList: []
  92. })
  93. watch(
  94. () => time.value,
  95. () => {
  96. if (time.value && time.value.length === 2) {
  97. queryParams.startTime = new Date(dayjs(time.value[0])).getTime()
  98. queryParams.endTime = new Date(dayjs(time.value[1])).getTime()
  99. } else {
  100. queryParams.startTime = ''
  101. queryParams.endTime = ''
  102. }
  103. }
  104. )
  105. const exportExcel = async () => {
  106. const { data } = await DataController.exportHistoryExecel(queryParams)
  107. useExportExcel(data, '历史数据')
  108. }
  109. const changePage = ({ current }) => {
  110. queryParams.page = current
  111. getHistoryPage()
  112. }
  113. const getDeviceList = async () => {
  114. const { data } = await DeviceContriller.list()
  115. state.deviceList = data
  116. }
  117. const getModelList = async () => {
  118. const { data: modelData } = await ModelController.list()
  119. state.modelList = modelData
  120. }
  121. const getHistoryPage = async () => {
  122. state.loading = true
  123. const { data: historyData, sum } = await DataController.pageHistory(queryParams)
  124. state.loading = false
  125. state.dataSource = historyData
  126. queryParams.total = sum
  127. }
  128. onMounted(() => {
  129. getModelList()
  130. getDeviceList()
  131. })
  132. </script>
  133. <style lang='less' scoped >
  134. </style>