|
@@ -37,7 +37,14 @@
|
|
|
placeholder="请输入验证码"
|
|
placeholder="请输入验证码"
|
|
|
clearable
|
|
clearable
|
|
|
/>
|
|
/>
|
|
|
- <div class="captcha-img" @click="refreshCaptcha">{{ captchaText }}</div>
|
|
|
|
|
|
|
+ <img
|
|
|
|
|
+ v-if="captchaImage"
|
|
|
|
|
+ :src="captchaImage"
|
|
|
|
|
+ class="captcha-img"
|
|
|
|
|
+ title="点击刷新验证码"
|
|
|
|
|
+ @click="refreshCaptcha"
|
|
|
|
|
+ />
|
|
|
|
|
+ <div v-else class="captcha-img captcha-loading" @click="refreshCaptcha">加载中...</div>
|
|
|
</div>
|
|
</div>
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
<el-form-item>
|
|
@@ -58,7 +65,7 @@
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
import md5 from 'js-md5'
|
|
import md5 from 'js-md5'
|
|
|
-import { loginApi } from '@/api'
|
|
|
|
|
|
|
+import { loginApi, getCaptcha } from '@/api'
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
name: 'Login',
|
|
name: 'Login',
|
|
@@ -75,36 +82,50 @@ export default {
|
|
|
captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
|
|
captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
|
|
|
},
|
|
},
|
|
|
loading: false,
|
|
loading: false,
|
|
|
- captchaText: '0000'
|
|
|
|
|
|
|
+ captchaImage: '',
|
|
|
|
|
+ captchaUuid: '',
|
|
|
|
|
+ needCaptcha: true
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
+ mounted() {
|
|
|
|
|
+ this.refreshCaptcha()
|
|
|
|
|
+ },
|
|
|
methods: {
|
|
methods: {
|
|
|
- refreshCaptcha() {
|
|
|
|
|
- // 模拟验证码,固定为0000
|
|
|
|
|
- this.captchaText = '0000'
|
|
|
|
|
|
|
+ async refreshCaptcha() {
|
|
|
|
|
+ this.captchaImage = ''
|
|
|
|
|
+ try {
|
|
|
|
|
+ const data = await getCaptcha()
|
|
|
|
|
+ this.needCaptcha = data.captcha
|
|
|
|
|
+ if (data.captcha) {
|
|
|
|
|
+ this.captchaImage = 'data:image/jpeg;base64,' + data.image
|
|
|
|
|
+ this.captchaUuid = data.uuid
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ this.$message.error('获取验证码失败')
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
handleLogin() {
|
|
handleLogin() {
|
|
|
this.$refs.loginForm.validate(async (valid) => {
|
|
this.$refs.loginForm.validate(async (valid) => {
|
|
|
if (!valid) return
|
|
if (!valid) return
|
|
|
|
|
|
|
|
- // 验证码校验
|
|
|
|
|
- if (this.form.captcha !== '0000') {
|
|
|
|
|
- this.$message.error('验证码错误')
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
this.loading = true
|
|
this.loading = true
|
|
|
try {
|
|
try {
|
|
|
const params = {
|
|
const params = {
|
|
|
account: this.form.username,
|
|
account: this.form.username,
|
|
|
password: md5(this.form.password)
|
|
password: md5(this.form.password)
|
|
|
}
|
|
}
|
|
|
|
|
+ if (this.needCaptcha) {
|
|
|
|
|
+ params.code = this.form.captcha
|
|
|
|
|
+ params.uuid = this.captchaUuid
|
|
|
|
|
+ }
|
|
|
const res = await loginApi(params)
|
|
const res = await loginApi(params)
|
|
|
this.$store.dispatch('login', { token: res.data.token, userInfo: {} })
|
|
this.$store.dispatch('login', { token: res.data.token, userInfo: {} })
|
|
|
this.$message.success('登录成功')
|
|
this.$message.success('登录成功')
|
|
|
this.$router.push('/lab-status')
|
|
this.$router.push('/lab-status')
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
- this.$message.error('登录失败,请重试')
|
|
|
|
|
|
|
+ this.$message.error(err.message || '登录失败,请重试')
|
|
|
|
|
+ this.refreshCaptcha()
|
|
|
|
|
+ this.form.captcha = ''
|
|
|
} finally {
|
|
} finally {
|
|
|
this.loading = false
|
|
this.loading = false
|
|
|
}
|
|
}
|
|
@@ -208,21 +229,26 @@ export default {
|
|
|
.captcha-img {
|
|
.captcha-img {
|
|
|
width: 120px;
|
|
width: 120px;
|
|
|
height: 44px;
|
|
height: 44px;
|
|
|
- line-height: 44px;
|
|
|
|
|
- text-align: center;
|
|
|
|
|
- background: rgba(30, 144, 255, 0.15);
|
|
|
|
|
border: 1px solid rgba(30, 144, 255, 0.3);
|
|
border: 1px solid rgba(30, 144, 255, 0.3);
|
|
|
border-radius: 4px;
|
|
border-radius: 4px;
|
|
|
- color: $accent-cyan;
|
|
|
|
|
- font-size: 20px;
|
|
|
|
|
- letter-spacing: 8px;
|
|
|
|
|
cursor: pointer;
|
|
cursor: pointer;
|
|
|
user-select: none;
|
|
user-select: none;
|
|
|
|
|
+ object-fit: cover;
|
|
|
|
|
+ display: block;
|
|
|
|
|
+ flex-shrink: 0;
|
|
|
|
|
|
|
|
&:hover {
|
|
&:hover {
|
|
|
- background: rgba(30, 144, 255, 0.25);
|
|
|
|
|
|
|
+ border-color: rgba(30, 144, 255, 0.6);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ .captcha-loading {
|
|
|
|
|
+ line-height: 44px;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ background: rgba(30, 144, 255, 0.15);
|
|
|
|
|
+ color: $text-secondary;
|
|
|
|
|
+ font-size: 13px;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
.login-btn {
|
|
.login-btn {
|