<template>
  <section class="app-main" :style="{ paddingTop: show ? '140px' : '80px' }">
    <div class="app-main-view">
      <keep-alive>
        <router-view v-if="$route.meta.isCache == 1 && nameKey.indexOf($route.name) == 0" :key="nameKey" />
      </keep-alive>
      <router-view v-if="$route.meta.isCache != 1 && nameKey.indexOf($route.name) == 0" :key="nameKey" />
      <zj-watermark color="rgba(200,200,200,.3)" position="absolute" :str="str" zIndex="99" />
    </div>
  </section>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'AppMain',
  data() {
    return {
      key: 0,
      nameKey: ""
    }
  },
  computed: {
    ...mapGetters(['show']),
    str() {
      return this.$store.state?.user?.name
    },
  },
  watch: {
    $route(val, oval) {
      this.setNameKey()
    },
  },
  created() {
    this.setNameKey()
  },
  methods: {
    setNameKey() {
      var { name, params } = this.$route
      var { pageType, pageCode, pagePam } = params
      var item = this.$store.state.tagsView.visitedViews.find(item => {
        return item?.nameKey.indexOf(`${name}_${pageType}_${pageCode}_${pagePam}`) === 0
      })
      if (!item) {
        setTimeout(() => {
          this.setNameKey()
        }, 50)
      } else {
        this.nameKey = item.nameKey
      }
    }
  }
}
</script>

<style scoped>
.app-main {
  /*50 = navbar  */
  height: 100vh;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.fixed-header+.app-main {
  /* padding-top: 50px; */
  /* padding-top: 80px; */
}

.app-main-view {
  width: 100%;
  height: 100%;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
}
</style>
