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

@lx-frontend/wx-authorize

v0.4.3

Published

微信小程序用户授权

Downloads

35

Readme

@lx-frontend/wx-authorize

微信小程序发起用户授权过程封装

Description

微信小程序部分接口需要经过用户授权同意才能调用,该工具方法封装了 发起授权请求和引导用户打开授权 的统一流程,适合在调用需授权的接口前发起用户授权或引导用户打开相关授权。

该方法调用后会先校验对应授权所需的系统权限(包括系统开关和应用权限开关),如无对应系统权限会提示引导用户打开相关配置;系统权限校验通过后走小程序授权流程。

小程序授权流程如下:

首次触发弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,用户同意返回成功,拒绝返回失败。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。用户之前已经拒绝授权则返回失败并弹出提示引导用户打开授权。

Usage

import wxAuthorize from '@lx-frontend/wx-authorize';

const handleAuth = async () => {
  const wxAuthorizeRes = await wxAuthorize('scope.writePhotosAlbum', '没有保存图片到相册的权限,请重新授权');
  if (wxAuthorizeRes) {
    // 获取授权成功
  } else {
    // 获取授权失败
  }
};

参数说明

wxAuthorize(scope, guidanceContent)

  • scope (string):需要获取权限的 scope
  • guidanceContent (string):引导用户打开授权时的文案(可选),默认文案为 没有权限,请重新授权

返回结果说明

  • 授权成功返回 true
  • 授权失败返回 false