月球大数据地理空间分析展示平台-【前端】-月球2期前端
WX
2023-08-18 415ec3c6e33a74c0259af64d726c58070ac119e8
src/views/layer/layerManage.vue
@@ -23,6 +23,7 @@
        @check="handleCheckChange"
        ref="estreeRef"
        v-if="treeData.length"
        :default-checked-keys="DefaultId"
      >
        <template #default="{ node, data }">
          <span class="custom-tree-node">
@@ -33,7 +34,7 @@
                Delete
              </a>
            </span> -->
            <span class="button" v-if="data.type == 2">
            <span class="button" v-if="data.isLayer == 1">
              <el-dropdown trigger="click">
                <span class="el-dropdown-link">
                  <el-icon class="el-icon--right">
@@ -58,7 +59,7 @@
    </div>
  </div>
  <layer-set
    v-show="layerSetIsshow"
    v-if="layerSetIsshow"
    @SETstate="SETstate"
    :layerTree="treeData"
    @addlayer="addlayer"
@@ -84,83 +85,24 @@
  reactive,
  defineProps,
  defineEmits,
  nextTick,
} from "vue";
import layerSet from "./layerSet";
import attributeList from "./attributeList";
import layerDetail from "./layerDetail";
import { useStore } from "vuex"; // 引入useStore 方法
import { layer_selectAll } from "@/api/api";
import { perms_selectLayers } from "@/api/api";
import server from "@/assets/js/Map/server";
import { ElMessage } from "element-plus";
const store = useStore(); // 该方法用于返回store 实例
const stretchValue = ref("");
let estreeRef = ref();
const stretchOptions = [
  {
    value: "Option1",
    label: "Option1",
  },
  {
    value: "Option2",
    label: "Option2",
  },
  {
    value: "Option3",
    label: "Option3",
  },
  {
    value: "Option4",
    label: "Option4",
  },
  {
    value: "Option5",
    label: "Option5",
  },
];
const transparence = ref(0);
var treeData = ref([]);
let menuOption = reactive([
  {
    id: 1,
    name: "测试",
    isShow: false,
    checkedAll: false,
    type: 1,
    parentId: null,
  },
  {
    id: 2,
    layerState: false,
    name: "图层名称",
    layerUrl: "",
    type: 2,
    parentId: 1,
  },
  {
    id: 3,
    layerState: false,
    name: "图层菜单",
    layerUrl: "",
    type: 1,
    parentId: 1,
  },
  {
    id: 5,
    layerState: false,
    name: "图层名称11",
    layerUrl: "",
    type: 2,
    parentId: 3,
  },
  {
    id: 4,
    name: "测试1",
    isShow: false,
    checkedAll: true,
    layerState: false,
    type: 1,
    parentId: null,
  },
]);
var layerListData = ref([]);
let menuOption = reactive([]);
const layerSetIsshow = ref(false);
const layerAttributeIsshow = ref(false);
@@ -173,7 +115,8 @@
// 当前选中的节点 id
const selectedNodeId = ref(null as any); //做类型断言处理
const emits = defineEmits(["setCloseLayer"]);
//默认选中id
const DefaultId = ref([]);
//图层设置弹框
const layerSetBox = () => {
  layerSetIsshow.value = !layerSetIsshow.value;
@@ -187,9 +130,47 @@
};
//选择图层
const handleCheckChange = (data, checked) => {
  layerAttributeIsshow.value = false;
  layerDetailIsshow.value = false;
  let isCheck = checked.checkedKeys.indexOf(data.id) > -1;
  // this.setVisiable(data, isCheck);
  let son = estreeRef.value.getCheckedNodes();
  store.commit("SET_CHECKLAYER", son);
  setVisiable(data, isCheck);
  // server.addLayer(layerArr, isCheck);
};
const setVisiable = (treeNode, checked) => {
  if (checked !== undefined) {
    treeNode.checked = checked;
  } else {
    treeNode.checked = !treeNode.checked;
  }
  if (treeNode.children) {
    treeNode.children.forEach((item) => {
      setVisiable(item, treeNode.checked);
    });
    return;
  }
  if (!treeNode.isAdd) {
    server.addTreeData(treeNode);
    return;
  }
};
const defaultLayer = (val) => {
  val.forEach((e) => {
    DefaultId.value.forEach((v) => {
      if (e.id == v) {
        setVisiable(e, true);
        // return;
      }
    });
  });
};
const clickdropdown = (res, e) => {
  layerAttributeIsshow.value = false;
@@ -198,6 +179,9 @@
  if (res == 2) {
    layerAttributeIsshow.value = true;
  } else {
    if (!e.checked) {
      return ElMessage.error("请先勾选图层");
    }
    layerDetailIsshow.value = true;
  }
};
@@ -209,25 +193,78 @@
};
//编辑图层树
const addlayer = (res) => {
  menuOption.push(res);
  treeData.value = handleTree(menuOption, "id", "pid", "children");
  let node;
  layerListData.value.forEach((e) => {
    if (e.id == res.id) {
      node = estreeRef.value.getNode(e);
    }
  });
  // 将变动之前的node备份
  let copyNode = { ...node };
  copyNode.previousSibling = { ...node.previousSibling };
  copyNode.nextSibling = { ...node.nextSibling };
  if (res.type === 1) {
    // 上移
    if (node.previousSibling) {
      // 删除原先的node
      estreeRef.value.remove(node.data);
      // 拿到copy的node
      // nodeData = CircularJSON.parse(window.sessionStorage.getItem("menuNode"));
      // 复制该node到指定位置(参数:1. 要增加的节点的 data 2. 要增加的节点的后一个节点的 data、key 或者 node)
      estreeRef.value.insertBefore(
        copyNode.data,
        copyNode.previousSibling.data
      );
      // window.sessionStorage.removeItem("menuNode");
    }
  } else {
    // 下移
    if (node.nextSibling) {
      estreeRef.value.remove(node.data);
      estreeRef.value.insertAfter(copyNode.data, copyNode.nextSibling.data);
    }
  }
};
//删除图层树
const delLayer = (res) => {
  menuOption = menuOption.filter((item) => {
    return item.id != res;
  });
  console.log(res);
  console.log(menuOption);
  // menuOption = menuOption.filter((item) => {
  //   return item.id != res;
  // });
  // treeData = handleTree(menuOption, "id", "pid", "children");
};
const getLayer = async () => {
  const dt = await layer_selectAll();
  treeData.value = setTreeData(dt.result);
  treeData.value = JSON.parse(JSON.stringify(treeData.value));
  const dt = await perms_selectLayers();
  if (dt.code == 200) {
    treeData.value = setTreeData(dt.result).sort(function (a, b) {
      return a.sort - b.sort;
    });
    var std = [];
    var terrainId = null;
    dt.result.filter((res) => {
      if (res.isLayer == 1 && res.status == 1) {
        if (res.type == 1 && res.data == 2) {
          if (!terrainId) {
            terrainId = res.id;
            std.push(res.id);
          }
        } else {
          std.push(res.id);
        }
      }
    });
    DefaultId.value = std;
  console.log(treeData.value);
    //添加默认选中图层
    layerListData.value = dt.result;
    defaultLayer(dt.result);
    nextTick(() => {
      let son = estreeRef.value.getCheckedNodes();
      store.commit("SET_CHECKLAYER", son);
    });
  }
};
//构造树
@@ -238,7 +275,7 @@
    let branchArr = cloneData.filter((child) => father.id == child.pid);
    if (branchArr.length > 0) {
      branchArr.sort(function (a, b) {
        return a.orderNum - b.orderNum;
        return a.sort - b.sort;
      });
    }
@@ -248,9 +285,8 @@
    return father.pid == 0; // 返回一级菜单
  });
}
onMounted(() => {
  getLayer();
});
getLayer();
onMounted(() => {});
</script>
<style lang="less" scoped>
@@ -294,7 +330,7 @@
    }
  }
  .layerContent {
    height: 635px;
    height: 625px;
    padding: 0 8px;
    overflow: auto;
    overflow-y: auto;