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 🙏

© 2024 – Pkg Stats / Ryan Hefner

chenms-routate-captcha

v0.1.2

Published

旋转图片角度验证码

Downloads

50

Readme

使用

安装

npm i chenms-routate-captcha

页面中使用

<template>
  <cms-routate-captcha
    :options="captchaOptions"
    :size="size"
    @close="close"
    @complete="captchaComplete"
    @success="captchaSuccess"
    @fail="captchaFail"
  />
</template>

<script setup>
import cmsRoutateCaptcha from 'chenms-routate-captcha/index.vue'

// 图形验证码相关的 start
const captchaOptions = ref({
  theme: '#07f',
  desc: '滑动将图片转正',
  successClose: 1500, // 验证成功后页面关闭时间
  timerProgressBar: true, // 验证成功后关闭时是否显示进度条
  timerProgressBarColor: 'rgba(0, 0, 0, 0.2)', // 验证成功后关闭时是否显示进度条的背景颜色设置
  successCode: 1, // 接口请求成功的成功码
  isShowCloseIcon: false, // 是否显示关闭按钮
  request: {
    // 获取验证码信息
    info: (callback) => {
      getJSON(
        'axios的baseURL' + '获取选择图片信息接口(你们后端提供)'
        null,
        function (res, xhr) {
          if (xhr.status != 200) {
            $message.warn('系统出错:' + res.statusCode + ',请关闭重试!')
            return false
          }
          // 第二个参数传递从header中获取的token, 如果嫌麻烦, 可以在res内返回token
          callback(res.code, res.data.token, res.data.str)
        }
      )
    },
    // 验证, angle用户旋转角度
    check: (angle, token, callback) => {
      // 将token设置好, 数据验证时传递给后端
      // 当然这里的数据请求只作为参考, 实际使用中以你的数据请求组件方式为准
      getJSON(
        'axios的baseURL' + '验证旋转图片接口(你们后端提供)',
        { angle: angle, token },
        function (res, xhr) {
          if (xhr.status != 200) {
            $message.warn('系统出错:' + res.statusCode + ',请关闭重试!')
            return false
          }
          callback(res.code)
        }
      )
    },
    // 交换图片
    img: (id) => {
      return 'axios的baseURL' + '获取图片(你们后端提供)' + '?id=' + id
    }
  }
})

const size = ref({
  // 动态旋转图片验证的布局宽度
  width: 250,
  // 里面图片的宽度
  img: 200,
  // 滑动条布局的宽度
  control: 220,
  // 图片上下的margin值
  imgMargin: 20
})

// ajax请求, 这里只做演示, 请使用自己项目中的
const getJSON = (url, data, callback) => {
  let params = ''
  if (data && typeof data == 'object') {
    params = Object.keys(data)
      .map(function (key) {
        return encodeURIComponent(key) + '=' + encodeURIComponent(data[key])
      })
      .join('&')

    url = url + ((url.indexOf('?') == -1 ? '?' : '&') + params)
  }

  let xhr,
    formData = null
  xhr = new XMLHttpRequest()
  xhr.withCredentials = false

  xhr.open('GET', url)
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
  xhr.onload = function () {
    if (xhr.status != 200) {
      return
    }

    try {
      let res = JSON.parse(xhr.responseText) || null
      if (!res) {
        return
      }
      callback(res, xhr)
    } catch (e) {
      return
    }
  }

  xhr.send(formData)
}

// 验证失败的回调
const captchaFail = () => {
  
}
// 验证成功的回调
const captchaSuccess = (data) => {
 
}

// 验证完成的回调
const captchaComplete = (status) => {
 
}
// 弹窗关闭的回调
const close = () => {
 
}
// 图形验证码相关的 end
</script>

详细使用文档

https://juejin.cn/post/7367997561511149604