index.vue 5.5 KB
Newer Older
1 2 3 4
<template>
  <div id="userLayout">
    <div class="login_panle">
      <div class="login_panle_form">
D
Devil 已提交
5
        <div class="login_panle_form_title">
B
bypanghu 已提交
6 7 8 9 10
          <img
            class="login_panle_form_title_logo"
            :src="$GIN_VUE_ADMIN.appLogo"
            alt
          >
11
          <p class="login_panle_form_title_p">{{ $GIN_VUE_ADMIN.appName }}</p>
D
Devil 已提交
12
        </div>
B
bypanghu 已提交
13 14 15 16 17 18
        <el-form
          ref="loginForm"
          :model="loginForm"
          :rules="rules"
          @keyup.enter="submitForm"
        >
19 20
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" placeholder="请输入用户名">
21 22 23
              <template #suffix>
                <i class="el-input__icon el-icon-user" />
              </template>
24 25 26 27 28 29 30 31
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="loginForm.password"
              :type="lock === 'lock' ? 'password' : 'text'"
              placeholder="请输入密码"
            >
32
              <template #suffix>
B
bypanghu 已提交
33 34 35 36
                <i
                  :class="'el-input__icon el-icon-' + lock"
                  @click="changeLock"
                />
37
              </template>
38 39
            </el-input>
          </el-form-item>
40
          <el-form-item style="position: relative" prop="captcha">
41 42 43 44 45 46 47
            <el-input
              v-model="loginForm.captcha"
              name="logVerify"
              placeholder="请输入验证码"
              style="width: 60%"
            />
            <div class="vPic">
B
bypanghu 已提交
48 49 50 51 52 53
              <img
                v-if="picPath"
                :src="picPath"
                alt="请输入验证码"
                @click="loginVerify()"
              >
54 55 56
            </div>
          </el-form-item>
          <el-form-item>
B
bypanghu 已提交
57 58 59 60 61 62 63 64 65 66
            <el-button
              type="primary"
              style="width: 46%"
              @click="checkInit"
            >前往初始化</el-button>
            <el-button
              type="primary"
              style="width: 46%; margin-left: 8%"
              @click="submitForm"
            >登 录</el-button>
67 68 69 70 71 72
          </el-form-item>
        </el-form>
      </div>
      <div class="login_panle_right" />
      <div class="login_panle_foot">
        <div class="links">
73 74 75 76 77 78 79 80 81 82 83 84
          <a href="http://doc.henrongyi.top/">
            <img src="@/assets/docs.png" class="link-icon">
          </a>
          <a href="https://www.yuque.com/flipped-aurora/">
            <img src="@/assets/yuque.png" class="link-icon">
          </a>
          <a href="https://github.com/flipped-aurora/gin-vue-admin">
            <img src="@/assets/github.png" class="link-icon">
          </a>
          <a href="https://space.bilibili.com/322210472">
            <img src="@/assets/video.png" class="link-icon">
          </a>
85
        </div>
B
bypanghu 已提交
86 87 88
        <div class="copyright">
          <bootomInfo />
        </div>
89 90 91 92 93 94 95
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from 'vuex'
import { captcha } from '@/api/user'
Mr.奇淼('s avatar
Mr.奇淼( 已提交
96
import { checkDB } from '@/api/initdb'
B
bypanghu 已提交
97
import bootomInfo from '@/view/layout/bottomInfo/bottomInfo.vue'
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
export default {
  name: 'Login',
  data() {
    const checkUsername = (rule, value, callback) => {
      if (value.length < 5) {
        return callback(new Error('请输入正确的用户名'))
      } else {
        callback()
      }
    }
    const checkPassword = (rule, value, callback) => {
      if (value.length < 6) {
        return callback(new Error('请输入正确的密码'))
      } else {
        callback()
      }
    }
    return {
      lock: 'lock',
      loginForm: {
        username: 'admin',
        password: '123456',
        captcha: '',
        captchaId: ''
      },
      rules: {
        username: [{ validator: checkUsername, trigger: 'blur' }],
125 126 127 128 129 130
        password: [{ validator: checkPassword, trigger: 'blur' }],
        captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' },
          {
            message: '验证码格式不正确',
            trigger: 'blur',
          }]
131 132 133 134 135
      },
      logVerify: '',
      picPath: ''
    }
  },
B
bypanghu 已提交
136 137 138
  components:{
    bootomInfo
  },
139 140 141 142 143
  created() {
    this.loginVerify()
  },
  methods: {
    ...mapActions('user', ['LoginIn']),
Mr.奇淼('s avatar
Mr.奇淼( 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157
    async checkInit() {
      const res = await checkDB()
      if (res.code === 0) {
        if (res.data?.needInit) {
          this.$store.commit('user/NeedInit')
          this.$router.push({ name: 'Init' })
        } else {
          this.$message({
            type: 'info',
            message: '已配置数据库信息,无法初始化'
          })
        }
      }
    },
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    async login() {
      return await this.LoginIn(this.loginForm)
    },
    async submitForm() {
      this.$refs.loginForm.validate(async(v) => {
        if (v) {
          const flag = await this.login()
          if (!flag) {
            this.loginVerify()
          }
        } else {
          this.$message({
            type: 'error',
            message: '请正确填写登录信息',
            showClose: true
          })
          this.loginVerify()
          return false
        }
      })
    },
    changeLock() {
      this.lock = this.lock === 'lock' ? 'unlock' : 'lock'
    },
    loginVerify() {
      captcha({}).then((ele) => {
B
bypanghu 已提交
184 185
        this.rules.captcha[1].max = ele.data.captchaLength
        this.rules.captcha[1].min = ele.data.captchaLength
186 187 188 189 190 191
        this.picPath = ele.data.picPath
        this.loginForm.captchaId = ele.data.captchaId
      })
    }
  }
}
B
bypanghu 已提交
192

193 194 195 196 197
</script>

<style lang="scss" scoped>
@import "@/style/newLogin.scss";
</style>