Forráskód Böngészése

pms 设备状态调整

zhangcl 3 hónapja
szülő
commit
fe5e953173

+ 5 - 0
src/api/pms/device/index.ts

@@ -82,6 +82,11 @@ export const IotDeviceApi = {
     return await request.post({ url: `/rq/iot-device/create`, data })
   },
 
+  // 保存 设备-状态 的关联关系
+  saveDeviceStatuses: async (data: any) => {
+    return await request.post({ url: `/rq/iot-device/saveDeviceStatuses`, data })
+  },
+
   // 修改设备台账
   updateIotDevice: async (data: IotDeviceVO) => {
     return await request.put({ url: `/rq/iot-device/update`, data })

+ 44 - 0
src/api/pms/iotdevicestatuslog/index.ts

@@ -0,0 +1,44 @@
+import request from '@/config/axios'
+
+// 设备状态调整日志 VO
+export interface IotDeviceStatusLogVO {
+  id: number // 主键id
+  deviceId: number // 设备id
+  oldStatus: string // 设备修改前状态
+  newStatus: string // 设备修改后状态
+  reason: string // 设备状态调整原因
+  remark: string // 备注
+}
+
+// 设备状态调整日志 API
+export const IotDeviceStatusLogApi = {
+  // 查询设备状态调整日志分页
+  getIotDeviceStatusLogPage: async (params: any) => {
+    return await request.get({ url: `/pms/iot-device-status-log/page`, params })
+  },
+
+  // 查询设备状态调整日志详情
+  getIotDeviceStatusLog: async (id: number) => {
+    return await request.get({ url: `/pms/iot-device-status-log/get?id=` + id })
+  },
+
+  // 新增设备状态调整日志
+  createIotDeviceStatusLog: async (data: IotDeviceStatusLogVO) => {
+    return await request.post({ url: `/pms/iot-device-status-log/create`, data })
+  },
+
+  // 修改设备状态调整日志
+  updateIotDeviceStatusLog: async (data: IotDeviceStatusLogVO) => {
+    return await request.put({ url: `/pms/iot-device-status-log/update`, data })
+  },
+
+  // 删除设备状态调整日志
+  deleteIotDeviceStatusLog: async (id: number) => {
+    return await request.delete({ url: `/pms/iot-device-status-log/delete?id=` + id })
+  },
+
+  // 导出设备状态调整日志 Excel
+  exportIotDeviceStatusLog: async (params) => {
+    return await request.download({ url: `/pms/iot-device-status-log/export-excel`, params })
+  },
+}

+ 1 - 1
src/views/pms/bom/index.vue

@@ -71,8 +71,8 @@
           v-if="refreshTable"
           style="width: 100%"
         >
-          <el-table-column prop="deviceCategoryName" label="设备分类" />
           <el-table-column prop="name" label="BOM节点" />
+          <!-- <el-table-column prop="deviceCategoryName" label="设备分类" /> -->
           <el-table-column prop="sort" label="排序" />
           <el-table-column prop="status" label="状态" >
             <template #default="scope">

+ 113 - 176
src/views/pms/device/ConfigDeviceStatus.vue

@@ -1,8 +1,8 @@
 <template>
   <div class="container">
-    <el-row :gutter="20">
+    <el-row :gutter="20" class="equal-height-row">
       <!-- 左侧设备列表 -->
-      <el-col :span="12">
+      <el-col :span="12" class="col-wrapper">
         <div class="card">
           <h3>设备列表</h3>
           <div class="dept-select">
@@ -34,12 +34,18 @@
         </div>
       </el-col>
 
-      <!-- 右侧责任人选择 -->
-      <el-col :span="12">
+      <!-- 右侧设备状态 -->
+      <el-col :span="12" class="col-wrapper">
         <div class="card">
           <h3>设备状态</h3>
           <div class="dept-select">
-            <el-select v-model="formData.deviceStatus" placeholder="请选择" clearable>
+            <el-select
+              v-model="formData.deviceStatus"
+              @change="handleStatusChange"
+              placeholder="请选择"
+              clearable
+              :disabled="selectedDevices.length === 0"
+            >
               <el-option
                 v-for="dict in getStrDictOptions(DICT_TYPE.PMS_DEVICE_STATUS)"
                 :key="dict.label"
@@ -52,7 +58,7 @@
           <el-input
             v-model="formData.reason"
             placeholder="请输入调整原因"
-            :disabled="!selectedDevice"
+            :disabled="!formData.deviceStatus"
             class="reason-input"
             type="textarea"
             :rows="3"
@@ -70,7 +76,11 @@
     <div class="temp-list card">
       <h3>待提交的关联关系</h3>
       <el-table :data="tempRelations" style="width: 100%">
-        <el-table-column prop="deviceNames" label="设备" width="200" />
+        <el-table-column prop="deviceNames" label="设备" width="200" >
+          <template #default="{ row }">
+            {{ row.deviceNames }}
+          </template>
+        </el-table-column>
         <el-table-column prop="status" label="状态" />
         <el-table-column prop="reason" label="调整原因" />
         <el-table-column label="操作" width="120">
@@ -78,7 +88,7 @@
             <el-button
               type="danger"
               size="small"
-              @click="removeTempRelation(row.deviceIds)"
+              @click="removeTempRelation(row.deviceId)"
             >
               删除
             </el-button>
@@ -145,13 +155,6 @@ const queryParams = reactive({
 
 const emit = defineEmits(['success', 'node-click']) // 定义 success 树点击 事件,用于操作成功后的回调
 
-const userList = ref([
-  { id: 'u1', name: '张三', position: '工程师', deptId: 'dept1' },
-  { id: 'u2', name: '李四', position: '技术员', deptId: 'dept1' },
-  { id: 'u3', name: '王五', position: '质检员', deptId: 'dept2' },
-  // 更多用户...
-])
-
 // 响应式数据
 const selectedDevice = ref<number>(0)
 const selectedDept = ref('')
@@ -159,19 +162,11 @@ const selectedUsers = ref<number[]>([])
 const tempRelations = ref<Array<{
   deviceId: number
   deviceNames: string
-  deviceStatus: number
+  status: string
+  statusLabel: string
   reason: string
 }>>([])
 
-const canSave = computed(() => {
-  return !!selectedDevice.value && selectedUsers.value.length > 0
-})
-
-// 方法
-const loadUsers = () => {
-  selectedUsers.value = []
-}
-
 // 设备切换时清空状态
 const handleDeviceChange = () => {
   currentStatus.value = ''
@@ -184,91 +179,47 @@ const handleDeviceChange = () => {
   }
 }
 
-// 添加设备选择监听
-watch(selectedDevice, (newVal) => {
-  if (newVal) {
-    // 切换设备时清空人员选择
-    selectedUsers.value = []
-    // 可选:清空部门选择
-    formData.value.deptId = undefined
-    simpleUsers.value = []
+// 修改watch监听
+watch(selectedDevices, (newVal, oldVal) => {
+  // 删除取消选择的设备
+  const removedDevices = oldVal.filter(id => !newVal.includes(id))
+  removedDevices.forEach(deviceId => {
+    const index = tempRelations.value.findIndex(r => r.deviceId === deviceId)
+    if (index > -1) tempRelations.value.splice(index, 1)
+  })
+
+  // 自动应用当前状态到新选设备
+  if (formData.value.deviceStatus && formData.value.reason) {
+    saveCurrentRelation()
   }
 })
 
-// 处理人员选择变化
-const handleUserSelectionChange = (value: number[]) => {
-  if (!selectedDevice.value) {
-    ElMessage.warning('请先选择设备')
-    selectedUsers.value = []
-    return
-  }
-
-  // 获取当前选择的设备
-  const device = simpleDevices.value.find(d => d.id === selectedDevice.value)
-  if (!device) return
-
-  // 新增或更新关联关系
-  updateDeviceRelation(device, value)
-}
-
-// 保存当前关联关系
+// 修改保存方法
 const saveCurrentRelation = () => {
-  if (!selectedDevice.value || !currentDevice.value) return
-  if (!currentStatus.value) {
-    ElMessage.warning('请先选择设备状态')
-    return
-  }
+  if (!formData.value.deviceStatus || !formData.value.reason) return
 
   const statusDict = getStrDictOptions(DICT_TYPE.PMS_DEVICE_STATUS)
-    .find(d => d.value === currentStatus.value)
-
-  const newRelation: DeviceStatusRelation = {
-    deviceId: selectedDevice.value,
-    deviceName: `${currentDevice.value.deviceCode} (${currentDevice.value.deviceName})`,
-    status: currentStatus.value,
-    statusLabel: statusDict?.label || '未知状态',
-    reason: adjustReason.value
-  }
-
-  const existIndex = tempRelations.value
-    .findIndex(r => r.deviceId === selectedDevice.value)
-
-  if (existIndex > -1) {
-    tempRelations.value[existIndex] = newRelation
-  } else {
-    tempRelations.value.push(newRelation)
-  }
-}
-
-// 修改 暂时 保存关联方法
-const saveTempRelation = () => {
-  if (!selectedDevice.value || selectedUsers.value.length === 0) return
-
-  const device = simpleDevices.value.find(d => d.id === selectedDevice.value)
-  const users = simpleUsers.value.filter(u => selectedUsers.value.includes(u.id))
-
-  if (!device) return
-
-  const newRelation = {
-    deviceIds: [selectedDevice.value], // 保持数组结构但只包含单个设备
-    deviceNames: `${device.deviceCode} (${device.deviceName})`,
-    userIds: users.map(u => u.id),
-    userNames: users.map(u => u.nickname).join(', ')
-  }
-
-  // 覆盖已存在的设备关联
-
-  const existIndex = tempRelations.value.findIndex(
-    r => r.deviceIds[0] === selectedDevice.value
-  )
-
-  if (existIndex > -1) {
-    tempRelations.value[existIndex] = newRelation
-  } else {
-    tempRelations.value.push(newRelation)
-  }
+    .find(d => d.value === formData.value.deviceStatus)
+
+  selectedDevices.value.forEach(deviceId => {
+    const device = simpleDevices.value.find(d => d.id === deviceId)
+    if (!device) return
+
+    const newRelation = {
+      deviceId,
+      deviceNames: `${device.deviceCode} (${device.deviceName})`,
+      status: formData.value.deviceStatus!,
+      statusLabel: statusDict?.label || '未知状态',
+      reason: formData.value.reason
+    }
 
-  clearSelection()
+    const existIndex = tempRelations.value.findIndex(r => r.deviceId === deviceId)
+    if (existIndex > -1) {
+      tempRelations.value[existIndex] = newRelation
+    } else {
+      tempRelations.value.push(newRelation)
+    }
+  })
 }
 
 /** 处理 部门-设备 树 被点击 */
@@ -290,87 +241,49 @@ const getDeviceList = async () => {
   }
 }
 
-/** 处理 部门-人员 树 被点击 */
-const handleDeptUserTreeNodeClick = async (row: { [key: string]: any }) => {
-  emit('node-click', row)
-  formData.value.deptId = row.id
-  await getUserList()
-}
-
-/** 获得 部门下的人员 列表 */
-const getUserList = async () => {
-  try {
-    const params = {
-      deptId: formData.value.deptId,
-      pageNo: 1,
-      pageSize: 10 }
-    const data = await UserApi.simpleUserList(params)
-    simpleUsers.value = data || []
-  } catch (error) {
-    simpleUsers.value = []
-    console.error('获取人员列表失败:', error)
+// 添加状态变更处理
+const handleStatusChange = () => {
+  if (selectedDevices.value.length > 0) {
+    saveCurrentRelation()
   }
 }
 
-// 更新设备关联关系
-const updateDeviceRelation = (device: IotDeviceVO, userIds: number[]) => {
-  // 获取当前选择的人员
-  const users = simpleUsers.value.filter(u => userIds.includes(u.id))
+// 添加多设备判断方法
+const isMultiDevice = (row: any) => {
+  return selectedDevices.value.includes(row.deviceId) && selectedDevices.value.length > 1
+}
 
-  const newRelation = {
-    deviceIds: [device.id],
-    deviceNames: `${device.deviceCode} (${device.deviceName})`,
-    userIds: users.map(u => u.id),
-    userNames: users.map(u => u.nickname).join(', ')
-  }
+// 修改删除方法
+const removeTempRelation = (deviceId: number) => {
+  // 从暂存列表删除
+  tempRelations.value = tempRelations.value.filter(r => r.deviceId !== deviceId)
 
-  // 查找是否已存在该设备的关联
-  const existIndex = tempRelations.value.findIndex(
-    r => r.deviceIds[0] === device.id
-  )
+  // 从选中设备中移除
+  selectedDevices.value = selectedDevices.value.filter(id => id !== deviceId)
 
-  if (existIndex > -1) {
-    // 如果没有选择人员,移除该关联
-    if (userIds.length === 0) {
-      tempRelations.value.splice(existIndex, 1)
-    } else {
-      // 更新关联
-      tempRelations.value[existIndex] = newRelation
-    }
-  } else if (userIds.length > 0) {
-    // 添加新关联
-    tempRelations.value.push(newRelation)
+  // 如果当前表单状态为空,尝试恢复其他设备的状态
+  if (!formData.value.deviceStatus && tempRelations.value.length > 0) {
+    const firstRelation = tempRelations.value[0]
+    formData.value.deviceStatus = firstRelation.status
+    formData.value.reason = firstRelation.reason
   }
 }
 
-const clearSelection = () => {
-  selectedDevice.value = ''
-  selectedUsers.value = []
-  selectedDept.value = ''
-}
-
-const removeTempRelation = (deviceIds: string[]) => {
-  tempRelations.value = tempRelations.value.filter(
-    r => r.deviceIds.join() !== deviceIds.join()
-  )
-}
-
+// 提交时处理数据
 const submitRelations = async () => {
   try {
-    // 转换为后端需要的格式
-    const submitData = tempRelations.value.flatMap(relation => {
-      return relation.deviceIds.map(deviceId => ({
-        deviceId,
-        userIds: relation.userIds
-      }))
-    })
-    await IotDevicePersonApi.saveDevicePersonRelation(submitData)
-    // 模拟API调用
-    console.log('提交数据:', submitData)
-    ElMessage.success('关联关系提交成功')
+    // 转换数据结构
+    const submitData = tempRelations.value.map(r => ({
+      deviceId: r.deviceId,
+      status: r.status,
+      reason: r.reason
+    }))
+
+    await IotDeviceApi.saveDeviceStatuses(submitData)
+    ElMessage.success('提交成功')
     tempRelations.value = []
   } catch (error) {
-    ElMessage.error('提交失败,请重试')
+    ElMessage.error('提交失败')
   }
 }
 
@@ -389,11 +302,10 @@ onMounted(async () => {
 }
 
 .card {
-  border: 1px solid #ebeef5;
-  border-radius: 4px;
-  padding: 20px;
-  margin-bottom: 20px;
-  background: white;
+  flex: 1;
+  display: flex;
+  flex-direction: column;
+  overflow: hidden;
 }
 
 .list-item {
@@ -401,6 +313,11 @@ onMounted(async () => {
   border-bottom: 1px solid #f0f0f0;
 }
 
+.col-wrapper {
+  display: flex;
+  flex-direction: column;
+}
+
 .dept-select {
   margin-bottom: 20px;
 }
@@ -447,4 +364,24 @@ h3 {
   overflow: hidden;
   text-overflow: ellipsis;
 }
+
+.equal-height-row {
+  display: flex;
+  align-items: stretch;
+}
+
+.el-scrollbar {
+  flex: 1;
+}
+
+.reason-input {
+  margin-top: 20px;
+}
+
+/* 添加多设备标签样式 */
+.el-tag {
+  margin-left: 8px;
+  vertical-align: middle;
+}
+
 </style>

+ 1 - 1
src/views/pms/device/DeviceAllot.vue

@@ -311,7 +311,7 @@ const { wsCache } = useCache()
 /** 初始化 **/
 onMounted(() => {
   const user = wsCache.get(CACHE_KEY.USER)
-  queryParams.deptId = user.user.deptId
+  // queryParams.deptId = user.user.deptId
   getList()
 })
 </script>

+ 1 - 1
src/views/pms/device/DevicePerson.vue

@@ -308,7 +308,7 @@ const { wsCache } = useCache()
 /** 初始化 **/
 onMounted(() => {
   const user = wsCache.get(CACHE_KEY.USER)
-  queryParams.deptId = user.user.deptId
+  // queryParams.deptId = user.user.deptId
   getList()
 })
 </script>

+ 25 - 6
src/views/pms/device/DeviceStatus.vue

@@ -140,16 +140,16 @@
             width="180px"
           />
           <el-table-column label="操作" align="center" min-width="120px">
-            <!-- <template #default="scope">
+            <template #default="scope">
               <el-button
                 link
                 type="primary"
-                @click="openForm('update', scope.row.id)"
+                @click="handleView(scope.row.id)"
                 v-hasPermi="['rq:iot-device:update']"
               >
-                编辑
+                调整记录
               </el-button>
-            </template> -->
+            </template>
           </el-table-column>
         </el-table>
         <!-- 分页 -->
@@ -162,6 +162,12 @@
       </ContentWrap>
     </el-col>
   </el-row>
+  <DeviceStatusLogDrawer
+    :model-value="drawerVisible"
+    @update:model-value="val => drawerVisible = val"
+    :device-id="currentDeviceId"
+    ref="showDrawer"
+  />
 </template>
 
 <script setup lang="ts">
@@ -171,6 +177,7 @@ import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
 import { dateFormatter } from '@/utils/formatTime'
 import DeptTree from '@/views/system/user/DeptTree.vue'
 import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import DeviceStatusLogDrawer from "@/views/pms/device/DeviceStatusLogDrawer.vue";
 
 /** 设备台账 列表 */
 defineOptions({ name: 'IotDeviceStatus' })
@@ -178,12 +185,13 @@ defineOptions({ name: 'IotDeviceStatus' })
 const message = useMessage() // 消息弹窗
 const { t } = useI18n() // 国际化
 const { push } = useRouter() // 路由跳转
-
+const drawerVisible = ref<boolean>(false)
 const loading = ref(true) // 列表的加载中
 const ifShow = ref(false)
 const isDetail = ref(false) // 是否查看详情
 const list = ref<IotDeviceVO[]>([]) // 列表的数据
 const total = ref(0) // 列表的总页数
+const currentDeviceId = ref() // 设备id
 const queryParams = reactive({
   pageNo: 1,
   pageSize: 10,
@@ -240,6 +248,17 @@ const getList = async () => {
   }
 }
 
+const showDrawer = ref()
+
+/** 查看物料详情 */
+const handleView = async (deviceId) => {
+  currentDeviceId.value = deviceId
+  drawerVisible.value = true
+  showDrawer.value.openDrawer()
+  // 强制刷新物料数据
+  // await showDrawer.value.loadMaterials(nodeId)
+}
+
 /** 处理部门被点击 */
 const handleDeptNodeClick = async (row) => {
   queryParams.deptId = row.id
@@ -311,7 +330,7 @@ const { wsCache } = useCache()
 /** 初始化 **/
 onMounted(() => {
   const user = wsCache.get(CACHE_KEY.USER)
-  queryParams.deptId = user.user.deptId
+  // queryParams.deptId = user.user.deptId
   getList()
 })
 </script>

+ 131 - 0
src/views/pms/device/DeviceStatusLogDrawer.vue

@@ -0,0 +1,131 @@
+<template>
+  <el-drawer
+    title="设备状态调整记录"
+    :append-to-body="true"
+    :model-value="modelValue"
+    @update:model-value="$emit('update:modelValue', $event)"
+    :show-close="false"
+    direction="rtl"
+    :size="computedSize"
+    :before-close="handleClose"
+  >
+    <template v-if="deviceId">
+      <div v-loading="loading" style="height: 100%">
+        <el-table :data="deviceStatuses" style="width: 100%">
+          <el-table-column prop="deviceName" label="设备名称" width="180" />
+          <el-table-column prop="deviceCode" label="设备编码" width="180" />
+          <el-table-column prop="oldStatus" label="调整前状态" width="180" >
+            <template #default="scope">
+              <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.oldStatus" />
+            </template>
+          </el-table-column>
+          <el-table-column prop="newStatus" label="调用后状态" width="180" >
+            <template #default="scope">
+              <dict-tag :type="DICT_TYPE.PMS_DEVICE_STATUS" :value="scope.row.newStatus" />
+            </template>
+          </el-table-column>
+          <el-table-column prop="reason" label="调整原因" width="180" />
+          <el-table-column prop="creatorName" label="调整人" width="180" />
+          <el-table-column
+            label="调整时间"
+            align="center"
+            prop="createTime"
+            width="180"
+            :formatter="dateFormatter"
+          />
+        </el-table>
+        <!-- 分页 -->
+        <Pagination
+          :total="total"
+          v-model:page="queryParams.pageNo"
+          v-model:limit="queryParams.pageSize"
+          @pagination="loadDeviceStatuses(props.deviceId)"
+        />
+      </div>
+    </template>
+
+  </el-drawer>
+</template>
+<script setup lang="ts">
+
+import { ref, watch, defineOptions, defineEmits } from 'vue'
+import { ElMessage } from 'element-plus'
+import * as IotDeviceStatusLogApi from '@/api/pms/iotdevicestatuslog'
+import {dateFormatter} from "@/utils/formatTime";
+import {DICT_TYPE} from "@/utils/dict";
+const drawerVisible = ref<boolean>(false)
+const emit = defineEmits(['update:modelValue', 'add', 'delete'])
+
+defineOptions({
+  name: 'DeviceStatusLogDrawer'
+})
+
+const queryParams = reactive({
+  pageNo: 1,
+  pageSize: 10,
+  createTime: [],
+  deviceId: '',
+  name: '',
+  code: ''
+})
+
+const windowWidth = ref(window.innerWidth)
+// 动态计算百分比
+const computedSize = computed(() => {
+  return windowWidth.value > 1200 ? '60%' : '80%'
+})
+
+const loading = ref(false)
+const total = ref(0) // 列表的总页数
+const deviceStatuses = ref([])
+
+const props = defineProps({
+  modelValue: Boolean,
+  deviceId: Number
+})
+
+// 监听bom树节点ID变化
+watch(() => props.deviceId, async (newVal) => {
+  if (newVal) {
+    await loadDeviceStatuses(newVal)
+  }
+})
+
+// 加载设备的状态调整记录
+const loadDeviceStatuses = async (deviceId) => {
+  queryParams.deviceId = deviceId
+  queryParams.pageNo = 1
+  try {
+    loading.value = true
+    // API调用
+    const data = await IotDeviceStatusLogApi.IotDeviceStatusLogApi.getIotDeviceStatusLogPage(queryParams)
+    deviceStatuses.value = data.list
+    total.value = data.total
+  } catch (error) {
+    ElMessage.error('数据加载失败')
+  } finally {
+    loading.value = false
+  }
+}
+
+// 打开抽屉
+const openDrawer = () => {
+  drawerVisible.value = true
+}
+
+// 关闭抽屉
+const closeDrawer = () => {
+  drawerVisible.value = false
+}
+
+// 关闭抽屉
+const handleClose = () => {
+  emit('update:modelValue', false)
+  deviceStatuses.value = []
+}
+
+defineExpose({ openDrawer, closeDrawer, loadDeviceStatuses }) // 暴露方法给父组件
+
+</script>
+
+<style lang="scss" scoped></style>

+ 116 - 0
src/views/pms/iotdevicestatuslog/IotDeviceStatusLogForm.vue

@@ -0,0 +1,116 @@
+<template>
+  <Dialog :title="dialogTitle" v-model="dialogVisible">
+    <el-form
+      ref="formRef"
+      :model="formData"
+      :rules="formRules"
+      label-width="100px"
+      v-loading="formLoading"
+    >
+      <el-form-item label="设备id" prop="deviceId">
+        <el-input v-model="formData.deviceId" placeholder="请输入设备id" />
+      </el-form-item>
+      <el-form-item label="设备修改前状态" prop="oldStatus">
+        <el-radio-group v-model="formData.oldStatus">
+          <el-radio value="1">请选择字典生成</el-radio>
+        </el-radio-group>
+      </el-form-item>
+      <el-form-item label="设备修改后状态" prop="newStatus">
+        <el-radio-group v-model="formData.newStatus">
+          <el-radio value="1">请选择字典生成</el-radio>
+        </el-radio-group>
+      </el-form-item>
+      <el-form-item label="设备状态调整原因" prop="reason">
+        <el-input v-model="formData.reason" placeholder="请输入设备状态调整原因" />
+      </el-form-item>
+      <el-form-item label="备注" prop="remark">
+        <el-input v-model="formData.remark" placeholder="请输入备注" />
+      </el-form-item>
+    </el-form>
+    <template #footer>
+      <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
+      <el-button @click="dialogVisible = false">取 消</el-button>
+    </template>
+  </Dialog>
+</template>
+<script setup lang="ts">
+import { IotDeviceStatusLogApi, IotDeviceStatusLogVO } from '@/api/pms/iotdevicestatuslog'
+
+/** 设备状态调整日志 表单 */
+defineOptions({ name: 'IotDeviceStatusLogForm' })
+
+const { t } = useI18n() // 国际化
+const message = useMessage() // 消息弹窗
+
+const dialogVisible = ref(false) // 弹窗的是否展示
+const dialogTitle = ref('') // 弹窗的标题
+const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
+const formType = ref('') // 表单的类型:create - 新增;update - 修改
+const formData = ref({
+  id: undefined,
+  deviceId: undefined,
+  oldStatus: undefined,
+  newStatus: undefined,
+  reason: undefined,
+  remark: undefined,
+})
+const formRules = reactive({
+  deviceId: [{ required: true, message: '设备id不能为空', trigger: 'blur' }],
+})
+const formRef = ref() // 表单 Ref
+
+/** 打开弹窗 */
+const open = async (type: string, id?: number) => {
+  dialogVisible.value = true
+  dialogTitle.value = t('action.' + type)
+  formType.value = type
+  resetForm()
+  // 修改时,设置数据
+  if (id) {
+    formLoading.value = true
+    try {
+      formData.value = await IotDeviceStatusLogApi.getIotDeviceStatusLog(id)
+    } finally {
+      formLoading.value = false
+    }
+  }
+}
+defineExpose({ open }) // 提供 open 方法,用于打开弹窗
+
+/** 提交表单 */
+const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
+const submitForm = async () => {
+  // 校验表单
+  await formRef.value.validate()
+  // 提交请求
+  formLoading.value = true
+  try {
+    const data = formData.value as unknown as IotDeviceStatusLogVO
+    if (formType.value === 'create') {
+      await IotDeviceStatusLogApi.createIotDeviceStatusLog(data)
+      message.success(t('common.createSuccess'))
+    } else {
+      await IotDeviceStatusLogApi.updateIotDeviceStatusLog(data)
+      message.success(t('common.updateSuccess'))
+    }
+    dialogVisible.value = false
+    // 发送操作成功的事件
+    emit('success')
+  } finally {
+    formLoading.value = false
+  }
+}
+
+/** 重置表单 */
+const resetForm = () => {
+  formData.value = {
+    id: undefined,
+    deviceId: undefined,
+    oldStatus: undefined,
+    newStatus: undefined,
+    reason: undefined,
+    remark: undefined,
+  }
+  formRef.value?.resetFields()
+}
+</script>

+ 233 - 0
src/views/pms/iotdevicestatuslog/index.vue

@@ -0,0 +1,233 @@
+<template>
+  <ContentWrap>
+    <!-- 搜索工作栏 -->
+    <el-form
+      class="-mb-15px"
+      :model="queryParams"
+      ref="queryFormRef"
+      :inline="true"
+      label-width="68px"
+    >
+      <el-form-item label="设备id" prop="deviceId">
+        <el-input
+          v-model="queryParams.deviceId"
+          placeholder="请输入设备id"
+          clearable
+          @keyup.enter="handleQuery"
+          class="!w-240px"
+        />
+      </el-form-item>
+      <el-form-item label="设备修改前状态" prop="oldStatus">
+        <el-select
+          v-model="queryParams.oldStatus"
+          placeholder="请选择设备修改前状态"
+          clearable
+          class="!w-240px"
+        >
+          <el-option label="请选择字典生成" value="" />
+        </el-select>
+      </el-form-item>
+      <el-form-item label="设备修改后状态" prop="newStatus">
+        <el-select
+          v-model="queryParams.newStatus"
+          placeholder="请选择设备修改后状态"
+          clearable
+          class="!w-240px"
+        >
+          <el-option label="请选择字典生成" value="" />
+        </el-select>
+      </el-form-item>
+      <el-form-item label="设备状态调整原因" prop="reason">
+        <el-input
+          v-model="queryParams.reason"
+          placeholder="请输入设备状态调整原因"
+          clearable
+          @keyup.enter="handleQuery"
+          class="!w-240px"
+        />
+      </el-form-item>
+      <el-form-item label="备注" prop="remark">
+        <el-input
+          v-model="queryParams.remark"
+          placeholder="请输入备注"
+          clearable
+          @keyup.enter="handleQuery"
+          class="!w-240px"
+        />
+      </el-form-item>
+      <el-form-item label="创建时间" prop="createTime">
+        <el-date-picker
+          v-model="queryParams.createTime"
+          value-format="YYYY-MM-DD HH:mm:ss"
+          type="daterange"
+          start-placeholder="开始日期"
+          end-placeholder="结束日期"
+          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
+          class="!w-220px"
+        />
+      </el-form-item>
+      <el-form-item>
+        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
+        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
+        <el-button
+          type="primary"
+          plain
+          @click="openForm('create')"
+          v-hasPermi="['pms:iot-device-status-log:create']"
+        >
+          <Icon icon="ep:plus" class="mr-5px" /> 新增
+        </el-button>
+        <el-button
+          type="success"
+          plain
+          @click="handleExport"
+          :loading="exportLoading"
+          v-hasPermi="['pms:iot-device-status-log:export']"
+        >
+          <Icon icon="ep:download" class="mr-5px" /> 导出
+        </el-button>
+      </el-form-item>
+    </el-form>
+  </ContentWrap>
+
+  <!-- 列表 -->
+  <ContentWrap>
+    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
+      <el-table-column label="主键id" align="center" prop="id" />
+      <el-table-column label="设备id" align="center" prop="deviceId" />
+      <el-table-column label="设备修改前状态" align="center" prop="oldStatus" />
+      <el-table-column label="设备修改后状态" align="center" prop="newStatus" />
+      <el-table-column label="设备状态调整原因" align="center" prop="reason" />
+      <el-table-column label="备注" align="center" prop="remark" />
+      <el-table-column
+        label="创建时间"
+        align="center"
+        prop="createTime"
+        :formatter="dateFormatter"
+        width="180px"
+      />
+      <el-table-column label="操作" align="center" min-width="120px">
+        <template #default="scope">
+          <el-button
+            link
+            type="primary"
+            @click="openForm('update', scope.row.id)"
+            v-hasPermi="['pms:iot-device-status-log:update']"
+          >
+            编辑
+          </el-button>
+          <el-button
+            link
+            type="danger"
+            @click="handleDelete(scope.row.id)"
+            v-hasPermi="['pms:iot-device-status-log:delete']"
+          >
+            删除
+          </el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+    <!-- 分页 -->
+    <Pagination
+      :total="total"
+      v-model:page="queryParams.pageNo"
+      v-model:limit="queryParams.pageSize"
+      @pagination="getList"
+    />
+  </ContentWrap>
+
+  <!-- 表单弹窗:添加/修改 -->
+  <IotDeviceStatusLogForm ref="formRef" @success="getList" />
+</template>
+
+<script setup lang="ts">
+import { dateFormatter } from '@/utils/formatTime'
+import download from '@/utils/download'
+import { IotDeviceStatusLogApi, IotDeviceStatusLogVO } from '@/api/pms/iotdevicestatuslog'
+import IotDeviceStatusLogForm from './IotDeviceStatusLogForm.vue'
+
+/** 设备状态调整日志 列表 */
+defineOptions({ name: 'IotDeviceStatusLog' })
+
+const message = useMessage() // 消息弹窗
+const { t } = useI18n() // 国际化
+
+const loading = ref(true) // 列表的加载中
+const list = ref<IotDeviceStatusLogVO[]>([]) // 列表的数据
+const total = ref(0) // 列表的总页数
+const queryParams = reactive({
+  pageNo: 1,
+  pageSize: 10,
+  deviceId: undefined,
+  oldStatus: undefined,
+  newStatus: undefined,
+  reason: undefined,
+  remark: undefined,
+  createTime: [],
+})
+const queryFormRef = ref() // 搜索的表单
+const exportLoading = ref(false) // 导出的加载中
+
+/** 查询列表 */
+const getList = async () => {
+  loading.value = true
+  try {
+    const data = await IotDeviceStatusLogApi.getIotDeviceStatusLogPage(queryParams)
+    list.value = data.list
+    total.value = data.total
+  } finally {
+    loading.value = false
+  }
+}
+
+/** 搜索按钮操作 */
+const handleQuery = () => {
+  queryParams.pageNo = 1
+  getList()
+}
+
+/** 重置按钮操作 */
+const resetQuery = () => {
+  queryFormRef.value.resetFields()
+  handleQuery()
+}
+
+/** 添加/修改操作 */
+const formRef = ref()
+const openForm = (type: string, id?: number) => {
+  formRef.value.open(type, id)
+}
+
+/** 删除按钮操作 */
+const handleDelete = async (id: number) => {
+  try {
+    // 删除的二次确认
+    await message.delConfirm()
+    // 发起删除
+    await IotDeviceStatusLogApi.deleteIotDeviceStatusLog(id)
+    message.success(t('common.delSuccess'))
+    // 刷新列表
+    await getList()
+  } catch {}
+}
+
+/** 导出按钮操作 */
+const handleExport = async () => {
+  try {
+    // 导出的二次确认
+    await message.exportConfirm()
+    // 发起导出
+    exportLoading.value = true
+    const data = await IotDeviceStatusLogApi.exportIotDeviceStatusLog(queryParams)
+    download.excel(data, '设备状态调整日志.xls')
+  } catch {
+  } finally {
+    exportLoading.value = false
+  }
+}
+
+/** 初始化 **/
+onMounted(() => {
+  getList()
+})
+</script>

+ 20 - 4
src/views/pms/maintenance/IotMaintenancePlan.vue

@@ -441,7 +441,8 @@ const saveConfig = () => {
 }
 
 const queryParams = reactive({
-  deviceIds: undefined
+  deviceIds: undefined,
+  planId: id
 })
 
 const deviceChoose = async(selectedDevices) => {
@@ -688,9 +689,24 @@ onMounted(async () => {
   formData.value.deptId = deptId
   if (id){
     formType.value = 'update'
-    const iotMaintain = await IotMaintainApi.getIotMaintain(id);
-    deviceLabel.value = iotMaintain.deviceName
-    formData.value = iotMaintain
+    const plan = await IotMaintenancePlanApi.getIotMaintenancePlan(id);
+    deviceLabel.value = plan.deviceName
+    formData.value = plan
+    // 查询保养责任人
+    const personId = formData.value.responsiblePerson ? Number(formData.value.responsiblePerson) : 0;
+    UserApi.getUser(personId).then((res) => {
+      formData.value.responsiblePerson = res.nickname;
+    })
+    // 查询保养计划明细
+    const data = await IotMaintenanceBomApi.getMainPlanBOMs(queryParams);
+    list.value = []
+    if (Array.isArray(data)) {
+      list.value = data.map(item => ({
+        ...item,
+        // 这里可以添加必要的字段转换(如果有日期等需要格式化的字段)
+        lastNaturalDate: item.lastNaturalDate ? dayjs(item.lastNaturalDate).format('YYYY-MM-DD') : null
+      }))
+    }
   } else {
     formType.value = 'create';
     const { wsCache } = useCache()