| | |
| | | import request from '@/utils/request' |
| | | |
| | | // 登录方法 |
| | | export function login(username, password, code, uuid) { |
| | | export function login(username, password, code, uuid, loginType, verifyType) { |
| | | // export function login(data) { |
| | | const data = { |
| | | username, |
| | | password, |
| | | code, |
| | | uuid |
| | | } |
| | | uuid, |
| | | loginType, |
| | | verifyType |
| | | }; |
| | | return request({ |
| | | url: '/login', |
| | | headers: { |
| | |
| | | // 获取验证码 |
| | | export function getCodeImg() { |
| | | return request({ |
| | | url: '/captchaImage', |
| | | // url: '/captchaImage', |
| | | url: '/captcha/image', |
| | | headers: { |
| | | isToken: false |
| | | }, |
| | | method: 'get', |
| | | timeout: 20000 |
| | | }) |
| | | } |
| | | } |
| | | |
| | | // 获取没有验证码情况,时克英,2023-03-14 |
| | | export function getCodeNone() { |
| | | return request({ |
| | | // url: '/captchaNone', |
| | | url: '/captcha/none', |
| | | headers: { |
| | | isToken: false |
| | | }, |
| | | method: 'get', |
| | | timeout: 20000 |
| | | }) |
| | | } |
| | |
| | | import { login, logout, getInfo } from '@/api/login' |
| | | import { getToken, setToken, removeToken } from '@/utils/auth' |
| | | import log from "@/views/monitor/job/log"; |
| | | |
| | | const user = { |
| | | state: { |
| | |
| | | const password = userInfo.password |
| | | const code = userInfo.code |
| | | const uuid = userInfo.uuid |
| | | const loginType = userInfo.loginType |
| | | const verifyType = userInfo.verifyType |
| | | |
| | | return new Promise((resolve, reject) => { |
| | | login(username, password, code, uuid).then(res => { |
| | | login(username, password, code, uuid, loginType, verifyType).then(res => { |
| | | // console.log(res.data.token) |
| | | // setToken(res.token) |
| | | setToken(res.data.token) |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | import { getCodeImg } from "@/api/login"; |
| | | import dragVerify from './dragVerify/index.vue'// 滑动验证组件 |
| | | import Cookies from "js-cookie"; |
| | | import { encrypt, decrypt } from '@/utils/jsencrypt' |
| | | import {getCodeImg, getCodeNone} from "@/api/login"; |
| | | import dragVerify from './dragVerify/index.vue' // 滑动验证组件 |
| | | import Cookies from "js-cookie"; |
| | | import {encrypt} from '@/utils/jsencrypt' |
| | | |
| | | export default { |
| | | export default { |
| | | components: { |
| | | 'drag-verify': dragVerify |
| | | }, |
| | |
| | | verify:false, // 滑动校验 |
| | | codeUrl: "", |
| | | loginForm: { |
| | | verifyType: 'code',// 'code': 验证码 'slide':滑块 'jigsaw':拼图 |
| | | username: "supervisor", |
| | | password: "123456", |
| | | rememberMe: false, |
| | | username: 'supervisor', |
| | | password: '123456', |
| | | code:'', |
| | | uuid: "" |
| | | uuid: '', |
| | | loginType: 'user_pass', // 用户名、密码方式登录 |
| | | verifyType: 'slide'// 'code': 验证码 'slide':滑块 'jigsaw':拼图 |
| | | // rememberMe: false, |
| | | }, |
| | | loginRules: { |
| | | username: [ |
| | |
| | | } |
| | | }, |
| | | created() { |
| | | if(this.loginForm.verifyType==='code'){ |
| | | this.getCode(); |
| | | } |
| | | // if(this.loginForm.verifyType==='code'){ |
| | | // } |
| | | this.getCode(); |
| | | this.getCookie(); |
| | | }, |
| | | methods: { |
| | |
| | | this.verify = true |
| | | }, |
| | | getCode() { |
| | | getCodeImg().then(res => { |
| | | // console.log(res); |
| | | // this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled; |
| | | this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled; |
| | | console.log("captchaEnabled = " + this.captchaEnabled); |
| | | if (this.captchaEnabled) { |
| | | // this.codeUrl = "data:image/gif;base64," + res.img; |
| | | this.codeUrl = "data:image/jpeg;base64," + res.data.img; |
| | | // this.loginForm.uuid = res.uuid; |
| | | } |
| | | // 有没有验证码,都需要uuid作为唯一标识,2022-12-01 |
| | | this.loginForm.uuid = res.data.uuid; |
| | | if(this.loginForm.verifyType==='code'){ |
| | | getCodeImg().then(res => { |
| | | // console.log(res); |
| | | // this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled; |
| | | this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled; |
| | | console.log("captchaEnabled = " + this.captchaEnabled); |
| | | if (this.captchaEnabled) { |
| | | // this.codeUrl = "data:image/gif;base64," + res.img; |
| | | this.codeUrl = "data:image/jpeg;base64," + res.data.img; |
| | | // this.loginForm.uuid = res.uuid; |
| | | } |
| | | // 有没有验证码,都需要uuid作为唯一标识,2022-12-01 |
| | | this.loginForm.uuid = res.data.uuid; |
| | | |
| | | }).catch(err=>{console.log(err);}); |
| | | }).catch(err=>{console.log(err);}); |
| | | |
| | | } else if(this.loginForm.verifyType==='jigsaw'){ |
| | | // 拼图方式,看需要啥参数,暂未实现 |
| | | |
| | | } else if(this.loginForm.verifyType==='slide' || this.loginForm.verifyType==='sms'){ |
| | | // 不需要验证码,但仍需要请求接口获取uuid |
| | | getCodeNone().then(res => { |
| | | this.loginForm.uuid = res.data.uuid; |
| | | }).catch(err=>{console.error(err);}); |
| | | |
| | | } else { |
| | | this.$message.error('不支持的验证码类型:' + this.loginForm.verifyType); |
| | | } |
| | | }, |
| | | getCookie() { |
| | | const username = Cookies.get("username"); |
| | |
| | | Cookies.remove("password"); |
| | | Cookies.remove('rememberMe'); |
| | | } |
| | | // console.log(this.loginForm); |
| | | // console.log("-----------------------------"); |
| | | this.$store.dispatch("Login", this.loginForm).then(() => { |
| | | this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); |
| | | }).catch(() => { |