| | |
| | | captchaId: '', |
| | | clickIds: [], |
| | | loggingIn: false, |
| | | captchaRequired: true |
| | | captchaRequired: false |
| | | } |
| | | }, |
| | | created() { |
| | | axios.get('/api/auth/captcha-config') |
| | | // 验证码是否启用一律以后端 /api/auth/captcha-config 为准: |
| | | // 默认不显示,只有后端明确返回 required=true 才渲染验证码组件。 |
| | | // 修复:此前默认 true 且请求失败时静默忽略,切换网络后该配置读不到, |
| | | // 登录页就会残留一个加载不出来的验证码白框并提示“验证码加载失败,请检查网络”。 |
| | | axios.get('/api/auth/captcha-config', { timeout: 10000 }) |
| | | .then(res => { |
| | | const d = res.data |
| | | if (d && d.code === 200) this.captchaRequired = d.data.required !== false |
| | | this.captchaRequired = !!(d && d.code === 200 && d.data && d.data.required === true) |
| | | }) |
| | | .catch(() => {}) |
| | | .catch(() => { this.captchaRequired = false }) |
| | | }, |
| | | methods: { |
| | | onCaptchaVerified(payload) { |
| | |
| | | password: this.form.password, |
| | | captchaId: this.captchaId, |
| | | captchaClickIds: this.clickIds |
| | | }).then(res => { |
| | | }, { timeout: 15000 }).then(res => { |
| | | this.loggingIn = false |
| | | const d = res.data |
| | | if (d.code === 200) { |
| | | localStorage.setItem('token', d.data.token) |
| | | localStorage.setItem('username', d.data.username) |
| | | localStorage.setItem('realName', d.data.realName || '') |
| | | localStorage.setItem('modules', d.data.modules || '') |
| | | sessionStorage.setItem('token', d.data.token) |
| | | sessionStorage.setItem('username', d.data.username) |
| | | sessionStorage.setItem('realName', d.data.realName || '') |
| | | sessionStorage.setItem('modules', d.data.modules || '') |
| | | this.$message.success('登录成功') |
| | | this.$router.push('/dashboard') |
| | | } else if (d.code === 401) { |
| | |
| | | this.$message.error(d.message || '登录失败,请重试') |
| | | if (this.$refs.captcha) this.$refs.captcha.load() |
| | | } |
| | | }).catch(() => { |
| | | }).catch(e => { |
| | | this.loggingIn = false |
| | | if (e && e.code === 'ECONNABORTED') { this.$message.error('登录请求超时,请重试'); return } |
| | | this.$message.error('网络错误,登录失败') |
| | | }) |
| | | }) |