diff --git a/components/service-modal/index.js b/components/service-modal/index.js index 16a7442..8ff1144 100644 --- a/components/service-modal/index.js +++ b/components/service-modal/index.js @@ -38,6 +38,42 @@ Component({ this.setData({ showModal: false }) - } + }, + saveImage: function (e) { + console.log('saveImage', e.currentTarget.dataset.src); + const imageUrl = e.currentTarget.dataset.src; + // 给出确认弹窗 + wx.downloadFile({ + url: imageUrl, + success: res => { + if (res.statusCode === 200) { + wx.saveImageToPhotosAlbum({ + filePath: res.tempFilePath, + success: () => { + wx.showToast({ + title: '保存成功', + icon: 'success' + }); + }, + fail: err => { + console.error('保存失败', err); + wx.showToast({ + title: '保存失败', + icon: 'none' + }); + } + }); + } + }, + fail: err => { + console.error('下载失败', err); + wx.showToast({ + title: '下载失败', + icon: 'none' + }); + } + }); + }, + } }) \ No newline at end of file diff --git a/components/service-modal/index.wxml b/components/service-modal/index.wxml index 87fb4dc..1a2cee2 100644 --- a/components/service-modal/index.wxml +++ b/components/service-modal/index.wxml @@ -16,7 +16,13 @@ 加载中... + + + + + + 长按识别二维码 diff --git a/pages/changeAvatar/index.js b/pages/changeAvatar/index.js index ad9c11e..3c2be54 100644 --- a/pages/changeAvatar/index.js +++ b/pages/changeAvatar/index.js @@ -76,7 +76,23 @@ Page({ }); }, }); - }, + }, + chooseAnImage() { + const that = this; + wx.chooseMedia({ + sizeType: ["original"], // 可以指定是原图还是压缩图,默认二者都有 + sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有 + success(res) { + // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 + console.log(res); + that.setData({ + files: that.data.files.concat(res.tempFilePaths), + temporaryImg: res.tempFiles[0].tempFilePath, + isSure: true, + }); + }, + }); + }, changeUserImgsrc: function () { var that = this; // wx.chooseImage({ diff --git a/pages/changeAvatar/index.wxml b/pages/changeAvatar/index.wxml index e9e0df0..3a899b2 100644 --- a/pages/changeAvatar/index.wxml +++ b/pages/changeAvatar/index.wxml @@ -14,8 +14,10 @@ - + + + diff --git a/pages/login/index.wxml b/pages/login/index.wxml index 2108b63..99e817a 100644 --- a/pages/login/index.wxml +++ b/pages/login/index.wxml @@ -64,9 +64,9 @@ -