<template>
  <div :class="[prefixCls, getLayoutContentMode, { 'layout-content-full': getShowFullHeader }]" v-loading="getOpenPageLoading && getPageLoading">
    <PageLayout class="page-box" />
    <!-- update-begin-author:zyf date:20211129 for:qiankun 挂载子应用盒子 -->
    <div v-if="getShowFullHeader && loading" class="app-loading">
      <div id="loader-wrapper" class="app-loading">
        <div class="app-loading-wrap">
          <div class="app-loading-dots">
            <span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
          </div>
        </div>
      </div>
    </div>
    <!-- <div id="content" class="app-view-box" v-show="openQianKun == 'true' && currentRoute.path.startsWith('/micro-') && !noContentLink.includes(currentRoute.path)" :style="{top: getShowFullHeader ? 0 : '48px'}"> </div> -->
    <!-- update-end-author:zyf date:20211129 for: qiankun 挂载子应用盒子-->
  </div>
</template>
<script lang="ts">
  import { defineComponent, onMounted, unref, computed, ref, onBeforeMount, watch } from 'vue';
  import PageLayout from '/@/layouts/page/index.vue';
  import { useDesign } from '/@/hooks/web/useDesign';
  import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
  import { useContentViewHeight } from './useContentViewHeight';
  import { useHeaderSetting } from '/@/hooks/setting/useHeaderSetting';
  import { useRouter } from 'vue-router';
  import { registerApps } from '/@/qiankun';
  import { useGlobSetting } from '/@/hooks/setting';
  import { getActions } from '/@/qiankun/state';
  import { nextTick } from 'vue';
  import { noContentLink } from '../layout.data';

  export default defineComponent({
    name: 'LayoutContent',
    components: { PageLayout },
    setup() {
      const { prefixCls } = useDesign('layout-content');
      const { getOpenPageLoading } = useTransitionSetting();
      const { getLayoutContentMode, getPageLoading } = useRootSetting();
      const { getShowFullHeaderRef } = useHeaderSetting();
      const router = useRouter();
      const { currentRoute } = router;
      const globSetting = useGlobSetting();
      const openQianKun = globSetting.openQianKun;
      const loading = ref(false);
      let actions;
      if (openQianKun == 'true') {
        actions = getActions();
        actions.setGlobalState({ isMounted: false });
        actions.onGlobalStateChange((newState, prev) => {
          for (const key in newState) {
            if (key === 'isMounted') {
              if (newState[key] !== prev[key] && newState[key] === true) {
                loading.value = false;
                console.log('首页已经渲染完毕');
              }
            }
          }
        });
      }
      useContentViewHeight();

      const getShowFullHeader = computed(() => {
        const route = unref(currentRoute);
        if (route.path.startsWith('/micro-')) {
        }
        return getShowFullHeaderRef.value || route.path.startsWith('/micro-');
      });

      onBeforeMount(() => {});
      onMounted(() => {
        //注册openQianKun
        // console.log('window.qiankunStarted------>', window.qiankunStarted);
        // if (openQianKun == 'true') {
        //   if (!window.qiankunStarted) {
        //     window.qiankunStarted = true;
        //     registerApps();
        //   }
        // }
      });
      return {
        prefixCls,
        openQianKun,
        getOpenPageLoading,
        getLayoutContentMode,
        getPageLoading,
        getShowFullHeader,
        loading,
        currentRoute,
        noContentLink,
      };
    },
  });
</script>
<style lang="less" scoped>
  @import '/@/design/vent/color.less';
  @prefix-cls: ~'@{namespace}-layout-content';
  @ventSpace: zxm;

  .@{prefix-cls} {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    &.fixed {
      width: 1200px;
      margin: 0 auto;
    }

    &-loading {
      position: absolute;
      top: 200px;
      z-index: @page-loading-z-index;
    }
  }
  .app-view-box {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: transparent;
  }

  .layout-content-full {
    // height: calc(100vh - 48px);
    // margin-top: 48px;
    // overflow-y: auto;
    height: 100%;
  }
  .app-loading {
    display: flex;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    // background-color: #f4f7f900;
    background-image: url('/@/assets/images/vent/loading-bg.png');
    background-size: cover;
    background-repeat: no-repeat;
    background-color: var(--vent-base-color);
  }

  .app-loading .app-loading-wrap {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    -webkit-transform: translate3d(-50%, -50%, 0);
    transform: translate3d(-50%, -50%, 0);
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }

  .app-loading .dots {
    display: flex;
    padding: 98px;
    justify-content: center;
    align-items: center;
  }

  .app-loading .app-loading-title {
    display: flex;
    margin-top: 30px;
    font-size: 30px;
    color: rgba(0, 0, 0, 0.85);
    justify-content: center;
    align-items: center;
  }

  .dot {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 32px;
    margin-top: 30px;
    font-size: 32px;
    transform: rotate(45deg);
    box-sizing: border-box;
    animation: antRotate 1.2s infinite linear;
  }

  .dot i {
    position: absolute;
    display: block;
    width: 14px;
    height: 14px;
    background-color: #0065cc;
    // background-color: #d1d1d1;
    border-radius: 100%;
    opacity: 0.3;
    transform: scale(0.75);
    animation: antSpinMove 1s infinite linear alternate;
    transform-origin: 50% 50%;
  }

  .dot i:nth-child(1) {
    top: 0;
    left: 0;
  }

  .dot i:nth-child(2) {
    top: 0;
    right: 0;
    -webkit-animation-delay: 0.4s;
    animation-delay: 0.4s;
  }

  .dot i:nth-child(3) {
    right: 0;
    bottom: 0;
    -webkit-animation-delay: 0.8s;
    animation-delay: 0.8s;
  }

  .dot i:nth-child(4) {
    bottom: 0;
    left: 0;
    -webkit-animation-delay: 1.2s;
    animation-delay: 1.2s;
  }
  @keyframes antRotate {
    to {
      -webkit-transform: rotate(405deg);
      transform: rotate(405deg);
    }
  }
  @-webkit-keyframes antRotate {
    to {
      -webkit-transform: rotate(405deg);
      transform: rotate(405deg);
    }
  }
  @keyframes antSpinMove {
    to {
      opacity: 1;
    }
  }
  @-webkit-keyframes antSpinMove {
    to {
      opacity: 1;
    }
  }
  :deep(.@{ventSpace}-layout) {
    background: transparent !important;
  }
</style>
