基于廊坊系统为基础,国防科技大学系统演示Demo
lixuliang
2024-04-29 f3e9c51852c875f02a9ab5047fcfa36e0725cd7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<template>
  <div class="InfoPopup">
    <Popup
      ref="pop"
      v-for="(data, index) in PopupData"
      :key="data.id"
      title="图层管理"
      :maxHeight="data.maxHeight || '700px'"
      @close="close(data.id)"
      :left="data.left || left"
      :top="data.top || top + index * 30 + 'px'"
    >
      <div id="eagleMapContainer">
        <div
          style="height:400px;"
          v-drag
          @mousedown="dragEagle"
        >
          <layer-tree />
        </div>
      </div>
      <!-- <div class="InfoPopupContianer">
       
      </div> -->
    </Popup>
  </div>
</template>
 
<script>
import Popup from "./Popup.vue";
import LayerTree from "./LayerTree.vue";
export default {
  name: "maplayer",
 
  components: {
    Popup,
    LayerTree,
  },
  data() {
    return {
      // 弹窗数据
      PopupData: ["maplayer"],
      left: "calc(100% - 370px)",
      top: 10,
    };
  },
  directives: {
    drag: {
      inserted: function (el) {
        const dragDom = el;
        dragDom.style.cursor = "nwse-resize";
        dragDom.onmousedown = (e) => {
          // 鼠标按下,计算当前元素距离可视区的距离
          const disX = e.clientX;
          const w = dragDom.clientWidth;
          const minW = 300;
          const maxW = 1000;
          const disY = e.clientY;
          const h = dragDom.clientHeight;
          const minH = 300;
          const maxH = 700;
          var nw, nh;
          document.onmousemove = function (e) {
            // 通过事件委托,计算移动的距离
            const l = e.clientX - disX;
            const r = e.clientY - disY;
            // 改变当前元素宽度,不可超过最小最大值
            nw = w + l;
            nw = nw < minW ? minW : nw;
            nw = nw > maxW ? maxW : nw;
            dragDom.style.width = `${nw}px`;
            nh = h + r;
            nh = nh < minH ? minH : nh;
            nh = nh > maxH ? maxH : nh;
            dragDom.style.height = `${nh}px`;
          };
 
          document.onmouseup = function (e) {
            document.onmousemove = null;
            document.onmouseup = null;
          };
        };
      },
    },
  },
  computed: {},
  mounted() { },
  methods: {
    dragEagle: function (e) {
      var targetDiv = document.getElementById('eagleMapContainer');
      //得到点击时该地图容器的宽高:
      var targetDivHeight = targetDiv.offsetHeight;
      var startX = e.clientX;
      var startY = e.clientY;
      var _this = this;
      document.onmousemove = function (e) {
        e.preventDefault();
        //得到鼠标拖动的宽高距离:取绝对值
        var distX = Math.abs(e.clientX - startX);
        var distY = Math.abs(e.clientY - startY);
        //往上方拖动:
        if (e.clientY < startY) {
          targetDiv.style.height = targetDivHeight + distY + 'px';
        }
        //往下方拖动:
        if (e.clientX < startX && e.clientY > startY) {
          targetDiv.style.height = (targetDivHeight - distY) + 'px';
        }
        if (parseInt(targetDiv.style.height) >= 300) {
          targetDiv.style.height = 300 + 'px';
        }
        if (parseInt(targetDiv.style.height) <= 150) {
          targetDiv.style.height = 150 + 'px';
        }
      }
      document.onmouseup = function () {
        document.onmousemove = null;
      }
    },
    // 关闭所有
    closeAll() {
      this.PopupData.forEach((item) => {
        item.close && item.close();
      });
      this.PopupData = [];
    },
    // 关闭弹窗
    close(id) {
      this.$bus.$emit("treeDataCopy", "true");
      let index = this.PopupData.findIndex((item) => {
        return item.id === id;
      });
      let data = this.PopupData.splice(index, 1)[0];
      data.close && data.close();
      this.$store.state.layerMnage = false;
    },
    // 打开弹窗
    open(title, value, style = {}) {
      this.PopupData.push({
        id: this.createRandomId(),
        title,
        value,
        ...style,
      });
      let index = this.PopupData.length - 1;
      this.$nextTick(() => {
        this.$refs.pop[index].open();
      });
      return this.PopupData[index];
    },
    // 随机id
    createRandomId() {
      return (
        (Math.random() * 10000000).toString(16).substr(0, 4) +
        "-" +
        new Date().getTime() +
        "-" +
        Math.random().toString().substr(2, 5)
      );
    },
  },
};
</script>