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

@tjdata/s-scan

v1.0.2

Published

该插件主要是用纯H5实现扫一扫功能的,主要适用于一些无法调用原生扫一扫功能的情况 ### 实现原理

Downloads

3

Readme

H5扫一扫

该插件主要是用纯H5实现扫一扫功能的,主要适用于一些无法调用原生扫一扫功能的情况

实现原理

二维码识别功能使用的是jsQR这个库,调用摄像头使用的 navigator.mediaDevices.getUserMedia 这个H5的api。通过canvas画布把摄像头获取到的数据展现到页面上,同时循环监听jsQR解析。

使用环境

经测试发现大部分浏览器都可以正常使用(微信,QQ,谷歌,火狐,safari),少数的安卓自带浏览器无法使用(浏览器内核版本过低)。需要https环境才能使用,本地测试可以在 manifest.json 中点击源码展示,找到h5 ,添加:"devServer" : { "https" : true}

需要https环境才能使用!!!

小知识点:苹果设备上不论什么浏览器都是safari套壳的,不论是谷歌还是火狐都是safari套壳。这也就是代表在苹果上无需担心无法使用此插件。(造成这样的现象是因为苹果有一则协议,浏览器只能使用safari内核)

在安卓系统上可以打开闪光灯

# 安装 jsQR
npm install jsqr --save
# 修改组件源码对 jsQR 依赖
import jsQR from "jsqr"

插件使用

插件已支持 uni_modules 支持组件easycom,以下代码演示的是普通使用

<!-- HTML -->
	<s-get-qrcode @success='qrcodeSucess' @error="qrcodeError" ></s-get-qrcode>
// js  项目中本组件的文件路径
import sGetQrcode from '@/uni_modules/s-getQrcode/s-getQrcode.vue'

// 嫌路径长的话可以单独复制出来
export default {
		components: {
			sGetQrcode
		},
		methods: {
			qrcodeSucess(data) {
				uni.showModal({
					title: '成功',
					content: data,
					success: () => {
						uni.navigateBack({})
					}
				})
			},
      qrcodeError(err) {
        uni.showModal({
          title: '摄像头授权失败',
          content: '摄像头授权失败,请检测当前浏览器是否有摄像头权限。',
          success: () => {
            uni.navigateBack({})
          }
        })
      }
		}
	}

相关API

可传属性(Props)

| 参数 | 说明 | 类型 | 默认值 | | ---------- | ------------------------------------------------- | ------- | ----------- | | continue | 是否连续获取。false 监听一次 true 持续监听 | Boolean | false | | exact | 选调用摄像头。environment 后摄像头 user 前摄像头 | String | environment | | size | 扫码屏幕大小。whole 全屏 balf 半屏 | String | whole | | definition | 调用摄像头清晰度。fasle 正常 true 高清 | Boolean | false |

事件(Events)

| 事件名 | 说明 | 回调参数 | | ------- | ------------------------------------------ | ------------------ | | success | 检测到图中有二维码并读取到数据是回调 | 二维码数据 | | error | 组件内部发送错误,通常是摄像头没有调用成功 | 错误信息,详情见下 |

常见的错误信息:

  • AbortError[中止错误]

    尽管用户和操作系统都授予了访问设备硬件的权利,而且未出现可能抛出NotReadableError异常的硬件问题,但仍然有一些问题的出现导致了设备无法被使用。

  • NotAllowedError[拒绝错误]

    用户拒绝了当前的浏览器实例的访问请求;或者用户拒绝了当前会话的访问;或者用户在全局范围内拒绝了所有媒体访问请求。

  • NotFoundError[找不到错误]

    找不到满足请求参数的媒体类型。

  • NotReadableError[无法读取错误]

    尽管用户已经授权使用相应的设备,操作系统上某个硬件、浏览器或者网页层面发生的错误导致设备无法被访问。

  • OverconstrainedError[无法满足要求错误]

    指定的要求无法被设备满足,此异常是一个类型为OverconstrainedError的对象,拥有一个constraint属性,这个属性包含了当前无法被满足的constraint对象,还拥有一个message属性,包含了阅读友好的字符串用来说明情况。

  • SecurityError[安全错误]

    getUserMedia() 被调用的 Document 上面,使用设备媒体被禁止。这个机制是否开启或者关闭取决于单个用户的偏好设置。

  • TypeError[类型错误]

    constraints 对象未设置[空],或者都被设置为false

插槽 (slot)

| 插槽名称 | 说明 | 默认值 | | -------- | -------------------------------- | ------------------ | | error | 当发送错误时,在页面上显示的内容 | 相机权限被拒绝提示 |