|
77 | 77 | @click="savePDF"> |
78 | 78 | {{ saving ? 'saving' : 'keep' }} |
79 | 79 | </button> |
| 80 | + |
| 81 | + <div v-if="pages.length" class="flex items-center gap-4"> |
| 82 | + <button :disabled="currentPage==0" @click="onPreviousPage">Previous</button> |
| 83 | + <input class="" v-model="currentPage"/> |
| 84 | + <button @click="onNextPage">Next</button> |
| 85 | + </div> |
| 86 | + |
80 | 87 | </div> |
81 | 88 | <div v-if="addingDrawing"> |
82 | 89 | <div class="fixed z-10 top-0 left-0 right-0 border-b border-gray-300 bg-white shadow-lg" |
|
107 | 114 |
|
108 | 115 | <!-- PDF main body --> |
109 | 116 | <div class="w-full" style="text-align: center;"> |
110 | | - <div v-for="(page,pIndex) in pages" :key="pIndex" style="display: inline-block;"> |
| 117 | + <div style="display: inline-block;"> |
111 | 118 | <div class="p-5 items-center" |
112 | 119 | style="text-align: center" |
113 | | - @mousedown="selectPage(pIndex)" |
114 | | - @touchstart="selectPage(pIndex)"> |
| 120 | + @mousedown="selectPage(currentPage)" |
| 121 | + @touchstart="selectPage(currentPage)"> |
115 | 122 | <div style="display: inline-block;" |
116 | | - class="relative shadow-lg" |
117 | | - :class="[pIndex === selectedPageIndex ?'shadowOutline':'']"> |
118 | | - <PDFPage :ref="`page${pIndex}`" |
| 123 | + class="relative shadow-lg"> |
| 124 | + <PDFPage :ref="`page${currentPage}`" |
119 | 125 | :scale="scale" |
120 | | - :data-key="pIndex" |
121 | | - :page="page" |
122 | | - @onMeasure="onMeasure($event, pIndex)" /> |
| 126 | + :data-key="currentPage" |
| 127 | + :page="pages[currentPage]" |
| 128 | + @onMeasure="onMeasure($event, currentPage)" /> |
123 | 129 | <div class="absolute top-0 left-0 transform origin-top-left noTouchAction" |
124 | | - :style="{transform: `scale(${pagesScale[pIndex]})`}"> |
125 | | - <div v-for="(object, oIndex) in allObjects[pIndex]" :key="oIndex"> |
| 130 | + :style="{transform: `scale(${pagesScale[currentPage]})`}"> |
| 131 | + <div v-for="(object, oIndex) in allObjects[currentPage]" :key="oIndex"> |
126 | 132 | <div> |
127 | 133 | <div v-if="object.type === 'custom'"> |
128 | 134 | <slot name="custom" |
129 | 135 | :object="object" |
130 | | - :pagesScale="pagesScale[pIndex]" |
| 136 | + :pagesScale="pagesScale[currentPage]" |
131 | 137 | @onUpdate="updateObject(object.id, $event)" |
132 | 138 | @onDelete="deleteObject(object.id)" /> |
133 | 139 | </div> |
|
141 | 147 | :height="object.height" |
142 | 148 | :origin-width="object.originWidth" |
143 | 149 | :origin-height="object.originHeight" |
144 | | - :page-scale="pagesScale[pIndex]" |
| 150 | + :page-scale="pagesScale[currentPage]" |
145 | 151 | @onUpdate="updateObject(object.id, $event)" |
146 | 152 | @onDelete="deleteObject(object.id)" /> |
147 | 153 | </div> |
|
157 | 163 | :line-height="object.lineHeight" |
158 | 164 | :font-family="object.fontFamily" |
159 | 165 | :current-page="object.currentPage" |
160 | | - :page-scale="pagesScale[pIndex]" |
| 166 | + :page-scale="pagesScale[currentPage]" |
161 | 167 | @onUpdate="updateObject(object.id, $event)" |
162 | 168 | @onDelete="deleteObject(object.id)" |
163 | 169 | @onSelectFont="selectFontFamily" /> |
|
169 | 175 | :width="object.width" |
170 | 176 | :origin-width="object.originWidth" |
171 | 177 | :origin-height="object.originHeight" |
172 | | - :page-scale="pagesScale[pIndex]" |
| 178 | + :page-scale="pagesScale[currentPage]" |
173 | 179 | @onUpdate="updateObject(object.id, $event)" |
174 | 180 | @onDelete="deleteObject(object.id)" /> |
175 | 181 | </div> |
@@ -324,6 +330,7 @@ export default { |
324 | 330 | numPages: null, |
325 | 331 | pdfDocument: null, |
326 | 332 | pages: [], |
| 333 | + currentPage: 0, |
327 | 334 | pagesScale: [], |
328 | 335 | allObjects: [], |
329 | 336 | currentFont: 'Courier', |
@@ -397,20 +404,20 @@ export default { |
397 | 404 | for (let i = 0; i < this.pages.length; i++) { |
398 | 405 | this.selectedPageIndex = i |
399 | 406 | for (let j = 0; j < this.initTextFields.length; j++) { |
400 | | - const text = this.initTextFields[j] |
401 | | - this.addTextField(text, 0, j * 60, this.selectedPageIndex) |
| 407 | + // const text = this.initTextFields[j] |
| 408 | + // this.addTextField(text, 0, j * 60, this.selectedPageIndex) |
402 | 409 | } |
403 | 410 | } |
404 | 411 | this.selectedPageIndex = 0 |
405 | 412 | const checker = setInterval(() => { |
406 | | - if (this.$refs.textItem.length === this.initTextFields.length * this.pages.length) { |
407 | | - document.getElementById('pdfBody').dispatchEvent(new MouseEvent('mousedown', { |
408 | | - bubbles: true, |
409 | | - cancelable: true, |
410 | | - view: window, |
411 | | - })) |
| 413 | + // if (this.$refs.textItem.length === this.initTextFields.length * this.pages.length) { |
| 414 | + // document.getElementById('pdfBody').dispatchEvent(new MouseEvent('mousedown', { |
| 415 | + // bubbles: true, |
| 416 | + // cancelable: true, |
| 417 | + // view: window, |
| 418 | + // })) |
412 | 419 | clearInterval(checker) |
413 | | - } |
| 420 | + // } |
414 | 421 | }, 100) |
415 | 422 |
|
416 | 423 | }, |
@@ -681,7 +688,19 @@ export default { |
681 | 688 | this.saving = false |
682 | 689 | } |
683 | 690 | }, |
684 | | - }, |
| 691 | + onPreviousPage(){ |
| 692 | + const previousPage = this.currentPage-1 |
| 693 | + const canSetPreviousPage = previousPage >= 0 |
| 694 | + if(!canSetPreviousPage) return; |
| 695 | + this.currentPage = previousPage; |
| 696 | + }, |
| 697 | + onNextPage(){ |
| 698 | + const nextPage = this.currentPage+1 |
| 699 | + const canSetNextPage = nextPage <= this.pages.length-1 |
| 700 | + if(!canSetNextPage) return; |
| 701 | + this.currentPage = nextPage; |
| 702 | + }, |
| 703 | + } |
685 | 704 | } |
686 | 705 | </script> |
687 | 706 |
|
|
0 commit comments