feat: 首次提交

This commit is contained in:
peerless_hero
2023-08-17 21:28:49 +08:00
parent 36f80fb971
commit ec1e5e16cd
571 changed files with 95322 additions and 0 deletions

View File

@ -0,0 +1,123 @@
<!--本文件由FirstUI授权予新疆天衡创新研究院有限公司手机号18 61 40 725 4 9身份证尾号5A07X5专用请尊重知识产权勿私下传播违者追究法律责任-->
<template>
<view class="fui-wrap">
<view class="fui-page__hd">
<view class="fui-page__title fui-align__center" @tap="vip">PuzzleVerify <image
src="/static/images/index/light/icon_member_3x.png"></image>
</view>
<view class="fui-page__desc">PuzzleVerify 滑块拼图验证根据提示进行行为验证此组件为 SliderCaptcha 组件的功能补充详见文档</view>
</view>
<view class="fui-page__bd">
<view class="fui-btn__box">
<fui-button type="gray" btn-size="medium" text="点击按钮进行验证" bold :margin="['48rpx']"
@click="btnVerify">
</fui-button>
</view>
<fui-puzzle-verify :width="width" :height="height" :src="src" :cutSrc="cutSrc" :x="40" :y="49" @init="init"
@verify="verify" ref="pvRef">
</fui-puzzle-verify>
</view>
</view>
</template>
<script>
export default {
data() {
return {
resUrl: this.fui.resUrl(),
src: '',
cutSrc: '',
width: 300,
height: 150,
x: 0,
y: 0
}
},
methods: {
//rpx转化为px
getPx(value) {
let val = parseInt(uni.upx2px(Number(value)))
return val % 2 === 0 ? val : val + 1
},
//初始化事件中请求接口获取 有黑块的背景图、裁剪图、位置等信息
//画布大小可使用rpx转化为px传回给后端使用动态生成背景图这样可做到自适应适配所有终端
//示例使用的是已生成好的图,所以使用的是固定宽高
init(e) {
//裁剪图片宽度固定为44px
let cutGraphWidth = e.cutGraphWidth
this.width = 300 //this.getPx(640)
this.height = 150 //this.getPx(320)
//以上参数传给后端获取验证信息
//示例仅为演示,使用预处理内容
this.getVerifyImage()
},
//注意为了避免图片显示失真后端处理图片大小需按照提供的参数等比放大倍数可根据设备pixelRatio设备像素比等比放大
getVerifyImage() {
//以下由后端获取返回x1裁剪位置由后端存储不返回
//带黑块的背景图,后端接口提供
this.src = `${this.resUrl}/component/sc/bg_img_verify.png`
//裁剪下的图片,后端接口提供
this.cutSrc = `${this.resUrl}/component/sc/cut_img.png`
//裁剪图在背景图内的left值 ,后端接口提供
this.x = 40;
//裁剪图在背景图内的top值 ,后端接口提供
this.y = 49
},
btnVerify() {
//需要等组件初始化完成
this.$refs.pvRef && this.$refs.pvRef.show()
},
//开始验证,将返回的滑动距离传给后端进行验证
verify(e) {
//示例仅为演示,以下为模拟后端验证
//滑动距离
let slipDistance = e.slipDistance
//验证方法参考js方法自行转为后端方法
//x1为裁剪黑块的left值该值仅后端知道示例使用的预处理数据此处仅为演示
let x1 = 222;
//width为需要滑动的总距离
let width = x1 - this.x
//误差范围后端自行定义px
let range = 3
//滑动距离 减去 总距离 的绝对值 小于等于误差范围即为验证通过
if (Math.abs(slipDistance - width) <= range) {
this.success()
} else {
this.fui.toast('验证失败!')
//重置验证nvue下需延时重置
setTimeout(() => {
this.$refs.pvRef.reset()
}, 50)
//当失败多次时,可重新生成验证数据返回
//...
}
},
success() {
this.fui.toast('验证通过!')
setTimeout(() => {
//关闭验证框
this.$refs.pvRef.closeVerify()
}, 200)
},
vip() {
this.fui.href("/pages/my/qa/qa?index=2&title=VIP专属内容")
}
}
}
</script>
<style>
.fui-section__title {
margin-left: 32rpx;
}
.fui-btn__box {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style>