1
1
import { ref , computed } from "vue/dist/vue.esm-bundler" ;
2
2
import { NButton , NIcon , NModal , NCard } from "naive-ui" ;
3
- import { biBook , biListUl , biDownload , biShareFill , biFiletypeCsv } from "../icons.js" ;
3
+ import { biBook , biListUl , biDownload , biShareFill , biFiletypeCsv , biGraphUp } from "../icons.js" ;
4
4
import { formatToTable , timestampToYear } from "../utils.js" ;
5
5
import { useStore } from "vuex" ;
6
6
import CsvWriterGen from "csvwritergen" ;
@@ -64,34 +64,30 @@ export const subButtons = {
64
64
}
65
65
66
66
const downloadCsv = async ( ) => {
67
- let sick = store . state . content . form . sickImmunizer ;
68
- if ( ! sick || ! sick . length ) {
69
- store . commit ( 'message/ERROR' , "Selecione conteúdo para poder gerar csv" )
70
- return ;
71
- }
72
67
const periodStart = store . state . content . form . periodStart ;
73
68
const periodEnd = store . state . content . form . periodEnd ;
74
69
let years = [ ] ;
75
70
if ( periodStart ) {
76
- let y = timestampToYear ( periodStart ) ;
77
- while ( y <= timestampToYear ( periodEnd ) ) {
71
+ let y = periodStart ;
72
+ while ( y <= periodEnd ) {
78
73
years . push ( y ++ ) ;
79
74
}
80
75
}
81
76
82
- sick = Array . isArray ( store . state . content . form . sickImmunizer ) ?
83
- store . state . content . form . sickImmunizer : [ store . state . content . form . sickImmunizer ] ;
84
-
85
77
const currentResult = await store . dispatch ( "content/requestData" , { detail : true } ) ;
78
+ if ( ! currentResult ) {
79
+ store . commit ( 'message/ERROR' , "Preencha os seletores para gerar csv" )
80
+ return ;
81
+ }
86
82
const csvwriter = new CsvWriterGen ( currentResult . data . shift ( ) , currentResult . data ) ;
87
- csvwriter . anchorElement ( 'monitor- tabela' ) ;
83
+ csvwriter . anchorElement ( 'tabela' ) ;
88
84
}
89
85
90
86
const clickShowModal = ( ) => {
91
87
const map = document . querySelector ( "#canvas" ) ;
92
88
svg . value = map ?. innerHTML ;
93
89
const canvas = document . getElementById ( "chart" ) ;
94
- chartPNG . value = canvas ? .toDataURL ( 'image/png' , 1 ) ;
90
+ chartPNG . value = ! [ ... canvas . classList ] . includes ( "element-hidden" ) ? canvas ? .toDataURL ( 'image/png' , 1 ) : null ;
95
91
showModal . value = true ;
96
92
}
97
93
@@ -108,6 +104,10 @@ export const subButtons = {
108
104
const downloadChartAsImage = ( ) => {
109
105
const imageLink = document . createElement ( "a" ) ;
110
106
imageLink . download = 'chart.png' ;
107
+ if ( ! chartPNG . value ) {
108
+ store . commit ( 'message/ERROR' , "Preencha os seletores para gerar imagem" )
109
+ return ;
110
+ }
111
111
imageLink . href = chartPNG . value ;
112
112
imageLink . click ( ) ;
113
113
}
@@ -124,6 +124,7 @@ export const subButtons = {
124
124
biDownload,
125
125
biShareFill,
126
126
biFiletypeCsv,
127
+ biGraphUp,
127
128
downloadSvg,
128
129
downloadPng,
129
130
downloadCsv,
@@ -220,7 +221,7 @@ export const subButtons = {
220
221
>
221
222
Faça o download de conteúdos<br><br>
222
223
223
- <div v-if="svg || chartPNG" style="display: flex; flex-direction: column; gap: 12px">
224
+ <div style="display: flex; flex-direction: column; gap: 12px">
224
225
<div style="padding: 0px 0px 12px;">Gráficos</div>
225
226
<n-card v-if="svg" embedded :bordered="false">
226
227
<div style="display: flex; align-items: center; justify; justify-content: space-between;">
@@ -252,10 +253,19 @@ export const subButtons = {
252
253
</n-button>
253
254
</div>
254
255
</n-card>
255
- <n-card v-if="chartPNG" embedded :bordered="false">
256
+ <n-card embedded :bordered="false">
256
257
<div style="display: flex; align-items: center; justify; justify-content: space-between;">
257
- <div style="display: flex; gap: 12px">
258
- <img :src="chartPNG" style="max-width: 100px; background-color: white; box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;" />
258
+ <div style="display: flex; gap: 12px; align-items: center">
259
+ <img
260
+ v-if="chartPNG"
261
+ :src="chartPNG"
262
+ style="max-width: 100px;
263
+ background-color: white;
264
+ box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;"
265
+ />
266
+ <div v-else style="padding: 0px 24px">
267
+ <n-icon v-html="biGraphUp" size="50" />
268
+ </div>
259
269
<div>
260
270
<h3>Gráfico PNG</h3>
261
271
<p>Para impressões de alta qualidade e editável em softwares gráficos</p>
@@ -268,7 +278,24 @@ export const subButtons = {
268
278
</div>
269
279
</n-card>
270
280
</div>
271
- <div style="padding: 14px 0px 12px;">Dados</div>
281
+ <div style="padding: 14px 0px 12px; gap: 12px">Dados</div>
282
+ <n-card embedded :bordered="false">
283
+ <div style="display: flex; align-items: center; justify; justify-content: space-between;">
284
+ <div style="display: flex; gap: 12px; align-items: center">
285
+ <div style="padding: 0px 24px">
286
+ <n-icon v-html="biFiletypeCsv" size="50" />
287
+ </div>
288
+ <div>
289
+ <h3>Dados utilizados na interface em CSV</h3>
290
+ <p>Os dados que estão sendo utilizados nesta interface</p>
291
+ </div>
292
+ </div>
293
+ <n-button quaternary type="primary" style="font-weight: 500" @click="downloadCsv">
294
+ <template #icon><n-icon v-html="biDownload" /></template>
295
+ Baixar
296
+ </n-button>
297
+ </div>
298
+ </n-card>
272
299
<n-card embedded :bordered="false">
273
300
<div style="display: flex; align-items: center; justify; justify-content: space-between;">
274
301
<div style="display: flex; gap: 12px; align-items: center">
0 commit comments