123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- <template>
- <uni-popup ref="popupRef" @change="change">
- <view class="popup-box">
- <view class="verifyBox">
- <view class="verify-title">
- <text>安全验证</text>
- <text @click.stop="$refs.popupRef.close()" class="verify-close iconfont"></text>
- </view>
- <view class="verify-hint">
- 滑动下方滑块完成拼图
- </view>
- <view class="slide-content">
- <view class="slider-pintu">
- <image id="pintuImg" :src="pintuImgs[pintuIndex]" class="pintu">
- </image>
- <!-- <image id="pintuImg" :src="'@/static/images/slider-verify/' + img + '.png'" class="pintu">
- </image> -->
- <view class="pintukuai" :style="{ top: top + 'px', left: oldx + 'px' }">
- <image :src="pintuImgs[pintuIndex]"
- :style="{ top: '-' + top + 'px', left: '-' + left + 'px'}">
- </image>
- </view>
- <view class="yinying" :style="{ top: top + 'px', left: left + 'px' }"></view>
- <view class="slider-success" v-show="moveSuccess">
- <text class="slider-success-icon iconfont"></text>
- <text class="slider-success-text">只用了{{ moveTime }}S,简直比闪电还快</text>
- </view>
- </view>
- <view class="slider-movearea" @touchend="endTouchMove">
- <movable-area :animation="true">
- <movable-view :x="x" direction="horizontal" @change="startMove">
- <text class="movable-item"></text>
- <text class="movable-item"></text>
- <text class="movable-item"></text>
- </movable-view>
- </movable-area>
- <view class="huadao"></view>
- </view>
- </view>
- <view class="slider-btn-group">
- <text class="slider-err"> {{ sliderErrText }} </text>
- <view class="slide-btn-refresh iconfont" @tap="refreshVerify"></view>
- </view>
- </view>
- </view>
- </uni-popup>
- </template>
- <script>
- export default {
- data() {
- return {
- pintuImgs: [
- require('@/static/images/login/img_01.jpg'),
- require('@/static/images/login/img_02.jpg'),
- require('@/static/images/login/img_03.jpg'),
- ],
- pintuIndex: 0,
- x: 0, //初始距离
- oldx: 0, //移动的距离
- img: 'logo', //显示哪张图片
- left: 0, //随机拼图的最终X轴距离
- top: 0, //拼图的top距离
- moveTime: 0,
- moveInterval: null,
- moveSuccess: false,
- sliderErrText: '',
- };
- },
- mounted() {
- // this.open();
- },
- methods: {
- open() {
- this.refreshVerify();
- this.$nextTick(() => {
- this.$refs.popupRef.open();
- })
- },
- setPintuIndex() {
- const n = Math.random() * 10;
- if (n < 3) {
- this.pintuIndex = 0
- } else if (n >= 3 && n <= 6) {
- this.pintuIndex = 1
- } else {
- this.pintuIndex = 2
- };
- },
- //刷新验证
- refreshVerify() {
- this.setPintuIndex()
- this.moveSuccess = false;
- this.sliderErrText = '';
- this.clearMoveTime()
- var gl = Math.random().toFixed(2);
- const leftNum = uni.upx2px(560) * gl > uni.upx2px(280) ? uni.upx2px(280) : uni.upx2px(560) * gl + uni
- .upx2px(
- 150); //生成随机X轴最终距离
- this.top = uni.upx2px(190) * gl; //生成随机Y轴初始距离
- const maxLeft = uni.upx2px(560) - uni.upx2px(90) - uni.upx2px(70)
- this.left = leftNum > maxLeft ? maxLeft : leftNum
- if (gl <= 0.2) {
- this.img = 1;
- }
- if (gl > 0.2 && gl <= 0.4) {
- this.img = 2;
- }
- if (gl > 0.4 && gl <= 0.6) {
- this.img = 3;
- }
- if (gl > 0.6 && gl <= 0.8) {
- this.img = 4;
- }
- if (gl > 0.8 && gl <= 1) {
- this.img = 5;
- }
- this.resetMove(); //重置阴影位置
- },
- /* 滑动中 */
- startMove(e) {
- if (e.detail.source) {
- this.setMoveTime();
- const maxNum = uni.upx2px(560) - uni.upx2px(70)
- if (e.detail.x <= maxNum) {
- this.oldx = e.detail.x;
- }
- };
- },
- setMoveTime(clear = false) {
- if (!this.moveInterval) {
- this.moveTime = 0;
- this.moveInterval = setInterval(() => {
- this.moveTime = Math.floor((this.moveTime + 0.1) * 100) / 100;
- // console.log('this.moveTime = ', this.moveTime)
- }, 100)
- }
- if (clear) {
- try {
- setTimeout(() => {
- clearInterval(this.moveInterval)
- this.moveInterval = null;
- }, 100)
- // console.log('this.moveInterval 1= ', this.moveInterval)
- // console.log('this.moveInterval 2= ', this.moveInterval)
- } catch {}
- }
- },
- clearMoveTime() {
- this.setMoveTime(true);
- },
- change(e) {
- this.$emit('change', e.show)
- console.log('change = ', e.show)
- },
- /* 滑动结束 */
- endTouchMove() {
- var that = this;
- this.clearMoveTime()
- if (Math.abs(that.oldx - that.left) <= 5) {
- // uni.showToast({
- // title: '验证成功',
- // duration: 2500,
- // success() {
- // that.$emit('touchSliderResult', true);
- // }
- // });
- this.moveSuccess = true;
- setTimeout(() => {
- this.$refs.popupRef.close();
- this.$emit('slideImgSuccess')
- }, 1000)
- } else {
- this.sliderErrText = '请控制拼图对齐切口'
- setTimeout(() => {
- this.sliderErrText = ''
- that.refreshVerify();
- }, 1000)
- }
- },
- /* 重置阴影位置 */
- resetMove() {
- this.x = 1;
- this.oldx = 1;
- setTimeout(() => {
- this.x = 0;
- this.oldx = 0;
- }, 300);
- },
- // 关闭
- closeSlider() {
- this.$emit('touchSliderResult', false);
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- $imgSize: 80rpx;
- $pintuH: 360rpx;
- .verifyBox {
- // position: absolute;
- // top: 50%;
- // left: 50%;
- // transform: translate(-50%, -50%);
- // width: 560rpx;
- background-color: #fff;
- border-radius: 4rpx;
- padding: 8px;
- // box-shadow: 0 0 5upx rgba(0, 0, 0);
- .verify-title {
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: space-between;
- font-size: 20rpx;
- color: #ccc;
- .verify-close {
- font-size: 40rpx;
- color: #666;
- }
- }
- .verify-hint {
- font-size: 28rpx;
- }
- .slide-content {
- width: 100%;
- padding: 5px 0;
- margin: 0 auto;
- .slide-tips {
- font-size: 28rpx;
- color: rgba(2, 20, 33, 0.45);
- padding: 0.5em 0;
- }
- .slider-pintu {
- position: relative;
- width: 100%;
- border-radius: 10rpx;
- overflow: hidden;
- .pintu {
- width: 560rpx;
- height: $pintuH;
- display: block;
- margin: 0 auto;
- }
- .pintukuai {
- position: absolute;
- top: 0;
- left: 0;
- width: $imgSize;
- height: $imgSize;
- z-index: 100;
- box-shadow: 0 0 5upx rgba(0, 0, 0, 0.3);
- overflow: hidden;
- image {
- display: block;
- position: absolute;
- top: 0;
- left: 0;
- width: 560rpx;
- height: $pintuH;
- }
- }
- }
- .yinying {
- position: absolute;
- width: $imgSize;
- height: $imgSize;
- background-color: rgba(0, 0, 0, 0.5);
- }
- // <view class="slider-success">
- // <text class="slider-success-icon"></text>
- // <text class="slider-success-text">只用了2S,</text>
- // </view>
- .slider-success {
- width: 100%;
- height: 100%;
- position: absolute;
- z-index: 101;
- left: 0;
- top: 0;
- background-color: rgba(255, 255, 255, 0.8);
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- .slider-success-icon {
- font-size: 80rpx;
- color: $Theme-Color;
- }
- .slider-success-text {
- padding-top: 20rpx;
- font-size: 26rpx;
- color: $Theme-Color;
- }
- }
- }
- }
- .slider-movearea {
- position: relative;
- height: 50rpx;
- width: 100%;
- margin: 18rpx auto;
- movable-area {
- height: 50rpx;
- width: calc(100% - 90rpx);
- movable-view {
- width: 90rpx;
- height: 50rpx;
- border-radius: 25rpx;
- background-color: #007cff;
- position: relative;
- z-index: 100;
- box-shadow: 0px 0px 10px -1px #007cff;
- display: flex;
- justify-content: center;
- align-items: center;
- .movable-item {
- width: 3rpx;
- height: 20rpx;
- background-color: #fff;
- margin-right: 4px;
- &:last-child {
- margin-right: 0;
- }
- }
- }
- }
- }
- .huadao {
- width: 100%;
- height: 22rpx;
- background: #c2c2c2;
- box-shadow: inset 0 0 5upx #ccc;
- border-radius: 40rpx;
- position: absolute;
- top: 50%;
- left: 0;
- transform: translateY(-50%);
- font-size: 28rpx;
- z-index: 99;
- }
- .slider-btn-group {
- width: 100%;
- display: flex;
- justify-content: space-between;
- align-items: center;
- .slider-err {
- font-size: 24rpx;
- color: red;
- }
- .slide-btn-refresh {
- font-size: 40rpx;
- color: #c1c1c1;
- }
- }
- </style>
|