Sanakey
2021-06-04 355a84d740a2a9dfa1d67cb2d2e11843d42809ac
提交 | 用户 | age
8724a4 1
S 2 // const app = getApp<IAppOption>();
3 Component({
4   /**
5    * 组件的属性列表
6    */
7   options: {
8     addGlobalClass: true,
9     multipleSlots: true // 在组件定义时的选项中启用多slot支持
10   },
11   properties: {
12     showQrCode:{
13       type: Boolean,
14       value: false
15     },
16     color:{
17       type: String,
18       value: ''
d8c37e 19     },
S 20     description: {
21       type: String,
22       value: '当前微信未实名认证,请将该二维码截屏或保存到本地,分享给主播扫码认证后,再重复添加一次。'
8724a4 23     }
S 24   },
25
26   /**
27    * 组件的初始数据
28    */
29   data: {
30     qrCodeTempUrl:''
31   },
32
33   /**
34    * 组件的方法列表
35    */
36   methods: {
37     async showQrCodeDialog(qrCode:string){
38       await this.downloadQr(qrCode);
39       wx.hideLoading();
40       this.setData({
41         showQrCode: true,
42         qrCodeUrl:qrCode
43       });
44     },
45     async downloadQr(qrCodeUrl:string) {
46       let [err, res] = await wx.$utils.to(
47         wx.pro.downloadFile({
48           // url: this.data.qrCodeUrl
49           url: qrCodeUrl,
50         })
51       );
52       if (err) {
53         console.log("downloadQr", err);
54         return;
55       }
56       console.log("----downloadQr",res);
57       if (res.statusCode === 200) {
58         // imgDownloadSum++;
59         console.log('......头像',res.tempFilePath)
60         this.setData({
61           qrCodeTempUrl: res.tempFilePath
62         })
63       }else{
64         wx.showToast({
65           title: '二维码下载失败,请重试',
66           icon: "none",
67           duration: 3000,
68         });
69       }
70     },
71     async isAuthorizeSave() {
72       let [err, res] = await wx.$utils.to(wx.pro.getSetting());
73       if (err) {
74         return false;
75       }
76       console.log("getSetting", res);
77       return res.authSetting["scope.writePhotosAlbum"] !== false;
78     },
79     async saveQrImg() {
80       wx.showLoading({
81         title: "保存中...",
82       });
83       let isAuthorizeSave = await this.isAuthorizeSave();
84       if (!isAuthorizeSave) {
85         wx.hideLoading();
355a84 86         // wx.showLoading({
S 87         //   title: "保存失败",
88         // });
8724a4 89         wx.showModal({
S 90           title: "提示",
91           content: "您还未授权保存到相册,请在接下来打开的设置页面开启相册授权!",
92           success(res) {
93             if (res.confirm) {
94               console.log("用户点击确定");
95               wx.openSetting({
96                 success(res) {
97                   console.log(res.authSetting);
98                 },
99               });
100             } else if (res.cancel) {
101               console.log("用户点击取消");
102             }
103           },
104         });
105         return;
106       }
107       wx.saveImageToPhotosAlbum({
108         filePath: this.data.qrCodeTempUrl,
109         success: () => {
110           wx.showToast({
111             title: "二维码已保存到本地,赶紧分享给主播认证吧!",
112             icon: "none",
113             duration: 3000,
114           });
115         },
355a84 116         fail:(err)=>{
S 117           console.log('保存图片失败。。',err);
118           wx.showModal({
119             title:'提示',
120             content:JSON.stringify(err)
121           })
122         },
8724a4 123         complete: () => {
355a84 124           // wx.hideLoading();
8724a4 125         },
S 126       });
127     },
128   }
129 })