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


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

      //保存图片
      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

  • 相关阅读:
    Django 批量保存图片文件 自定义上传方法
    Pycharm 激活码
    Django项目关闭debug模式后,静态文件无法加载的解决办法
    python 获取环境变量
    django 中多字段主键(复合、联合主键)
    在pycharm中启动Django服务器
    Django Aggregation聚合 django orm 求平均、去重、总和等常用方法
    nohup 后台启动程序,并输出到指定日志
    Android网络开发之WIFI
    WebView和JavaScript如何实现相互调用
  • 原文地址:https://www.cnblogs.com/stumpx/p/13183779.html
Copyright © 2020-2023  润新知