|
|
@ -8,20 +8,19 @@
|
|
|
|
<div class="login_container">
|
|
|
|
<div class="login_container">
|
|
|
|
<!-- 顶部logo -->
|
|
|
|
<!-- 顶部logo -->
|
|
|
|
<div class="login_title">
|
|
|
|
<div class="login_title">
|
|
|
|
<img src="@/assets/images/home-logo.png"
|
|
|
|
<img src="@/assets/images/home-logo.png" alt="logo" />
|
|
|
|
alt="logo" />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="login_contant">
|
|
|
|
<div class="login_contant">
|
|
|
|
<img src="@/assets/images/login.png"
|
|
|
|
<img src="@/assets/images/login.png" alt="image" class="login_img" />
|
|
|
|
alt="image"
|
|
|
|
<el-form
|
|
|
|
class="login_img" />
|
|
|
|
ref="loginForm"
|
|
|
|
<el-form ref="loginForm"
|
|
|
|
:model="loginForm"
|
|
|
|
:model="loginForm"
|
|
|
|
:rules="loginRules"
|
|
|
|
:rules="loginRules"
|
|
|
|
class="login_form"
|
|
|
|
class="login_form"
|
|
|
|
autocomplete="on"
|
|
|
|
autocomplete="on"
|
|
|
|
label-position="left"
|
|
|
|
label-position="left"
|
|
|
|
@keyup.enter.native="handleLogin"
|
|
|
|
@keyup.enter.native="handleLogin">
|
|
|
|
>
|
|
|
|
<div class="title_container">
|
|
|
|
<div class="title_container">
|
|
|
|
<h3 class="title">
|
|
|
|
<h3 class="title">
|
|
|
|
HELLO,
|
|
|
|
HELLO,
|
|
|
@ -37,41 +36,48 @@
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<p>用户名</p>
|
|
|
|
<p>用户名</p>
|
|
|
|
<el-form-item prop="loginName">
|
|
|
|
<el-form-item prop="loginName">
|
|
|
|
<el-input ref="loginName"
|
|
|
|
<el-input
|
|
|
|
v-model="loginForm.loginName"
|
|
|
|
ref="loginName"
|
|
|
|
placeholder="用户名"
|
|
|
|
v-model="loginForm.loginName"
|
|
|
|
name="loginName"
|
|
|
|
placeholder="用户名"
|
|
|
|
type="text"
|
|
|
|
name="loginName"
|
|
|
|
tabindex="1"
|
|
|
|
type="text"
|
|
|
|
autocomplete="on"
|
|
|
|
tabindex="1"
|
|
|
|
@focus="setTop('0')"
|
|
|
|
autocomplete="on"
|
|
|
|
@change="getPsw" />
|
|
|
|
@focus="setTop('0')"
|
|
|
|
|
|
|
|
@change="getPsw"
|
|
|
|
|
|
|
|
/>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<p>密码</p>
|
|
|
|
<p>密码</p>
|
|
|
|
<input name="password"
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
name="password"
|
|
|
|
autocomplete="off"
|
|
|
|
type="password"
|
|
|
|
class="take" />
|
|
|
|
autocomplete="off"
|
|
|
|
<el-tooltip v-model="capsTooltip"
|
|
|
|
class="take"
|
|
|
|
content="Caps lock is On"
|
|
|
|
/>
|
|
|
|
placement="right"
|
|
|
|
<el-tooltip
|
|
|
|
manual>
|
|
|
|
v-model="capsTooltip"
|
|
|
|
|
|
|
|
content="Caps lock is On"
|
|
|
|
|
|
|
|
placement="right"
|
|
|
|
|
|
|
|
manual
|
|
|
|
|
|
|
|
>
|
|
|
|
<el-form-item prop="password">
|
|
|
|
<el-form-item prop="password">
|
|
|
|
<el-input :key="passwordType"
|
|
|
|
<el-input
|
|
|
|
ref="password"
|
|
|
|
:key="passwordType"
|
|
|
|
v-model="loginForm.password"
|
|
|
|
ref="password"
|
|
|
|
:type="passwordType"
|
|
|
|
v-model="loginForm.password"
|
|
|
|
placeholder="用户密码"
|
|
|
|
:type="passwordType"
|
|
|
|
name="password"
|
|
|
|
placeholder="用户密码"
|
|
|
|
tabindex="2"
|
|
|
|
name="password"
|
|
|
|
autocomplete="on"
|
|
|
|
tabindex="2"
|
|
|
|
@blur="capsTooltip = false"
|
|
|
|
autocomplete="on"
|
|
|
|
@focus="setTop('50')"
|
|
|
|
@blur="capsTooltip = false"
|
|
|
|
@keyup.native="checkCapslock" />
|
|
|
|
@focus="setTop('50')"
|
|
|
|
<span class="show_pwd"
|
|
|
|
@keyup.native="checkCapslock"
|
|
|
|
@click="showPwd">
|
|
|
|
/>
|
|
|
|
|
|
|
|
<span class="show_pwd" @click="showPwd">
|
|
|
|
<i class="el-icon-view" />
|
|
|
|
<i class="el-icon-view" />
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form-item>
|
|
|
@ -80,180 +86,181 @@
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="control">
|
|
|
|
<div class="control">
|
|
|
|
<div class="remember">
|
|
|
|
<div class="remember">
|
|
|
|
<input v-model="rememberPsw"
|
|
|
|
<input v-model="rememberPsw" type="checkbox" />
|
|
|
|
type="checkbox" />
|
|
|
|
|
|
|
|
<p>记住密码</p>
|
|
|
|
<p>记住密码</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<el-button :loading="loading"
|
|
|
|
<el-button
|
|
|
|
type="primary"
|
|
|
|
:loading="loading"
|
|
|
|
class="login_btn"
|
|
|
|
type="primary"
|
|
|
|
@click.native.prevent="handleLogin">登录</el-button>
|
|
|
|
class="login_btn"
|
|
|
|
|
|
|
|
@click.native.prevent="handleLogin"
|
|
|
|
|
|
|
|
>登录</el-button
|
|
|
|
|
|
|
|
>
|
|
|
|
</el-form>
|
|
|
|
</el-form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- 验证码 -->
|
|
|
|
<!-- 验证码 -->
|
|
|
|
<Verify v-if="needCaptcha"
|
|
|
|
<Verify
|
|
|
|
ref="verify"
|
|
|
|
v-if="needCaptcha"
|
|
|
|
:captcha-type="'blockPuzzle'"
|
|
|
|
ref="verify"
|
|
|
|
:img-size="{ width: '400px', height: '200px' }"
|
|
|
|
:captcha-type="'blockPuzzle'"
|
|
|
|
@success="verifylogin" />
|
|
|
|
:img-size="{ width: '400px', height: '200px' }"
|
|
|
|
|
|
|
|
@success="verifylogin"
|
|
|
|
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import Verify from '@/components/verifition/Verify'
|
|
|
|
import Verify from "@/components/verifition/Verify";
|
|
|
|
import cookies from 'js-cookie'
|
|
|
|
import cookies from "js-cookie";
|
|
|
|
import { Decrypt, Encrypt } from '@/utils/index'
|
|
|
|
import { Decrypt, Encrypt } from "@/utils/index";
|
|
|
|
import { login } from '@/api/login'
|
|
|
|
import { login } from "@/api/login";
|
|
|
|
import { transPsw } from '@/utils/encrypted'
|
|
|
|
import { transPsw } from "@/utils/encrypted";
|
|
|
|
import { setToken, setAccessUser } from "@/utils/auth";
|
|
|
|
import { setToken, setAccessUser } from "@/utils/auth";
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
name: 'Login',
|
|
|
|
name: "Login",
|
|
|
|
components: {
|
|
|
|
components: {
|
|
|
|
Verify,
|
|
|
|
Verify
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
activeTop: '-50%', // 色条滑块控制
|
|
|
|
activeTop: "-50%", // 色条滑块控制
|
|
|
|
rememberPsw: false, // 记住密码选择框
|
|
|
|
rememberPsw: false, // 记住密码选择框
|
|
|
|
loginForm: {
|
|
|
|
loginForm: {
|
|
|
|
loginName: 'admin',
|
|
|
|
loginName: "admin",
|
|
|
|
password: '123456',
|
|
|
|
password: "123456",
|
|
|
|
verifyCode: '',
|
|
|
|
verifyCode: ""
|
|
|
|
}, // 登录表单
|
|
|
|
}, // 登录表单
|
|
|
|
loginRules: {
|
|
|
|
loginRules: {
|
|
|
|
loginName: [{ required: true, message: '用户名必填', trigger: 'blur' }],
|
|
|
|
loginName: [{ required: true, message: "用户名必填", trigger: "blur" }],
|
|
|
|
password: [
|
|
|
|
password: [{ required: true, message: "用户密码必填", trigger: "blur" }]
|
|
|
|
{ required: true, message: '用户密码必填', trigger: 'blur' },
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
}, // 登录表单验证
|
|
|
|
}, // 登录表单验证
|
|
|
|
passwordType: 'password', // 用来控制查看密码操作时的输入框类型
|
|
|
|
passwordType: "password", // 用来控制查看密码操作时的输入框类型
|
|
|
|
capsTooltip: false, // 键盘大写是否打开
|
|
|
|
capsTooltip: false, // 键盘大写是否打开
|
|
|
|
loading: false, // 登录loding
|
|
|
|
loading: false, // 登录loding
|
|
|
|
redirect: undefined, // 记录重定向地址
|
|
|
|
redirect: undefined, // 记录重定向地址
|
|
|
|
otherQuery: {}, // 记录重定向地址中的参数
|
|
|
|
otherQuery: {}, // 记录重定向地址中的参数
|
|
|
|
needCaptcha: false,
|
|
|
|
needCaptcha: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
watch: {
|
|
|
|
$route: {
|
|
|
|
$route: {
|
|
|
|
// 监听路由获取上个路由(from)的地址和参数
|
|
|
|
// 监听路由获取上个路由(from)的地址和参数
|
|
|
|
handler: function (route) {
|
|
|
|
handler: function(route) {
|
|
|
|
const query = route.query
|
|
|
|
const query = route.query;
|
|
|
|
if (query) {
|
|
|
|
if (query) {
|
|
|
|
this.redirect = query.redirect
|
|
|
|
this.redirect = query.redirect;
|
|
|
|
this.otherQuery = this.getOtherQuery(query)
|
|
|
|
this.otherQuery = this.getOtherQuery(query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
immediate: true,
|
|
|
|
immediate: true
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
mounted() {
|
|
|
|
// 获取焦点
|
|
|
|
// 获取焦点
|
|
|
|
if (this.loginForm.loginName === '') {
|
|
|
|
if (this.loginForm.loginName === "") {
|
|
|
|
this.$refs.loginName.focus()
|
|
|
|
this.$refs.loginName.focus();
|
|
|
|
} else if (this.loginForm.password === '') {
|
|
|
|
} else if (this.loginForm.password === "") {
|
|
|
|
this.$refs.password.focus()
|
|
|
|
this.$refs.password.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
// 获取存储的密码并解密
|
|
|
|
// 获取存储的密码并解密
|
|
|
|
getPsw () {
|
|
|
|
getPsw() {
|
|
|
|
const cookVal = cookies.get(`u_${this.loginForm.loginName}`)
|
|
|
|
const cookVal = cookies.get(`u_${this.loginForm.loginName}`);
|
|
|
|
this.loginForm.password = cookVal && Decrypt(cookVal)
|
|
|
|
this.loginForm.password = cookVal && Decrypt(cookVal);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 滑动条块的top控制
|
|
|
|
// 滑动条块的top控制
|
|
|
|
setTop (val) {
|
|
|
|
setTop(val) {
|
|
|
|
this.activeTop = val
|
|
|
|
this.activeTop = val;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 检测大写锁定键是否开启
|
|
|
|
// 检测大写锁定键是否开启
|
|
|
|
checkCapslock (e) {
|
|
|
|
checkCapslock(e) {
|
|
|
|
const { key } = e
|
|
|
|
const { key } = e;
|
|
|
|
this.capsTooltip = key && key.length === 1 && key >= 'A' && key <= 'Z'
|
|
|
|
this.capsTooltip = key && key.length === 1 && key >= "A" && key <= "Z";
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 查看密码
|
|
|
|
// 查看密码
|
|
|
|
showPwd () {
|
|
|
|
showPwd() {
|
|
|
|
if (this.passwordType === 'password') {
|
|
|
|
if (this.passwordType === "password") {
|
|
|
|
this.passwordType = ''
|
|
|
|
this.passwordType = "";
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.passwordType = 'password'
|
|
|
|
this.passwordType = "password";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.password.focus()
|
|
|
|
this.$refs.password.focus();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 滑动验证码
|
|
|
|
// 滑动验证码
|
|
|
|
useVerify () {
|
|
|
|
useVerify() {
|
|
|
|
this.$refs.loginForm.validate((valid) => {
|
|
|
|
this.$refs.loginForm.validate(valid => {
|
|
|
|
if (valid) {
|
|
|
|
if (valid) {
|
|
|
|
this.$refs.verify.show()
|
|
|
|
this.$refs.verify.show();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 验证成功的回调
|
|
|
|
// 验证成功的回调
|
|
|
|
verifylogin (params) {
|
|
|
|
verifylogin(params) {
|
|
|
|
this.loginForm.verifyCode = params.captchaVerification
|
|
|
|
this.loginForm.verifyCode = params.captchaVerification;
|
|
|
|
if (this.loginForm.verifyCode) {
|
|
|
|
if (this.loginForm.verifyCode) {
|
|
|
|
this.loginApi()
|
|
|
|
this.loginApi();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// 登录操作
|
|
|
|
// 登录操作
|
|
|
|
handleLogin () {
|
|
|
|
handleLogin() {
|
|
|
|
this.$refs.loginForm.validate((valid) => {
|
|
|
|
this.$refs.loginForm.validate(valid => {
|
|
|
|
if (valid) {
|
|
|
|
if (valid) {
|
|
|
|
this.loading = true
|
|
|
|
this.loading = true;
|
|
|
|
// 登录失败次数过多需要展示滑动验证码
|
|
|
|
// 登录失败次数过多需要展示滑动验证码
|
|
|
|
if (this.needCaptcha) {
|
|
|
|
if (this.needCaptcha) {
|
|
|
|
this.useVerify()
|
|
|
|
this.useVerify();
|
|
|
|
return
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.loginApi()
|
|
|
|
this.loginApi();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async loginApi () {
|
|
|
|
async loginApi() {
|
|
|
|
let obj = {
|
|
|
|
let obj = {
|
|
|
|
loginName: this.loginForm.loginName,
|
|
|
|
loginName: this.loginForm.loginName,
|
|
|
|
password: transPsw(this.loginForm.password),
|
|
|
|
password: transPsw(this.loginForm.password),
|
|
|
|
verifyCode: '',
|
|
|
|
verifyCode: ""
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const { code, data } = await login(obj)
|
|
|
|
const { code, data } = await login(obj);
|
|
|
|
console.log(data)
|
|
|
|
this.loading = false;
|
|
|
|
this.loading = false
|
|
|
|
if (code != "200") return;
|
|
|
|
if (code != '200') return
|
|
|
|
setToken(data.token);
|
|
|
|
setToken(data.token)
|
|
|
|
setAccessUser(data);
|
|
|
|
setAccessUser(data)
|
|
|
|
|
|
|
|
// 选中记住密码时 把密码存到cookie里,时效15天
|
|
|
|
// 选中记住密码时 把密码存到cookie里,时效15天
|
|
|
|
this.rememberPsw &&
|
|
|
|
this.rememberPsw &&
|
|
|
|
cookies.set(
|
|
|
|
cookies.set(
|
|
|
|
`u_${this.loginForm.loginName}`,
|
|
|
|
`u_${this.loginForm.loginName}`,
|
|
|
|
Encrypt(this.loginForm.password),
|
|
|
|
Encrypt(this.loginForm.password),
|
|
|
|
{ expires: 15 }
|
|
|
|
{ expires: 15 }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
if (data && data.captcha) {
|
|
|
|
if (data && data.captcha) {
|
|
|
|
this.needCaptcha = true
|
|
|
|
this.needCaptcha = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.needCaptcha = false
|
|
|
|
this.needCaptcha = false;
|
|
|
|
this.$router.push({
|
|
|
|
this.$router.push({
|
|
|
|
path: this.redirect || '/index',
|
|
|
|
path: this.redirect || "/index",
|
|
|
|
query: this.otherQuery,
|
|
|
|
query: this.otherQuery
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getOtherQuery (query) {
|
|
|
|
getOtherQuery(query) {
|
|
|
|
return Object.keys(query).reduce((acc, cur) => {
|
|
|
|
return Object.keys(query).reduce((acc, cur) => {
|
|
|
|
if (cur !== 'redirect') {
|
|
|
|
if (cur !== "redirect") {
|
|
|
|
acc[cur] = query[cur]
|
|
|
|
acc[cur] = query[cur];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return acc
|
|
|
|
return acc;
|
|
|
|
}, {})
|
|
|
|
}, {});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
<style lang="scss">
|
|
|
|