市面上开发小程序的工具有很多,如果你只是个人开发者,或者是小公司,前端技术没有那么精通的。还是用uniapp吧。确实比较简单,会一点vue就行了。就当开发一个网页就行了。非网页的地方用 #ifndef H5 之类的判断一下处理就OK,然后还能编译成APP。试了一下。在现代的机器下面,性能也确实可以
当然你要说什么ApiCloud/taro/mpvue等都支持,我也没话说。但从便捷性上来说。确实是uniapp更方便一点。而且可找的资料,别人写的代码、插件也确实更多。硬要说不爽的,那就是。。。。公司自己的编辑器HBuilderX实在太烂。连代码跳传都做不到(也可能是我姿势不对。)
这里贴一段别人的长按保存到相册,长按事件是小程序自带的longpress。所以uniapp里的事件就是:
/**
* @description 保存图片,保存到系统相册
* @param {String} imgSrc 图片路径
* @param {String} content 授权提示语句
* @param {String} failTip 无图片保存时失败提示
* @param {String} successTip 保存成功提示
*/
saveImage(imgSrc, content="是否允许获取保存相册权限", failTip='暂无图片', successTip="已保存到本地相册,请打开相册扫描") {
uni.saveImageToPhotosAlbum({
filePath: imgSrc,
// 保存成功,直接给出提示
success: (res) => {
uni.showModal({
title: '提示',
content: successTip,
showCancel: false,
confirmText: "好的"
})
},
// 保存失败,判断是否授权,未授权则调用授权,否则弹出失败信息
fail(err) {
console.error(err);
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg ===
"saveImageToPhotosAlbum:fail authorize no response" || err.errMsg === "saveImageToPhotosAlbum:fail auth denied") { // 没有授权,重新授权,兼容iso和Android
uni.showModal({
title: '授权提示',
content: content,
success: (res) => {
if (res.confirm) { // 点击确定,则调用相册授权
uni.openSetting({
success(settingdata) {
if (settingdata.authSetting["scope.writePhotosAlbum"]) {
console.log("获取权限成功,再次点击图片保存到相册")
uni.showToast({
title: '授权成功,请重试哦~'
});
} else {
console.log("获取权限失败")
uni.showToast({
title: '请确定已打开保存权限',
icon: "none"
});
}
}
})
}
}
})
} else if (err.errMsg === "saveImageToPhotosAlbum:fail file not found" || err.errMsg ===
"saveImageToPhotosAlbum:fail file not exists" || err.errMsg ===
"saveImageToPhotosAlbum:fail get file data fail"
) { // 无图片,则提示
uni.showToast({
title: failTip,
icon: "none"
});
}
}
})
},
原文地址在这里:https://blog.csdn.net/liuxin00020/article/details/104843960,如果保存还是失败,那就先用uni.getImageInfo(),会自动调用图片下载的(特别是微信小程序,还要设置downloadFilePath,否则也不能下载图片,这其实就是很多生成canvas失败的原因之一)

评论 (0)
暂无评论