|
@@ -1,9 +1,9 @@
|
1
|
|
-import React, { useEffect, useState, useCallback, useRef } from 'react'
|
|
1
|
+import React, { useEffect, useState, useCallback, useRef, useMemo } from 'react'
|
2
|
2
|
import { useModel } from 'umi'
|
3
|
3
|
import { Form, Input, Button, message } from 'antd';
|
4
|
4
|
import ProCard from '@ant-design/pro-card';
|
5
|
5
|
import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
6
|
|
-import QRCode from 'qrcodejs2'
|
|
6
|
+import QRCode from '@/components/QRCode'
|
7
|
7
|
import md5 from 'md5';
|
8
|
8
|
import { getDetail, saveOrg, updateOrg, saveOrgUser, getOrgAdminDetail } from '@/services/org';
|
9
|
9
|
|
|
@@ -16,17 +16,18 @@ export default (props) => {
|
16
|
16
|
const [formData, setFormData] = useState()
|
17
|
17
|
const [loading, setLoading] = useState(false)
|
18
|
18
|
const qrcodeRef = useRef()
|
19
|
|
- const linkRef = useRef()
|
|
19
|
+ const qrcodeText = useMemo(() => initialState.report_url + '#resume-work-form?org=' + id, [id, initialState.report_url])
|
20
|
20
|
|
21
|
21
|
const [adminForm] = Form.useForm();
|
22
|
22
|
const [adminFormData, setAdminFormData] = useState()
|
23
|
23
|
const [adminLoading, setAdminLoading] = useState(false)
|
24
|
24
|
|
25
|
25
|
const downloadQrcode = useCallback(() => {
|
26
|
|
- if (linkRef.current) {
|
27
|
|
- linkRef.current.click();
|
|
26
|
+ if (qrcodeRef.current) {
|
|
27
|
+ qrcodeRef.current.download();
|
28
|
28
|
}
|
29
|
29
|
}, [])
|
|
30
|
+
|
30
|
31
|
const onFinish = (values) => {
|
31
|
32
|
setLoading(true)
|
32
|
33
|
if (id) {
|
|
@@ -72,19 +73,6 @@ export default (props) => {
|
72
|
73
|
getDetail(id).then(res => {
|
73
|
74
|
setFormData(res);
|
74
|
75
|
form.setFieldsValue(res);
|
75
|
|
-
|
76
|
|
- // 初始化二维码
|
77
|
|
- const qrcode = new QRCode(qrcodeRef.current, {
|
78
|
|
- width: 160,
|
79
|
|
- height: 160, // 高度
|
80
|
|
- text: initialState.report_url + '#resume-work-form?org=' + id
|
81
|
|
- })
|
82
|
|
- const canvas = qrcodeRef.current.querySelector('canvas')
|
83
|
|
- // 创建下载链接
|
84
|
|
- const aElement = document.createElement('a');
|
85
|
|
- linkRef.current = aElement;
|
86
|
|
- linkRef.current.download = res.orgName + '.png'
|
87
|
|
- linkRef.current.href = canvas.toDataURL('image/jpg')
|
88
|
76
|
})
|
89
|
77
|
getOrgAdminDetail(id).then((res) => {
|
90
|
78
|
setAdminFormData(res);
|
|
@@ -124,7 +112,7 @@ export default (props) => {
|
124
|
112
|
</Form.Item>
|
125
|
113
|
{
|
126
|
114
|
id && <Form.Item label=' ' colon={false} wrapperCol={{ offset: 3 }}>
|
127
|
|
- <div ref={qrcodeRef} />
|
|
115
|
+ <QRCode ref={qrcodeRef} border width={200} content={qrcodeText} title={formData?.orgName} fileName={formData?.orgName} />
|
128
|
116
|
</Form.Item>
|
129
|
117
|
}
|
130
|
118
|
<Form.Item label=' ' colon={false} >
|