Browse Source

父级节点也需保存

lxf 2 years ago
parent
commit
a9e07eb914
1 changed files with 21 additions and 6 deletions
  1. 21 6
      src/views/system/tenant/index.vue

+ 21 - 6
src/views/system/tenant/index.vue

@@ -62,7 +62,7 @@ const defaultProps = {
   children: "children",
   label: "label",
 };
-const tree = ref(null)
+const tree = ref(null);
 const sourceList = ref({
   data: [],
   pagination: {
@@ -325,21 +325,38 @@ const select = (_selection, row) => {
   selection.value.data = _selection;
   console.log(_selection.length);
 };
+const getSubset = (list, data) => {
+  for (let i = 0; i < list.length; i++) {
+    if (list[i].children && list[i].children.length > 0) {
+      getSubset(list[i].children, data);
+    } else {
+      data.push(list[i].id);
+    }
+  }
+  return data;
+};
 const openRoomModal = () => {
   proxy.get("/tenantInfo/roleMenuTreeSelect/" + selection.value.data[0].tenantId).then((res) => {
-    console.log(res);
     if (res.code == 200) {
-      formData.treeData = res.checkedKeys;
       treeData.value = res.menus;
+      let data = getSubset(res.menus, []);
+      formData.treeData = res.checkedKeys.filter((item) => {
+        return data.some((i) => item == i);
+      });
       roomDialogVisible.value = true;
     }
   });
 };
+const noRepeat = (arr) => {
+  var newArr = [...new Set(arr)];
+  return newArr;
+};
 const submitTree = () => {
+  let data = noRepeat(tree.value.getHalfCheckedKeys().concat(tree.value.getCheckedKeys()));
   proxy
     .post("/tenantInfo/bindingMenu", {
       tenantId: selection.value.data[0].tenantId,
-      menuIdList: tree.value.getCheckedKeys(),
+      menuIdList: data,
     })
     .then((res) => {
       ElMessage({
@@ -349,11 +366,9 @@ const submitTree = () => {
       roomDialogVisible.value = false;
     });
 };
-
 const submitForm = () => {
   byform.value.handleSubmit((valid) => {
     submitLoading.value = true;
-
     proxy
       .post("/tenantInfo/" + modalType.value, formData.data)
       .then((res) => {