<!--
 * @Description:
 * @Author: He Jiecong
 * @Date: 2019-12-30 17:00:32
 * @LastEditTime : 2020-01-08 09:37:00
 * @LastEditors  : Wang Minjie
 -->
<style lang="less">
  @import './login.less';
</style>
<template>
  <div class="login">
    <div class="login__logomini">
      <img src="@/assets/images/logo-min.png" alt="">
      <p>{{projectName}}{{$t('open_platform')}}</p>
    </div>
    <p class="login__title">{{$t('login')}}</p>
    <div class="login__loginyuan"></div>
    <div class="login__loginyuan-rightcen"></div>
    <!-- <img class="login__img" src="./pic_illustration.png" alt=""> -->
    <img class="login__img" src="../../assets/images/pic_illustration.png" alt="">
    <div class="login-con">
      <div class="form-con">
        <login-form :logincaptcha="platform_login_catpcha" @on-success-valid="handleSubmit"></login-form>
      </div>
    </div>
    <div class="login-tip">
      <p class="login-tip-p">©2020 PhalApi Pro All Rights Reserved.</p>
    </div>
    <!-- <div class="login-con">
        <div class="login-title">{{name}}管理后台</div>
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
          <p class="login-tip">©2020 PhalApi Pro All Rights Reserved.</p>
        </div>
      </Card>
    </div> -->
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
import Cookies from 'js-cookie'
import { setCookies } from '@/libs/util'
export default {
  components: {
    LoginForm
  },
  data () {
    return {
      projectName: '',
      platform_login_catpcha: false
    }
  },
  mounted () {
    // this.$i18n.locale = 'zh-CN'
  },
  created () {
    this.getSiteData()
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'GetPlatformData',
      'GetAccountData'
    ]),
    getSiteData () {
      this.GetPlatformData().then(res => {
        this.projectName = res.data.name
        this.platform_login_catpcha = res.data.catpcha_switch.platform_login_catpcha
        // this.platform_login_catpcha = true
        if (!this.$i18n.locale) {
          let lang = res.data.language_list[0].language
          this.$i18n.locale = lang
          setCookies('language', lang)
        }
      })
    },
    handleSubmit ({ username, password, captcha, cookiesExp }) {
      this.handleLogin({ username, password, captcha, cookiesExp }).then((res) => {
        const loginStatus = res.ret
        const loginToken = res.data.access_token
        if (loginStatus === 200 && loginToken) {
          this.$Message.success(this.$t('Sign_in_successfully'))
          this.$router.push({ name: 'home' })
          Cookies.set('username', username, { expires: 1 })
          this.GetAccountData()
        } else { this.$Message.warning(res.msg) }
      })
    }
  }
}
</script>

<style>

</style>
