shuishen
2022-11-02 764cb58899b8ca0e9632a5e83c6950569442c41c
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
<template>
  <div class="baseMapMap" :key="Refresh">
    <MapInThere ref="baseMapMapsMap" />
    <div class="controlbaseMapMap">
      <div v-for="(item, index) in mapServiceValue" :key="index">
        {{ item.name }}
        <div style="float: right">
          <el-switch class="around_left" v-model="item.show"> </el-switch>
          <el-button
            class="around_left"
            type="danger"
            icon="el-icon-delete"
            circle
            @click="deleteMapService(index)"
            :disabled="notSet"
          ></el-button>
        </div>
        <el-divider v-if="index != mapServiceValue.length - 1"></el-divider>
      </div>
    </div>
  </div>
</template>
 
<script>
import { mapGetters } from "vuex";
import MapInThere from "@/components/basemap/mainInThere.vue";
export default {
  name: "getMapData",
  components: {
    MapInThere,
  },
  computed: {
    ...mapGetters(["mapServiceValue", "notSet"]),
  },
  watch: {
    mapServiceValue: {
      handler(val) {
        // console.log("深度监听:", val);
        //改变父级标单字段验证状态
        this.$emit("changeMapSI");
        this.checkDom("baseMapMapsMap", (dom) => {
          //更改地图图层数据
          dom.setServiceData(this.mapServiceValue);
        });
      },
      deep: true,
    },
  },
  data() {
    return {
      mapServiceData: [],
    };
  },
  destroyed() {
    //销毁清楚数据
    this.$store.commit("clearMapServiceValue");
    this.checkDom("baseMapMapsMap", (dom) => {
      //更改地图图层数据
      dom.clearServiceData();
    });
  },
  mounted() {},
  methods: {
    deleteMapService(index) {
      // console.log(index);
      this.$store.commit("deleteMapServiceValue", index);
    },
    // addService(data) {
    //   this.mapServiceData.push({
    //     ...data,
    //     show: true,
    //   });
    //   console.log(this.mapServiceData);
    //   this.$refs.baseMapMapsMap.addMapService();
    // },
    checkDom(name, fn) {
      //  声明定时器
      let that = this;
      var timer = null;
      //  检查dom是否执行完成
      function checkDom() {
        let dom = that.$refs[name];
        if (dom) {
          //  执行dom加载完成后的操作
          //  清除定时器
          if (!timer) {
            clearTimeout(timer);
          }
          if (fn) {
            //回调函数
            fn(dom);
            return;
          } else {
            return dom;
          }
        } else {
          //  自我调用
          timer = setTimeout(checkDom, 100);
        }
      }
      //  首次执行
      checkDom();
    },
  },
};
</script>
 
<style lang="scss">
.flexCenter {
  display: flex;
  align-items: center;
  justify-content: center;
}
.baseMapMap {
  width: 100%;
  height: 100%;
  position: relative;
  .controlbaseMapMap {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: #fff;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0px 0px 10px -3px #000;
    max-height: 370px;
    overflow-x: auto;
    overflow-y: scroll;
  }
  // 验证
  .notPath {
    // border-bottom: 0.5px solid red;
  }
}
 
//过度动画
.list-enter {
  opacity: 0;
  transform: translateY(10px);
}
.list-leave-to {
  opacity: 0;
  transform: translateY(-10px);
}
 
.list-enter-to,
.list-leave {
  opacity: 1;
}
​ .list-enter-active,
.list-leave-active {
  transition: all 0.3s;
}
.around_left {
  padding: 0 5px;
}
</style>