history.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <a-card>
  3. <a-row>
  4. <a-col>
  5. <a-space>
  6. <span>产品: </span>
  7. <a-select v-model:value="queryParams.modelId" style="width: 170px;" >
  8. <a-select-option
  9. v-for="item in state.modelList"
  10. :key="item.id"
  11. :value="item.id"
  12. >
  13. {{item.modelLabel}}
  14. </a-select-option>
  15. </a-select>
  16. <span>设备: </span>
  17. <a-select v-model:value="queryParams.deviceId" style="width: 170px;" >
  18. <a-select-option
  19. v-for="item in state.deviceList"
  20. :key="item.id"
  21. :value="item.id"
  22. >
  23. {{item.deviceLabel}}
  24. </a-select-option>
  25. </a-select>
  26. <span>触发时间: </span>
  27. <a-range-picker v-model:value="time" :format="['DD/MM/YYYY', 'DD/MM/YYYY']" />
  28. <a-button type="primary" @click="getHistoryPage">搜索</a-button>
  29. </a-space>
  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 name="aaa" >
  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. const columns = [
  49. {
  50. title: '设备ID',
  51. dataIndex: 'deviceId'
  52. },
  53. {
  54. title: 'key',
  55. dataIndex: 'key'
  56. },
  57. {
  58. title: 'keyLabel',
  59. dataIndex: 'keyLabel'
  60. },
  61. {
  62. title: 'stringValue',
  63. dataIndex: 'stringValue'
  64. },
  65. {
  66. title: 'doubleValue',
  67. dataIndex: 'doubleValue'
  68. },
  69. {
  70. title: 'longValue',
  71. dataIndex: 'longValue'
  72. },
  73. {
  74. title: 'booleanValue',
  75. dataIndex: 'booleanValue'
  76. },
  77. {
  78. title: 'jsonValue',
  79. dataIndex: 'jsonValue'
  80. },
  81. {
  82. title: 'dataUnit',
  83. dataIndex: 'dataUnit'
  84. }
  85. ]
  86. const time = ref([])
  87. const queryParams = reactive({
  88. page: 1,
  89. pageSize: 10,
  90. total: 0,
  91. deviceId: '',
  92. modelId: '',
  93. attributeKey: '',
  94. startTime: '',
  95. endTime: ''
  96. })
  97. const state = reactive<{
  98. loading: boolean,
  99. dataSource: IOT.API.DATA.History[],
  100. modelList: IOT.API.MODEL.Model[]
  101. deviceList: IOT.API.DEVICE.Device[]
  102. }>({
  103. loading: false,
  104. dataSource: [],
  105. modelList: [],
  106. deviceList: []
  107. })
  108. watch(
  109. () => time.value,
  110. () => {
  111. if (time.value && time.value.length === 2) {
  112. queryParams.startTime = new Date(dayjs(time.value[0])).getTime()
  113. queryParams.endTime = new Date(dayjs(time.value[1])).getTime()
  114. } else {
  115. queryParams.startTime = ''
  116. queryParams.endTime = ''
  117. }
  118. }
  119. )
  120. const changePage = ({ current }) => {
  121. queryParams.page = current
  122. getHistoryPage()
  123. }
  124. const getDeviceList = async () => {
  125. const { data } = await DeviceContriller.list()
  126. state.deviceList = data
  127. }
  128. const getModelList = async () => {
  129. const { data: modelData } = await ModelController.list()
  130. state.modelList = modelData
  131. }
  132. const getHistoryPage = async () => {
  133. state.loading = true
  134. const { data: historyData, sum } = await DataController.pageHistory(queryParams)
  135. state.loading = false
  136. state.dataSource = historyData
  137. queryParams.total = sum
  138. }
  139. onMounted(() => {
  140. getModelList()
  141. getDeviceList()
  142. })
  143. </script>
  144. <style lang='less' scoped >
  145. </style>