浏览代码

二维码封装

Baozhangchao 3 年前
父节点
当前提交
160dbed11f

+ 21
- 16
src/pages/activity/SignupActivity/detail.jsx 查看文件

@@ -16,6 +16,7 @@ import AuthButton from '@/components/AuthButton';
16 16
 import { getImgURL } from '@/utils/image';
17 17
 import Share from '@/components/Share';
18 18
 import Poster from '@/components/Poster';
19
+import PictureQRcode from '@/utils/imageQC'
19 20
 
20 21
 const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
21 22
 const { TextArea } = Input;
@@ -38,21 +39,21 @@ const getSignList = dynamicId => {
38 39
   });
39 40
 };
40 41
 
41
-const newQrcode = row => {
42
-  const x = new XMLHttpRequest();
43
-  const resourceUrl = row.qrCode;
44
-  x.open('GET', resourceUrl, true);
45
-  x.responseType = 'blob';
46
-  x.onload = function(e) {
47
-    const url = window.URL.createObjectURL(x.response);
48
-    const a = document.createElement('a');
49
-    a.href = url;
50
-    a.style.display = 'none';
51
-    a.download = '活动二维码.png';
52
-    a.click();
53
-  };
54
-  x.send();
55
-};
42
+// const newQrcode = row => {
43
+//   const x = new XMLHttpRequest();
44
+//   const resourceUrl = row.qrCode;
45
+//   x.open('GET', resourceUrl, true);
46
+//   x.responseType = 'blob';
47
+//   x.onload = function (e) {
48
+//     const url = window.URL.createObjectURL(x.response);
49
+//     const a = document.createElement('a');
50
+//     a.href = url;
51
+//     a.style.display = 'none';
52
+//     a.download = '活动二维码.png';
53
+//     a.click();
54
+//   };
55
+//   x.send();
56
+// };
56 57
 
57 58
 const BasicForm = props => {
58 59
   const detailData = props.detailData || {};
@@ -190,7 +191,11 @@ const BasicForm = props => {
190 191
           {(detailData.activityStatus === 0 || detailData.activityStatus === 2) && (
191 192
             <span
192 193
               style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }}
193
-              onClick={newQrcode.bind(this, detailData)}
194
+              // onClick={newQrcode.bind(this, detailData)}
195
+              onClick={() => {
196
+                PictureQRcode(detailData, '活动二维码')
197
+                  , console.log(detailData)
198
+              }}
194 199
             >
195 200
               {<Button>下载二维码</Button>}
196 201
             </span>

+ 24
- 16
src/pages/activity/groupRoomActivity/detail.jsx 查看文件

@@ -16,6 +16,7 @@ import AuthButton from '@/components/AuthButton';
16 16
 import { getImgURL } from '@/utils/image';
17 17
 import Share from '@/components/Share';
18 18
 import Poster from '@/components/Poster';
19
+import PictureQRcode from '@/utils/imageQC'
19 20
 
20 21
 const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
21 22
 const { TextArea } = Input;
@@ -38,21 +39,23 @@ const getSignList = dynamicId => {
38 39
   });
39 40
 };
40 41
 
41
-const newQrcode = row => {
42
-  const x = new XMLHttpRequest();
43
-  const resourceUrl = row.qrCode;
44
-  x.open('GET', resourceUrl, true);
45
-  x.responseType = 'blob';
46
-  x.onload = function(e) {
47
-    const url = window.URL.createObjectURL(x.response);
48
-    const a = document.createElement('a');
49
-    a.href = url;
50
-    a.style.display = 'none';
51
-    a.download = '活动二维码.png';
52
-    a.click();
53
-  };
54
-  x.send();
55
-};
42
+
43
+
44
+// const newQrcode = row => {
45
+//   const x = new XMLHttpRequest();
46
+//   const resourceUrl = row.qrCode;
47
+//   x.open('GET', resourceUrl, true);
48
+//   x.responseType = 'blob';
49
+//   x.onload = function (e) {
50
+//     const url = window.URL.createObjectURL(x.response);
51
+//     const a = document.createElement('a');
52
+//     a.href = url;
53
+//     a.style.display = 'none';
54
+//     a.download = '活动二维码.png';
55
+//     a.click();
56
+//   };
57
+//   x.send();
58
+// };
56 59
 
57 60
 const BasicForm = props => {
58 61
   const detailData = props.detailData || {};
@@ -193,7 +196,12 @@ const BasicForm = props => {
193 196
           {(detailData.activityStatus === 0 || detailData.activityStatus === 2) && (
194 197
             <span
195 198
               style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }}
196
-              onClick={newQrcode.bind(this, detailData)}
199
+              // onClick={newQrcode.bind(this, detailData)}
200
+
201
+              onClick={() => {
202
+                PictureQRcode(detailData, '测试')
203
+                  , console.log(detailData)
204
+              }}
197 205
             >
198 206
               {<Button>下载二维码</Button>}
199 207
             </span>

+ 21
- 16
src/pages/activity/lookHouseActivity/detail.jsx 查看文件

@@ -16,6 +16,7 @@ import AuthButton from '@/components/AuthButton';
16 16
 import { getImgURL } from '@/utils/image';
17 17
 import Share from '@/components/Share';
18 18
 import Poster from '@/components/Poster';
19
+import PictureQRcode from '@/utils/imageQC'
19 20
 
20 21
 const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
21 22
 const { TextArea } = Input;
@@ -38,21 +39,21 @@ const getSignList = dynamicId => {
38 39
   });
39 40
 };
40 41
 
41
-const newQrcode = row => {
42
-  const x = new XMLHttpRequest();
43
-  const resourceUrl = row.qrCode;
44
-  x.open('GET', resourceUrl, true);
45
-  x.responseType = 'blob';
46
-  x.onload = function(e) {
47
-    const url = window.URL.createObjectURL(x.response);
48
-    const a = document.createElement('a');
49
-    a.href = url;
50
-    a.style.display = 'none';
51
-    a.download = '活动二维码.png';
52
-    a.click();
53
-  };
54
-  x.send();
55
-};
42
+// const newQrcode = row => {
43
+//   const x = new XMLHttpRequest();
44
+//   const resourceUrl = row.qrCode;
45
+//   x.open('GET', resourceUrl, true);
46
+//   x.responseType = 'blob';
47
+//   x.onload = function (e) {
48
+//     const url = window.URL.createObjectURL(x.response);
49
+//     const a = document.createElement('a');
50
+//     a.href = url;
51
+//     a.style.display = 'none';
52
+//     a.download = '活动二维码.png';
53
+//     a.click();
54
+//   };
55
+//   x.send();
56
+// };
56 57
 
57 58
 const BasicForm = props => {
58 59
   const detailData = props.detailData || {};
@@ -184,7 +185,11 @@ const BasicForm = props => {
184 185
           {(detailData.activityStatus === 0 || detailData.activityStatus === 2) && (
185 186
             <span
186 187
               style={{ color: '#1990FF', marginRight: '20px', cursor: 'pointer' }}
187
-              onClick={newQrcode.bind(this, detailData)}
188
+              // onClick={newQrcode.bind(this, detailData)}
189
+              onClick={() => {
190
+                PictureQRcode(detailData, '活动二维码')
191
+                  , console.log(detailData)
192
+              }}
188 193
             >
189 194
               {<Button>下载二维码</Button>}
190 195
             </span>

+ 29
- 0
src/utils/imageQC.js 查看文件

@@ -0,0 +1,29 @@
1
+
2
+import { message } from 'antd';
3
+//测试封装
4
+export default function PictureQRcode(res, title) {
5
+  if (res.qrCode === null || res.qrCode == 'null') {
6
+    message.error(`保存失败${res.qrCode}`);
7
+
8
+  } else {
9
+    const x = new XMLHttpRequest();
10
+    const resourceUrl = res.qrCode;
11
+    x.open('GET', resourceUrl, true);
12
+    x.responseType = 'blob';
13
+    x.onload = function (e) {
14
+      const url = window.URL.createObjectURL(x.response);
15
+      const a = document.createElement('a');
16
+      a.href = url;
17
+      a.style.display = 'none';
18
+      a.download = `${title}.png`;
19
+      a.click();
20
+    };
21
+    x.send();
22
+    message.info(`保存成功`);
23
+
24
+
25
+  }
26
+
27
+
28
+}
29
+