微信登录、用户信息
  • 微信官方宣布getUserInfo已失效,使用getUserProfile替代,getUserProfile必须得用户手动获取才行(其他任何方法都不可行),并且不需要设置组件的open-type,可以直接用事件触发 ```html

  1. <a name="gBmGt"></a>
  2. ###### 查看用户已授权选项
  3. ```javascript
  4. getSettingMes() {
  5. let _this = this;
  6. uni.getSetting({
  7. success(res) {
  8. console.log("已授权列表", res)
  9. },
  10. fail() {
  11. console.log("获取已授权选项失败")
  12. }
  13. })
  14. },

获取手机号
  1. <button type="primary" open-type="getPhoneNumber" lang="zh_CN" @getphonenumber="getPhoneNumber">获取手机号</button>
  2. //methods
  3. getPhoneNumber(e) {
  4. console.log(e); //拿到结果去后台解析
  5. },

保存图片
  1. handleSaveMsCode() {
  2. uni.saveImageToPhotosAlbum({
  3. filePath: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
  4. success: function() {
  5. console.log('save success');
  6. },
  7. fail(err) {
  8. if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg ===
  9. "saveImageToPhotosAlbum:fail auth deny" || err.errMsg ===
  10. "saveImageToPhotosAlbum:fail authorize no response") {
  11. uni.openSetting({
  12. success(res) {
  13. console.log(res.authSetting)
  14. }
  15. });
  16. } else {
  17. uni.showToast({
  18. title: err.errMsg,
  19. icon: 'none',
  20. duration: 2000
  21. });
  22. }
  23. }
  24. });
  25. }

下载文件、保存、查看
  1. handleSaveFile() {
  2. uni.downloadFile({
  3. url: 'https://www.example.com/file/test', //仅为示例,并非真实的资源
  4. success: (res) => {
  5. if (res.statusCode === 200) {
  6. uni.saveFile({
  7. tempFilePath: res.tempFilePath,
  8. success: function(res) {
  9. uni.showToast({
  10. icon: 'none',
  11. mask: true,
  12. title: '文件已保存:' + res.savedFilePath, //保存路径
  13. duration: 3000,
  14. });
  15. // setTimeout(() => {
  16. // uni.openDocument({ //打开文档查看
  17. // filePath: res.savedFilePath,
  18. // success: function(res) {
  19. // // console.log('打开文档成功');
  20. // }
  21. // });
  22. // }, 3000)
  23. }
  24. });
  25. }
  26. }
  27. });
  28. }