login 默认账号密码修改

qianlishi 3 years ago
parent 5fbe3f6000
commit 2134ad604d

@ -8,24 +8,23 @@
<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,
<br> <br />
<p class="title_name">在线大屏</p> <p class="title_name">在线大屏</p>
</h3> </h3>
</div> </div>
@ -37,7 +36,8 @@
<div> <div>
<p>用户名</p> <p>用户名</p>
<el-form-item prop="username"> <el-form-item prop="username">
<el-input ref="username" <el-input
ref="username"
v-model="loginForm.username" v-model="loginForm.username"
placeholder="用户名" placeholder="用户名"
name="username" name="username"
@ -45,21 +45,27 @@
tabindex="1" tabindex="1"
autocomplete="on" autocomplete="on"
@focus="setTop('0')" @focus="setTop('0')"
@change="getPsw" /> @change="getPsw"
/>
</el-form-item> </el-form-item>
</div> </div>
<div> <div>
<p>密码</p> <p>密码</p>
<input name="password" <input
name="password"
type="password" type="password"
autocomplete="off" autocomplete="off"
class="take"> class="take"
<el-tooltip v-model="capsTooltip" />
<el-tooltip
v-model="capsTooltip"
content="Caps lock is On" content="Caps lock is On"
placement="right" placement="right"
manual> manual
>
<el-form-item prop="password"> <el-form-item prop="password">
<el-input :key="passwordType" <el-input
:key="passwordType"
ref="password" ref="password"
v-model="loginForm.password" v-model="loginForm.password"
:type="passwordType" :type="passwordType"
@ -69,9 +75,9 @@
autocomplete="on" autocomplete="on"
@blur="capsTooltip = false" @blur="capsTooltip = false"
@focus="setTop('50')" @focus="setTop('50')"
@keyup.native="checkCapslock" /> @keyup.native="checkCapslock"
<span class="show_pwd" />
@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,168 +86,180 @@
</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
:loading="loading"
type="primary" type="primary"
class="login_btn" class="login_btn"
@click.native.prevent="handleLogin">登录</el-button> @click.native.prevent="handleLogin"
>登录</el-button
>
</el-form> </el-form>
</div> </div>
<!-- 验证码 --> <!-- 验证码 -->
<Verify v-if="needCaptcha" <Verify
v-if="needCaptcha"
ref="verify" ref="verify"
:captcha-type="'blockPuzzle'" :captcha-type="'blockPuzzle'"
:img-size="{ width: '400px', height: '200px' }" :img-size="{ width: '400px', height: '200px' }"
@success="verifylogin" /> @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 { setItem, getItem } from '@/utils/storage'; import { setItem, getItem } from "@/utils/storage";
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: {
username: 'admin', username: "guest",
password: '123456', password: "guest",
verifyCode: '', verifyCode: ""
}, // }, //
loginRules: { loginRules: {
username: [{ required: true, message: '用户名必填', trigger: 'blur' }], username: [{ required: true, message: "用户名必填", trigger: "blur" }],
password: [{ required: true, message: '用户密码必填', trigger: 'blur' }], password: [{ 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.username === '') { if (this.loginForm.username === "") {
this.$refs.username.focus() this.$refs.username.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.username}`) const cookVal = cookies.get(`u_${this.loginForm.username}`);
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 = {
username: this.loginForm.username, username: this.loginForm.username,
password: transPsw(this.loginForm.password), password: transPsw(this.loginForm.password),
verifyCode: "" verifyCode: ""
} };
const { code, data } = await login(obj) const { code, data } = await login(obj);
if (code != '200') return if (code != "200") return;
setItem("token", data.token) setItem("token", data.token);
this.loading = false this.loading = false;
// cookie,15 // cookie,15
this.rememberPsw && cookies.set(`u_${this.loginForm.username}`, Encrypt(this.loginForm.password), { expires: 15 }) this.rememberPsw &&
cookies.set(
`u_${this.loginForm.username}`,
Encrypt(this.loginForm.password),
{ 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({ path: this.redirect || '/index', query: this.otherQuery }) this.$router.push({
path: this.redirect || "/index",
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">

Loading…
Cancel
Save