| | |
| | | </template>
|
| | |
|
| | | <script>
|
| | | import { getCodeImg } from "@/api/login";
|
| | | import Cookies from "js-cookie";
|
| | | import { getCodeImg } from "@/api/login"
|
| | | import Cookies from "js-cookie"
|
| | | import { encrypt, decrypt } from '@/utils/jsencrypt'
|
| | |
|
| | | export default {
|
| | |
| | | // 注册开关
|
| | | register: false,
|
| | | redirect: undefined
|
| | | };
|
| | | }
|
| | | },
|
| | | watch: {
|
| | | $route: {
|
| | | handler: function(route) {
|
| | | this.redirect = route.query && route.query.redirect;
|
| | | this.redirect = route.query && route.query.redirect
|
| | | },
|
| | | immediate: true
|
| | | }
|
| | | },
|
| | | created() {
|
| | | this.getCode();
|
| | | this.getCookie();
|
| | | this.getCode()
|
| | | this.getCookie()
|
| | | },
|
| | | methods: {
|
| | | getCode() {
|
| | | getCodeImg().then(res => {
|
| | | this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
| | | this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
|
| | | if (this.captchaEnabled) {
|
| | | this.codeUrl = "data:image/gif;base64," + res.img;
|
| | | this.loginForm.uuid = res.uuid;
|
| | | this.codeUrl = "data:image/gif;base64," + res.img
|
| | | this.loginForm.uuid = res.uuid
|
| | | }
|
| | | });
|
| | | })
|
| | | },
|
| | | getCookie() {
|
| | | const username = Cookies.get("username");
|
| | | const password = Cookies.get("password");
|
| | | const username = Cookies.get("username")
|
| | | const password = Cookies.get("password")
|
| | | const rememberMe = Cookies.get('rememberMe')
|
| | | this.loginForm = {
|
| | | username: username === undefined ? this.loginForm.username : username,
|
| | | password: password === undefined ? this.loginForm.password : decrypt(password),
|
| | | rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
| | | };
|
| | | }
|
| | | },
|
| | | handleLogin() {
|
| | | this.$refs.loginForm.validate(valid => {
|
| | | if (valid) {
|
| | | this.loading = true;
|
| | | this.loading = true
|
| | | if (this.loginForm.rememberMe) {
|
| | | Cookies.set("username", this.loginForm.username, { expires: 30 });
|
| | | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
| | | Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
| | | Cookies.set("username", this.loginForm.username, { expires: 30 })
|
| | | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 })
|
| | | Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 })
|
| | | } else {
|
| | | Cookies.remove("username");
|
| | | Cookies.remove("password");
|
| | | Cookies.remove('rememberMe');
|
| | | Cookies.remove("username")
|
| | | Cookies.remove("password")
|
| | | Cookies.remove('rememberMe')
|
| | | }
|
| | | this.$store.dispatch("Login", this.loginForm).then(() => {
|
| | | this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
| | | this.$router.push({ path: this.redirect || "/" }).catch(()=>{})
|
| | | }).catch(() => {
|
| | | this.loading = false;
|
| | | this.loading = false
|
| | | if (this.captchaEnabled) {
|
| | | this.getCode();
|
| | | this.getCode()
|
| | | }
|
| | | });
|
| | | })
|
| | | }
|
| | | });
|
| | | })
|
| | | }
|
| | | }
|
| | | };
|
| | | }
|
| | | </script>
|
| | |
|
| | | <style rel="stylesheet/scss" lang="scss">
|