<template>
  <div id="app">
    <dv-loading v-if="loading">Loading...</dv-loading>
    <Header></Header>
    <MainMap v-if="shouldShowMainMap"></MainMap>
    <MiddleMenu></MiddleMenu>
    <router-view />
  </div>
</template>

<script>
import MainMap from "@/components/mainMap/index.vue";
import Header from "@/components/layout/header";
import MiddleMenu from "@/components/layout/middleMenu";
import { getCode, silenceLogin } from "@/api/login";

export default {
  components: { Header, MiddleMenu, MainMap },
  data() {
    return {
      loading: true,
      currtime: "",
    };
  },
  computed: {
    shouldShowMainMap() {
      // 默认显示MainMap，除非路由meta中明确设置showMainMap为false
      return this.$route.meta.showMainMap !== false;
    },
  },
  watch: {
    $route(val) {
      console.log(val, "oooo");
      if (val.query.areaCode) {
        this.$store.commit("CHANGE_AREA_CODE", val.query.areaCode);
        if (val.query.name) {
          this.$store.commit("CHANGE_APP_NAME", `${val.query.name}`);
        } else {
          this.$store.commit("CHANGE_APP_NAME", `住宅小区电梯大数据管理平台`);
        }
      }
    },
  },
  mounted() {
    this.cancelLoading();
    // 定时刷新当前时间
    this.currentTime();
    this.silenceOperate();
  },
  methods: {
    //进入大屏默认登陆
    async silenceOperate() {
      await getCode({});
    },
    getTime: function () {
      var _this = this;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      _this.currtime =
        yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
    },
    currentTime() {
      setInterval(this.getTime, 500);
    },
    cancelLoading() {
      setTimeout(() => {
        this.loading = false;
      }, 500);
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .amap-info-content {
  padding: 0 !important;
}
body {
  margin: 0;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

}
</style>