字节跳动小程序版易盾验证码
npm install @yidun/tt-ne-captcha
npm install @yidun/tt-ne-captcha
`使用
1. 引用声明组件,在页面或组件的json文件中声明
`
{
"usingComponents": {
"ne-captcha": "path-to-component/ne-captcha/index"
}
}
`2. 使用组件
`
id="neCaptcha"
captcha-id="yourCaptchaID"
width="640rpx"
bindverify="handleVerify">
`
`js
Page({
handleVerify (ev) {
if (ev.detail[0]) {
// 验证失败
return
}
// TODO: 验证成功
console.log(ev.detail[1])
},
openCaptcha () {
this.selectComponent('#neCaptcha', res => {
res && res.popup()
// 智能无感知请调用 res.verify()
})
}
})
``| 可配项 | 类型 | 默认值 | 描述 |
|--------|-------|----------|-------|
| captchaId | String | 无 | 验证码ID |
| lang | String | 'zh-CN' | 语言 |
| width | String | 'auto' | 验证码弹框宽度,接受单位'rpx'/'px'/'rem'/'%' |
| captchaType | String | 无 | 配置验证码类型 |
| customStyles | Object | null | 自定义验证码样式,包含imagePanel/controlBar/gap/popTitle/popPadding,详情查看下面 |
注意:小程序的超时设置可在app.json全局配置
| 事件名 | 参数 | 描述 |
|-------|------|------|
| error | 无 | 验证码配置失败 |
| init | 无 | 验证码配置成功(初始化)|
| ready | 无 | 验证码准备就绪 |
| verify | err,validate | 验证码验证完成 |
| close | 无 | 验证码弹框准备关闭 |