| | |
| | | var that = this; |
| | | uni.showActionSheet({ |
| | | // itemList按钮的文字接受的是数组 |
| | | itemList: ["查看头像","更换头像"], |
| | | itemList: ["查看头像","拍摄","从相册选择"], |
| | | success(e){ |
| | | var index = e.tapIndex; |
| | | if(index === 0){ |
| | | if(index == 0){ |
| | | // 用户点击了预览当前图片 |
| | | // 可以自己实现当前头像链接的读取 |
| | | let url = that.useimg; |
| | |
| | | urls: arr |
| | | }) |
| | | } |
| | | if(index === 1){ |
| | | // 用户点击了从图库上传 |
| | | if(index == 1 || index==2 ){ |
| | | //拍照或从图库上传 |
| | | that.uploadPictrue(index); |
| | | } |
| | | } |
| | | }); |
| | | }, |
| | | //图片上传 |
| | | uploadPictrue(e){ |
| | | var that = this; |
| | | var sourceTypeArr = []; |
| | | e==1 ? sourceTypeArr.push("camera") : sourceTypeArr.push("album") |
| | | uni.chooseImage({ |
| | | count: 1, //可选择数量,默认9 |
| | | sizeType: ['compressed','original'], //上传压缩图,原图 |
| | | sourceType: ['album','camera'], //从相册选择或从使用相机 |
| | | sourceType: sourceTypeArr, //从相册选择 |
| | | success: async (res) => { |
| | | if(res.tempFiles[0].size > 10 * 1024 * 1000){ //上传图片大小限制 |
| | | uni.showToast({ |
| | |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }, |
| | | } |