|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
|
<div class="login-main">
|
|
|
- <div class="login-main-block">
|
|
|
+ <div class="login-main-block" v-loading="loadingForm" element-loading-background="rgba(0, 0, 0, 0.7)">
|
|
|
<div class="lmb-head">
|
|
|
欢迎使用社管总体平台
|
|
|
</div>
|
|
@@ -28,19 +28,19 @@
|
|
|
</template>
|
|
|
</el-input>
|
|
|
</el-form-item>
|
|
|
- <el-form-item class="code" label="" prop="code" :rules="[
|
|
|
+ <el-form-item class="code" label="" prop="validCode" :rules="[
|
|
|
{ required: true, trigger: 'blur', message: '请输入验证码' }]">
|
|
|
- <el-input @keyup.enter="onNormalClick" v-model="form.code" placeholder="验证码" class="code">
|
|
|
+ <el-input @keyup.enter="onNormalClick" v-model="form.validCode" placeholder="验证码">
|
|
|
<template v-slot:prefix>
|
|
|
<img src="./img/login-bg-code.png"/>
|
|
|
</template>
|
|
|
- <template v-slot:suffix>
|
|
|
- <img v-if="codeImg" :src="codeImg"/>
|
|
|
- </template>
|
|
|
</el-input>
|
|
|
+ <div class="code-img __hover" @click="initCode" v-loading="loadingCode">
|
|
|
+ <img :src="codeImg"/>
|
|
|
+ </div>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
- <div class="__hover login-button">安全登录</div>
|
|
|
+ <div class="__hover login-button" @click="onNormalClick">安全登录</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -62,6 +62,9 @@ import {
|
|
|
} from 'vue'
|
|
|
import {useStore} from 'vuex'
|
|
|
import {useRouter, useRoute} from 'vue-router'
|
|
|
+import { v4 } from "uuid";
|
|
|
+import { FormInstance } from 'element-plus';
|
|
|
+import { ElMessage } from "element-plus";
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: '',
|
|
@@ -71,16 +74,57 @@ export default defineComponent({
|
|
|
const router = useRouter();
|
|
|
const route = useRoute();
|
|
|
const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
|
|
|
+ const ref_form = ref<FormInstance>()
|
|
|
const state = reactive({
|
|
|
- form: {},
|
|
|
- codeImg: ''
|
|
|
+ form: {
|
|
|
+ deviceId: '',
|
|
|
+ username: '',
|
|
|
+ password: '',
|
|
|
+ validCode: ''
|
|
|
+ },
|
|
|
+ codeImg: '',
|
|
|
+ loadingCode: false,
|
|
|
+ loadingForm: false,
|
|
|
})
|
|
|
const onNormalClick = () => {
|
|
|
-
|
|
|
+ if (!ref_form.value) return
|
|
|
+ ref_form.value.validate((valid, fields) => {
|
|
|
+ if (valid) {
|
|
|
+ state.loadingForm = true
|
|
|
+ that.$api.login(state.form).then(res => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ ElMessage.success(res.msg)
|
|
|
+ localStorage.setItem('sc_token', res.sessionToken)
|
|
|
+ location.reload()
|
|
|
+ } else {
|
|
|
+ ElMessage.success(res.msg)
|
|
|
+ }
|
|
|
+ state.loadingForm = false
|
|
|
+ }).catch(() => {
|
|
|
+ state.loadingForm = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
+ const initCode = () => {
|
|
|
+ state.loadingCode = true
|
|
|
+ state.form.deviceId = v4()
|
|
|
+ that.$api.getLoginCode(state.form.deviceId).then((res: BlobPart) => {
|
|
|
+ const myBlob = new window.Blob([res], { type: 'image/gif'})
|
|
|
+ state.codeImg = window.URL.createObjectURL(myBlob)
|
|
|
+ state.loadingCode = false
|
|
|
+ }).catch(() => {
|
|
|
+ state.loadingCode = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ onMounted(() => {
|
|
|
+ initCode()
|
|
|
+ })
|
|
|
return {
|
|
|
...toRefs(state),
|
|
|
- onNormalClick
|
|
|
+ onNormalClick,
|
|
|
+ ref_form,
|
|
|
+ initCode
|
|
|
}
|
|
|
},
|
|
|
})
|
|
@@ -217,6 +261,24 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ &.code {
|
|
|
+ $codeImgWidth: 156px;
|
|
|
+ .el-input {
|
|
|
+ width: calc(100% - #{$codeImgWidth} - 12px);
|
|
|
+ }
|
|
|
+ .code-img {
|
|
|
+ box-sizing: border-box;
|
|
|
+ margin-left: auto;
|
|
|
+ width: $codeImgWidth;
|
|
|
+ height: 100%;
|
|
|
+ background: rgba(107,185,248,0.4);
|
|
|
+ border: 1px solid #17396F;
|
|
|
+ >img {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
.login-button {
|