<template>
  <section class="app-main">
      <template v-for="view in visitedViews" >
<!--        <iframe v-show="tag.name==$store.state.tagsView.selectedView" frameborder="0" width="100%" height="100%">-->
          <component class="app-page" :ref="view.name" :is="view.component" v-if="livingViews[view.name]>=0"
                     v-show="view.name== selectedView" :params="setParams(view)" :key="view.name"></component>
<!--        </iframe>-->
      </template>
  </section>
</template>

<script>
export default {
    name: 'AppMain',
    data(){
        return {
            livingViews:{}
        }
    },
    watch:{
        "selectedView":{
            handler(val) {
                this.$nextTick(() => {
                    let com=this.$refs[val];
                    if (com) {
                        if (com.$refs&&com.$refs.layout&&com.$refs.layout.resize) {
                            com.$refs.layout.resize();
                        } else if (com[0].$refs&&com[0].$refs.layout&&com[0].$refs.layout.resize) {
                            com[0].$refs.layout.resize();
                        }
                    }
                })
            },
            immediate: true
        }
    },
    computed: {
        visitedViews() { //这个里面保存的是完整信息
            let livingViews={};
            for(let i in this.$store.state.tagsView.visitedViews){
                livingViews[this.$store.state.tagsView.visitedViews[i].name]=i;
            }
            this.livingViews=livingViews;
            return this.$store.state.tagsView.visitedViews
        },
        selectedView(){
            return this.$store.state.tagsView.selectedView
        }
    },
    mounted(){
        // if(this.$refs[this.$store.state.tagsView.selectedView].resize)
        //   this.$refs[this.$store.state.tagsView.selectedView].resize();
    },
    methods: {
        setParams(view) {
            if(view.url)
              return this.$core.getParams(view.url);
        }
    }
}
</script>

<style lang="scss" scoped>
.app-main {
  /* 50= navbar  50  */
  min-height: calc(100vh - 50px);
  width: 100%;
  position: relative;
  overflow: auto;
}

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

.hasTagsView {
  .app-main {
    /* 84 = navbar + tags-view = 50 + 34 */
    height: calc(100vh - 69px);
    min-height: calc(100vh - 69px);
  }
  .fixed-header+.app-main {
    padding-top: 69px;
  }
}
</style>

<style lang="scss">
// fix css style bug in open el-dialog
.el-popup-parent--hidden {
  .fixed-header {
    padding-right: 15px;
  }
}
</style>
