activeLocation.vue 4.82 KB
<template>
  <v-full-layout class="active_location">
    <template slot="breadcrumb">
      <el-breadcrumb-item>激活位置</el-breadcrumb-item>
    </template>
    <template slot="main">
      <div class="device_list">
        <div class="title">
          <span>设备列表(3)</span>
          <i class="el-icon-close i_close"></i>
        </div>
        <div class="list_box">
          <div class="cell" v-for="(item,index) in 3" :key="index">
            <div class="top">
              <i class="i_circle"></i>
              <span>陈庆红</span>
              <span>1700151515(无线)</span>
            </div>
            <div class="bottom">
              <span>车架号:</span>
              <span>LDSKF5522555555</span>
            </div>
          </div>
        </div>
        <div class="device_footer">
          <i class="i_circle"></i>
          <span>在线</span>
          <i class="i_circle i_red"></i>
          <span>离线</span>
        </div>
      </div>
      <div id="map" class="map-container"></div>
    </template>
  </v-full-layout>
</template>
<script>
import mapService from "utils/mapService.js";
import "utils/mapEvent.js";
import EventBus from "../../event-bus";
import remoteLoad from "utils/remoteLoad.js";
import { CONSTANT } from "../../constant";
export default {
  data() {
    return {
      AMap: null,
      mapObj: null,
      checkLoadedTimeoutId: "",
    };
  },
  created() {
    console.log(history.state);
    if (window.AMap) {
      this.initMap();
    } else {
      remoteLoad(`${CONSTANT.AMAP_URL}`).then(() => {
        remoteLoad(`https://webapi.amap.com/ui/1.0/main.js?v=1.0.11`).then(
          () => {
            this.initMap();
          }
        );
      });
    }
  },
  methods: {
    // 初始化地图
    initMap() {
      let check = () => {
        if (this.checkLoadedTimeoutId) {
          window.clearTimeout(this.checkLoadedTimeoutId);
        }
        return setTimeout(() => {
          if (
            "AMap" in window &&
            typeof AMap.Map == "function" &&
            !this.mapObj
          ) {
            window.AMap = AMap;
            this.mapObj = mapService.init("map");
            this.isInitMap = true;
            let o = history.state;
            console.log(o);
            if (o.lng || o.bsLng) {
              o.elat = o.lat;
              o.elng = o.lng;
              this.addLocation(o);
            }
          } else {
            this.checkLoadedTimeoutId = check();
          }
        }, 100);
      };
      this.checkLoadedTimeoutId = check();
    },

    // 添加位置点
    addLocation(row) {
      let drawData = row;
      EventBus.$emit("uiMap.monitor.drawMaker", drawData, true);
    },
  },
};
</script>
<style lang="scss" scoped>
.active_location {
  .full-width {
    position: absolute;
    top: 0px;
    height: 100%;
    left: 0;
    width: 100%;
    bottom: 0;
    .map-container {
      width: 100%;
      height: 100%;
      z-index: 100;
      position: absolute;
      top: 0px;
      left: 0;
      bottom: 0;
      overflow: hidden;
    }
    .device_list {
      position: absolute;
      top: 16px;
      left: 16px;
      width: 260px;
      height: 300px;
      background: #fff;
      border-radius: 4px;
      z-index: 101;
      display: flex;
      flex-direction: column;
      border: 1px solid #f2f2f2;
      .title {
        position: relative;
        text-align: center;
        height: 36px;
        line-height: 36px;
        border-bottom: 1px solid #f2f2f2;
        span {
          font-weight: bold;
        }
        .i_close {
          position: absolute;
          right: 10px;
          top: 50%;
          transform: translateY(-50%);
          font-size: 16px;
          cursor: pointer;
        }
        .i_close:hover {
          color: #f00;
        }
      }
      .list_box {
        flex: 1;
        padding: 10px 0;
        .cell {
          position: relative;
          padding: 4px 10px;
          line-height:2;
          cursor: pointer;
          .bottom{
            padding-left:12px;
          }
        }
        .cell:hover{
          background:#f2f2f2;
        }
        .cell:after{
          position:absolute;
          display: block;
          content:"";
          height:1px;
          left:0;
          right:0;
          bottom:0;
          background: #f2f2f2;
        }
      }
      .device_footer {
        height: 30px;
        line-height: 30px;
        border-top: 1px solid #f2f2f2;
        padding: 0 10px;
        display: flex;
        align-items: center;
        span {
          position: relative;
          font-size: 12px;
          color: #333;
          margin: 0 10px 0 0;
        }
        .i_circle {
          margin: 0 4px 0 0;
        }
      }
    }
  }
}
.i_circle {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 100%;
  background: #09bf99;
}
.i_red {
  background: #f00;
}
</style>