<template>
  <div class="login-container" ref="login" @keyup.enter="handleLogin">
    <div class="login-weaper animated bounceInDown">
      <!-- 横幅顶部 -->
      <!-- <div class="top">
          <img src="https://www.v6g.cn/IMAGE/top.png" />
        </div> -->
      <div class="login-left">
        <div class="login-time">
          {{ time }}
        </div>
        <!-- 对联左 -->
        <!-- <div class="left">
          <img src="https://www.v6g.cn/IMAGE/left.png" />
        </div> -->
        <!-- 本地图片 -->
        <!-- <img src="../../../public/img/indexbg.png" /> -->
        <!-- 线上图片 -->
        <img src="https://www.v6g.cn/IMAGE/indexbg.png" />
        <!-- <p class="title">{{ $t('login.info') }}</p> -->

        <!-- <img class="img" src="/img/logo.png" alt="" /> -->
      </div>
      <div class="login-border">
        <div class="login-main">
          <h4 class="login-title">
            <img src="../../../public/img/logo-login.png" />
            <!-- {{ $t('login.title') }} -->
            <!-- {{ website.title }} -->
            <span>物流信息平台</span>
            <!-- <top-lang></top-lang> -->
            <!-- 语言转换 -->
          </h4>
          <userLogin v-if="activeName === 'user'"></userLogin>
          <codeLogin v-else-if="activeName === 'code'"></codeLogin>
          <thirdLogin v-else-if="activeName === 'third'"></thirdLogin>
          <div class="login-menu">
            <!-- <a href="#" @click.stop="activeName = 'user'">{{ $t('login.userLogin') }}</a> -->
            <!-- <a href="#" @click.stop="activeName = 'code'">{{ $t('login.phoneLogin') }}</a> -->
            <!-- <a href="#" @click.stop="activeName = 'third'">{{ $t('login.thirdLogin') }}</a> -->
            <!-- <a :href="website.ssoUrl + website.redirectUri">{{ $t('login.ssoLogin') }}</a> -->
          </div>
        </div>
        <!-- 对联右 -->
        <!-- <div class="right">
          <img src="https://www.v6g.cn/IMAGE/right.png" />
        </div> -->
      </div>
    </div>
    <div class="index_footer">
      <p>© 2023-2025 由成都数联物科信息技术有限公司提供技术支持</p>
    </div>
  </div>
</template>
<script>
import userLogin from './userlogin.vue';
import codeLogin from './codelogin.vue';
import thirdLogin from './thirdlogin.vue';
import { mapGetters } from 'vuex';
import { validatenull } from '@/utils/validate';
import topLang from '@/page/index/top/top-lang.vue';
import { getQueryString, getTopUrl } from '@/utils/util';
import website from '@/config/website';

export default {
  name: 'login',
  components: {
    userLogin,
    codeLogin,
    thirdLogin,
    topLang,
  },
  data() {
    return {
      website: website,
      time: '',
      activeName: 'user',
      socialForm: {
        tenantId: '000000',
        source: '',
        code: '',
        state: '',
      },
    };
  },
  watch: {
    $route() {
      this.handleLogin();
    },
  },
  created() {
    this.handleLogin();
    this.getTime();
  },
  mounted() { },
  computed: {
    ...mapGetters(['tagWel']),
  },
  props: [],
  methods: {
    getTime() {
      setInterval(() => {
        this.time = this.$dayjs().format('YYYY-MM-DD HH:mm:ss');
      }, 1000);
    },
    handleLogin() {
      const topUrl = getTopUrl();
      const redirectUrl = '/oauth/redirect/';
      const ssoCode = '?code=';
      this.socialForm.source = getQueryString('source');
      this.socialForm.code = getQueryString('code');
      this.socialForm.state = getQueryString('state');
      if (validatenull(this.socialForm.source) && topUrl.includes(redirectUrl)) {
        let source = topUrl.split('?')[0];
        source = source.split(redirectUrl)[1];
        this.socialForm.source = source;
      }
      if (
        topUrl.includes(redirectUrl) &&
        !validatenull(this.socialForm.source) &&
        !validatenull(this.socialForm.code) &&
        !validatenull(this.socialForm.state)
      ) {
        const loading = this.$loading({
          lock: true,
          text: '第三方系统登录中,请稍后',
          background: 'rgba(0, 0, 0, 0.7)',
        });
        this.$store
          .dispatch('LoginBySocial', this.socialForm)
          .then(() => {
            window.location.href = topUrl.split(redirectUrl)[0];
            this.$router.push(this.tagWel);
            loading.close();
          })
          .catch(() => {
            loading.close();
          });
      } else if (
        !topUrl.includes(redirectUrl) &&
        !validatenull(this.socialForm.code) &&
        !validatenull(this.socialForm.state)
      ) {
        const loading = this.$loading({
          lock: true,
          text: '单点系统登录中,请稍后',
          background: 'rgba(0, 0, 0, 0.7)',
        });
        this.$store
          .dispatch('LoginBySso', this.socialForm)
          .then(() => {
            window.location.href = topUrl.split(ssoCode)[0];
            this.$router.push(this.tagWel);
            loading.close();
          })
          .catch(() => {
            loading.close();
          });
      }
    },
  },
};
</script>

<style lang="scss">
@import '@/styles/login.scss';

.index_footer {
  position: fixed;
  bottom: 0;
  width: 100%;

  p {
    text-align: center;
    color: #999;
    color: #fff;
    margin-bottom: 4px;
  }
}

.login-title {
  display: flex;
  align-items: center;
  justify-content: center;

  img {
    width: 130px;
    height: 60px;
  }

  span {
    margin-left: 10px;
  }
}

.left {
  position: absolute;
  left: 0;
  width: 80px;
  height: 100%;
  mask: linear-gradient(to right, #000000, #ffffffb0);

  img {
    width: 100%;
    height: 100%;
  }
}

.right {
  position: absolute;
  right: 0;
  width: 80px;
  height: 100%;
  mask: linear-gradient(to left, #000000, #ffffffb0);

  img {
    width: 100%;
    height: 100%;
  }
}

.login-weaper {
  position: relative;
}

.top {
  position: absolute;
  top: -18%;
  left: 35%;
  width: 30%;
  height: 70px;
  z-index: 1;
  overflow: hidden;
  border-radius: 15px;

  img {
    width: 100%;
    height: 100%;
  }
}

.login-left {
  /* 新增 */
    box-sizing: border-box !important;
    border: 1px solid #ebebeb !important;
    background: #ffffff5c;
    box-shadow: -1px -5px 8px #00000003;
    backdrop-filter: blur(6px);

  img {
    width: 78%;
    height: 100%;
  }

}
</style>
