<!--Created by 熊超超 on 2020/5/29.-->
<template>
  <div class="h-100" data-flex="main:center cross:center">
    <el-card class="login">
      <template v-slot:header>
        <span class="f-16 f-b">登录</span>
      </template>
      <form-create :rule="rule" :option="option" class="inline-btn"></form-create>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      rule: [
        {
          type: 'el-input',
          title: '用户名',
          field: 'userName',
          validate: [{type: 'string', required: true, message: '请输入用户名'}],
        },
        {
          type: 'el-input',
          title: '密码',
          field: 'password',
          props: {type: 'password'},
          validate: [{type: 'string', required: true, message: '请输入密码'}],
        },
      ],
      option: {
        // form: {inline: true},
        submitBtn: {
          icon: 'el-icon-user',
          innerText: '登录',
        },
        onSubmit: async (formData, $f) => {
          $f.btn.loading(true)
          const {data} = await this.$store.dispatch(this.$config?.actions?.login || 'login', formData)
          $f.btn.loading(false)
          if (data) {
            localStorage.setItem('token', data.token)
            this.$router.push('/')
            this.$utils.message.success('登录成功')
          }
        }
      },
    }
  },
}
</script>

<style lang="scss" scoped>
  .login{
    width: 500px;
  }
</style>
