npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

b-captcha-vue

v0.2.4

Published

一个基于 Vue 3 的行为验证码组件库,支持多种验证方式,轻量、易用、可定制。

Readme

b-captcha-vue

一个基于 Vue 3 的行为验证码组件库,支持多种验证方式,轻量、易用、可定制。

demo

特性

  • 🎯 三种验证码类型:点选、旋转、拼图
  • 🎨 支持主题定制(CSS 变量)
  • 📱 支持移动端触摸事件
  • 🔧 灵活的配置项和事件回调
  • 💡 基于 Vue 3 Composition API

安装

npm install b-captcha-vue
# 或
pnpm add b-captcha-vue

快速开始

<script setup>
import { ClickCaptcha, RotateCaptcha, SlideCaptcha } from 'b-captcha-vue'
import 'b-captcha-vue/style'
</script>

组件

1. ClickCaptcha 点选验证码

用户按顺序点击图片中指定的文字或图标。

<template>
  <ClickCaptcha
    :data="data"
    :events="events"
    :config="config"
    ref="captchaRef"
  />
</template>

<script setup>
import { reactive, ref } from 'vue'

const captchaRef = ref(null)

const data = reactive({
  image: 'base64或图片URL', // 主图
  thumb: 'base64或图片URL', // 提示缩略图
})

const config = {
  width: 400, // 图片宽度
  height: 340, // 图片高度
  thumbWidth: 150, // 缩略图宽度
  thumbHeight: 60, // 缩略图高度
  title: '请在下图依次点击',
  buttonText: '验证',
  iconSize: 22,
  dotSize: 24, // 点击标记大小
}

const events = {
  click: (x, y) => {
    console.log('点击坐标:', x, y)
  },
  confirm: (dots, reset) => {
    // dots: [{ key, index, x, y }, ...]
    console.log('提交验证:', dots)
    // 验证失败时调用 reset() 重置
  },
  refresh: () => {
    console.log('刷新验证码')
    // 重新获取验证码数据
  },
}
</script>

2. RotateCaptcha 旋转验证码

用户拖动滑块旋转图片至正确角度。

<template>
  <RotateCaptcha
    :data="data"
    :events="events"
    :config="config"
    ref="captchaRef"
  />
</template>

<script setup>
import { reactive, ref } from 'vue'

const captchaRef = ref(null)

const data = reactive({
  image: 'base64或图片URL', // 背景图
  thumb: 'base64或图片URL', // 需要旋转的图片
  thumbSize: 100, // 旋转图片尺寸
})

const config = {
  width: 400,
  height: 340,
  size: 220, // 圆形区域尺寸
  title: '请拖动滑块完成拼图',
  iconSize: 22,
}

const events = {
  rotate: (angle) => {
    console.log('当前角度:', angle)
  },
  confirm: (angle, reset) => {
    console.log('提交角度:', angle)
    // 验证失败时调用 reset() 重置
  },
  refresh: () => {
    console.log('刷新验证码')
  },
}
</script>

3. SlideCaptcha 拖拽拼图验证码

用户直接拖拽拼图块到正确位置(支持任意方向拖动)。

<template>
  <SlideCaptcha
    :data="data"
    :events="events"
    :config="config"
    ref="captchaRef"
  />
</template>

<script setup>
import { reactive, ref } from 'vue'

const captchaRef = ref(null)

const data = reactive({
  image: 'base64或图片URL',
  thumb: 'base64或图片URL',
  thumbX: 10,
  thumbY: 80,
  thumbWidth: 50,
  thumbHeight: 50,
})

const config = {
  width: 400,
  height: 340,
  title: '请拖拽贴图完成拼图',
  iconSize: 22,
  scope: true,
}

const events = {
  move: (x, y) => {
    console.log('拖拽位置:', x, y)
  },
  confirm: (point, reset) => {
    console.log('提交位置:', point)
  },
  refresh: () => {
    console.log('刷新验证码')
  },
}
</script>

主题定制

通过 CSS 变量自定义样式:

:root {
  --b-captcha-theme-text-color: #333333;
  --b-captcha-theme-bg-color: #ffffff;
  --b-captcha-theme-active-color: #3e7cff;
  --b-captcha-theme-icon-color: #3c3c3c;
  --b-captcha-theme-drag-bar-color: #e0e0e0;
  --b-captcha-theme-drag-bg-color: #3e7cff;
  --b-captcha-theme-drag-icon-color: #ffffff;
  --b-captcha-theme-loading-icon-color: #3e7cff;
  --b-captcha-theme-body-bg-color: #34383e;
  --b-captcha-theme-dot-color-color: #cedffe;
  --b-captcha-theme-dot-bg-color: #4e87ff;
  --b-captcha-theme-round-color: #e0e0e0;
}

组件方法

所有组件都暴露了 refresh 方法,可通过 ref 调用:

captchaRef.value.refresh()

开发

# 安装依赖
pnpm install

# 启动开发服务器
pnpm dev

# 构建
pnpm build

发布

npm run build
# 更新 package.json 中的版本号
npm adduser --registry=https://registry.npmjs.org
npm publish --registry=https://registry.npmjs.org

致谢

本项目的开发灵感来自于 go-captcha-vue,感谢原作者的开源贡献。

License

MIT