| | |
| | | <el-form-item v-if="loginForm.verifyType==='slide'"> |
| | | <drag-verify @success="verifyTrue" ref="verify"/> |
| | | </el-form-item> |
| | | <el-form-item v-if="loginForm.verifyType==='jigsaw'"> |
| | | <!-- <drag-verify @success="verifyTrue" ref="verify"/>--> |
| | | <transition duration="1000" name="el-fade-in"> |
| | | <jigsaw-verify v-if="loginForm.verifyType==='jigsaw'" :left="left" :top="top" @hide="verifyFalse" @success="handleLogin" /> |
| | | </transition> |
| | | </el-form-item> |
| | | <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> |
| | | <el-form-item style="width:100%;"> |
| | | <el-button |
| | |
| | | </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 jigsawVerify from '@/views/components/verify' // 拼图验证组件,2023-04-06 |
| | | import Cookies from "js-cookie"; |
| | | // import {encrypt} from '@/utils/jsencrypt' |
| | | |
| | | export default { |
| | | export default { |
| | | components: { |
| | | 'drag-verify': dragVerify |
| | | 'drag-verify': dragVerify, |
| | | 'jigsaw-verify': jigsawVerify |
| | | }, |
| | | data() { |
| | | return { |
| | | verify:false, // 滑动校验 |
| | | codeUrl: "", |
| | | left: null, // 拼图验证码位置 |
| | | top: null, // 拼图验证码位置 |
| | | loginForm: { |
| | | verifyType: 'code',// 'code': 验证码 'slide':滑块 'jigsaw':拼图 |
| | | username: "supervisor", |
| | | password: "123456", |
| | | rememberMe: false, |
| | | username: 'supervisor', |
| | | password: '123456', |
| | | code:'', |
| | | uuid: "" |
| | | uuid: '', |
| | | loginType: 'user_pass', // 用户名、密码方式登录 |
| | | verifyType: 'jigsaw'// '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: { |
| | | verifyTrue () { |
| | | this.verify = true |
| | | }, |
| | | verifyFalse() { |
| | | this.verify = false |
| | | }, |
| | | 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'){ |
| | | // 拼图方式,看需要啥参数,暂未实现 |
| | | console.log('jigsaw...'); |
| | | this.loginForm.code = 'jigsaw'; // 填充code默认值,否则验证不通过。2023-04-06 |
| | | |
| | | } 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"); |
| | |
| | | this.loginForm.password = password === undefined ? this.loginForm.password : password |
| | | this.loginForm.rememberMe = rememberMe === undefined ? this.loginForm.rememberMe : rememberMe |
| | | }, |
| | | handleLogin() { |
| | | handleLogin(param) { |
| | | if(this.loginForm.verifyType==='jigsaw' && param != null){ |
| | | // console.log(param); |
| | | // console.log("拼图提交参数"); |
| | | // 拼图验证码时,调用方会传入code(用户验证码位置),uuid |
| | | this.loginForm.code = param.x; |
| | | this.loginForm.uuid = param.uuid; |
| | | } |
| | | this.$refs.loginForm.validate(valid => { |
| | | if (valid) { |
| | | if (this.loginForm.verifyType==='slide' && !this.verify) { |
| | |
| | | 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(() => { |