微信登录、用户信息
- 微信官方宣布getUserInfo已失效,使用getUserProfile替代,getUserProfile必须得用户手动获取才行(其他任何方法都不可行),并且不需要设置组件的open-type,可以直接用事件触发
```html
微信一键登录
<a name="gBmGt"></a>
###### 查看用户已授权选项
```javascript
getSettingMes() {
let _this = this;
uni.getSetting({
success(res) {
console.log("已授权列表", res)
},
fail() {
console.log("获取已授权选项失败")
}
})
},
获取手机号
<button type="primary" open-type="getPhoneNumber" lang="zh_CN" @getphonenumber="getPhoneNumber">获取手机号</button>
//methods
getPhoneNumber(e) {
console.log(e); //拿到结果去后台解析
},
保存图片
handleSaveMsCode() {
uni.saveImageToPhotosAlbum({
filePath: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
success: function() {
console.log('save success');
},
fail(err) {
if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg ===
"saveImageToPhotosAlbum:fail auth deny" || err.errMsg ===
"saveImageToPhotosAlbum:fail authorize no response") {
uni.openSetting({
success(res) {
console.log(res.authSetting)
}
});
} else {
uni.showToast({
title: err.errMsg,
icon: 'none',
duration: 2000
});
}
}
});
}
下载文件、保存、查看
handleSaveFile() {
uni.downloadFile({
url: 'https://www.example.com/file/test', //仅为示例,并非真实的资源
success: (res) => {
if (res.statusCode === 200) {
uni.saveFile({
tempFilePath: res.tempFilePath,
success: function(res) {
uni.showToast({
icon: 'none',
mask: true,
title: '文件已保存:' + res.savedFilePath, //保存路径
duration: 3000,
});
// setTimeout(() => {
// uni.openDocument({ //打开文档查看
// filePath: res.savedFilePath,
// success: function(res) {
// // console.log('打开文档成功');
// }
// });
// }, 3000)
}
});
}
}
});
}