.detailList)[0
)chosePhoto() { const that = this wx.chooseImage({ count: 1 sizeType: ['compressed'
sourceType: ['album' 'camera'
complete(res) { that.setData({ userChosePhoho: res.tempFilePaths[0
resultPhoto: undefined ))headimgHD(imageUrl) { imageUrl = imageUrl.split('/'); //把头像的路径切成数组 //把大小数值为 46 || 64 || 96 || 132 的转换为0 if (imageUrl[imageUrl.length - 1
(imageUrl[imageUrl.length - 1
== 46 || imageUrl[imageUrl.length - 1
== 64 || imageUrl[imageUrl.length - 1
== 96 || imageUrl[imageUrl.length - 1
== 132)) { imageUrl[imageUrl.length - 1
= 0;imageUrl = imageUrl.join('/'); //重新拼接为字符串 return imageUrl;getUserAvatar() { const that = this wx.getUserProfile({ desc: \"获取您的头像\" success(res) { const newAvatar = that.headimgHD(res.userInfo.avatarUrl) wx.getImageInfo({ src: newAvatar success(res) { that.setData({ userChosePhoho: res.path resultPhoto: undefined )))previewImage(e) { wx.previewImage({ urls: [e.currentTarget.dataset.image
)editImage() { const that = this wx.editImage({ src: this.data.userChosePhoho success(res) { that.setData({ userChosePhoho: res.tempFilePath ))getNewPhoto() { const that = this wx.showLoading({ title: '图片生成中' ) this.setData({ getPhotoStatus: true ) app.doRequest(this.data.styleList[this.data.currentStyle
.detailList[this.data.currentSubStyle
.uri { style: this.data.styleList[this.data.currentStyle
.detailList[this.data.currentSubStyle
.name image: wx.getFileSystemManager().readFileSync(this.data.userChosePhoho \"base64\")option = { method: \"POST\" ).then(function (result) { wx.hideLoading() that.setData({ resultPhoto: result.error ? \"error\" : result.photo getPhotoStatus: false ) )saveImage() { wx.saveImageToPhotosAlbum({ filePath: this.data.resultPhoto success(res) { wx.showToast({ title: \"保存成功\" )fail(res) { wx.showToast({ title: \"异常 , 稍后重试\" ))onShareAppMessage: function () { return { title: \"头头是道个性头像\"onShareTimeline() { return { title: \"头头是道个性头像\"showModal(e) { if(e.currentTarget.dataset.target==\"Image\"){ const previewSubStyle = e.currentTarget.dataset.substyle const previewSubStyleUrl = this.data.styleList[this.data.currentStyle
.detailList[previewSubStyle
.preview if(previewSubStyleUrl){ this.setData({ previewStyle: previewSubStyleUrl ) else{ wx.showToast({ title: \"暂无模板预览\" icon: \"error\" ) returnthis.setData({ modalName: e.currentTarget.dataset.target )hideModal(e) { this.setData({ modalName: null )copyData(e) { wx.setClipboardData({ data: e.currentTarget.dataset.data success(res) { wx.showModal({ title: '复制完成' content: `已将${e.currentTarget.dataset.data复制到了剪切板` )) ) 因为项目会请求比较多次的后台接口 , 所以 , 我将请求方法进行额外的抽象: // 统一请求接口 doRequest: async function (uri data option) { const that = this return new Promise((resolve reject) ={ wx.request({ url: that.url + uri data: data header: { \"Content-Type\": 'application/json'method: optionoption.method ? option.method : \"POST\" success: function (res) { resolve(res.data)fail: function (res) { reject(null)) )完成之后配置一下后台接口 , 发布审核即可 。本文作者刘宇(花名:江昱) 原文链接:https://developer.aliyun.com/article/882384?utm_content=g_1000334557 本文为阿里云原创内容 , 未经允许不得转载 。
相关经验推荐
- 安卓|三星One UI 5.0系统7月开启公测 基于Android 13深度定制
- 雷军|雷军卸任小米有品公司董事!仍持股70%,为大股东及疑似实际控制人
- vivo|小米12在海外火了,大家都在讨论这一点
- 耳机|简单好用的小耳机,听歌游戏好伙伴,尊客X22上手
- 真我gt2|从1到2的一小步,聆听奇迹的一大步——评OPPO Enco X2
- USB|同为3600元,小米12Pro和小米11Ultra要怎么选
- OPPO|比小米还快吗?OPPO首款手机处理器曝光,或采用4nm打造
- 单反|4月份拍照最好的4部手机,堪比“小单反”,拍照党必备
- Apple Watch|雷军怎么了?小米12已开始降价,骁龙8Gen1新机都撑不住吗?
- 小米科技|这款摩托罗拉手机跌至999元!配备120Hz高刷居中打孔屏和5000万像素主摄
