<template>
  <div :class="$style.wrapper">
    <header>
      <div :class="$style.logotitle" :title="appTitle">
        <div v-if="configInfo.loginLogo">
          <img
            src="api/xcoa-mobile/v1/iamlogoconfig/we-open-api/downloadBackGrounImg?name=loginLogo"
            alt=""
            :class="$style.title"
        /></div>
        <span :class="configInfo.loginLogo ? $style.title : $style.wulogotitle">{{
          platformName
        }}</span>
      </div>
    </header>
    <div :class="$style.art"></div>
    <footer>
      <span>建议使用Chrome或Firefox最新的三个版本浏览器，1920*1080分辨率访问本系统.</span>
    </footer>
    <!--
      @slot 输入框+登录页按钮区域
    -->
    <slot></slot>
  </div>
</template>

<script>
import axios from '@/common/services/axios-instance'
import { xmLocalStorage } from '@/common/services/storage-service'
import storeMixin from '@/common/store-mixin'
import store from '@/common/store'
import components from './_import-components/ext-layout-import'

export default {
  name: 'ExtLayout',
  metaInfo: {
    title: 'ExtLayout',
  },
  components,
  mixins: [storeMixin],
  data() {
    return {
      configInfo: {},
      platformName: '',
    }
  },
  created() {
    xmLocalStorage.removeItem('homeLogo', true)
    const oldLogoTheme = document.getElementById('background-style')
    const style = document.createElement('style')
    style.id = 'background-style'
    style.type = 'text/css'
    axios
      .post('api/xcoa-mobile/v1/iamlogoconfig/we-open-api/getLogos')
      .then((res) => {
        if (res?.data) {
          this.configInfo = res.data
          style.innerText =
            `.art_ext-layout_custom{background: url(${
              this.configInfo.backgroundImg
                ? 'api/xcoa-mobile/v1/iamlogoconfig/we-open-api/downloadBackGrounImg?name=backgroundImg'
                : require('../../../src_custom/images/login-background.jpg')
            }) center center / cover no-repeat !important}`
          this.platformName = this.configInfo.platformName || store.state.sd.common.appTitle
          if (this.configInfo.homeLogo) xmLocalStorage.setItem('homeLogo', true)
        }
      })
      .catch(() => {
        this.platformName = store.state.sd.common.appTitle
        style.innerText =
          `.art_ext-layout_custom{background: url(${require('../../../src_custom/images/login-background.jpg')}) center center / cover no-repeat !important}` +
          `.title_sd-header_common{background: url(${require('@custom/images/logo.png')}) no-repeat center center !important}`
      })
      .finally(() => {
        if (oldLogoTheme) {
          document.head.removeChild(oldLogoTheme)
        }
        document.head.appendChild(style)
      })
  },
  methods: {},
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.art {
  position: absolute;
  top: 15%;
  width: 100%;
  height: 70%;
  background: no-repeat center url('../../../src_custom/images/bg-slogan.png');
  background-size: cover;
}

.wrapper {
  height: 100%;
  background: $body-background;

  footer {
    position: absolute;
    bottom: 5%;
    width: 100%;
    font-size: $font-size-sm;
    color: $text-color;
    text-align: center;
    span {
      margin: 0 5px;
    }
  }
  header {
    top: 5%;
    height: 5%;
    padding: 4%;
    h2 {
      color: $text-color;
    }
    .action {
      float: right;
    }
  }
}

.logotitle {
  display: flex;
  align-items: center;
  float: left;
  height: 100%;

  .logo {
    position: relative;
    top: -0.33em;
  }
  .title {
    margin-left: 10px;
    font-size: 1.1em;
    line-height: 1.15;
    color: $text-color;
  }
  .wulogotitle {
    margin-left: 10px;
    font-size: 1.1em;
    line-height: 1.15;
    color: $text-color;
  }
  .title::before {
    content: '|';
    position: relative;
    top: -1px;
    height: 100px;
    font-size: 20px;
    margin: 0 18px 0 10px;
  }
}
</style>
