浏览代码

pdf mok fix

amenpunk 2 年之前
父节点
当前提交
0060f8d9a2
共有 4 个文件被更改,包括 176 次插入78 次删除
  1. 9 11
      src/Components/Generics/loading.jsx
  2. 8 44
      src/Pages/Puestos.jsx
  3. 79 23
      src/Pages/Resultados.jsx
  4. 80 0
      src/pdf.css

+ 9 - 11
src/Components/Generics/loading.jsx

@@ -13,19 +13,17 @@ export function Loading() {
13 13
   return (
14 14
     <div className="content-section">
15 15
       <Paper>
16
-      <div className="main">
17
-        <Box className="loadingGeneric">
18
-
19
-              <div className="loading_or_content">
20
-                <div className="snippet" data-title=".dot-pulse">
21
-                  <div className="stage">
22
-                    <div className={types[0]}></div>
23
-                  </div>
16
+        <div className="main">
17
+          <Box className="loadingGeneric">
18
+            <div className="loading_or_content">
19
+              <div className="snippet" data-title=".dot-pulse">
20
+                <div className="stage">
21
+                  <div className={types[0]}></div>
24 22
                 </div>
25 23
               </div>
26
-
27
-        </Box>
28
-      </div>
24
+            </div>
25
+          </Box>
26
+        </div>
29 27
       </Paper>
30 28
     </div>
31 29
 

+ 8 - 44
src/Pages/Puestos.jsx

@@ -110,56 +110,21 @@ export function Puestos() {
110 110
   const total_items = Divide(filter ? filter : result.data).length
111 111
 
112 112
   return (
113
-    <div  className="content-section">
113
+    <div className="content-section">
114 114
       <div className="main">
115 115
         <Box>
116 116
           <Paper sx={{ mb: 2, padding: 2, }}>
117
-            <Row style={{ alignItems: 'center', padding : 10 }}>
118
-              <Col md="6" sm="12" xs="12">
117
+            <Row style={{ alignItems: 'center', padding: 10, justifyContent: 'space-between' }}>
118
+              <Col md="4" sm="4" xs="4">
119 119
                 <div className="breadcrumb-header">
120 120
                   <Box sx={{ float: 'left', display: 'flex', flexDirection: 'row', alignItems: 'center' }} >
121 121
                     <ToggleButtonGroup style={{ marginRight: 20 }} size="small" {...control}>
122 122
                       {children}
123 123
                     </ToggleButtonGroup>
124
-
125
-
126
-                    {/*
127
-                      <TextField
128
-                        id="search_plaza_input"
129
-                        onChange={(event) => {
130
-                          let nombre = event.target.value
131
-                          if (nombre) {
132
-                            let temp = result.data.filter(plaza => {
133
-                              let isset = plaza.nombrepuesto.toUpperCase().includes(nombre.toUpperCase())
134
-                              return isset
135
-                            })
136
-                            if(temp.lenght <= 0){
137
-                              setFilter(null)
138
-                            }
139
-                            setFilter(temp)
140
-                          } else {
141
-                            setFilter(null)
142
-                          }
143
-                        }}
144
-                        InputProps={{
145
-                          startAdornment: (
146
-                            <InputAdornment position="start">
147
-                              <SearchIcon />
148
-                            </InputAdornment>
149
-                          ),
150
-                        }}
151
-                        variant="standard"
152
-                      />
153
-*/}
154
-
155
-
156
-
157
-
158 124
                   </Box>
159
-
160 125
                 </div>
161 126
               </Col>
162
-              <Col md="6" sm='12' xs="12">
127
+              <Col md="8" sm='8' xs="4">
163 128
                 <div className="add_producto">
164 129
                   <div onClick={() => setManual(true)} className="btn_add_producto">
165 130
                     <span className="btn_plaza_common" >Agregar manual <AddIcon fontSize="small" /></span>
@@ -172,10 +137,9 @@ export function Puestos() {
172 137
                 </div>
173 138
               </Col>
174 139
             </Row>
175
-
176
-            <div style={{padding:7}}>
140
+            <div style={{ padding: 7 }}>
177 141
               <div className={` main_grid_plazas main_productos ${alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'}`} id="grid_view">
178
-                <Row style={{minHeight:'75vh'}}>
142
+                <Row style={{ minHeight: '75vh' }}>
179 143
                   <GridMode
180 144
                     toggle={toggle}
181 145
                     showing={alignment}
@@ -185,7 +149,7 @@ export function Puestos() {
185 149
                 </Row>
186 150
               </div>
187 151
               <div className={`main_list_products ${alignment === 'list' ? 'activar_vista' : 'desactivar_vista'}`} id="list_view_products">
188
-                <Row style={{minHeight:'75vh'}}>
152
+                <Row style={{ minHeight: '75vh' }}>
189 153
                   <ListMode
190 154
                     toggle={toggle}
191 155
                     showing={alignment}
@@ -239,7 +203,7 @@ export function Puestos() {
239 203
                       variant="standard"
240 204
                     />
241 205
 
242
-                    <Chip style={{ marginLeft: 10, margin: 5 }} label={"Total: " + ( filter?  filter.length :  ( result ? result.data.length : 0 ))} />
206
+                    <Chip style={{ marginLeft: 10, margin: 5 }} label={"Total: " + (filter ? filter.length : (result ? result.data.length : 0))} />
243 207
                   </div>
244 208
                 </Col>
245 209
               </Row>

+ 79 - 23
src/Pages/Resultados.jsx

@@ -2,15 +2,33 @@ import { useEffect, useState } from 'react';
2 2
 import { useParams } from 'react-router-dom'
3 3
 import { Service } from '../Utils/HTTP';
4 4
 import { useSelector } from 'react-redux';
5
-import { Button, Box, Paper } from '@mui/material'
6 5
 import { Document, Page, pdfjs } from 'react-pdf/dist/esm/entry.webpack';
7
-// import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
6
+import { Loading } from '../Components/Generics/loading'
7
+import DownloadIcon from '@mui/icons-material/Download';
8 8
 import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
9 9
 import 'react-pdf/dist/esm/Page/TextLayer.css';
10
+import '../pdf.css'
11
+// import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
12
+import { 
13
+  Button, Box, Paper,LinearProgress,
14
+  Typography
15
+} from '@mui/material'
10 16
 
11
-const Cargando = () => <div><h2>loading...</h2></div>
17
+function LinearProgressWithLabel(props) {
18
+  return (
19
+    <Box sx={{ display: 'flex', alignItems: 'center' }}>
20
+      <Box sx={{ width: '100%', mr: 1 }}>
21
+        <LinearProgress variant="determinate" {...props} />
22
+      </Box>
23
+      <Box sx={{ minWidth: 35 }}>
24
+        <Typography variant="body2" color="text.secondary">{`${Math.round(
25
+          props.value,
26
+        )}%`}</Typography>
27
+      </Box>
28
+    </Box>
29
+  );
30
+}
12 31
 
13
-// Create Document Component
14 32
 const MyDocument = (props) => {
15 33
 
16 34
   let { pdf } = props;
@@ -22,30 +40,72 @@ const MyDocument = (props) => {
22 40
     setNumPages(numPages);
23 41
   }
24 42
 
25
-  function onLoadError(error) {
26
-    console.log('error: ', error)
43
+  const [progress, setProgress] = useState(10);
44
+
45
+  if(!pdf){
46
+    <Loading/>
27 47
   }
28 48
 
49
+  console.log(progress)
50
+
29 51
   return (
30 52
     <div>
53
+
54
+        {
55
+          progress < 100 ?
56
+          <LinearProgressWithLabel value={progress}/>
57
+            : null
58
+        }
59
+
31 60
       <div className="pdf_controls">
32
-        <Button variant="contained" onClick={() => pageNumber > 1 ? setPageNumber(pageNumber - 1) : null} >
61
+
62
+
63
+      <div className="btn_pdfcontrol">
64
+        <Button 
65
+            className="btnmain"
66
+            style={{ margin: 2 }} 
67
+            variant="contained" 
68
+            onClick={() => pageNumber > 1 ? setPageNumber(pageNumber - 1) : null} >
33 69
           Anterior
34 70
         </Button>
35
-        <Button style={{ margin: 5 }} variant="contained" onClick={() => pageNumber + 1 <= numPages   ? setPageNumber(pageNumber + 1) : null} >
71
+        <Button 
72
+            className="btnmain"
73
+            style={{ margin: 2 }} 
74
+            variant="contained" 
75
+            onClick={() => pageNumber + 1 <= numPages   ? setPageNumber(pageNumber + 1) : null} >
36 76
           Siguiente
37 77
         </Button>
78
+      </div>
79
+
80
+        <div>
81
+          <b style={{marginRight : 15}}>
82
+            Página {pageNumber} de {numPages}
83
+          </b>
38 84
 
39
-        <p>
40
-          Página {pageNumber} de {numPages}
41
-        </p>
85
+          <Button 
86
+            className="btnmain"
87
+            variant="contained" 
88
+            onClick={() => console.log('download')} >
89
+            <DownloadIcon/>
90
+          </Button>
91
+        </div>
42 92
 
43 93
       </div>
44 94
 
45
-      <div className="Example__container__document">
46
-        <Document renderMode="canvas" file={pdf.data} onLoadSuccess={onDocumentLoadSuccess} onLoadError={onLoadError}>
47
-          <Page width={800} pageNumber={pageNumber} loading={<Cargando />} />
48
-        </Document>
95
+      <div className="Example__container">
96
+        <div className="Example__container__document">
97
+          <Document 
98
+            renderMode="canvas" 
99
+            file={pdf?.data} 
100
+            onLoadSuccess={onDocumentLoadSuccess} 
101
+            loading={Loading}
102
+            onLoadProgress={({loaded, total}) => {
103
+              setProgress((loaded / total) * 100)
104
+            }}
105
+          >
106
+              <Page loading={Loading} pageNumber={pageNumber} />
107
+          </Document>
108
+        </div>
49 109
       </div>
50 110
     </div>
51 111
   )
@@ -76,14 +136,10 @@ export function Resultados() {
76 136
     <div className="content-section">
77 137
       <div className="main">
78 138
         <Box sx={{ width: '100%' }}>
79
-          <Paper elevation={0} sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh', boxShadow: 'none !important' }}>
80
-            <h1>Resultados {id}</h1>
81
-            <hr />
82
-            {
83
-              pdf ?
84
-                <MyDocument pdf={pdf} />
85
-                : <div> <h5> loading...</h5></div>
86
-            }
139
+          <Paper 
140
+            elevation={2} 
141
+            sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh', boxShadow: 'none !important' }}>
142
+            <MyDocument pdf={pdf} />
87 143
           </Paper>
88 144
         </Box>
89 145
       </div>

+ 80 - 0
src/pdf.css

@@ -0,0 +1,80 @@
1
+body {
2
+  margin: 0;
3
+  background-color: #525659;
4
+  font-family: Segoe UI, Tahoma, sans-serif;
5
+}
6
+
7
+.Example input,
8
+.Example button {
9
+  font: inherit;
10
+}
11
+
12
+.Example header {
13
+  background-color: #323639;
14
+  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
15
+  padding: 20px;
16
+  color: white;
17
+}
18
+
19
+.Example header h1 {
20
+  font-size: inherit;
21
+  margin: 0;
22
+}
23
+
24
+.Example__container {
25
+  display: flex;
26
+  flex-direction: column;
27
+  align-items: center;
28
+  margin: 0px;
29
+  padding: 0px;
30
+}
31
+
32
+.Example__container__load {
33
+  margin-top: 1em;
34
+  color: white;
35
+}
36
+
37
+.Example__container__document {
38
+  margin: 1em 0;
39
+}
40
+
41
+.Example__container__document .react-pdf__Document {
42
+  display: flex;
43
+  flex-direction: column;
44
+  align-items: center;
45
+}
46
+
47
+.Example__container__document .react-pdf__Page {
48
+  max-width: calc(100% - 2em);
49
+  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
50
+  margin: 1em;
51
+}
52
+
53
+.Example__container__document .react-pdf__Page canvas {
54
+  max-width: 100%;
55
+  height: auto !important;
56
+}
57
+
58
+.Example__container__document .react-pdf__message {
59
+  padding: 20px;
60
+  color: white;
61
+}
62
+
63
+.pdf_controls{
64
+  display: flex;
65
+  align-items: baseline;
66
+  justify-content: space-between;
67
+  align-content: stretch;
68
+}
69
+.btnmain:hover{
70
+  background:var(--main) !important;
71
+  color:white !important;
72
+}
73
+.btn_pdfcontrol{
74
+  display:flex;
75
+  gap:1
76
+}
77
+.btnmain{
78
+  color:white !important;
79
+  background:var(--main) !important;
80
+}