|
@@ -257,7 +257,7 @@
|
|
|
multiple
|
|
multiple
|
|
|
v-model="currentTask.deptIds"
|
|
v-model="currentTask.deptIds"
|
|
|
:data="deptList"
|
|
:data="deptList"
|
|
|
- :props="defaultProps"
|
|
|
|
|
|
|
+ :props="treeSelectProps"
|
|
|
:default-expanded-keys="defaultExpandedKeys"
|
|
:default-expanded-keys="defaultExpandedKeys"
|
|
|
check-strictly
|
|
check-strictly
|
|
|
node-key="id"
|
|
node-key="id"
|
|
@@ -592,7 +592,7 @@
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
// 导入部分保持不变,与原始代码相同
|
|
// 导入部分保持不变,与原始代码相同
|
|
|
import { IotProjectInfoApi, IotProjectInfoVO } from '@/api/pms/iotprojectinfo'
|
|
import { IotProjectInfoApi, IotProjectInfoVO } from '@/api/pms/iotprojectinfo'
|
|
|
-import {defaultProps,handleTree} from "@/utils/tree";
|
|
|
|
|
|
|
+import {defaultProps, handleTree} from "@/utils/tree";
|
|
|
import * as DeptApi from "@/api/system/dept";
|
|
import * as DeptApi from "@/api/system/dept";
|
|
|
import {ref, reactive, computed, onMounted, watch} from "vue";
|
|
import {ref, reactive, computed, onMounted, watch} from "vue";
|
|
|
import {useUserStore} from "@/store/modules/user";
|
|
import {useUserStore} from "@/store/modules/user";
|
|
@@ -707,6 +707,16 @@ const isSpecialDept = computed(() => {
|
|
|
return formData.value.deptId === 163;
|
|
return formData.value.deptId === 163;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+// 定义新的树选择器配置,添加禁用逻辑
|
|
|
|
|
+const treeSelectProps = {
|
|
|
|
|
+ children: 'children',
|
|
|
|
|
+ label: 'name',
|
|
|
|
|
+ disabled: (data: any) => {
|
|
|
|
|
+ // 只有叶子节点(type = 3)可以选择,非叶子节点禁用
|
|
|
|
|
+ return data.type !== '3';
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
const getProjectInfo = async (contractId: number) => {
|
|
const getProjectInfo = async (contractId: number) => {
|
|
|
const project = projectList.value.find(item => item.id === contractId);
|
|
const project = projectList.value.find(item => item.id === contractId);
|
|
|
if (project) {
|
|
if (project) {
|
|
@@ -2015,10 +2025,33 @@ watch(() => currentTask.value.deptIds, (newVal) => {
|
|
|
// 监听部门列表加载完成
|
|
// 监听部门列表加载完成
|
|
|
watch(() => deptList.value, (newVal) => {
|
|
watch(() => deptList.value, (newVal) => {
|
|
|
if (newVal && newVal.length > 0 && currentTask.value.deptIds && currentTask.value.deptIds.length > 0) {
|
|
if (newVal && newVal.length > 0 && currentTask.value.deptIds && currentTask.value.deptIds.length > 0) {
|
|
|
- defaultExpandedKeys.value = [...currentTask.value.deptIds];
|
|
|
|
|
|
|
+ // defaultExpandedKeys.value = [...currentTask.value.deptIds];
|
|
|
|
|
+ // 过滤掉非叶子节点的ID,只保留叶子节点
|
|
|
|
|
+ const leafNodeIds = currentTask.value.deptIds.filter(id => {
|
|
|
|
|
+ const node = findDeptNodeById(newVal, id);
|
|
|
|
|
+ return node && node.type === '3';
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (leafNodeIds.length > 0) {
|
|
|
|
|
+ defaultExpandedKeys.value = [...leafNodeIds];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}, { immediate: true, deep: true });
|
|
}, { immediate: true, deep: true });
|
|
|
|
|
|
|
|
|
|
+// 根据ID在部门树中查找节点
|
|
|
|
|
+const findDeptNodeById = (tree: any[], id: number): any => {
|
|
|
|
|
+ for (const node of tree) {
|
|
|
|
|
+ if (node.id === id) {
|
|
|
|
|
+ return node;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (node.children && node.children.length > 0) {
|
|
|
|
|
+ const found = findDeptNodeById(node.children, id);
|
|
|
|
|
+ if (found) return found;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
// 监听项目列表变化,确保列表加载完成后才执行自动选择
|
|
// 监听项目列表变化,确保列表加载完成后才执行自动选择
|
|
|
watch(projectList, (newVal) => {
|
|
watch(projectList, (newVal) => {
|
|
|
if (newVal && newVal.length > 0) {
|
|
if (newVal && newVal.length > 0) {
|
|
@@ -2058,6 +2091,19 @@ onMounted(async () => {
|
|
|
deptList.value = handleTree(await DeptApi.companyLevelChildrenDepts())
|
|
deptList.value = handleTree(await DeptApi.companyLevelChildrenDepts())
|
|
|
let deptId = useUserStore().getUser.deptId
|
|
let deptId = useUserStore().getUser.deptId
|
|
|
projectList.value = await IotProjectInfoApi.getIotProjectInfoUser(deptId);
|
|
projectList.value = await IotProjectInfoApi.getIotProjectInfoUser(deptId);
|
|
|
|
|
+
|
|
|
|
|
+ // 初始化时过滤当前任务中的部门ID,移除非叶子节点
|
|
|
|
|
+ if (currentTask.value.deptIds && currentTask.value.deptIds.length > 0) {
|
|
|
|
|
+ const validDeptIds = currentTask.value.deptIds.filter(id => {
|
|
|
|
|
+ const node = findDeptNodeById(deptList.value, id);
|
|
|
|
|
+ return node && node.type === '3';
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (validDeptIds.length !== currentTask.value.deptIds.length) {
|
|
|
|
|
+ currentTask.value.deptIds = validDeptIds;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 查询当前任务已经选中的设备信息
|
|
// 查询当前任务已经选中的设备信息
|
|
|
open();
|
|
open();
|
|
|
})
|
|
})
|