<template>
  <el-dialog
      title="快速登录"
      :visible.sync="editor.showLogin"
      width="40%">

    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
      <el-form-item label="账号" prop="username">
        <el-input style="width: 80%" v-model="ruleForm.username" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input show-password style="width: 80%" v-model="ruleForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即登录</el-button>
        <!--          <el-button @click="resetForm('ruleForm')">重置</el-button>-->
      </el-form-item>
    </el-form>

  </el-dialog>
</template>

<script>
import {mapActions, mapState} from "vuex";

export default {
  name: "FpLogin",
  computed: {
    ...mapState({
      'editor': state => state.editor
    })
  },
  data() {
    return {
      ruleForm: {
        username: 'demo',
        password: 'demo'
      },
      rules: {
        username: [
          {required: true, message: '请输入账号', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          { min: 3, max: 32, message: '长度在 3 到 32 个字符', trigger: 'blur' }
        ],
      }
    }
  },
  methods: {
    ...mapActions({
      'login': 'editor/login',
      'openPoster': 'aside/openPoster'
    }),
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.login(this.ruleForm).then(r => {
            this.openPoster()
          })
        }
      });
      return false;
    }
  }
}
</script>

<style scoped>

</style>