1.保存图片1.API:wx.getImageInfo():获取图片路径;wx.saveImageToPhotosAlbum()保存图片关键点:通过模态框去引导用户进行授权操作:wx.showModal(),wx.openSetting()
//保存图片saveImg(){letcurrentthis.data.imageurlletthatthisconsole.log("saveImgBtn",current)wx.showLoading({title:'保存中'})wx.getImageInfo({src:current,success:function(res){wx.saveImageToPhotosAlbum({filePath:res.path,success:function(res){wx.hideLoading();wx.showToast({title:'保存成功',icon:'success'},2000)},fail:function(res){wx.hideLoading()if(res.errMsg"saveImageToPhotosAlbum:fail:authdenied"||res.errMsg"saveImageToPhotosAlbum:failauthdeny"||res.errMsg"saveImageToPhotosAlbum:failauthorizenoresponse"){//这边微信做过调整,必须要在按钮中触发,因此需要在弹框回调中进行调用that.imageRrrorAuth()}else{wx.showToast({title:'保存失败',icon:'none'})}}})},fail:function(error){console.log("roo",error)}})},//授权失败提示授权操作imageRrrorAuth(){wx.showModal({title:'提示',content:'需要您授权保存相册',showCancel:false,success:modalSuccess{wx.openSetting({success(settingdata){console.log("settingdata",settingdata)if(settingdata.authSetting['scope.writePhotosAlbum']){wx.showModal({title:'提示',content:'获取权限成功,再次保存图片即可',showCancel:false,})}else{wx.showModal({title:'提示',content:'获取权限失败,将无法保存到相册',showCancel:false,})}},fail(failData){console.log("failData",failData)},complete(finishData){console.log("finishData",finishData)}})}})},2.上传图片2.先使用wx.chooseImage()选择图片,然后wx.uploadFile()将filePath图片的路径POST到服务器。tips:限制最多三张上传
viewclass'addImage'viewclass'commentImage'wx:for"{{imgList}}"wx:key"{{index}}"imagebindtap'previewImage'data-index"{{index}}"data-url'{{imageHost+item}}'src"{{imageHost+item}}"/imageimagedata-index"{{index}}"bindtap"deleteImage"class'close'style"width:50rpx;height:50rpx;"src'/images/closed.png'/image/viewimagewx:if"{{imgList.length3}}"src"/images/addImageIcon.png"bindtap"chooseimage"/image/viewchooseImage:function(e){letthatthis;letuserIdwx.getStorageSync("id");letimgListthat.data.imgListletimgCount3-imgList.length;//为了确定已经还能上传几张,设置最多三张上传wx.chooseImage({count:imgCount,//默认9,最多上传9sizeType:['original','compressed'],//可以指定是原图还是压缩图,默认二者都有sourceType:['album','camera'],//可以指定来源是相册还是相机,默认二者都有success:function(res){//返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片lettempFilePathsres.tempFilePaths//console.log("tempFilePaths",JSON.stringify(tempFilePaths))for(leti0;itempFilePaths.length;i++){lettempFilePathtempFilePaths[i]+''that.uploadImg(tempFilePath)}}})},uploadImg(tempFilePath){letimgListthis.data.imgListlettokenwx.getStorageSync("token");letthatthis;wx.uploadFile({url:API.api.userMemos,method:'POST',header:{"Content-Type":"application/json",'Authorization':token},filePath:tempFilePath,name:'file',//文件对应的参数名字(key)success:function(res){varfPath[];fPath.push(JSON.parse(res.data).filePath);console.log("图片上传完成:"+res.data);if(res.statusCode500){wx.showToast({title:'图片大小不超过5M',icon:'none'})}else{imgList.push(fPath[0])that.setData({imgList})console.log("imgList2",imgList)}}})},//预览图片previewImage(e){console.log("previewImage:::::"+e.currentTarget.dataset.url)leturle.currentTarget.dataset.url;letimgListthis.data.imgList;letimageHostthis.data.imageHost;leturls[];for(leti0;iimgList.length;i++){urls.push(imageHost+""+imgList[i])}console.log("urls:::::"+JSON.stringify(urls))wx.previewImage({current:url,//当前显示图片的http链接urls:urls//需要预览的图片http链接列表})},//删除图片deleteImage(e){console.log(JSON.stringify(e));letthatthis;letindexe.currentTarget.dataset.index;letimgListthat.data.imgList;imgListimgList.splice(index,1);that.setData({imgList:imgList})},3.用户授权获取用户信息buttonclass'btn'open-type"getUserInfo"bindgetuserinfo'authorize'/buttonauthorize(){if(e.detail.errMsg'getUserInfo:failauthdeny'){//弹提示框,重新授权wx.showModal({title:'授权失败',content:'请重新授权',showCancel:false,success:function(e){}})}else{//授权成功进行的操作console.log(JSON.parse(e.detail.rawData).avatarUrl);console.log(JSON.parse(e.detail.rawData).nickName);}}4.获取formId,用于发送模板消息formbindsubmit'getFormId'report-submit'true'buttonform-type'submit'确认/button/formgetFormId(e){letformIde.detail.formIdconsole.log("formId",formId)},5.小程序版本更新updataApp:function(){//版本更新if(wx.canIUse('getUpdateManager')){constupdateManagerwx.getUpdateManager()updateManager.onCheckForUpdate(function(res){if(res.hasUpdate){//请求完新版本信息的回调updateManager.onUpdateReady(function(){wx.showModal({title:'更新提示',content:'新版本已经准备好,是否重启应用?',success:function(res){if(res.confirm){//新的版本已经下载好,调用applyUpdate应用新版本并重启updateManager.applyUpdate()}}})})updateManager.onUpdateFailed(function(){wx.showModal({//新的版本下载失败title:'已经有新版本了哟~',content:'新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',})})}})}else{wx.showModal({//如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示title:'提示',content:'当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'})}},
微信小程序常用API-微信小程序入驻收费吗-小程序付费推广
浏览量:2176
时间:
来源:七块oooo
版权声明
即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。
最新资讯
-

即速应用,赋能企业玩转微信小程序智慧经营
作为国内领军的智慧商业经营服务商,即速应用始终秉承“让每个企业都拥有自己的智慧店铺”的愿景,持续赋能更多企业玩转智慧经营。即速应用旗下拥有“小程序搭建工具-即速应用”、“私域流量专家-即客云”等产品,帮助商家打通互联网全生态营销闭环。 -

即客云2.0重磅更新,让微信小程序运营更简单!
即客云作为一款基于企业微信的第三方工具,现从多维度提供超过30种功能,自上线以来,已服务多家企业,受到一致好评。近期,我们根据客户反馈和市场调研正式推出升级版 即客云2.0!更新了私域运营SOP,群日历功能,批量拓客,客户雷达,消息推送,个人欢迎语,帮助企业更好运用企业微信;同时提升了社群运营工作标准化,提升运营效率,帮助企业实现客户增长,玩转私域流量。 -

零代码 + AI 双轮驱动|即速应用解锁人工智能小程序开发新范式
无需代码、无需 AI 算法功底,普通人也能快速搭建智能小程序。即速应用将人工智能与零代码开发深度融合,推出 AI 智能生成能力,用户通过自然语言描述需求,AI 自动生成小程序页面、功能模块与后台配置,覆盖商城、预约、同城、社区团购等全场景。平台内置 AI 智能推荐、智能客服、用户画像分析等能力,一键对接微信生态,打通视频号、企业微信、短信跳转,帮企业快速落地 AI 应用,抢占智慧经营先机,让每家企业都拥有 AI 驱动的智慧店铺。










