Skip to content

SlideVerify 滑动验证

滑动验证组件,用于人机验证场景。

组件类型

基本用法

html
<wd-slide-verify @success="handleSuccess" @fail="handleFail" />
ts
const toast = useToast()

function handleSuccess() {
  toast.success('验证成功')
}

function handleFail() {
  toast.error('验证失败,请重试')
}

组件状态

禁用状态

设置 disabled 后禁用滑动验证。

html
<wd-slide-verify disabled />

组件样式

自定义文案

通过 textsuccess-text 属性自定义提示文字。

html
<wd-slide-verify text="请拖动滑块" success-text="验证成功" />

自定义颜色

通过 background-coloractive-background-color 属性自定义颜色。

html
<wd-slide-verify background-color="#E8F4FF" active-background-color="#4D94FF" />

自定义图标

通过 iconsuccess-icon 属性自定义图标。

html
<wd-slide-verify icon="arrow-right" success-icon="thumb-up-fill" />

特殊样式

自定义容错范围

通过 tolerance 属性设置容错范围(单位:px),默认为 10px。

html
<wd-slide-verify :tolerance="20" />

重置方法

通过 ref 获取组件实例,调用 reset 方法重置验证状态。

html
<wd-slide-verify ref="slideVerifyRef" @success="handleSuccess" @fail="handleFail" />
<wd-button type="primary" @click="handleReset">重置</wd-button>
ts
import { ref } from 'vue'
import type { SlideVerifyInstance } from '@/uni_modules/wot-ui/components/wd-slide-verify/types'

const slideVerifyRef = ref<SlideVerifyInstance>()

function handleReset() {
  slideVerifyRef.value?.reset()
}

插槽用法

支持通过插槽自定义内容。

html
<wd-slide-verify>
  <template #text>
    <text>向右滑动完成验证</text>
  </template>
  <template #success-text>
    <text>验证通过</text>
  </template>
  <template #icon>
    <view>ICON</view>
  </template>
  <template #success-icon>
    <view style="color: red">OK</view>
  </template>
</wd-slide-verify>

Attributes

参数说明类型默认值
tolerance容错范围,单位为 pxnumber10
text提示文字,为空时显示内置文案string''
success-text验证成功提示文字,为空时显示内置文案string''
disabled是否禁用booleanfalse
background-color背景颜色string-
active-background-color激活时的背景颜色string-
icon滑块图标名称stringdouble-right
success-icon成功图标名称stringcheck-circle-fill
icon-size图标大小string / number-
success-icon-size成功图标大小string / number-

Events

事件名称说明参数
success验证成功时触发-
fail验证失败时触发-

Methods

方法名说明参数
init初始化尺寸信息-
reset重置验证组件到初始状态-

Slots

name说明
text自定义提示文字内容
success-text自定义验证成功提示文字内容
icon自定义滑块图标
success-icon自定义成功图标

外部样式类

类名说明
custom-class根节点样式类
custom-style根节点样式

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-slide-verify-height$n-40组件高度
--wot-slide-verify-width100%组件宽度
--wot-slide-verify-bg$filled-bottom组件背景色
--wot-slide-verify-radius$radius-large圆角
--wot-slide-verify-track-bg$success-main成功态track背景色
--wot-slide-verify-disabled-opacity$opacity-disabled禁用态透明度
--wot-slide-verify-text-color$text-main提示文字颜色
--wot-slide-verify-text-font-size$typography-label-size-main提示文字字号
--wot-slide-verify-text-line-height$typography-label-line--height-size-main提示文字行高
--wot-slide-verify-success-text-color$text-white成功态文字颜色
--wot-slide-verify-button-bg$filled-oppo滑块背景色
--wot-slide-verify-button-shadow$n-0 $n-2 $n-8 $opac-4_15滑块阴影色
--wot-slide-verify-button-color$icon-secondary滑块图标颜色
--wot-slide-verify-button-success-color$success-main滑块图标成功态颜色
--wot-slide-verify-button-size$slide-verify-height滑块尺寸
--wot-slide-verify-button-border-color$border-light滑块边框颜色
--wot-slide-verify-success-icon-size$n-20滑块图标尺寸

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.