123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657 |
- <template>
- <view style="position: relative;">
- <view v-if="type === '2'" class="verify-img-out" :style="{height: (parseInt(imgSize.height) + vSpace) + 'px'}">
- <view class="verify-img-panel" :style="{width: imgSize.width,
- height: imgSize.height,}">
- <image :src="backImgBase?('data:image/png;base64,'+backImgBase):defaultImg" alt=""
- style="width:100%;height:100%;display:block"></image>
- <view class="verify-refresh" @click="refresh" v-show="showRefresh">
- <text class="iconfont icon-refresh"></text>
- </view>
- <transition name="tips">
- <text class="verify-tips" v-if="tipWords" :class="passFalg ? 'suc-bg':'err-bg'">{{tipWords}}</text>
- </transition>
- </view>
- </view>
-
- <view class="verify-bar-area" :style="{width: imgSize.width,
- height: '40px',
- 'line-height':'40px'}">
- <text class="verify-msg" v-text="text"></text>
- <view class="verify-left-bar"
- :style="{width: leftBarWidth?leftBarWidth:'40px', height: '40px', 'border-color': leftBarBorderColor, transaction: transitionWidth}">
- <text class="verify-msg" v-text="finishText"></text>
- <view class="verify-move-block" @touchstart="start" @touchend="end" @touchmove="move"
- :style="{width:'40px', height: '40px', 'background-color': moveBlockBackgroundColor, left: moveBlockLeft, transition: transitionLeft}">
- <text :class="['verify-icon iconfont', iconClass]" :style="{color: iconColor}"></text>
- <view v-if="type === '2'" class="verify-sub-block" :style="{'width':Math.floor(parseInt(imgSize.width)*47/310)+ 'px' ,
- 'height': imgSize.height,
- 'top':'-' + (parseInt(imgSize.height) + vSpace) + 'px',
- }">
- <image :src="'data:image/png;base64,'+blockBackImgBase" alt=""
- style="width:100%;height:100%;display:block"></image>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
-
-
-
-
-
-
-
-
-
-
- import {
- aesEncrypt
- } from "./../utils/ase.js"
- import {
- getAjcaptcha,
- ajcaptchaCheck
- } from '@/api/api.js';
- export default {
- name: 'VerifySlide',
- props: {
- captchaType: {
- type: String,
- },
- type: {
- type: String,
- default: '1'
- },
-
- mode: {
- type: String,
- default: 'fixed'
- },
- vSpace: {
- type: Number,
- default: 5
- },
- explain: {
- type: String,
- default: '向右滑动完成验证'
- },
- imgSize: {
- type: Object,
- default () {
- return {
- width: '310px',
- height: '155px'
- }
- }
- },
- blockSize: {
- type: Object,
- default () {
- return {
- width: '50px',
- height: '50px'
- }
- }
- },
- barSize: {
- type: Object,
- default () {
- return {
- width: '100%',
- height: '40px'
- }
- }
- },
- defaultImg: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- secretKey: '',
- passFalg: false,
- backImgBase: '',
- blockBackImgBase: '',
- backToken: "",
- startMoveTime: "",
- endMovetime: '',
- tipsBackColor: '',
- tipWords: '',
- text: '',
- finishText: '',
- setSize: {
- imgHeight: 0,
- imgWidth: 0,
- barHeight: 0,
- barWidth: 0
- },
- top: 0,
- left: 0,
- moveBlockLeft: undefined,
- leftBarWidth: undefined,
-
- moveBlockBackgroundColor: undefined,
- leftBarBorderColor: '#ddd',
- iconColor: undefined,
- iconClass: 'icon-right',
- status: false,
- isEnd: false,
- showRefresh: true,
- transitionLeft: '',
- transitionWidth: ''
- }
- },
- methods: {
- init() {
- this.text = this.explain
- this.getPictrue();
- this.$nextTick(() => {
- this.$parent.$emit('ready', this)
- })
- },
-
- start: function(e) {
- this.startMoveTime = new Date().getTime();
- if (this.isEnd == false) {
- this.text = ''
- this.moveBlockBackgroundColor = '#337ab7'
- this.leftBarBorderColor = '#337AB7'
- this.iconColor = '#fff'
- e.stopPropagation();
- this.status = true;
- }
- },
-
- move: function(e) {
- var query = uni.createSelectorQuery().in(this);
- this.barArea = query.select('.verify-bar-area')
- var bar_area_left, barArea_offsetWidth;
- this.barArea.boundingClientRect(data => {
- bar_area_left = Math.ceil(data.left)
- barArea_offsetWidth = Math.ceil(data.width)
- if (this.status && this.isEnd == false) {
- if (!e.touches) {
- var x = Math.ceil(e.clientX);
- } else {
- var x = Math.ceil(e.touches[0].pageX);
- }
-
- var move_block_left = x - bar_area_left
- if (this.type !== '1') {
- if (move_block_left >= barArea_offsetWidth - parseInt(parseInt(this.blockSize
- .width) / 2) - 2) {
- move_block_left = barArea_offsetWidth - parseInt(parseInt(this.blockSize
- .width) / 2) - 2;
- }
- }
- if (move_block_left <= 0) {
- move_block_left = parseInt(parseInt(this.blockSize.width) / 2);
- }
-
- this.moveBlockLeft = (move_block_left - parseInt(parseInt(this.blockSize.width) / 2)) +
- "px"
- this.leftBarWidth = (move_block_left - parseInt(parseInt(this.blockSize.width) / 2)) +
- "px"
- }
- }).exec();
- },
-
- end: function() {
- this.endMovetime = new Date().getTime();
- var _this = this;
-
- if (this.status && this.isEnd == false) {
- if (this.type !== '1') {
- var moveLeftDistance = parseInt((this.moveBlockLeft || '').replace('px', ''));
- moveLeftDistance = moveLeftDistance * 310 / parseInt(this.imgSize.width)
- 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
- })
- let 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
- }
- ajcaptchaCheck(data).then((result) => {
- let res = result.data
- this.moveBlockBackgroundColor = '#5cb85c'
- this.leftBarBorderColor = '#5cb85c'
- this.iconColor = '#fff'
- this.iconClass = 'icon-check'
- this.showRefresh = true
- this.isEnd = true;
- setTimeout(() => {
- if (this.mode == 'pop') {
- this.$parent.clickShow = false;
- }
- this.refresh();
- }, 1500)
- this.passFalg = true
- this.tipWords =
- `${((this.endMovetime-this.startMoveTime)/1000).toFixed(2)}s验证成功`
- setTimeout(() => {
- this.tipWords = ""
- this.$emit('success', {
- captchaVerification
- })
- }, 1000)
- }).catch(res => {
- this.moveBlockBackgroundColor = '#d9534f'
- this.leftBarBorderColor = '#d9534f'
- this.iconColor = '#fff'
- this.iconClass = 'icon-close'
- this.passFalg = false
- setTimeout(() => {
- this.refresh();
- }, 1000);
- this.$parent.$emit('error', this)
- this.tipWords = "验证失败"
- setTimeout(() => {
- this.tipWords = ""
- }, 1000)
- })
- }
- this.status = false;
- }
- },
- refresh: function() {
- this.showRefresh = true
- this.finishText = ''
- this.transitionLeft = 'left .3s'
- this.moveBlockLeft = 0
- this.leftBarWidth = false
- this.transitionWidth = 'width .3s'
- this.leftBarBorderColor = '#ddd'
- this.moveBlockBackgroundColor = '#fff'
- this.iconColor = '#000'
- this.iconClass = 'icon-right'
- this.getPictrue()
- this.isEnd = false
- setTimeout(() => {
- this.transitionWidth = ''
- this.transitionLeft = ''
- this.text = this.explain
- }, 300)
- },
-
- getLeft: function(node) {
- let leftValue = 0;
- while (node) {
- leftValue += node.offsetLeft;
- node = node.offsetParent;
- }
- let finalvalue = leftValue;
- return finalvalue;
- },
-
- getPictrue() {
- let data = {
- captchaType: this.captchaType,
- clientUid: uni.getStorageSync('slider'),
- ts: Date.now(),
- }
- getAjcaptcha(data).then((result) => {
- let res = result.data
- this.backImgBase = res.originalImageBase64
- this.blockBackImgBase = res.jigsawImageBase64
- this.backToken = res.token
- this.secretKey = res.secretKey
- }).catch(() => {
- this.backImgBase = null
- this.blockBackImgBase = null
- })
- },
- },
- watch: {
-
- type: {
- immediate: true,
- handler() {
- this.init()
- }
- }
- },
- mounted() {},
- }
- </script>
- <style scoped>
- .verifybox {
- position: relative;
- box-sizing: border-box;
- border-radius: 2px;
- border: 1px solid #e4e7eb;
- background-color: #fff;
- box-shadow: 0 0 10px rgba(0, 0, 0, .3);
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- }
- .verifybox-top {
- padding: 0 15px;
- height: 50px;
- line-height: 50px;
- text-align: left;
- font-size: 16px;
- color: #45494c;
- border-bottom: 1px solid #e4e7eb;
- box-sizing: border-box;
- }
- .verifybox-bottom {
-
- box-sizing: border-box;
- }
- .verifybox-close {
- position: absolute;
- top: 13px;
- right: 9px;
- width: 24px;
- height: 24px;
- text-align: center;
- cursor: pointer;
- }
- .mask {
- position: fixed;
- top: 0;
- left: 0;
- z-index: 1001;
- width: 100%;
- height: 100vh;
- background: rgba(0, 0, 0, .3);
-
- transition: all .5s;
- }
- .verify-tips {
- position: absolute;
- left: 0px;
- bottom: 0px;
- width: 100%;
- height: 30px;
- background-color: rgb(231, 27, 27, .5);
- line-height: 30px;
- color: #fff;
- }
- .suc-bg {
- background-color: rgba(92, 184, 92, .5);
- filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=#7f5CB85C, endcolorstr=#7f5CB85C);
- }
- .err-bg {
- background-color: rgba(217, 83, 79, .5);
- filter: progid:DXImageTransform.Microsoft.gradient(startcolorstr=#7fD9534F, endcolorstr=#7fD9534F);
- }
- .tips-enter,
- .tips-leave-to {
- bottom: -30px;
- }
- .tips-enter-active,
- .tips-leave-active {
- transition: bottom .5s;
- }
-
-
- .verify-code {
- font-size: 20px;
- text-align: center;
- cursor: pointer;
- margin-bottom: 5px;
- border: 1px solid #ddd;
- }
- .cerify-code-panel {
- height: 100%;
- overflow: hidden;
- }
- .verify-code-area {
- float: left;
- }
- .verify-input-area {
- float: left;
- width: 60%;
- padding-right: 10px;
- }
- .verify-change-area {
- line-height: 30px;
- float: left;
- }
- .varify-input-code {
- display: inline-block;
- width: 100%;
- height: 25px;
- }
- .verify-change-code {
- color: #337AB7;
- cursor: pointer;
- }
- .verify-btn {
- width: 200px;
- height: 30px;
- background-color: #337AB7;
- color: #FFFFFF;
- border: none;
- margin-top: 10px;
- }
-
- .verify-bar-area {
- position: relative;
- background: #FFFFFF;
- text-align: center;
- -webkit-box-sizing: content-box;
- -moz-box-sizing: content-box;
- box-sizing: content-box;
- border: 1px solid #ddd;
- -webkit-border-radius: 4px;
- }
- .verify-bar-area .verify-move-block {
- position: absolute;
- top: 0px;
- left: 0;
- background: #fff;
- cursor: pointer;
- -webkit-box-sizing: content-box;
- -moz-box-sizing: content-box;
- box-sizing: content-box;
- box-shadow: 0 0 2px #888888;
- -webkit-border-radius: 1px;
- }
- .verify-bar-area .verify-move-block:hover {
- background-color: #337ab7;
- color: #FFFFFF;
- }
- .verify-bar-area .verify-left-bar {
- position: absolute;
- top: -1px;
- left: -1px;
- background: #f0fff0;
- cursor: pointer;
- -webkit-box-sizing: content-box;
- -moz-box-sizing: content-box;
- box-sizing: content-box;
- border: 1px solid #ddd;
- }
- .verify-img-panel {
- margin: 0;
- -webkit-box-sizing: content-box;
- -moz-box-sizing: content-box;
- box-sizing: content-box;
- border-top: 1px solid #ddd;
- border-bottom: 1px solid #ddd;
- border-radius: 3px;
- position: relative;
- }
- .verify-img-panel .verify-refresh {
- width: 25px;
- height: 25px;
- text-align: center;
- padding: 5px;
- cursor: pointer;
- position: absolute;
- top: 0;
- right: 0;
- z-index: 2;
- }
- .verify-img-panel .icon-refresh {
- font-size: 20px;
- color: #fff;
- }
- .verify-img-panel .verify-gap {
- background-color: #fff;
- position: relative;
- z-index: 2;
- border: 1px solid #fff;
- }
- .verify-bar-area .verify-move-block .verify-sub-block {
- position: absolute;
- text-align: center;
- z-index: 3;
-
- }
- .verify-bar-area .verify-move-block .verify-icon {
- width: 80rpx;
- height: 80rpx;
- font-size: 18px;
- }
- .verify-bar-area .verify-msg {
- z-index: 3;
- }
-
-
-
-
-
-
-
-
- .iconfont {
- font-family: "iconfont" !important;
- font-size: 16px;
- font-style: normal;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- }
- .icon-check:before {
- content: " ";
- display: block;
- width: 16px;
- height: 16px;
- position: absolute;
- margin: auto;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- z-index: 9999;
- background-image: url("@/static/images/arrow-good.png");
- background-size: contain;
- }
- .icon-close:before {
- content: " ";
- display: block;
- width: 16px;
- height: 16px;
- position: absolute;
- margin: auto;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- z-index: 9999;
- background-image: url("@/static/images/arrow-close.png");
- background-size: contain;
- }
- .icon-right:before {
- content: " ";
- display: block;
- width: 16px;
- height: 16px;
- position: absolute;
- margin: auto;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- background-size: cover;
- z-index: 9999;
- background-image: url("@/static/images/arrow-right.png");
- background-size: contain;
- }
- .icon-refresh:before {
- content: " ";
- display: block;
- width: 16px;
- height: 16px;
- position: absolute;
- margin: auto;
- left: 0;
- right: 0;
- top: 0;
- bottom: 0;
- z-index: 9999;
- background-image: url("@/static/images/refresh.png");
- background-size: contain;
- }
- </style>
|