zoukankan      html  css  js  c++  java
  • 小程序相册授权后保存图片到相册

    小程序相册授权和保存图片到相册

      //保存图片
      saveImgToAlbum: function () {
        const _this = this;
        console.log('has.this.data.tempFilePath', _this.data.tempFilePath);
        if (!!_this.data.tempFilePath) {
          tt.saveImageToPhotosAlbum({
            filePath: _this.data.tempFilePath,
            success(rres) {
              console.log(`tt.saveImageToPhotosAlbum.success`, rres);
    
              //成功提示
              tt.showToast({
                title: "图片结果保存成功",
                duration: 3000,
                icon: 'success',
                success(tres) {
                  console.log(`${tres}`);
                },
                fail(tres) {
                  console.log(`showToast调用失败`, tres);
                }
              });
            },
            complete(rres) {
              console.log(`tt.saveImageToPhotosAlbum.complete`, rres);
            },
            fail(rres) {
              console.log(`tt.saveImageToPhotosAlbum.fail`, rres);
            }
          });
        } else {
          console.error('this.data.tempFilePath.isEmpty', _this.data.tempFilePath);
        }
      },
      //相册授权
      saveImgAuth: function () {
        const _this = this;
        tt.getSetting({
          success: function (res) {
            console.log('tt.getSetting.success', res);
    
            console.log('is.scope.album', res.authSetting['scope.album']);
            if (res.authSetting['scope.album'] && res.authSetting['scope.album'] == true) {//已授权
              console.log('has.scope.album');
    
              console.log('start.saveImg');
              //保存图片
              _this.saveImgToAlbum();
            } else {//未授权
              console.error('non.scope.album');
    
              console.log('start.tt.authorize');
              //授权
              tt.authorize({
                scope: "scope.album",
                success(rres) {
                  // 用户同意授权
                  console.log('tt.authorize.success', rres);
    
                  console.log('start.saveImg');
                  //保存图片
                  _this.saveImgToAlbum();
                },
                complete(rres) {
                  console.log('tt.authorize.complete', rres);
                },
                fail(rres) {
                  // 用户取消授权 或 取消过授权
                  console.error('tt.authorize.fail', rres);
    
                  tt.showModal({
                    title: "系统提示",
                    content: "打开相册权限才能保存图片哦!",
                    success(mres) {
                      if (mres.confirm) {
                        // console.log("confirm, continued");
                        console.log('start.tt.openSetting');
                        // 取消过授权需要打开设置页面
                        tt.openSetting({
                          success: function (rrres) {
                            console.log('tt.openSetting.success', rrres);
                            if (rrres.authSetting['scope.album'] && rrres.authSetting['scope.album'] == true) {//已授权
                              console.log('start.saveImg');
                              //保存图片
                              _this.saveImgToAlbum();
                            }
                          },
                          complete: function (rrres) {
                            console.log('tt.openSetting.complete', rrres);
                          },
                          fail: function (rrres) {
                            console.log('tt.openSetting.fail', rrres);
                          },
                        });
                      } else if (mres.cancel) {
                        // console.log("cancel, cold");
                        //成功提示
                        tt.showToast({
                          title: "图片结果保存失败",
                          duration: 3000,
                          icon: 'fail',
                          success(tres) {
                            console.log(`${tres}`);
                          },
                          fail(tres) {
                            console.log(`showToast调用失败`, tres);
                          }
                        });
                      } else {
                        // what happend?
                      }
                    },
                    fail(mres) {
                      console.log(`showModal调用失败`);
                    }
                  });
                },
              });
            }
          },
          complete: function (res) {
            console.log('tt.getSetting.complete', res);
          },
          fail: function (res) {
            console.error('tt.getSetting.fail', res);
          },
        });
      },

    本文地址:

    https://www.cnblogs.com/stumpx/p/13183779.html

  • 相关阅读:
    XAF中实现Combox属性编辑(官方)
    XAF 支持多数据库
    XAF 如何使用复合主键和复合外键
    如何禁止双击ListView记录显示DetailView?
    XAF中主从列表模式下获取当前主对象实例
    使用一个非持久字段PersistentAlias
    XAF 如何将文件存储在文件系统中而不是数据库中
    XAF中如何制作弹出窗体选择数据到ListView列表
    XAF 如何用其他线程更新对象
    XPO中 聚合函数的使用(Count,Max,Sum,Min)
  • 原文地址:https://www.cnblogs.com/stumpx/p/13183779.html
Copyright © 2011-2022 走看看