Pārlūkot izejas kodu

Merge branch 'dev' of http://git.ycjcjy.com/ubpa/pc-admin into dev

李志伟 3 gadus atpakaļ
vecāks
revīzija
fe79fc7621

+ 7
- 0
src/components/QRCode/index.jsx Parādīt failu

47
           resolve()
47
           resolve()
48
         }).catch(reject)
48
         }).catch(reject)
49
       })
49
       })
50
+    },
51
+    getCanvas: () => {
52
+      return new Promise((resolve, reject) => {
53
+        html2canvas(rootRef.current).then((canvas) => {
54
+          resolve(canvas)
55
+        }).catch(reject)
56
+      })
50
     }
57
     }
51
   }), [fileName])
58
   }), [fileName])
52
 
59
 

+ 1
- 1
src/components/QRCode/style.less Parādīt failu

11
   }
11
   }
12
 
12
 
13
   h3 {
13
   h3 {
14
-    font-size: 18px;
14
+    font-size: 24px;
15
     font-weight: bold;
15
     font-weight: bold;
16
     line-height: 3em;
16
     line-height: 3em;
17
   }
17
   }

+ 4
- 15
src/pages/org/org/Edit/components/BasicPage.jsx Parādīt failu

1
 import { Form, Input, Button } from 'antd';
1
 import { Form, Input, Button } from 'antd';
2
-import QRCode from '@/components/QRCode'
3
 import { history } from 'umi';
2
 import { history } from 'umi';
4
 import React, { useEffect, useState, useCallback, useRef, useMemo } from 'react'
3
 import React, { useEffect, useState, useCallback, useRef, useMemo } from 'react'
5
 import { useModel } from 'umi'
4
 import { useModel } from 'umi'
6
 import { getDetail, saveOrg, updateOrg } from '@/services/org';
5
 import { getDetail, saveOrg, updateOrg } from '@/services/org';
7
-
6
+import QRCode from './QRCode'
8
 
7
 
9
 export default (props) => {
8
 export default (props) => {
10
   const { id } = props;
9
   const { id } = props;
13
   const [form] = Form.useForm();
12
   const [form] = Form.useForm();
14
   const [formData, setFormData] = useState()
13
   const [formData, setFormData] = useState()
15
   const [loading, setLoading] = useState(false)
14
   const [loading, setLoading] = useState(false)
16
-  const qrcodeRef = useRef()
15
+
17
   const qrcodeText = useMemo(() => initialState.report_url + '#resume-work-form?org=' + id, [id, initialState.report_url])
16
   const qrcodeText = useMemo(() => initialState.report_url + '#resume-work-form?org=' + id, [id, initialState.report_url])
18
-  const downloadQrcode = useCallback(() => {
19
-    if (qrcodeRef.current) {
20
-      qrcodeRef.current.download();
21
-    }
22
-  }, [])
23
 
17
 
24
   const onFinish = (values) => {
18
   const onFinish = (values) => {
25
     setLoading(true)
19
     setLoading(true)
76
           <Input type='number' min='0' />
70
           <Input type='number' min='0' />
77
         </Form.Item>
71
         </Form.Item>
78
         {
72
         {
79
-          id && <Form.Item label=' ' colon={false} wrapperCol={{ offset: 3 }}>
80
-            <QRCode ref={qrcodeRef} border width={200} content={qrcodeText} title={formData?.orgName} fileName={formData?.orgName} />
73
+          id && <Form.Item label='申报二维码' >
74
+            <QRCode text={qrcodeText} title={formData?.orgName} />
81
           </Form.Item>
75
           </Form.Item>
82
         }
76
         }
83
         <Form.Item label=' ' colon={false} >
77
         <Form.Item label=' ' colon={false} >
84
           <Button type="primary" htmlType="submit" loading={loading}>
78
           <Button type="primary" htmlType="submit" loading={loading}>
85
             保存
79
             保存
86
           </Button>
80
           </Button>
87
-          {id &&
88
-            <Button style={{ marginLeft: '32px' }} onClick={downloadQrcode} >
89
-              下载二维码
90
-            </Button>
91
-          }
92
           <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }} >返回</Button>
81
           <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }} >返回</Button>
93
         </Form.Item>
82
         </Form.Item>
94
       </Form>
83
       </Form>

+ 41
- 0
src/pages/org/org/Edit/components/QRCode.jsx Parādīt failu

1
+import React, { useRef } from 'react'
2
+import { Popover, Button } from 'antd';
3
+import { QrcodeOutlined } from '@ant-design/icons';
4
+import QRCode from '@/components/QRCode'
5
+
6
+const style = {
7
+  display: 'flex',
8
+  alignItem: 'center'
9
+}
10
+
11
+export default (props) => {
12
+  const { text, title } = props
13
+
14
+  const qrcodeRef = useRef()
15
+  const download = () => {
16
+    if (qrcodeRef.current) {
17
+      qrcodeRef.current.getCanvas().then((canvas) => {
18
+        const imageData = canvas.toDataURL('image/png', .8);
19
+        const link = document.createElement('a');
20
+        link.download = `${title}.png`
21
+        link.href = imageData
22
+        link.click()
23
+      });
24
+    }
25
+  }
26
+
27
+  const content = (
28
+    <QRCode ref={qrcodeRef} border content={text} title={title} />
29
+  )
30
+
31
+  return (
32
+    <div style={style}>
33
+      {/* 这个 div 主要用于下载 */}
34
+      <div style={{ zIndex: -1, position: 'fixed', top: '-500vh' }}>{content}</div>
35
+      <Popover content={content} placement="right">
36
+        <QrcodeOutlined style={{ fontSize: '32px' }} />
37
+      </Popover>
38
+      <Button style={{ marginLeft: '16px' }} onClick={download} type='link'>下载</Button>
39
+    </div>
40
+  )
41
+}