浏览代码

download pdf

amenpunk 2 年之前
父节点
当前提交
28df2d4180
共有 1 个文件被更改,包括 15 次插入2 次删除
  1. 15 2
      src/Pages/Resultados.jsx

+ 15 - 2
src/Pages/Resultados.jsx

@@ -40,6 +40,19 @@ const MyDocument = (props) => {
40 40
     setNumPages(numPages);
41 41
   }
42 42
 
43
+  const Download = () => {
44
+    let url = `/report/cleaverResult/${props.id}?output=pdf`
45
+    let rest = new Service(url);
46
+
47
+    rest
48
+      .getBlob(props.token)
49
+      .then(blob => {
50
+        var file = window.URL.createObjectURL(blob.data);
51
+        window.location.assign(file);
52
+      })
53
+      .catch(error => console.log({ error }))
54
+  }
55
+
43 56
   const [progress, setProgress] = useState(10);
44 57
 
45 58
   if(!pdf){
@@ -85,7 +98,7 @@ const MyDocument = (props) => {
85 98
           <Button 
86 99
             className="btnmain"
87 100
             variant="contained" 
88
-            onClick={() => console.log('download')} >
101
+            onClick={Download} >
89 102
             <DownloadIcon/>
90 103
           </Button>
91 104
         </div>
@@ -139,7 +152,7 @@ export function Resultados() {
139 152
           <Paper 
140 153
             elevation={2} 
141 154
             sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh', boxShadow: 'none !important' }}>
142
-            <MyDocument pdf={pdf} />
155
+            <MyDocument token={auth.token} id={id} pdf={pdf} />
143 156
           </Paper>
144 157
         </Box>
145 158
       </div>