index.vue 3.24 KB
Newer Older
1 2 3
<!--
 * @Author: your name
 * @Date: 2022-02-12 11:07:10
纪泽龙's avatar
纪泽龙 committed
4
 * @LastEditTime: 2022-02-15 10:33:20
5 6 7 8 9 10 11 12 13 14 15 16
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /test/hello-world/src/components/GetPos.vue/index.vue
-->
<template>
  <el-dialog
    class="getpos"
    title="定位"
    :visible.sync="dialogVisible"
    width="60%"
    :before-close="handleClose"
  >
纪泽龙's avatar
纪泽龙 committed
17 18 19 20 21 22 23 24 25 26 27
    <template v-if="inputVisible">
      <div class="search-wrapper pos">
        <el-input
          v-model="searchinput"
          class="searchinput"
          placeholder="请输入内容"
          size="mini"
          style="width: 150px"
          ref="input"
        ></el-input>
      </div>
28

纪泽龙's avatar
纪泽龙 committed
29 30 31 32 33 34
      <div @click="pos" class="positionBtn pos">
        <el-button type="primary" size="mini" icon="el-icon-position"
          >定位</el-button
        >
      </div>
    </template>
35 36 37 38 39
    <div id="getposmap"></div>
  </el-dialog>
</template>

<script>
纪泽龙's avatar
纪泽龙 committed
40
import { EditorMap } from "@/utils/mapClass/getPath.js";
41 42
export default {
  props: {
纪泽龙's avatar
纪泽龙 committed
43
    //管道路径,二维数组s
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    pipePath: {
      type: Array,
      default: () => [],
    },
    // marker位置,数组
    devicePos: {
      type: Array,
      default: () => [],
    },
    // 设备类型,管道传pipe,marker就不用传值
    device: {
      type: String,
      default: "",
    },
    // 显示隐藏
纪泽龙's avatar
纪泽龙 committed
59 60 61 62 63 64 65 66 67
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    // input跟定位按钮是否展示
    inputVisible: {
      type: Boolean,
      default: true,
    },
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
  },
  data() {
    return {
      // dialogVisible: false,
      map: null,
      searchinput: "",
    };
  },
  watch: {
    dialogVisible(newValue) {
      if (newValue) {
        this.init();
      } else {
        this.map.destroy();
      }
      this.$nextTick(() => {
        const input = this.$refs.input.$refs.input;
        this.map.positionSearch(input);
      });
    },
  },
纪泽龙's avatar
纪泽龙 committed
89
  mounted() {},
90 91 92 93 94 95 96 97
  methods: {
    init() {
      this.$nextTick(() => {
        this.map = new EditorMap("getposmap", {}, this);
        // 如果不传值就是设备,传pipe就是管道
        if (this.device == "") {
          // 如果传了路径就创建一个marker,如果没传就直接激活手动创建
          if (this.devicePos.length > 0) {
纪泽龙's avatar
纪泽龙 committed
98
            this.map.addDevice({ path: this.devicePos });
99 100 101 102 103
          } else {
            this.map.mouseAddMarker();
          }
        } else {
          if (this.pipePath.length > 0) {
纪泽龙's avatar
纪泽龙 committed
104
            this.map.addPipeLine({ path: this.pipePath });
105 106 107 108 109 110 111
          } else {
            this.mouseAddPipeline();
          }
        }
      });
    },
    handleClose() {
纪泽龙's avatar
纪泽龙 committed
112
      this.$emit("close");
113 114 115 116 117 118 119 120
    },
    open() {
      this.dialogVisible = true;
    },
    // 返回坐标
    pos() {
      this.path = this.map.getPath();
      this.$emit("getPath", this.path);
纪泽龙's avatar
纪泽龙 committed
121
      console.log(this.path);
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
      if (this.path?.length > 0) {
        this.$emit("update:dialogVisible", false);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.search-wrapper {
  left: 30px;
}
.positionBtn {
  right: 30px;
}
.pos {
  position: absolute;
  top: 90px;
  z-index: 20;
}
#getposmap {
  width: 100%;
  height: 500px;
}
</style>