Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.05 KB | None | 0 0
  1. <template>
  2. <v-container>
  3. <v-app-bar app clipped-right clipped-left>
  4. <div class="d-flex align-center">
  5. <a href="/Catalogo">
  6. <v-img :src="require('../assets/Prysmian_Group_Logo.png')" width="100">
  7. </v-img>
  8. </a>
  9. </div>
  10.  
  11. <div style="padding-left: 20px">
  12. <v-toolbar-title style="padding-left:10px; margin-top:15px" @click="openEditTitleDialog"
  13. >Editor de Templates <span v-if="getTitle.length > 0">- {{ getTitle }}</span></v-toolbar-title
  14. >
  15. <v-toolbar-items v-if="bar" class="my-3">
  16. <v-menu offset-y>
  17. <template v-slot:activator="{ on }">
  18. <v-btn text small v-on="on">
  19. Arquivo
  20. </v-btn>
  21. </template>
  22. <v-list>
  23. <v-list-item
  24. v-for="(item, index) in arquivoList"
  25. :key="index"
  26. @click="arquivoClicked(item)"
  27. >
  28. <v-list-item-title>{{ item }}</v-list-item-title>
  29. </v-list-item>
  30. </v-list>
  31. </v-menu>
  32.  
  33. <v-menu offset-y>
  34. <template v-slot:activator="{ on }">
  35. <v-btn text small v-on="on">
  36. Editar
  37. </v-btn>
  38. </template>
  39. </v-menu>
  40.  
  41. <v-menu offset-y>
  42. <template v-slot:activator="{ on }">
  43. <v-btn text small v-on="on">
  44. Exibir
  45. </v-btn>
  46. </template>
  47. <v-list>
  48. <v-list-item
  49. v-for="(item, index) in exibirList"
  50. :key="index"
  51. @click="exibirFullScreen(item)"
  52. >
  53. <v-list-item-title>{{ item }}</v-list-item-title>
  54. </v-list-item>
  55. </v-list>
  56. </v-menu>
  57.  
  58. <v-menu offset-y>
  59. <template v-slot:activator="{ on }">
  60. <v-btn text small v-on="on">
  61. Inserir
  62. </v-btn>
  63. </template>
  64. <v-list>
  65. <v-list-item
  66. v-for="(item, index) in insertList"
  67. :key="index"
  68. @click="inserirChange(index)"
  69. >
  70. <v-list-item-title>{{ item }}</v-list-item-title>
  71. </v-list-item>
  72. </v-list>
  73. </v-menu>
  74.  
  75. <v-dialog v-model="editNameDialog" width="500px">
  76. <v-card>
  77. <v-card-title class="headline grey lighten-2">
  78. Renomear
  79. </v-card-title>
  80. <v-card min-height="200px">
  81. <v-container>
  82. <v-row>
  83. <v-col>
  84. <v-text-field
  85. class="mt-4"
  86. v-model="editName"
  87. label="Título"
  88. ></v-text-field>
  89. </v-col>
  90. </v-row>
  91. </v-container>
  92. </v-card>
  93. <v-footer absolute>
  94. <v-spacer></v-spacer>
  95. <v-btn class="ma-2" tile @click="updateTitle">Confirmar</v-btn>
  96. <v-btn class="ma-2" tile @click="closeEditTitleDialog()">
  97. Cancelar
  98. </v-btn>
  99. </v-footer>
  100. </v-card>
  101. </v-dialog>
  102.  
  103. <v-dialog v-model="tableDialog" width="1500">
  104. <v-card>
  105. <v-card-title class="headline grey lighten-2">
  106. Adicionar tabela
  107. </v-card-title>
  108. <v-card min-height="500px">
  109. <v-navigation-drawer
  110. v-model="vShowTableNavigation"
  111. absolute
  112. clipped
  113. left
  114. >
  115. <v-list>
  116. <v-list-group>
  117. <template v-slot:activator>
  118. <v-list-item-content>
  119. <v-list-item-title>Atributos</v-list-item-title>
  120. </v-list-item-content>
  121. </template>
  122. <v-list-item
  123. v-for="(key, i) in availableData.keys()"
  124. :key="i"
  125. >
  126. <v-checkbox
  127. v-model="availableData.get(key).value"
  128. :label="key"
  129. @change="checkTransposed($event, key)"
  130. ></v-checkbox>
  131. </v-list-item>
  132. </v-list-group>
  133. </v-list>
  134. </v-navigation-drawer>
  135. <div class="d-block pa-6" style="float: right" v-if="analysis != null > 0">
  136. <v-switch
  137. v-model="switchTranspose"
  138. label="Transpor"
  139. @change="transpose"
  140. ></v-switch>
  141. <v-switch
  142. v-model="switch2"
  143. label="Destacar"
  144. @change="tableChangeHighlight"
  145. ></v-switch>
  146. </div>
  147. <p v-if="analysis != null > 0"
  148. class="text-center font-weight-medium"
  149. style="margin-left: 200px"
  150. >
  151. Selecione os atributos da tabela
  152. </p>
  153. <p v-else class="text-center">No data available</p>
  154. <vue-table-dynamic
  155. v-show="showTable"
  156. style="width: 1000px"
  157. class="mx-auto pa-4"
  158. :params="params"
  159. ></vue-table-dynamic>
  160. </v-card>
  161. <v-footer absolute>
  162. <v-spacer></v-spacer>
  163. <v-btn class="ma-2" tile @click="teste()" v-if="analysis != null > 0">Confirmar</v-btn>
  164. <v-btn class="ma-2" tile @click="closeTableDialog()">
  165. Cancelar
  166. </v-btn>
  167. </v-footer>
  168. </v-card>
  169. </v-dialog>
  170. <v-dialog v-model="imageDialog" width="1200">
  171. <v-card>
  172. <v-card-title class="headline grey lighten-2">
  173. Adicionar imagens
  174. <div class="cursor align-right" @click="closeImageDialog()">
  175. <v-icon left>mdi-close</v-icon>
  176. </div>
  177. </v-card-title>
  178. <v-card min-height="500px">
  179. <v-tabs vertical>
  180. <v-tab>
  181. <v-icon left>mdi-image-multiple</v-icon>
  182. <div @click="getImages()">
  183. Banco de imagens
  184. </div>
  185. </v-tab>
  186. <v-tab>
  187. <v-icon left>mdi-image-multiple</v-icon>
  188. Upload de fotos
  189. </v-tab>
  190. <v-tab-item>
  191. <v-autocomplete
  192. v-model="select"
  193. :items="imgDataName"
  194. :search-input.sync="search"
  195. cache-items
  196. class="searchingImage"
  197. flat
  198. hide-no-data
  199. hide-details
  200. label="Pesquisar imagem"
  201. solo
  202. outlined
  203. ></v-autocomplete>
  204. <v-container
  205. style="max-height: 400px"
  206. class="overflow-y-auto"
  207. fluid
  208. >
  209. <v-row dense>
  210. <v-col
  211. v-for="img in tempImgData"
  212. :key="img.src"
  213. :cols="3"
  214. >
  215. <div class="cursor" @click="addImage($event, img)">
  216. <v-img
  217. :src="img.src"
  218. class="white--text align-end"
  219. gradient="to bottom, rgba(0,0,0,.1), rgba(0,0,0,.5)"
  220. height="200px"
  221. width="200px"
  222. >
  223. </v-img>
  224. </div>
  225. </v-col>
  226. </v-row>
  227. </v-container>
  228. </v-tab-item>
  229. <v-tab-item centered>
  230. <input
  231. type="file"
  232. ref="file"
  233. style="display: none;"
  234. @change="addImage($event)"
  235. />
  236. <div class="cursor" @click="$refs.file.click()">
  237. <v-content>
  238. <v-container class="fill-height" fluid>
  239. <v-row align="center" justify="center">
  240. <v-col align="center">
  241. <v-icon size="100">mdi-cloud-upload</v-icon>
  242. <p>
  243. Clique nesta região para fazer upload de imagem.
  244. </p>
  245. </v-col>
  246. </v-row>
  247. </v-container>
  248. </v-content>
  249. </div>
  250. </v-tab-item>
  251. </v-tabs>
  252. </v-card>
  253.  
  254. <v-footer absolute>
  255. <v-spacer></v-spacer>
  256. <v-btn class="ma-2" tile @click="closeImageDialog()">
  257. Fechar
  258. </v-btn>
  259. </v-footer>
  260. </v-card>
  261. </v-dialog>
  262. <v-menu offset-y>
  263. <template v-slot:activator="{ on }">
  264. <v-btn text small v-on="on">
  265. Página
  266. </v-btn>
  267. </template>
  268. </v-menu>
  269.  
  270. <v-menu offset-y>
  271. <template v-slot:activator="{ on }">
  272. <v-btn text small v-on="on">
  273. Organizar
  274. </v-btn>
  275. </template>
  276. </v-menu>
  277. </v-toolbar-items>
  278. </div>
  279. <v-spacer></v-spacer>
  280. <div>
  281. <v-btn
  282. small
  283. dark
  284. color="blue"
  285. @click="viewPdf()"
  286. style="margin-right: 10px;"
  287. >
  288. {{ this.viewDocLabel }}
  289. <v-btn small icon>
  290. <v-icon>{{ this.iconLabel }}</v-icon>
  291. </v-btn>
  292. </v-btn>
  293. <v-btn
  294. small
  295. dark
  296. color="blue"
  297. @click="openReportDialog()"
  298. style="margin-right: 10px;"
  299. >
  300. Visualizar em PDF
  301. </v-btn>
  302. <v-btn
  303. small
  304. dark
  305. color="blue"
  306. @click="save"
  307. style="margin-right: 10px;"
  308. >
  309. Salvar
  310. </v-btn>
  311. <v-btn small icon @click="getPDF()">
  312. <v-icon>mdi-download</v-icon>
  313. </v-btn>
  314. <v-btn icon>
  315. <v-icon>mdi-account</v-icon>
  316. </v-btn>
  317. </div>
  318. <template v-if="bar" v-slot:extension>
  319. <div id="toolbar" class="d-flex align-center">
  320. <v-row>
  321. <ToolBar
  322. @addPage="addPage"
  323. @nextPage="nextPage"
  324. @previousPage="previousPage"
  325. @addTable="addTableModal"
  326. @addImage="modalAddImage"
  327. @contextmenu.prevent="$refs.menu.open"
  328. @addText="addText('Texto')"
  329. @addSquare="addSquare"
  330. @addLine="addLine"
  331. :currentPage="selectedPage"
  332. :maxPage="allObjects.length"
  333. ></ToolBar>
  334. </v-row>
  335. </div>
  336. </template>
  337. </v-app-bar>
  338. <v-container style="margin: 0; min-width: 100%; padding: 0">
  339. <TemplateEditor
  340. :selected-page="this.selectedPage"
  341. style="margin-top: 100px"
  342. ref="template"
  343. :divideTable="dividir"
  344. :editTable="editar"
  345. ></TemplateEditor>
  346. </v-container>
  347. <!-- <vue-table-dynamic
  348. style="width: 1000px"
  349. id="tabela"
  350. v-if="vShowTable"
  351. :params="params"
  352. ></vue-table-dynamic> -->
  353. <v-dialog v-model="dataSource" persistent max-width="1000px">
  354. <v-card min-height="500px">
  355. <v-card-title class="headline grey lighten-2"
  356. >Adicionar fonte de dados:</v-card-title
  357. >
  358. <v-progress-linear
  359. indeterminate
  360. :active="loadingSourceData"
  361. ></v-progress-linear>
  362. <v-card-text>
  363. <div class="my-12">
  364. <v-row>
  365. <v-col class="my-auto">
  366. <p class="font-weight-medium">Escolher Fonte de Dados:</p>
  367. <v-select
  368. class="mr-12"
  369. :items="sourceList"
  370. v-model="dataSourceFont"
  371. ></v-select>
  372. </v-col>
  373. <v-col>
  374. <p class="font-weight-medium">Código: {{ dataSourceError }}</p>
  375. <v-text-field
  376. class="mt-4"
  377. v-model="dataSourceCode"
  378. ></v-text-field>
  379. </v-col>
  380. </v-row>
  381. </div>
  382. </v-card-text>
  383. <v-footer absolute>
  384. <v-spacer></v-spacer>
  385. <v-btn class="ma-2" @click="getData()">Confirmar</v-btn>
  386. <v-btn class="ma-2" @click="dataSourceCancelButton()">Cancelar</v-btn>
  387. </v-footer>
  388. </v-card>
  389. </v-dialog>
  390. <v-row justify="center">
  391. <v-dialog
  392. v-model="dialogPdf"
  393. fullscreen
  394. hide-overlay
  395. transition="dialog-bottom-transition"
  396. >
  397. <v-app-bar dark fixed>
  398. <v-btn icon dark @click="closeReportDialog()">
  399. <v-icon>mdi-close</v-icon>
  400. </v-btn>
  401. <v-toolbar-title>Visualizar relatório</v-toolbar-title>
  402. <v-spacer></v-spacer>
  403. <v-toolbar-items>
  404. <v-btn small class="mr-4" text icon @click="getPDF()">
  405. <v-icon>mdi-download</v-icon>
  406. </v-btn>
  407. </v-toolbar-items>
  408. </v-app-bar>
  409. <v-card color="#fafafa">
  410. <ReportViewer
  411. style="margin-top: 70px"
  412. :reportMode="true"
  413. :objects="this.allObjects"
  414. ></ReportViewer>
  415. </v-card>
  416. </v-dialog>
  417. </v-row>
  418. </v-container>
  419. </template>
  420.  
  421. <script>
  422. import Vue from "vue";
  423. import TemplateEditor from "../components/TemplateEditor.vue";
  424. import ReportViewer from "../components/ReportViewer.vue";
  425. import PdfService from "../services/PdfService";
  426. import ToolBar from "../components/ToolBar.vue";
  427. import VueTableDynamic from "vue-table-dynamic";
  428. //import html2canvas from "html2canvas";
  429. import { eventBus } from "../main";
  430. import HTTP from "../services/HttpService";
  431. import { mapGetters, mapMutations, mapActions } from "vuex";
  432. import Konva from "konva";
  433.  
  434. export default Vue.extend({
  435. name: "AppBar",
  436. components: {
  437. ToolBar,
  438. TemplateEditor,
  439. ReportViewer,
  440. VueTableDynamic
  441. },
  442. computed: {
  443. ...mapGetters([
  444. "allObjects",
  445. "selectedPage",
  446. "analysis",
  447. "getId",
  448. "getTitle",
  449. "stage",
  450. "layer"
  451. ])
  452. },
  453. data: () => ({
  454. // objects: [],
  455. //selectedPage: 0,
  456. select: null,
  457. bar: true,
  458. dataSource: false,
  459. loadingSourceData: false,
  460. dataSourceFont: 'Código da Família',
  461. dataSourceError: "",
  462. dataSourceCode: "",
  463. sourceList: ['Código da Família', 'Número de análise'],
  464. arquivoList: ["Novo", "Salvar", "Exportar para PDF"],
  465. imageDialog: false,
  466. exibirList: ["Tela cheia"],
  467. tableDialog: false,
  468. insertList: ["Fonte de dados"],
  469. params: {
  470. data: [],
  471. stripe: true,
  472. border: true,
  473. header: "column"
  474. },
  475. dialogPdf: false,
  476. isTransposed: false,
  477. imgData: [],
  478. viewDocLabel: "Visualizar",
  479. iconLabel: "mdi-eye-outline",
  480. imgDataName: [],
  481. tempImgData: [],
  482. viewDoc: false,
  483. search: null,
  484. showTable: false,
  485. printView: false,
  486. availableData: new Map(),
  487. vShowTableNavigation: false,
  488. vShowTable: false,
  489. switchTranspose: false,
  490. switch2: false,
  491. tableSliceLine: null,
  492. tableId: null,
  493. tableEditing: false,
  494. tableEditPositionX: null,
  495. tableEditPositionY: null,
  496. editNameDialog: false,
  497. editName: ""
  498. }),
  499. watch: {
  500. search(val) {
  501. if (!val) {
  502. this.getImages();
  503. } else {
  504. this.tempImgData = this.imgData.filter(img => img.name.includes(val));
  505. }
  506. }
  507. },
  508. methods: {
  509. ...mapMutations(["addObject", "addElement", "addAnalyse", "setTitle"]),
  510. ...mapActions(["addPage", "nextPage", "previousPage"]),
  511.  
  512. addElementTable(group){
  513. var ss = this;
  514. var groupMousedown = function(){
  515. ss.tableId = this.id();
  516. }
  517. var datap = this.params.data;
  518. var colors = datap;
  519. this.addElement({
  520. type: "TABLE",
  521. item: group,
  522. data: colors,
  523. mousedown: groupMousedown,
  524. transposed: this.isTransposed,
  525. });
  526. },
  527.  
  528. async teste(){
  529. console.log('funcao teste');
  530. var stage = this.stage;
  531. var name = 'TABLE' + Math.random() * 1561564;
  532. console.log(name);
  533. var group = {
  534. x: this.tableEditPositionX == null ? 0 : this.tableEditPositionX,
  535. y: this.tableEditPositionY == null ? 500 : this.tableEditPositionY,
  536. draggable: true,
  537. dragBoundFunc: this.dragFunction,
  538. name: name,
  539. }
  540. await this.addElementTable(group);
  541.  
  542. var node = stage.findOne('.' + name);
  543. console.log('NODE', node);
  544. var box = Konva.Text({
  545. x: 0,
  546. y: 300,
  547. width: 100,
  548. height: 20,//text.height(),
  549. fill: '#f0f5f5',
  550. })
  551. node.children.push(box);
  552.  
  553. // var stageChildremSize = stage.children.length;
  554. // for(var i = 0; i < stageChildremSize; i++){
  555. // var layer = stage.children[i];
  556. // var layerChildremSize = layer.children.length;
  557. // console.log(layer);
  558. // for(var j = 0; j < layerChildremSize; j++)
  559. // {
  560. // if(i > 0)console.log(layer.children[j]);
  561. // }
  562. // }
  563. },
  564.  
  565.  
  566. teste1(){
  567. var stage = this.stage;
  568. var layer = this.layer;
  569. var name = 'TABLE' + Math.random() * 1561564;
  570. console.log('name', name);
  571. var group = {
  572. x: this.tableEditPositionX == null ? 0 : this.tableEditPositionX,
  573. y: this.tableEditPositionY == null ? 500 : this.tableEditPositionY,
  574. draggable: true,
  575. dragBoundFunc: this.dragFunction,
  576. id: 'TABLE' + Math.random() * 1561564
  577. }
  578. var children = [];
  579. var datap = this.params.data;
  580. console.log(datap)
  581. console.log(datap[0].length);
  582. var colors = datap;
  583. var initialPosX = 30;
  584. var initialPosY = 18;
  585. var x = initialPosX;
  586. var y = initialPosY;
  587. var txtHeight;
  588. var konvaRectSize = 739/colors[0].length;
  589.  
  590. for(var j = 0; j < colors.length; j++)
  591. {
  592. // var groupItens = new Konva.Group();
  593. // groupItens.name = j;//`${j}`
  594. var child = {
  595. name: j, //mudar para idx
  596. list: [],
  597. mousedown: ''
  598. };
  599. var list = colors[j]
  600. for (var i = 0; i < list.length; i++) {
  601. var text = {
  602. x: x += konvaRectSize,
  603. y: y,
  604. width: konvaRectSize,
  605. height: 30,
  606. text: colors[j][i],
  607. fontSize: 12,
  608. padding: 10,
  609. align: 'center'
  610. };
  611. // if(this.switch2 && j == 0)text.fontStyle('bold');
  612. // else if(this.switch2 == false && i == 0)text.fontStyle('bold');
  613. txtHeight = 20//= text.height();
  614. var box = {
  615. x: x,
  616. y: y,
  617. width: konvaRectSize,
  618. height: 20,//text.height(),
  619. fill: j%2 == 0 ? '#f0f5f5' : '#ffffff',
  620. stroke: 'black',
  621. strokeWidth: 0
  622. };
  623. // groupItens.add(box);
  624. // groupItens.add(text);
  625. child.list.push(box);
  626. child.list.push(text);
  627. }
  628. const s = this;
  629. // groupItens.on('mousedown', function(){
  630. // console.log('mousedown', this.name);
  631. // s.tableSliceLine = this.name;
  632. // });
  633. child.mousedown = function(){
  634. console.log('mousedown', this.name);
  635. s.tableSliceLine = this.name;
  636. };
  637. //group.add(groupItens);
  638. children.push(child);
  639. x = initialPosX;
  640. y += txtHeight;
  641. }
  642. var ss = this;
  643. // group.on('mousedown', function(){
  644. // console.log(this.id());
  645. // ss.tableId = this.id();
  646. // });
  647. var groupMousedown = function(){
  648. ss.tableId = this.id();
  649. }
  650. if(this.tableEditing)
  651. {
  652. var idx;
  653. var obj = this.allObjects[0];
  654. for(var k = 0; k < obj.length; k++)
  655. {
  656. var item = obj[k];
  657. if(item.type === 'TABLE'){
  658. console.log('id: ', item.item.id()) //mudar isso
  659. if(this.tableId !== item.item.id())continue;
  660. idx = k;
  661. break;
  662. }
  663. }
  664. layer.add(group);
  665. // stage.add(layer);
  666. this.allObjects[0][idx] = {
  667. type: "TABLE",
  668. item: group,
  669. data: colors,
  670. // layer: layer,
  671. transposed: this.isTransposed
  672. }
  673. var len = stage.children.length;
  674. var removeThis = null;
  675. console.log('antes de td')
  676. for(k = 0; k < len; k++)
  677. {
  678. if(stage.children[k] instanceof Konva.Layer)
  679. {
  680. console.log('instance de layer')
  681. var lay = stage.children[k].children;
  682. var l = lay.length;
  683. for(var ks = 0; ks < l; ks++)
  684. {
  685. if(lay[ks] instanceof Konva.Group)
  686. {
  687. console.log('instance de group')
  688. console.log(lay[ks]);
  689. var gp = lay[ks];
  690. console.log(gp.id());
  691. if(gp.id() === this.tableId)
  692. {
  693. //remover layer
  694. // removeThis = k;
  695. gp.remove();
  696. // console.log('no q eu quero destruir', gp.id());
  697. // console.log('id', removeThis);
  698. break;
  699. }
  700. }
  701. }
  702. if(removeThis != null)break;
  703. }
  704. }
  705. // if(removeThis != null)stage.children[removeThis].remove(); //to removendo o layer inteiro
  706. layer.draw();
  707. }
  708. else{
  709. // layer.add(group)
  710. // layer.draw();
  711. // stage.add(layer)
  712. console.log('dentro do else')
  713. this.addElement({
  714. type: "TABLE",
  715. item: {
  716. x: this.tableEditPositionX == null ? 0 : this.tableEditPositionX,
  717. y: this.tableEditPositionY == null ? 500 : this.tableEditPositionY,
  718. draggable: true,
  719. dragBoundFunc: this.dragFunction,
  720. name: name //name-id
  721. },
  722. data: colors,
  723. mousedown: groupMousedown,
  724. transposed: this.isTransposed,
  725. });
  726. }
  727.  
  728. len = stage.children.length;
  729. var node;
  730. for(k = 0; k < len; k++){
  731. console.log('nome atual', name)
  732. var stagecl = stage.children[k];
  733. console.log(stagecl);
  734. var len2 = stagecl.children.length
  735. for(i = 0; i < len2; i++)
  736. {
  737. // console.log('no', l.children[i]);
  738. if(stagecl.children[i] instanceof Konva.Group)
  739. {
  740. console.log('idx', i)
  741. console.log('É GRUPO')
  742. console.log(stagecl.children[i])
  743. }
  744. if(stagecl.children[i].name() == name)
  745. {
  746. console.log('achei');
  747. node = stagecl.children[i];
  748. }
  749. }
  750. }
  751.  
  752. console.log(node);
  753. this.closeTableDialog();
  754. },
  755.  
  756. dividir(){
  757. if(this.tableSliceLine == null){
  758. console.log('tableSliceLine == null');
  759. return;
  760. }
  761. var idx = parseInt(this.tableSliceLine, 10);
  762. console.log('indice', this.tableSliceLine)
  763. var obj = this.allObjects[0]; //USAR SELECTED PAGE
  764. console.log(obj);
  765. // var stage = this.stage;
  766. var layer = this.layer;
  767. for(var i = 0; i < obj.length; i++)
  768. {
  769. var item = obj[i];
  770. if(item.type === 'TABLE'){
  771. console.log('id: ', item.item.id());
  772. if(this.tableId !== item.item.id())continue;
  773. console.log('is table')
  774. var group = new Konva.Group({
  775. x: 0,
  776. y: 500,
  777. draggable: true,
  778. dragBoundFunc: this.dragFunction,
  779. id: 'TABLE' + Math.random() * 1561564
  780. });
  781. var ss = this;
  782. group.on('mousedown', function(){
  783. console.log(this.id());
  784. ss.tableId = this.id();
  785. });
  786. var child = item.item;
  787. // console.log(child.children);
  788. // group.add(child.children[2]);
  789. // child.children[2].remove();
  790. // group.add(child.children[1]);
  791. // child.children[1].remove();
  792.  
  793. var list1 = []
  794. var list2 = []
  795. // list1.push(item.data[0]);
  796. // list2.push(item.data[1]);
  797. // list2.push(item.data[2]);
  798. //var indiceName = 0;
  799. console.log('idx', idx)
  800. var indiceName = 0;
  801. var len = child.children.length;
  802. console.log('tamanho da lista inteira', len);
  803. for(var j = idx; j < len; j++)
  804. {
  805. console.log(j)
  806. child.children[idx].name = indiceName;
  807. group.add(child.children[idx]);
  808. list2.push(item.data[j]);
  809. indiceName++;
  810. }
  811. // for(var j = child.children.length - 1; j >= idx; j--){
  812. // child.children[j].name = j - idx;
  813. // group.add(child.children[j]);
  814. // list2.push(item.data[j]);
  815. // }
  816. // group.draw();
  817. for(j = 0; j < idx; j++)
  818. {
  819. list1.push(item.data[j]);
  820. }
  821. item.data = list1;
  822. this.addElement({
  823. type: "TABLE",
  824. item: group,
  825. data: list2,
  826. // layer: layer,
  827. transposed: item.transposed,
  828. });
  829. layer.add(group)
  830. // stage.add(layer)
  831. layer.draw();
  832. // item.layer.draw();
  833. break;
  834. }
  835. }
  836. },
  837. editar(){
  838. var obj = this.allObjects[0]; //OBJETOS DA PAGINA 0
  839. for(var i = 0; i < obj.length; i++)
  840. {
  841. var item = obj[i];
  842. if(item.type === 'TABLE')
  843. {
  844. console.log('id: ', item.item.id())
  845. if(this.tableId !== item.item.id())continue;
  846. this.tableEditing = true;
  847. console.log('position: ', 'x ',item.item.x(), 'y ', item.item.y());
  848. this.tableEditPositionX = item.item.x();
  849. this.tableEditPositionY = item.item.y();
  850. // this.params.data = item.data;
  851. // console.log('params', this.params.data);
  852. this.isTransposed = item.transposed;
  853. this.addTableModal();
  854. console.log(' ITEM DATA ', item.data);
  855. var len = item.data.length;
  856. console.log(len);
  857. for(var j = 0; j < len; j++)
  858. {
  859. console.log(item.data[j][0]);
  860. // console.log(this.params.data[j][0]);
  861. this.checkTransposed(true, item.data[j][0]);
  862.  
  863. }
  864. // this.showTable = true;
  865.  
  866. }
  867. }
  868. },
  869. openEditTitleDialog() {
  870. this.editName = this.getTitle;
  871. this.editNameDialog = true;
  872. },
  873. closeEditTitleDialog() {
  874. this.editNameDialog = false;
  875. },
  876. updateTitle() {
  877. let id = this.getId;
  878. HTTP.patch(`Catalogos/${id}`, [{ "op": "replace", "path": "/Nome", "value": this.editName }]).then(() => {
  879. this.setTitle(this.editName);
  880. this.editNameDialog = false;
  881. });
  882. },
  883. dragFunction(pos) {
  884. return {
  885. x: Math.round(pos.x / 10) * 10,
  886. y: Math.round(pos.y / 10) * 10
  887. };
  888. },
  889. addText(txt) {
  890. this.addElement({
  891. type: "TEXT",
  892. item: {
  893. text: txt != "[object MouseEvent]" ? txt : "Texto",
  894. x: 270,
  895. y: 80,
  896. width: 250,
  897. height: 20,
  898. fill: "#000000",
  899. name: "text" + Math.random() * 1561564,
  900. fontSize: 14,
  901. fontStyle: "normal",
  902. draggable: true,
  903. dragBoundFunc: this.dragFunction
  904. }
  905. });
  906. },
  907. addSquare() {
  908. this.addElement({
  909. type: "RECT",
  910. item: {
  911. x: 10,
  912. y: 10,
  913. width: 100,
  914. height: 100,
  915. fill: "#7E7E7E",
  916. name: "rect" + Math.random() * 1561564,
  917. draggable: true,
  918. dragBoundFunc: this.dragFunction
  919. }
  920. });
  921. },
  922. addLine() {
  923. this.addElement({
  924. type: "LINE",
  925. item: {
  926. points: [250, 70, 250, 23],
  927. stroke: "#DCDCDC",
  928. strokeWidth: 2,
  929. name: "line" + Math.random() * 1561564
  930. }
  931. });
  932. },
  933. getImages() {
  934. this.imgData = [];
  935. HTTP.get("http://localhost:64285/api/Imagens/").then(response => {
  936. for (var i = 0; i < response.data.length; i++) {
  937. const imgName = response.data[i].Nome;
  938. HTTP.get(
  939. "http://localhost:64285/api/Imagens/" +
  940. response.data[i].Id +
  941. "/file",
  942. {
  943. responseType: "blob"
  944. }
  945. ).then(response => {
  946. const image = new window.Image();
  947. image.src = URL.createObjectURL(response.data);
  948. this.imgData.push({
  949. name: imgName,
  950. src: image.src
  951. });
  952. this.imgDataName.push(imgName);
  953. });
  954. }
  955. });
  956.  
  957. this.tempImgData = this.imgData;
  958. },
  959. addImage(event, img) {
  960. const image = new window.Image();
  961. let imgName = "";
  962. let file = "";
  963. if (img) {
  964. image.src = img.src;
  965. } else {
  966. file = event.target.files[0];
  967. imgName = file.name;
  968. image.src = URL.createObjectURL(file);
  969. }
  970. image.onload = () => {
  971. // set image only when it is loaded
  972. this.addElement({
  973. type: "IMAGE",
  974. item: {
  975. x: 200,
  976. y: 50,
  977. image: image,
  978. name: imgName || img.name,
  979. width: image.width || 250,
  980. height: image.height || 100,
  981. draggable: true,
  982. dragBoundFunc: this.dragFunction,
  983. type: "image"
  984. }
  985. });
  986. };
  987.  
  988. if (file) {
  989. let fd = new FormData();
  990. fd.append("image", file);
  991.  
  992. HTTP.post("http://localhost:64285/api/Imagens", fd).then(response =>
  993. console.log(response)
  994. );
  995. }
  996. this.closeImageDialog();
  997. },
  998. addTableElementAsImage(img, w, h) {
  999. const image = new window.Image();
  1000. image.src = img;
  1001. image.onload = () => {
  1002. // set image only when it is loaded
  1003. this.addElement({
  1004. type: "IMAGE",
  1005. item: {
  1006. x: 200,
  1007. y: 50,
  1008. image: image,
  1009. name: "table" + Math.random() * 1561564,
  1010. width: w,
  1011. height: h,
  1012. draggable: true,
  1013. dragBoundFunc: this.dragFunction,
  1014. type: "image"
  1015. }
  1016. });
  1017. };
  1018. },
  1019. getPDF() {
  1020. let a = new PdfService();
  1021. a.createPDF(this.allObjects);
  1022. },
  1023. viewPdf() {
  1024. this.viewDoc ^= true;
  1025. this.bar = !this.viewDoc;
  1026. this.viewDocLabel = this.viewDoc ? "Editar" : "Visualizar";
  1027. this.iconLabel = this.viewDoc ? "mdi-pencil" : "mdi-eye-outline";
  1028. eventBus.$emit("viewPdf", this.viewDoc);
  1029. },
  1030. openReportDialog() {
  1031. this.dialogPdf = true;
  1032. eventBus.$emit("viewPdf", this.dialogPdf);
  1033. },
  1034. closeReportDialog() {
  1035. this.dialogPdf = false;
  1036. eventBus.$emit("viewPdf", this.dialogPdf);
  1037. },
  1038. exibirChange(index) {
  1039. console.log("Exibir idx = " + index);
  1040. },
  1041. inserirChange(index) {
  1042. if (this.insertList[index] === "Fonte de dados") {
  1043. this.dataSource = true;
  1044. }
  1045. },
  1046. modalAddImage() {
  1047. this.imageDialog = true;
  1048. this.getImages();
  1049. },
  1050. addTableModal(){
  1051. this.tableDialog = true;
  1052. if(this.analysis != null > 0)
  1053. {
  1054. this.createTable();
  1055. }
  1056. },
  1057. createTable() { //marcar os objetos no map que ja tiverem na tabela de EDIT
  1058. var data = this.analysis;
  1059. var arr = Object.entries(data[0]);
  1060. for (var i = 1; i < data.length; i++) {
  1061. var j = Object.entries(data[i]);
  1062. for (var k = 0; k < j.length; k++) {
  1063. arr[k].push(j[k][1]);
  1064. }
  1065. }
  1066. for (var idx = 0; idx < arr.length; idx++) {
  1067. this.availableData.set(
  1068. arr[idx][0],
  1069. {
  1070. data: arr[idx],
  1071. value: false,
  1072. });
  1073. }
  1074. console.log(this.availableData);
  1075. this.vShowTableNavigation = true;
  1076. },
  1077. checkTransposed(isChecked, item) {
  1078. // console.log('aqui', isChecked, item);
  1079. if (this.isTransposed) {
  1080. if (this.params.data.length === 0) {
  1081. this.onSelect(isChecked, item);
  1082. this.transpose(true);
  1083. } else {
  1084. this.transpose(false);
  1085. this.onSelect(isChecked, item);
  1086. if (this.params.data.length != 0) {
  1087. this.transpose(true);
  1088. }
  1089. }
  1090. } else {
  1091. this.onSelect(isChecked, item);
  1092. }
  1093. },
  1094. onSelect(isChecked, item){
  1095. if (isChecked) {
  1096. this.params.data.push(this.availableData.get(item).data); //retorna a linha da tabela
  1097. this.availableData.get(item).value = true;
  1098. this.showTable = true;
  1099. } else {
  1100. if (this.params.data.length === 1) {
  1101. this.params.data = [];
  1102. this.showTable = false;
  1103. } else {
  1104. var arr1, arr2;
  1105. for (var i = 0; i < this.params.data.length; i++) {
  1106. if (this.params.data[i][0] === item) {
  1107. arr1 = this.params.data.slice(i + 1); //checar indice 0
  1108. arr2 = this.params.data.slice(0, i);
  1109. break;
  1110. }
  1111. }
  1112. this.params.data = arr1.concat(arr2);
  1113. }
  1114. this.availableData.get(item).value = false;
  1115. }
  1116. },
  1117. closeTableDialog() {
  1118. this.params.header = "column";
  1119. this.vShowTableNavigation = false;
  1120. this.vShowTable = false;
  1121. this.tableDialog = false;
  1122. this.params.data = [];
  1123. this.isTransposed = false;
  1124. this.showTable = false;
  1125. this.availableData = new Map();
  1126. this.switchTranspose = false;
  1127. this.switch2 = false;
  1128. this.tableEditPositionX = null,
  1129. this.tableEditPositionY = null,
  1130. this.tableEditing = false
  1131. },
  1132. closeImageDialog() {
  1133. this.imageDialog = false;
  1134. },
  1135. arquivoClicked(item) {
  1136. switch (item) {
  1137. case "Exportar para PDF":
  1138. this.getPDF();
  1139. break;
  1140. default:
  1141. break;
  1142. }
  1143. },
  1144. transpose(event){
  1145. this.isTransposed = event
  1146. if(this.params.data == null)return
  1147. var matrix = this.params.data
  1148. var arr = []
  1149. for(var i = 0; i < matrix[0].length; i++)
  1150. {
  1151. var list = []
  1152. for(var j = 0; j < matrix.length; j++)
  1153. {
  1154. // console.log(matrix[j][i])
  1155. list.push(matrix[j][i]);
  1156. // console.log(arr)
  1157. }
  1158. arr.push(list);
  1159. }
  1160. // console.log(arr)
  1161. this.params.data = arr;
  1162. },
  1163. showTableAsync() {
  1164. return (this.vShowTable = true);
  1165. },
  1166. // async addTable() { //COLOCAR AQUI para criar tabela com params.data
  1167. // window.scrollTo(0, 0);
  1168. // await this.showTableAsync();
  1169. // this.printTable();
  1170. // this.closeTableDialog();
  1171. // },
  1172. tableChangeHighlight(event) {
  1173. this.params.header = event == true ? "row" : "column";
  1174. },
  1175. // printTable() {
  1176. // html2canvas(document.querySelector("#tabela")).then(canvas => {
  1177. // // console.log(canvas.toDataURL("image/png"))
  1178. // var image = canvas.toDataURL("image/png");
  1179. // // console.log(canvas)
  1180. // // console.log(canvas.width)
  1181. // // console.log(canvas.height)
  1182. // this.addTableElementAsImage(
  1183. // image,
  1184. // canvas.width * 0.75,
  1185. // canvas.height * 0.75
  1186. // );
  1187. // });
  1188. // },
  1189. dataSourceCancelButton() {
  1190. this.dataSource = false;
  1191. this.dataSourceFont = "Código da Família";
  1192. this.dataSourceCode = "";
  1193. },
  1194. checkDataSource(dataSrc, type) {
  1195. if (dataSrc[0] != null) {
  1196. this.addAnalyse(dataSrc);
  1197. // var id = this.getId;
  1198. // var link = `catalogos/${id}`;
  1199. var link = "catalogos/1";
  1200. var value = "{" + '"' + type + '":' + '"' + this.dataSourceCode + '"' + "}";
  1201. //console.log(value, link);
  1202. HTTP.patch(link,
  1203. [
  1204. { "op": "replace", "path": "/JsonFonteDados", "value": value},
  1205. ]
  1206. );
  1207. this.dataSourceCancelButton();
  1208. } else {
  1209. this.dataSourceError = "Não encontrado";
  1210. setTimeout(
  1211. function() {
  1212. this.dataSourceError = "";
  1213. }.bind(this),
  1214. 3000
  1215. );
  1216. }
  1217. },
  1218. getData() {
  1219. this.dataSourceError = "";
  1220. this.loadingSourceData = true;
  1221. var link = "";
  1222. if (this.dataSourceFont === this.sourceList[0]) {
  1223. link = "Analises?codigoFamilia=" + this.dataSourceCode;
  1224. HTTP.get(link).then(response => {
  1225. var type = "codigoFamilia";
  1226. this.checkDataSource(response.data, type); //CHECKDATASRC
  1227. this.loadingSourceData = false;
  1228. });
  1229. } else {
  1230. link = "Analises?numeroAnalise=" + this.dataSourceCode;
  1231. HTTP.get(link).then(response => {
  1232. var type = "numeroAnalise";
  1233. this.checkDataSource(response.data, type);
  1234. this.loadingSourceData = false;
  1235. });
  1236. }
  1237. },
  1238. save() {
  1239. let id = this.getId;
  1240. let json = JSON.stringify(this.allObjects);
  1241. HTTP.get(`Catalogos/${id}`).then(response => {
  1242. let objectToSave = response.data;
  1243. objectToSave.JsonCanvas = json;
  1244. HTTP.put(`Catalogos/${id}`, objectToSave).then(resp => {
  1245. console.log(resp);
  1246. });
  1247. });
  1248. }
  1249. },
  1250. // mounted(){
  1251. // let currentShape;
  1252. // var menuNode = document.getElementById('tableMenu');
  1253. // document.getElementById('slice-button').addEventListener('click', () => {
  1254. // console.log('slice', currentShape);
  1255. // });
  1256.  
  1257. // document.getElementById('edit-button').addEventListener('click', () => {
  1258. // console.log('edit', currentShape);
  1259. // });
  1260.  
  1261. // window.addEventListener('click', () => {
  1262. // menuNode.style.display = 'none';
  1263. // });
  1264. // var stage = this.stage;
  1265. // stage.on('contextmenu', function(e) {
  1266. // // prevent default behavior
  1267. // e.evt.preventDefault();
  1268. // if (e.target === stage) {
  1269. // // if we are on empty place of the stage we will do nothing
  1270. // return;
  1271. // }
  1272. // currentShape = e.target;
  1273. // console.log('atual', currentShape);
  1274. // // show menu
  1275. // menuNode.style.display = 'initial';
  1276. // var containerRect = stage.container().getBoundingClientRect();
  1277. // menuNode.style.top = containerRect.top + stage.getPointerPosition().y + 4 +'px';
  1278. // menuNode.style.left = containerRect.left + stage.getPointerPosition().x + 4 + 'px';
  1279. // });
  1280. // }
  1281. });
  1282. </script>
  1283.  
  1284. <style></style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement