|
|
@@ -1,56 +1,70 @@
|
|
|
<template>
|
|
|
- <div style="position: relative;">
|
|
|
+ <div style="position: relative">
|
|
|
<div
|
|
|
v-if="type === '2'"
|
|
|
class="verify-img-out"
|
|
|
- :style="{height: (parseInt(setSize.imgHeight) + vSpace) + 'px'}"
|
|
|
+ :style="{ height: parseInt(setSize.imgHeight) + vSpace + 'px' }"
|
|
|
>
|
|
|
- <div
|
|
|
- class="verify-img-panel"
|
|
|
- :style="{width: setSize.imgWidth,
|
|
|
- height: setSize.imgHeight,}"
|
|
|
- >
|
|
|
- <img :src="backImgBase?('data:image/png;base64,'+backImgBase):defaultImg" alt="" style="width:100%;height:100%;display:block">
|
|
|
- <div v-show="showRefresh" class="verify-refresh" @click="refresh"><i class="iconfont icon-refresh" />
|
|
|
+ <div class="verify-img-panel" :style="{ width: setSize.imgWidth, height: setSize.imgHeight }">
|
|
|
+ <img
|
|
|
+ :src="backImgBase ? 'data:image/png;base64,' + backImgBase : defaultImg"
|
|
|
+ alt=""
|
|
|
+ style="width: 100%; height: 100%; display: block"
|
|
|
+ />
|
|
|
+ <div v-show="showRefresh" class="verify-refresh" @click="refresh"
|
|
|
+ ><i class="iconfont icon-refresh"></i>
|
|
|
</div>
|
|
|
<transition name="tips">
|
|
|
- <span v-if="tipWords" class="verify-tips" :class="passFlag ?'suc-bg':'err-bg'">{{ tipWords }}</span>
|
|
|
+ <span v-if="tipWords" class="verify-tips" :class="passFlag ? 'suc-bg' : 'err-bg'">{{
|
|
|
+ tipWords
|
|
|
+ }}</span>
|
|
|
</transition>
|
|
|
</div>
|
|
|
</div>
|
|
|
<!-- 公共部分 -->
|
|
|
<div
|
|
|
class="verify-bar-area"
|
|
|
- :style="{width: setSize.imgWidth,
|
|
|
- height: barSize.height,
|
|
|
- 'line-height':barSize.height}"
|
|
|
+ :style="{ width: setSize.imgWidth, height: barSize.height, 'line-height': barSize.height }"
|
|
|
>
|
|
|
- <span class="verify-msg" v-text="text" />
|
|
|
+ <span class="verify-msg" v-text="text"></span>
|
|
|
<div
|
|
|
class="verify-left-bar"
|
|
|
- :style="{width: (leftBarWidth!==undefined)?leftBarWidth: barSize.height, height: barSize.height, 'border-color': leftBarBorderColor, transaction: transitionWidth}"
|
|
|
+ :style="{
|
|
|
+ width: leftBarWidth !== undefined ? leftBarWidth : barSize.height,
|
|
|
+ height: barSize.height,
|
|
|
+ 'border-color': leftBarBorderColor,
|
|
|
+ transaction: transitionWidth
|
|
|
+ }"
|
|
|
>
|
|
|
- <span class="verify-msg" v-text="finishText" />
|
|
|
+ <span class="verify-msg" v-text="finishText"></span>
|
|
|
<div
|
|
|
class="verify-move-block"
|
|
|
- :style="{width: barSize.height, height: barSize.height, 'background-color': moveBlockBackgroundColor, left: moveBlockLeft, transition: transitionLeft}"
|
|
|
+ :style="{
|
|
|
+ width: barSize.height,
|
|
|
+ height: barSize.height,
|
|
|
+ 'background-color': moveBlockBackgroundColor,
|
|
|
+ left: moveBlockLeft,
|
|
|
+ transition: transitionLeft
|
|
|
+ }"
|
|
|
@touchstart="start"
|
|
|
@mousedown="start"
|
|
|
>
|
|
|
- <i
|
|
|
- :class="['verify-icon iconfont', iconClass]"
|
|
|
- :style="{color: iconColor}"
|
|
|
- />
|
|
|
+ <i :class="['verify-icon iconfont', iconClass]" :style="{ color: iconColor }"></i>
|
|
|
<div
|
|
|
v-if="type === '2'"
|
|
|
class="verify-sub-block"
|
|
|
- :style="{'width':Math.floor(parseInt(setSize.imgWidth)*47/310)+ 'px',
|
|
|
- 'height': setSize.imgHeight,
|
|
|
- 'top':'-' + (parseInt(setSize.imgHeight) + vSpace) + 'px',
|
|
|
- 'background-size': setSize.imgWidth + ' ' + setSize.imgHeight,
|
|
|
+ :style="{
|
|
|
+ width: Math.floor((parseInt(setSize.imgWidth) * 47) / 310) + 'px',
|
|
|
+ height: setSize.imgHeight,
|
|
|
+ top: '-' + (parseInt(setSize.imgHeight) + vSpace) + 'px',
|
|
|
+ 'background-size': setSize.imgWidth + ' ' + setSize.imgHeight
|
|
|
}"
|
|
|
>
|
|
|
- <img :src="'data:image/png;base64,'+blockBackImgBase" alt="" style="width:100%;height:100%;display:block">
|
|
|
+ <img
|
|
|
+ :src="'data:image/png;base64,' + blockBackImgBase"
|
|
|
+ alt=""
|
|
|
+ style="width: 100%; height: 100%; display: block"
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -59,19 +73,19 @@
|
|
|
</template>
|
|
|
<script type="text/babel">
|
|
|
/**
|
|
|
- * VerifySlide
|
|
|
- * @description 滑块
|
|
|
- * */
|
|
|
+ * VerifySlide
|
|
|
+ * @description 滑块
|
|
|
+ * */
|
|
|
import { aesEncrypt } from './../utils/ase'
|
|
|
import { resetSize } from './../utils/util'
|
|
|
-import {ajCaptcha, ajCaptchaCheck} from "../../../api/common";
|
|
|
+import { ajCaptcha, ajCaptchaCheck } from '@/api/login'
|
|
|
|
|
|
// "captchaType":"blockPuzzle",
|
|
|
export default {
|
|
|
name: 'VerifySlide',
|
|
|
props: {
|
|
|
captchaType: {
|
|
|
- type: String,
|
|
|
+ type: String
|
|
|
},
|
|
|
type: {
|
|
|
type: String,
|
|
|
@@ -151,7 +165,7 @@ export default {
|
|
|
iconColor: undefined,
|
|
|
iconClass: 'icon-right',
|
|
|
status: false, // 鼠标状态
|
|
|
- isEnd: false, // 是够验证完成
|
|
|
+ isEnd: false, // 是够验证完成
|
|
|
showRefresh: true,
|
|
|
transitionLeft: '',
|
|
|
transitionWidth: ''
|
|
|
@@ -176,7 +190,7 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
// 禁止拖拽
|
|
|
- this.$el.onselectstart = function() {
|
|
|
+ this.$el.onselectstart = function () {
|
|
|
return false
|
|
|
}
|
|
|
console.log(this.defaultImg)
|
|
|
@@ -186,53 +200,39 @@ export default {
|
|
|
this.text = this.explain
|
|
|
this.getPictrue()
|
|
|
this.$nextTick(() => {
|
|
|
- const setSize = this.resetSize(this) // 重新设置宽度高度
|
|
|
+ const setSize = this.resetSize(this) // 重新设置宽度高度
|
|
|
for (const key in setSize) {
|
|
|
- this.$set(this.setSize, key, setSize[key])
|
|
|
+ this.setSize[key] = setSize[key]
|
|
|
}
|
|
|
this.$parent.$emit('ready', this)
|
|
|
})
|
|
|
|
|
|
- var _this = this
|
|
|
-
|
|
|
- window.removeEventListener('touchmove', function(e) {
|
|
|
- _this.move(e)
|
|
|
- })
|
|
|
- window.removeEventListener('mousemove', function(e) {
|
|
|
- _this.move(e)
|
|
|
- })
|
|
|
+ // 使用箭头函数捕获 this
|
|
|
+ window.removeEventListener('touchmove', this.move)
|
|
|
+ window.removeEventListener('mousemove', this.move)
|
|
|
|
|
|
// 鼠标松开
|
|
|
- window.removeEventListener('touchend', function() {
|
|
|
- _this.end()
|
|
|
- })
|
|
|
- window.removeEventListener('mouseup', function() {
|
|
|
- _this.end()
|
|
|
- })
|
|
|
+ window.removeEventListener('touchend', this.end)
|
|
|
+ window.removeEventListener('mouseup', this.end)
|
|
|
|
|
|
- window.addEventListener('touchmove', function(e) {
|
|
|
- _this.move(e)
|
|
|
- })
|
|
|
- window.addEventListener('mousemove', function(e) {
|
|
|
- _this.move(e)
|
|
|
- })
|
|
|
+ window.addEventListener('touchmove', this.move)
|
|
|
+ window.addEventListener('mousemove', this.move)
|
|
|
|
|
|
// 鼠标松开
|
|
|
- window.addEventListener('touchend', function() {
|
|
|
- _this.end()
|
|
|
- })
|
|
|
- window.addEventListener('mouseup', function() {
|
|
|
- _this.end()
|
|
|
- })
|
|
|
+ window.addEventListener('touchend', this.end)
|
|
|
+ window.addEventListener('mouseup', this.end)
|
|
|
},
|
|
|
|
|
|
// 鼠标按下
|
|
|
- start: function(e) {
|
|
|
+ start: function (e) {
|
|
|
e = e || window.event
|
|
|
- if (!e.touches) { // 兼容PC端
|
|
|
- var x = e.clientX
|
|
|
- } else { // 兼容移动端
|
|
|
- var x = e.touches[0].pageX
|
|
|
+ let x = ''
|
|
|
+ if (!e.touches) {
|
|
|
+ // 兼容PC端
|
|
|
+ x = e.clientX
|
|
|
+ } else {
|
|
|
+ // 兼容移动端
|
|
|
+ x = e.touches[0].pageX
|
|
|
}
|
|
|
this.startLeft = Math.floor(x - this.barArea.getBoundingClientRect().left)
|
|
|
this.startMoveTime = +new Date() // 开始滑动的时间
|
|
|
@@ -246,42 +246,51 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
// 鼠标移动
|
|
|
- move: function(e) {
|
|
|
+ move: function (e) {
|
|
|
e = e || window.event
|
|
|
if (this.status && this.isEnd == false) {
|
|
|
- if (!e.touches) { // 兼容PC端
|
|
|
- var x = e.clientX
|
|
|
- } else { // 兼容移动端
|
|
|
- var x = e.touches[0].pageX
|
|
|
+ let x = ''
|
|
|
+ if (!e.touches) {
|
|
|
+ // 兼容PC端
|
|
|
+ x = e.clientX
|
|
|
+ } else {
|
|
|
+ // 兼容移动端
|
|
|
+ x = e.touches[0].pageX
|
|
|
}
|
|
|
- var bar_area_left = this.barArea.getBoundingClientRect().left
|
|
|
- var move_block_left = x - bar_area_left // 小方块相对于父元素的left值
|
|
|
- if (move_block_left >= this.barArea.offsetWidth - parseInt(parseInt(this.blockSize.width) / 2) - 2) {
|
|
|
- move_block_left = this.barArea.offsetWidth - parseInt(parseInt(this.blockSize.width) / 2) - 2
|
|
|
+ const bar_area_left = this.barArea.getBoundingClientRect().left
|
|
|
+ let move_block_left = x - bar_area_left // 小方块相对于父元素的left值
|
|
|
+ if (
|
|
|
+ move_block_left >=
|
|
|
+ this.barArea.offsetWidth - parseInt(parseInt(this.blockSize.width) / 2) - 2
|
|
|
+ ) {
|
|
|
+ move_block_left =
|
|
|
+ this.barArea.offsetWidth - parseInt(parseInt(this.blockSize.width) / 2) - 2
|
|
|
}
|
|
|
if (move_block_left <= 0) {
|
|
|
move_block_left = parseInt(parseInt(this.blockSize.width) / 2)
|
|
|
}
|
|
|
// 拖动后小方块的left值
|
|
|
- this.moveBlockLeft = (move_block_left - this.startLeft) + 'px'
|
|
|
- this.leftBarWidth = (move_block_left - this.startLeft) + 'px'
|
|
|
+ this.moveBlockLeft = move_block_left - this.startLeft + 'px'
|
|
|
+ this.leftBarWidth = move_block_left - this.startLeft + 'px'
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 鼠标松开
|
|
|
- end: function() {
|
|
|
+ end: function () {
|
|
|
this.endMovetime = +new Date()
|
|
|
- var _this = this
|
|
|
// 判断是否重合
|
|
|
if (this.status && this.isEnd == false) {
|
|
|
- var moveLeftDistance = parseInt((this.moveBlockLeft || '').replace('px', ''))
|
|
|
- moveLeftDistance = moveLeftDistance * 310 / parseInt(this.setSize.imgWidth)
|
|
|
+ let moveLeftDistance = parseInt((this.moveBlockLeft || '').replace('px', ''))
|
|
|
+ moveLeftDistance = (moveLeftDistance * 310) / parseInt(this.setSize.imgWidth)
|
|
|
const data = {
|
|
|
captchaType: this.captchaType,
|
|
|
- 'pointJson': this.secretKey ? aesEncrypt(JSON.stringify({ x: moveLeftDistance, y: 5.0 }), this.secretKey) : JSON.stringify({ x: moveLeftDistance, y: 5.0 }),
|
|
|
- 'token': this.backToken
|
|
|
+ pointJson: this.secretKey
|
|
|
+ ? aesEncrypt(JSON.stringify({ x: moveLeftDistance, y: 5.0 }), this.secretKey)
|
|
|
+ : JSON.stringify({ x: moveLeftDistance, y: 5.0 }),
|
|
|
+ token: this.backToken
|
|
|
}
|
|
|
- ajCaptchaCheck(data).then(res => {
|
|
|
+ ajCaptchaCheck(data)
|
|
|
+ .then((res) => {
|
|
|
this.moveBlockBackgroundColor = '#5cb85c'
|
|
|
this.leftBarBorderColor = '#5cb85c'
|
|
|
this.iconColor = '#fff'
|
|
|
@@ -296,32 +305,37 @@ export default {
|
|
|
}
|
|
|
this.passFlag = true
|
|
|
this.tipWords = `${((this.endMovetime - this.startMoveTime) / 1000).toFixed(2)}s验证成功`
|
|
|
- var captchaVerification = this.secretKey ? aesEncrypt(this.backToken + '---' + JSON.stringify({ x: moveLeftDistance, y: 5.0 }), this.secretKey) : this.backToken + '---' + JSON.stringify({ x: moveLeftDistance, y: 5.0 })
|
|
|
+ const captchaVerification = this.secretKey
|
|
|
+ ? aesEncrypt(
|
|
|
+ this.backToken + '---' + JSON.stringify({ x: moveLeftDistance, y: 5.0 }),
|
|
|
+ this.secretKey
|
|
|
+ )
|
|
|
+ : this.backToken + '---' + JSON.stringify({ x: moveLeftDistance, y: 5.0 })
|
|
|
setTimeout(() => {
|
|
|
this.tipWords = ''
|
|
|
this.$parent.closeBox()
|
|
|
this.$parent.$emit('success', { captchaVerification })
|
|
|
}, 1000)
|
|
|
- }).catch(res=>{
|
|
|
- this.moveBlockBackgroundColor = '#d9534f'
|
|
|
- this.leftBarBorderColor = '#d9534f'
|
|
|
- this.iconColor = '#fff'
|
|
|
- this.iconClass = 'icon-close'
|
|
|
- this.passFlag = false
|
|
|
- setTimeout(function() {
|
|
|
- _this.refresh()
|
|
|
- }, 1000)
|
|
|
- this.$parent.$emit('error', this)
|
|
|
- this.tipWords = '验证失败'
|
|
|
- setTimeout(() => {
|
|
|
- this.tipWords = ''
|
|
|
- }, 1000)
|
|
|
- })
|
|
|
+ })
|
|
|
+ .catch((res) => {
|
|
|
+ this.moveBlockBackgroundColor = '#d9534f'
|
|
|
+ this.leftBarBorderColor = '#d9534f'
|
|
|
+ this.iconColor = '#fff'
|
|
|
+ this.iconClass = 'icon-close'
|
|
|
+ this.passFlag = false
|
|
|
+ setTimeout(() => {
|
|
|
+ this.refresh()
|
|
|
+ }, 1000)
|
|
|
+ this.$parent.$emit('error', this)
|
|
|
+ this.tipWords = '验证失败'
|
|
|
+ setTimeout(() => {
|
|
|
+ this.tipWords = ''
|
|
|
+ }, 1000)
|
|
|
+ })
|
|
|
this.status = false
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
- refresh: function() {
|
|
|
+ refresh: function () {
|
|
|
this.showRefresh = true
|
|
|
this.finishText = ''
|
|
|
|
|
|
@@ -347,23 +361,25 @@ export default {
|
|
|
|
|
|
// 请求背景图片和验证图片
|
|
|
getPictrue() {
|
|
|
+ // console.log('请求验证码')
|
|
|
const data = {
|
|
|
captchaType: this.captchaType,
|
|
|
clientUid: localStorage.getItem('slider'),
|
|
|
- ts: Date.now(), // 现在的时间戳
|
|
|
+ ts: Date.now() // 现在的时间戳
|
|
|
}
|
|
|
- ajCaptcha(data).then(res => {
|
|
|
+ ajCaptcha(data)
|
|
|
+ .then((res) => {
|
|
|
this.backImgBase = res.data.originalImageBase64
|
|
|
this.blockBackImgBase = res.data.jigsawImageBase64
|
|
|
this.backToken = res.data.token
|
|
|
this.secretKey = res.data.secretKey
|
|
|
- }).catch(res =>{
|
|
|
- this.tipWords = res.msg
|
|
|
- this.backImgBase = null
|
|
|
- this.blockBackImgBase = null
|
|
|
- })
|
|
|
- },
|
|
|
- },
|
|
|
+ })
|
|
|
+ .catch((res) => {
|
|
|
+ this.tipWords = res.msg
|
|
|
+ this.backImgBase = null
|
|
|
+ this.blockBackImgBase = null
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
-
|