浏览代码

通讯录 组织树根据条件筛选出部门

Luka 1 月之前
父节点
当前提交
2b0651eabd

+ 3 - 0
src/types/global.d.ts

@@ -5,6 +5,9 @@ export interface IOptions {
 
 export interface TreeOptions {
 	id: string;
+	parentId: string;
 	label: string;
+	weight: number;
+	disabled: boolean;
 	children?: TreeOptions[];
 }

+ 15 - 7
src/views/notificationInfoManage/addressBook/components/detail.vue

@@ -295,22 +295,30 @@ async function setDialogVisible(isNew: boolean = true, check: boolean = false) {
 watch(
 	() => formData.value.unitName,
 	(newVal, oldVal) => {
+		console.log(newVal, oldVal);
 		belongsDeptOptions.value = getChildrenById(unitOptions.value, newVal);
 	}
 );
 
-/** 深度优先搜索,找到第一个 id 匹配的节点并返回它的 children */
-function getChildrenById(treeData: any[], targetId: string): any {
-	for (const node of treeData) {
+/**
+ * 根据 id 查找节点并返回其 children
+ * @param tree 树形结构数据
+ * @param targetId 目标 id
+ * @returns 匹配的节点的 children,未找到返回 undefined
+ */
+function getChildrenById(tree: TreeOptions[], targetId: string): TreeOptions[] | undefined {
+	for (const node of tree) {
 		if (node.id === targetId) {
 			return node.children;
 		}
-		if (node.children) {
-			const found = getChildrenById(node.children, targetId);
-			if (found) return found;
+		if (node.children && node.children.length > 0) {
+			const result = getChildrenById(node.children, targetId);
+			if (result !== undefined) {
+				return result;
+			}
 		}
 	}
-	return [];
+	return undefined;
 }
 
 // 点击确定

+ 60 - 52
src/views/notificationInfoManage/notificationListManage/index.vue

@@ -78,7 +78,7 @@
 				<el-button
 					type="primary"
 					link
-					@click="handleDelete(scope.row.rentalCompanyId)"
+					@click="handleStatus(scope.row.rentalCompanyId, '2', '启用')"
 					v-if="scope.row.releaseStatus == 1"
 				>
 					启用
@@ -86,7 +86,7 @@
 				<el-button
 					type="primary"
 					link
-					@click="handleDelete(scope.row.rentalCompanyId)"
+					@click="handleStatus(scope.row.rentalCompanyId, '3', '废止')"
 					v-if="scope.row.releaseStatus == 2"
 				>
 					废止
@@ -150,19 +150,19 @@ const handleAdd = () => {
 };
 const searchTableRef = ref();
 // 删除按钮
-function handleDelete(value: any) {
-	ElMessageBox.confirm('是否删除这条数据?', '删除提示', {
+function handleStatus(value: string, status: string, str: string) {
+	ElMessageBox.confirm(`是否${str}这条数据?`, '状态提示', {
 		confirmButtonText: '确定',
 		cancelButtonText: '取消',
 		type: 'warning',
 	})
 		.then(() => {
-			systemStore.deletePageDataAction(contentConfig.pageName, value);
+			// systemStore.deletePageDataAction(contentConfig.pageName, value);
 		})
 		.catch(() => {
 			ElMessage({
 				type: 'info',
-				message: '取消删除',
+				message: '取消操作',
 			});
 		});
 }
@@ -188,68 +188,76 @@ onMounted(async () => {
 	// treeData.value = await outDeptTree();
 	treeData.value = [
 		{
-			id: '1',
-			label: 'Level one 1',
+			id: '100',
+			parentId: '0',
+			label: '交通部测试1',
+			weight: 0,
+			disabled: false,
 			children: [
 				{
-					id: '1-1',
-					label: 'Level two 1-1',
+					id: '101',
+					parentId: '100',
+					label: 'XXXXX机构1',
+					weight: 1,
+					disabled: false,
 					children: [
 						{
-							id: '1-1-1',
-							label: 'Level three 1-1-1',
+							id: '103',
+							parentId: '101',
+							label: '研发部门',
+							weight: 1,
+							disabled: false,
 						},
-					],
-				},
-			],
-		},
-		{
-			id: '2',
-			label: 'Level one 2',
-			children: [
-				{
-					id: '2-1',
-					label: 'Level two 2-1',
-					children: [
 						{
-							id: '2-1-1',
-							label: 'Level three 2-1-1',
+							id: '104',
+							parentId: '101',
+							label: '市场部门',
+							weight: 2,
+							disabled: false,
 						},
-					],
-				},
-				{
-					id: '2-2',
-					label: 'Level two 2-2',
-					children: [
 						{
-							id: '2-2-1',
-							label: 'Level three 2-2-1',
+							id: '105',
+							parentId: '101',
+							label: '测试部门',
+							weight: 3,
+							disabled: false,
+						},
+						{
+							id: '106',
+							parentId: '101',
+							label: '财务部门',
+							weight: 4,
+							disabled: false,
 						},
-					],
-				},
-			],
-		},
-		{
-			id: '3',
-			label: 'Level one 3',
-			children: [
-				{
-					id: '3-1',
-					label: 'Level two 3-1',
-					children: [
 						{
-							id: '3-1-1',
-							label: 'Level three 3-1-1',
+							id: '107',
+							parentId: '101',
+							label: '运维部门',
+							weight: 5,
+							disabled: false,
 						},
 					],
 				},
 				{
-					value: '3-2',
-					label: 'Level two 3-2',
+					id: '102',
+					parentId: '100',
+					label: 'XXXXX机构2',
+					weight: 2,
+					disabled: false,
 					children: [
 						{
-							id: '3-2-1',
-							label: 'Level three 3-2-1',
+							id: '108',
+							parentId: '102',
+							label: '市场部门',
+							weight: 1,
+							disabled: false,
+						},
+						{
+							id: '109',
+							parentId: '102',
+							label: '财务部门',
+							weight: 2,
+							disabled: false,
 						},
 					],
 				},