|
|
@@ -144,7 +144,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, computed } from 'vue'
|
|
|
+import { ref, computed, onMounted } from 'vue'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import {defaultProps, handleTree} from "@/utils/tree";
|
|
|
import * as DeptApi from "@/api/system/dept";
|
|
|
@@ -152,8 +152,9 @@ import {IotDeviceApi, IotDeviceVO} from "@/api/pms/device";
|
|
|
import {IotDevicePersonApi, IotDevicePersonVO} from "@/api/pms/iotdeviceperson";
|
|
|
import * as UserApi from "@/api/system/user";
|
|
|
import {simpleUserList, UserVO} from "@/api/system/user";
|
|
|
-import { useRouter } from 'vue-router'
|
|
|
+import { useRouter, useRoute } from 'vue-router'
|
|
|
const router = useRouter()
|
|
|
+const route = useRoute() // 获取路由参数
|
|
|
const { t } = useI18n() // 国际化
|
|
|
import { useTagsViewStore } from "@/store/modules/tagsView";
|
|
|
|
|
|
@@ -538,29 +539,63 @@ onMounted(async () => {
|
|
|
const deptData = await DeptApi.getSimpleDeptList()
|
|
|
deptList.value = handleTree(deptData) // 转换为树形结构
|
|
|
|
|
|
- // 设置默认选中的部门(转换后树的第一个节点)
|
|
|
- if (deptList.value.length > 0) {
|
|
|
- // 获取转换后树的第一个节点
|
|
|
- const firstRootNode = deptList.value[0]
|
|
|
+ // 从路由参数获取部门ID
|
|
|
+ const routeDeptId = route.query.deptId ? Number(route.query.deptId) : null
|
|
|
|
|
|
- // 设置设备部门的默认值
|
|
|
- formData.value.deptId1 = firstRootNode.id
|
|
|
- // 触发设备部门的节点点击事件,加载设备列表
|
|
|
- await handleDeptDeviceTreeNodeClick(firstRootNode)
|
|
|
+ let targetDeptId: number
|
|
|
|
|
|
- // 设置责任人部门的默认值
|
|
|
- formData.value.deptIds = [firstRootNode.id]
|
|
|
- // 触发责任人部门的节点点击事件,加载人员列表
|
|
|
- await getUserList() //handleDeptUserTreeNodeClick(firstRootNode)
|
|
|
+ if (routeDeptId) {
|
|
|
+ // 如果路由参数有部门ID,使用路由参数中的部门ID
|
|
|
+ targetDeptId = routeDeptId
|
|
|
+ } else if (deptList.value.length > 0) {
|
|
|
+ // 否则使用第一个节点
|
|
|
+ targetDeptId = deptList.value[0].id
|
|
|
} else {
|
|
|
console.warn("部门树数据为空,无法设置默认值")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置默认选中的部门(转换后树的第一个节点)
|
|
|
+ // if (deptList.value.length > 0) {
|
|
|
+ // 获取转换后树的第一个节点
|
|
|
+ // const firstRootNode = deptList.value[0]
|
|
|
+
|
|
|
+ // 设置设备部门的默认值
|
|
|
+ formData.value.deptId1 = targetDeptId
|
|
|
+ // 触发设备部门的节点点击事件,加载设备列表
|
|
|
+ const targetDeptNode = findDeptNode(deptList.value, targetDeptId)
|
|
|
+ // 触发设备部门的节点点击事件,加载设备列表
|
|
|
+ if (targetDeptNode) {
|
|
|
+ await handleDeptDeviceTreeNodeClick(targetDeptNode)
|
|
|
}
|
|
|
+
|
|
|
+ // 设置责任人部门的默认值
|
|
|
+ formData.value.deptIds = [targetDeptId]
|
|
|
+ // 触发责任人部门的节点点击事件,加载人员列表
|
|
|
+ await getUserList() //handleDeptUserTreeNodeClick(firstRootNode)
|
|
|
+ // } else {
|
|
|
+ // console.warn("部门树数据为空,无法设置默认值")
|
|
|
+ // }
|
|
|
} catch (error) {
|
|
|
console.error("初始化部门树失败:", error)
|
|
|
ElMessage.error("加载部门数据失败")
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+// 在部门树中查找指定ID的节点
|
|
|
+const findDeptNode = (nodes: Tree[], deptId: number): Tree | null => {
|
|
|
+ for (const node of nodes) {
|
|
|
+ if (node.id === deptId) {
|
|
|
+ return node
|
|
|
+ }
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
+ const found = findDeptNode(node.children, deptId)
|
|
|
+ if (found) return found
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+}
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|