Crunchy
2024-11-07 673d58023f4c0fe8633a107238ec8b577496717a
src/page/login/userlogin.vue
@@ -35,6 +35,25 @@
        <i slot="prefix" class="iconfont icon-mima"></i>
      </el-input>
    </el-form-item>
    <el-form-item prop="loginCode">
      <el-col :span="16">
        <el-input
          v-model="loginCode"
          size="small"
          auto-complete="off"
          placeholder="请输入验证码"
          @keyup.enter.native="handleLogin"
        >
        </el-input>
      </el-col>
      <el-col :span="6" :offset="2">
        <login-code
          :key="refreshKey"
          :identifyCode="loginCodeValue"
          @refresh="refreshLoginValueCode"
        />
      </el-col>
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
@@ -51,16 +70,14 @@
</template>
<script>
import { randomLenNum } from '@/util/util'
import { mapGetters } from 'vuex'
import { getCode } from '@/api/code'
import Verify from '@/components/verifition/Verify'
import { getSsoAuthUrl } from '@/api/login'
import LoginCode from '@/page/login/LoginCode.vue'
export default {
  name: 'Userlogin',
  components: {
    Verify
    LoginCode
  },
  data() {
    return {
@@ -89,7 +106,12 @@
        ]
      },
      passwordType: 'password',
      SSO: window.location.hash
      SSO: window.location.hash,
      loginCode: null,
      loginCodeValue: Math.random()
        .toString(36)
        .substr(2, 4),
      refreshKey: 0
    }
  },
  created() {
@@ -112,11 +134,21 @@
        : (this.passwordType = '')
    },
    handleLogin() {
      if (!this.loginCode) {
        this.$message.error('请输入验证码')
        return
      }
      if (this.loginCode.toLowerCase() !== this.loginCodeValue) {
        this.$message.error('验证码不正确')
        return
      }
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.$store.dispatch('LoginByUsername', this.loginForm).then(() => {
            this.$router.push({ path: this.tagWel.value })
          })
        } else {
          this.refreshLoginValueCode()
        }
      })
    },
@@ -127,6 +159,13 @@
          this.$router.push({ path: this.tagWel.value })
        })
      }
    },
    // 刷新验证码
    refreshLoginValueCode() {
      this.loginCodeValue = Math.random()
        .toString(36)
        .substr(2, 4)
      this.refreshKey++
    }
  }
}