DeviceStatusLogDrawer.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <el-drawer
  3. title="设备状态调整记录"
  4. :append-to-body="true"
  5. :model-value="modelValue"
  6. @update:model-value="$emit('update:modelValue', $event)"
  7. :show-close="false"
  8. direction="rtl"
  9. :size="computedSize"
  10. :before-close="handleClose"
  11. >
  12. <template v-if="deviceId">
  13. <div v-loading="loading" style="height: 100%">
  14. <el-table :data="deviceStatuses" style="width: 100%">
  15. <el-table-column prop="deviceName" label="设备名称" width="180" />
  16. <el-table-column prop="deviceCode" label="设备编码" width="180" />
  17. <el-table-column prop="oldStatus" label="调整前状态" width="180" >
  18. <template #default="scope">
  19. <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.oldStatus" />
  20. </template>
  21. </el-table-column>
  22. <el-table-column prop="newStatus" label="调用后状态" width="180" >
  23. <template #default="scope">
  24. <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.newStatus" />
  25. </template>
  26. </el-table-column>
  27. <el-table-column prop="reason" label="调整原因" width="180" />
  28. <el-table-column prop="creatorName" label="调整人" width="180" />
  29. <el-table-column
  30. label="调整时间"
  31. align="center"
  32. prop="createTime"
  33. width="180"
  34. :formatter="dateFormatter"
  35. />
  36. </el-table>
  37. <!-- 分页 -->
  38. <Pagination
  39. :total="total"
  40. v-model:page="queryParams.pageNo"
  41. v-model:limit="queryParams.pageSize"
  42. @pagination="loadDeviceStatuses(props.deviceId)"
  43. />
  44. </div>
  45. </template>
  46. </el-drawer>
  47. </template>
  48. <script setup lang="ts">
  49. import { ref, watch, defineOptions, defineEmits } from 'vue'
  50. import { ElMessage } from 'element-plus'
  51. import * as IotDeviceStatusLogApi from '@/api/pms/iotdevicestatuslog'
  52. import {dateFormatter} from "@/utils/formatTime";
  53. import {DICT_TYPE} from "@/utils/dict";
  54. const drawerVisible = ref<boolean>(false)
  55. const emit = defineEmits(['update:modelValue', 'add', 'delete'])
  56. defineOptions({
  57. name: 'DeviceStatusLogDrawer'
  58. })
  59. const queryParams = reactive({
  60. pageNo: 1,
  61. pageSize: 10,
  62. createTime: [],
  63. deviceId: '',
  64. name: '',
  65. code: ''
  66. })
  67. const windowWidth = ref(window.innerWidth)
  68. // 动态计算百分比
  69. const computedSize = computed(() => {
  70. return windowWidth.value > 1200 ? '60%' : '80%'
  71. })
  72. const loading = ref(false)
  73. const total = ref(0) // 列表的总页数
  74. const deviceStatuses = ref([])
  75. const props = defineProps({
  76. modelValue: Boolean,
  77. deviceId: Number
  78. })
  79. // 监听bom树节点ID变化
  80. watch(() => props.deviceId, async (newVal) => {
  81. if (newVal) {
  82. await loadDeviceStatuses(newVal)
  83. }
  84. })
  85. // 加载设备的状态调整记录
  86. const loadDeviceStatuses = async (deviceId) => {
  87. queryParams.deviceId = deviceId
  88. queryParams.pageNo = 1
  89. try {
  90. loading.value = true
  91. // API调用
  92. const data = await IotDeviceStatusLogApi.IotDeviceStatusLogApi.getIotDeviceStatusLogPage(queryParams)
  93. deviceStatuses.value = data.list
  94. total.value = data.total
  95. } catch (error) {
  96. ElMessage.error('数据加载失败')
  97. } finally {
  98. loading.value = false
  99. }
  100. }
  101. // 打开抽屉
  102. const openDrawer = () => {
  103. drawerVisible.value = true
  104. }
  105. // 关闭抽屉
  106. const closeDrawer = () => {
  107. drawerVisible.value = false
  108. }
  109. // 关闭抽屉
  110. const handleClose = () => {
  111. emit('update:modelValue', false)
  112. deviceStatuses.value = []
  113. }
  114. defineExpose({ openDrawer, closeDrawer, loadDeviceStatuses }) // 暴露方法给父组件
  115. </script>
  116. <style lang="scss" scoped></style>