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

@xfl/hx_uniapp_img-downloader

v1.1.0

Published

使用环境为uniapp, 将网络或项目中的图片下载到本地 兼容 h5 小程序 app

Downloads

3

Readme

hx_uniapp_img-downloader

这是 HBuilerX 的插件, 使用环境为 uni-app
将网络或项目中的图片下载到本地 兼容 h5 小程序 app

背景

前段时间在做的一个项目,看视频学习,学习完成后会生成图片证书,然后点击可以下载保存到本地。
感觉这个功能也挺常用的,这两天专门详细测试了其中用到的两个方法:
uni.downloadFileuni.saveImageToPhotosAlbum,然后封装的这个插件。
希望对大家有用。

获取

github仓库: https://github.com/xiafl/hx_uniapp_img-downloader

npm安装: npm install @xfl/hx_uniapp_img-downloader

使用方法

import downloader from 'img-downloader';     //导入

let promise = downloader.load(url, imgName); //下载

promise.then(([err, res])=>{                 //下载结果 
    console.log(err, res);                   // err 和 res 只会有一个存在,另一个为null  
});

效果

示例页面

注意事项

  1. 没有下载进度。
  2. web端会有跨域问题。
  3. 支持 http 或 https 开头的绝对路径, 也支持 /static/aa.pngstatic/aa.png 这种项目中的相对路径。
  4. 不支持支付宝小程序。
  5. 只在 google浏览器 、 微信小程序开发者工具 、手机微信小程序 中测试过。只测试过下载图片,应该不支持下载其它文件。
  6. load 函数返回的是一个 promise 对象,并且一般只会回调 then , 不会回调 catch, 除非你自己在 then中写的代码报错了。
  7. 注意,在微信小程序中,第一次调用相册会弹出授权弹框,如果用户本次拒绝授权,则本次下载失败,并且下次再调用时,不会再弹授权框,而是直接下载失败。
  8. 只有在 web 端,才能重命名下载的图片的名字。
  9. 在 web 端,回调 then 时,其实只是 说明开始下载了,至于是否会下载成功,则是未知的。

权限

本插件需要申请的手机端权限列表:

  1. 系统相册权限: scope.writePhotosAlbum

问题反馈

如在使用中发现bug或有优化的建议和意见,请发邮件 [email protected] 或在 gitHub 上反馈。

更新日志

2019.6.1 v1.1.0 重构了代码、创建了 示例页面 、添加 jsDoc 注释

2019.5.10 v1.0.0 创建本插件