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-choose-media

v1.0.0

Published

微信小程序拍摄或从手机相册中选择图片或视频二次封装

Downloads

1

Readme

@lx-frontend/wx-choose-media

🍣 微信小程序媒体选择 api 封装

说明

该工具方法整合了小程序的三个媒体选择api,包括 wx.chooseImagewx.chooseVideowx.chooseMedia

该工具方法对 权限 和 取消操作 两种异常情况做了特殊处理

  • 因小程序接口本身使用需系统授权微信使用摄像头和相册才能正常使用,封装后的方法调用在由于权限问题导致调用异常时,会提示引导用户打开,并正常返回 false,不触发异常
  • 因取消操作触发异常时,正常返回false,不触发异常
  • 其他异常信息原样抛出

使用

import wxChooseMedia, { ImageResult } from '@lx-frontend/wx-choose-media';

let res: ImageResult;

try {
  res = await wxChooseMedia('image', {
    count: 1,
    sizeType: ['compressed'],
    sourceType: ['camera'],
  });
} catch (e) {
  // 无权限和取消操作之外的情况导致的中断异常
  return;
} finally {
  // 对应原生api中complete回调
}
if (!res) return; // 取消操作 或 因没授权微信使用摄像头和相册中断操作

// 接口调用成功
const { tempFilePaths, tempFiles } = res;

参数说明

async function wxChooseMedia<T extends ImageConfig | VideoConfig | MediaConfig>(type: mediaType, config: T, toastErr = true): Promise<ImageResult | VideoResult | MediaResult>;

type

指定对应调用的小程序原生接口

Type: 'image' | 'video' | 'media' Require: true

image: chooseImage video: chooseVideo media: chooseMedia

config

对应小程序原生api中的配置,参考小程序文档 image video media

toastErr

是否toast提示无权限和取消操作之外的情况导致的中断异常信息

Type: boolean Default: true

返回结果说明

  • 正常调用成功选择图片或视频,返回结果与原生api一致,参考小程序文档 image video media
  • 取消操作 或 因没授权微信使用摄像头和相册中断操作,返回 false

接口本身相关兼容性和支持信息请参考微信小程序官方开发文档