index.vue 3.45 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
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
<!--
 * @Author: your name
 * @Date: 2022-02-12 11:07:10
 * @LastEditTime: 2022-02-22 15:08:10
 * @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"
    append-to-body
  >
    <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>

      <div @click="pos" class="positionBtn pos">
        <el-button type="primary" size="mini" icon="el-icon-position"
          > 确定 </el-button
        >
      </div>
    </template>
    <div id="getposmap"></div>
  </el-dialog>
</template>

<script>
import { EditorMap } from "@/utils/mapClass/getPath.js";
export default {
  props: {
    //管道路径,二维数组s
    pipePath: {
      type: Array,
      default: () => [],
    },
    // marker位置,数组
    devicePos: {
      type: Array,
      default: () => [],
    },
    // 设备类型,管道传pipe,marker就不用传值
    device: {
      type: String,
      default: "",
    },
    // 显示隐藏
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    // input跟定位按钮是否展示
    inputVisible: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      // dialogVisible: false,
      map: null,
      searchinput: "",
    };
  },
  watch: {
    dialogVisible(newValue) {
      if (newValue) {
        this.init();
      } else {

        this.map.destroy();
        this.searchinput="";
      }
      this.$nextTick(() => {
        const input = this.$refs.input.$refs.input;
        this.map.positionSearch(input);
      });
    },
  },
  mounted() {},
  methods: {
    init() {
      this.$nextTick(() => {
        const path = eval(this.$store.state.user.systemSetting.map_center);
        console.log("path",path);
        this.map = new EditorMap("getposmap", {center:path}, this);
        // 如果不传值就是设备,传pipe就是管道
        if (this.device == "") {
          // 如果传了路径就创建一个marker,如果没传就直接激活手动创建
          if (this.devicePos.length > 0) {
            this.map.addDevice({ path: this.devicePos });
          } else {
            this.map.mouseAddMarker();
          }
        } else {
          //console.log(this.pipePath.length)
          if (this.pipePath!=null && this.pipePath.length > 0) {
            this.map.addPipeLine({ path: this.pipePath });
          } else {
            this.map.mouseAddPipeline();
          }
        }
      });
    },
    handleClose() {
      this.$emit("close");
    },
    open() {
      this.dialogVisible = true;
    },
    // 返回坐标
    pos() {
      this.path = this.map.getPath();
      this.$emit("getPath", this.path);
      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>