+++ client/resources/img/camera-rabbit.png
Binary file is not shown |
--- client/views/pages/main/AIDashboard.vue
+++ client/views/pages/main/AIDashboard.vue
... | ... | @@ -137,128 +137,22 @@ |
137 | 137 |
</div> |
138 | 138 |
<div class="box"> |
139 | 139 |
<div style="width: 100%;"> |
140 |
- <!-- 여기에 카메라 기능을 구현 --> |
|
141 |
- <!-- <p>카메라 모듈이 여기에 위치합니다.</p> --> |
|
142 |
- |
|
143 | 140 |
<div id="container" ref="container"> |
144 | 141 |
<video v-if="!photoTaken" autoplay="true" ref="modalVideoElement" class="mirrored" |
145 |
- @canplay="onVideoLoaded"></video> |
|
142 |
+ @canplay="onVideoLoaded" style="position: absolute;"> |
|
143 |
+ </video> |
|
144 |
+ <img src="../../../resources/img/camera-rabbit.png" class="camera-rabbit" |
|
145 |
+ style="position: absolute; "> |
|
146 |
+ <canvas ref="canvas" style="pointer-events: none;"></canvas> |
|
146 | 147 |
</div> |
147 |
- |
|
148 | 148 |
</div> |
149 | 149 |
</div> |
150 | 150 |
<div class="flex justify-center mt20"> |
151 |
- <button type="button" class="new-btn" v-if="!photoTaken" @click="capturePhoto" |
|
152 |
- :disabled="!videoReady"> |
|
153 |
- 사진 촬영 |
|
154 |
- </button> |
|
155 |
- |
|
151 |
+ <button class="new-btn" @click="takePhoto">사진 찍기</button> |
|
156 | 152 |
</div> |
157 | 153 |
</div> |
158 | 154 |
</article> |
159 | 155 |
|
160 |
- <!-- 사진 모달 --> |
|
161 |
- <article v-show="showPhotoModal" class="popup-wrap"> |
|
162 |
- <div class="popup-box" style="top: 500px; left: auto"> |
|
163 |
- <div class="flex mb10 justify-between"> |
|
164 |
- <p class="popup-title">사진 꾸미기</p> |
|
165 |
- <button type="button" class="popup-close-btn" @click="closePhotoModal"> |
|
166 |
- <svg-icon type="mdi" :path="mdiWindowClose" class="close-btn"></svg-icon> |
|
167 |
- </button> |
|
168 |
- </div> |
|
169 |
- <div class="flex justify-between align-center" style="gap: 40px;"> |
|
170 |
- <div class="content" style="padding: 30px; min-width: 401px; min-height: 710px;"> |
|
171 |
- <div class="tool"> |
|
172 |
- <div class="flex justify-center mb20" style="gap: 20px;"> |
|
173 |
- <button class="popTxt" style="width: 101px;" v-for="(item, index) in items_photo" |
|
174 |
- :key="index" @click="updateContent(index)" |
|
175 |
- :class="{ active: selectedIndex === index }"> |
|
176 |
- <img :src="item.imgSrc1" style="display: block;"> |
|
177 |
- <img :src="item.imgSrc2" v-if="selectedIndex === index" style="display: block;"> |
|
178 |
- </button> |
|
179 |
- </div> |
|
180 |
- </div> |
|
181 |
- |
|
182 |
- <div class="stickers" v-show="!stickersVisible"> |
|
183 |
- <div class="toolbar"> |
|
184 |
- <label for="brushSize" style="font-size: 9px;">펜 굵기</label> |
|
185 |
- <input type="color" v-model="color" /> |
|
186 |
- <input type="range" id="brushSize" min="1" max="10" v-model="brushSize" |
|
187 |
- @input="updateBrushSize" style="width: 100px; margin-left: 5px;" /> |
|
188 |
- <button class="new-btn" style="font-size: 9px;" @click="setTool('draw')">펜</button> |
|
189 |
- <button class="new-btn" style="font-size: 9px;" |
|
190 |
- @click="setTool('eraser')">지우개</button> |
|
191 |
- <button class="new-btn" style="font-size: 9px;" @click="clearAll">전체 지우개</button> |
|
192 |
- </div> |
|
193 |
- </div> |
|
194 |
- |
|
195 |
- <div class="stickers" v-show="stickersVisible"> |
|
196 |
- <button><img src="../../../resources/img/img146_75s.png" alt=""></button> |
|
197 |
- <button><img src="../../../resources/img/img147_75s.png" alt=""></button> |
|
198 |
- <button><img src="../../../resources/img/img148_75s.png" alt=""></button> |
|
199 |
- <button><img src="../../../resources/img/img149_75s.png" alt=""></button> |
|
200 |
- <button><img src="../../../resources/img/img150_75s.png" alt=""></button> |
|
201 |
- <button><img src="../../../resources/img/img151_75s.png" alt=""></button> |
|
202 |
- <button><img src="../../../resources/img/img152_75s.png" alt=""></button> |
|
203 |
- <button><img src="../../../resources/img/img153_75s.png" alt=""></button> |
|
204 |
- <button><img src="../../../resources/img/img154_75s.png" alt=""></button> |
|
205 |
- <button><img src="../../../resources/img/img155_75s.png" alt=""></button> |
|
206 |
- <button><img src="../../../resources/img/img156_75s.png" alt=""></button> |
|
207 |
- <button><img src="../../../resources/img/img157_75s.png" alt=""></button> |
|
208 |
- <button><img src="../../../resources/img/img158_75s.png" alt=""></button> |
|
209 |
- </div> |
|
210 |
- </div> |
|
211 |
- <div> |
|
212 |
- <div class="content" style="height: 549px; |
|
213 |
- position: relative; |
|
214 |
- width: 973px; |
|
215 |
- display: flex; |
|
216 |
- justify-content: center; |
|
217 |
- align-items: center;"> |
|
218 |
- <canvas ref="canvas" style="position: absolute;"></canvas> |
|
219 |
- </div> |
|
220 |
- <div class="btn-wrap flex justify-center mt40" style="gap: 40px;"> |
|
221 |
- <button class="login-btn" @click="openCameraModal"> |
|
222 |
- <img src="../../../resources/img/btn07_s.png" alt=""> |
|
223 |
- <p>재촬영</p> |
|
224 |
- </button> |
|
225 |
- |
|
226 |
- <button class="login-btn" type="submit" @click="goToPageImg('PhotoEdit')"> |
|
227 |
- <img src="../../../resources/img/btn07_s.png" alt=""> |
|
228 |
- <p>완성</p> |
|
229 |
- </button> |
|
230 |
- </div> |
|
231 |
- </div> |
|
232 |
- <div class="content" style="padding: 30px; min-width: 401px; min-height: 710px;"> |
|
233 |
- <div class="mb20"> |
|
234 |
- <p class="popup-title" style="font-size: 32px">랜덤 단어</p> |
|
235 |
- </div> |
|
236 |
- <div class="flex-column" style="gap: 10px;"> |
|
237 |
- <button class="login-btn"><img src="../../../resources/img/img141_75s.png" alt=""> |
|
238 |
- <p class="title">a</p> |
|
239 |
- </button> |
|
240 |
- <button class="login-btn"><img src="../../../resources/img/img152_75s_01.png" alt=""> |
|
241 |
- <p class="title">a</p> |
|
242 |
- </button> |
|
243 |
- <button class="login-btn"><img src="../../../resources/img/img144_75s.png" alt=""> |
|
244 |
- <p class="title" style="color: #fff;">a</p> |
|
245 |
- </button> |
|
246 |
- <button class="login-btn"><img src="../../../resources/img/img145_75s.png" alt=""> |
|
247 |
- <p class="title mt20" style="color: #fff;">a</p> |
|
248 |
- </button> |
|
249 |
- </div> |
|
250 |
- </div> |
|
251 |
- </div> |
|
252 |
- <!-- <div class="box"> |
|
253 |
- <div style="width: 100%;"> |
|
254 |
- <div id="container"> |
|
255 |
- <canvas ref="canvas"></canvas> |
|
256 |
- </div> |
|
257 |
- </div> |
|
258 |
- </div> --> |
|
259 |
- |
|
260 |
- </div> |
|
261 |
- </article> |
|
262 | 156 |
</div> |
263 | 157 |
<div class="complete-wrap myphoto"> |
264 | 158 |
<button class="login-btn mt10" type="submit" style="width: 100%;" @click="finishSchedule"><img |
... | ... | @@ -307,6 +201,8 @@ |
307 | 201 |
import { mdiMagnify, mdiHeart, mdiWindowClose } from '@mdi/js'; |
308 | 202 |
import axios from 'axios'; |
309 | 203 |
|
204 |
+//은진 |
|
205 |
+ |
|
310 | 206 |
export default { |
311 | 207 |
data() { |
312 | 208 |
return { |
... | ... | @@ -319,16 +215,6 @@ |
319 | 215 |
isSecondImageVisible: false |
320 | 216 |
}, |
321 | 217 |
], |
322 |
- items_photo: [ |
|
323 |
- { |
|
324 |
- imgSrc1: 'client/resources/img/btn20_75s_normal.png', //펜 선택되지 않음 |
|
325 |
- imgSrc2: 'client/resources/img/btn20_75s_click.png' //펜 선택됨 |
|
326 |
- }, |
|
327 |
- { |
|
328 |
- imgSrc1: 'client/resources/img/btn21_75s_normal.png', //스티커 선택되지 않음 |
|
329 |
- imgSrc2: 'client/resources/img/btn21_75s_click.png' //스티커 선택됨 |
|
330 |
- }, |
|
331 |
- ], |
|
332 | 218 |
mdiWindowClose: mdiWindowClose, |
333 | 219 |
mdiHeart: mdiHeart, |
334 | 220 |
showModal: false, |
... | ... | @@ -337,35 +223,13 @@ |
337 | 223 |
showCameraModal: false, // 카메라 모달창 |
338 | 224 |
showPhotoModal: false, // 사진꾸미기 모달창 |
339 | 225 |
photoTaken: false, |
340 |
- photo: null, //캡쳐 사진 |
|
341 |
- videoReady: false, // 비디오 준비 상태를 나타내는 플래그 |
|
226 |
+ photo: null, //캡쳐 사진 |
|
342 | 227 |
stream: null, |
343 |
- canvasWidth: 0, |
|
344 |
- canvasHeight: 0, |
|
345 |
- selectedIndex: 0, //툴 선택 여부 인덱스 |
|
346 |
- stickersVisible: false, // 스티커 표시 여부 |
|
347 |
- |
|
348 |
- //사진 꾸미기 관련 변수 |
|
349 |
- drawHistory: [], //도형 기록 |
|
350 |
- tempLines: [], //펜 기록 |
|
351 |
- stickers: [], //스티커 파일 기록 |
|
352 |
- draggingStickerIndex: null, //스티커 드래그 |
|
353 |
- activeStickerIndex: null, // 현재 활성화된 스티커의 인덱스 |
|
354 |
- nextLineId: 0, //획 아이디 |
|
355 |
- tool: 'draw', //툴 결정 |
|
356 |
- color: '#000000', //펜 기본 색상 |
|
357 |
- isDrawing: false, //그리는 중인지 판단하는 변수 |
|
358 |
- brushSize: 5, // 초기 펜 굵기 |
|
359 |
- startX: 0, |
|
360 |
- startY: 0, |
|
361 |
- canvasRect: { |
|
362 |
- topLeft: { x: 0, y: 0 }, |
|
363 |
- bottomRight: { x: 0, y: 0 } |
|
364 |
- }, |
|
365 |
- |
|
366 | 228 |
|
367 | 229 |
isHidden: false, |
368 |
- images: [] |
|
230 |
+ images: [], |
|
231 |
+ |
|
232 |
+ photoTaken: false |
|
369 | 233 |
|
370 | 234 |
} |
371 | 235 |
}, |
... | ... | @@ -439,36 +303,14 @@ |
439 | 303 |
toggleImage(index) { |
440 | 304 |
this.items[index].isSecondImageVisible = !this.items[index].isSecondImageVisible; |
441 | 305 |
}, |
442 |
- toggleImageAndShowPopup(index, dataNum) { |
|
443 |
- this.toggleImage(index); |
|
444 |
- if (dataNum === '11') { // 최종 평가 버튼 클릭 시 |
|
445 |
- this.searchOpen2 = true; // 모달창 열기 |
|
446 |
- } |
|
447 |
- }, |
|
448 | 306 |
ShowPopup() { |
449 |
- this.searchOpen2 = true; // 촬영 여부 묻는 모달창 열기 |
|
450 |
- }, |
|
451 |
- updateContent(index) { |
|
452 |
- this.selectedIndex = index; |
|
453 |
- |
|
454 |
- // 선택된 버튼이 스티커 버튼(인덱스 1)인지 확인 |
|
455 |
- if (index === 1) { |
|
456 |
- this.stickersVisible = true; // 스티커 툴 보이기 |
|
457 |
- } else { |
|
458 |
- this.stickersVisible = false; // 스티커 툴 숨기기 |
|
459 |
- } |
|
307 |
+ this.searchOpen2 = true; |
|
460 | 308 |
}, |
461 | 309 |
goToPage(page) { |
462 | 310 |
this.$router.push({ name: page }); |
463 | 311 |
}, |
464 | 312 |
openCameraModal() { |
465 | 313 |
this.closeModal(); |
466 |
- this.closePhotoModal(); |
|
467 |
- |
|
468 |
- this.drawHistory = []; |
|
469 |
- this.stickers = []; |
|
470 |
- this.tempLines = []; |
|
471 |
- this.videoReady = false; // 비디오 준비 상태 초기화 |
|
472 | 314 |
|
473 | 315 |
this.showCameraModal = true; |
474 | 316 |
navigator.mediaDevices.getUserMedia({ video: true }) |
... | ... | @@ -476,7 +318,6 @@ |
476 | 318 |
const modalVideo = this.$refs.modalVideoElement; |
477 | 319 |
modalVideo.srcObject = stream; |
478 | 320 |
this.stream = stream; |
479 |
- modalVideo.addEventListener('loadedmetadata', this.adjustContainerSize); |
|
480 | 321 |
}) |
481 | 322 |
.catch(error => { |
482 | 323 |
console.log("error>>>>>>>>", error); |
... | ... | @@ -498,24 +339,47 @@ |
498 | 339 |
this.stream = null; |
499 | 340 |
} |
500 | 341 |
}, |
501 |
- closePhotoModal() { //사진꾸미기 팝업 닫기 |
|
502 |
- this.showPhotoModal = false; |
|
503 |
- this.closeModal(); |
|
504 |
- }, |
|
342 |
+ |
|
343 |
+ |
|
344 |
+ //은진 |
|
505 | 345 |
onVideoLoaded() { |
506 |
- this.videoReady = true; |
|
507 |
- this.adjustContainerSize(); |
|
508 |
- }, |
|
509 |
- adjustContainerSize() { |
|
510 | 346 |
const video = this.$refs.modalVideoElement; |
511 |
- const container = this.$refs.container; |
|
512 |
- const body = this.$refs.body; |
|
513 |
- if (video && container) { |
|
514 |
- container.style.width = `${video.videoWidth}px`; |
|
515 |
- container.style.height = `${video.videoHeight}px`; |
|
516 |
- body.style.height = `${video.videoHeight}px`; |
|
517 |
- } |
|
347 |
+ const canvas = this.$refs.canvas; |
|
348 |
+ const ctx = canvas.getContext('2d'); |
|
349 |
+ |
|
350 |
+ canvas.width = video.videoWidth; |
|
351 |
+ canvas.height = video.videoHeight; |
|
352 |
+ }, takePhoto() { |
|
353 |
+ const video = this.$refs.modalVideoElement; |
|
354 |
+ const canvas = this.$refs.canvas; |
|
355 |
+ const ctx = canvas.getContext('2d'); |
|
356 |
+ |
|
357 |
+ ctx.save(); // 현재 상태 저장 |
|
358 |
+ |
|
359 |
+ // 캔버스 좌우 반전 |
|
360 |
+ ctx.scale(-1, 1); |
|
361 |
+ ctx.drawImage(video, -canvas.width, 0, canvas.width, canvas.height); |
|
362 |
+ |
|
363 |
+ ctx.restore(); |
|
364 |
+ |
|
365 |
+ const overlayImg = new Image(); |
|
366 |
+ overlayImg.src = 'client/resources/img/camera-rabbit.png'; |
|
367 |
+ overlayImg.onload = () => { |
|
368 |
+ const overlayWidth = canvas.width * 0.4; |
|
369 |
+ const overlayHeight = (overlayImg.height / overlayImg.width) * overlayWidth; |
|
370 |
+ const overlayX = canvas.width - overlayWidth; |
|
371 |
+ const overlayY = canvas.height - overlayHeight; |
|
372 |
+ |
|
373 |
+ // 오버레이 이미지 그리기 |
|
374 |
+ ctx.drawImage(overlayImg, overlayX, overlayY, overlayWidth, overlayHeight); |
|
375 |
+ |
|
376 |
+ // 사진 저장 함수 호출 |
|
377 |
+ // this.savePhoto('PhotoEdit'); |
|
378 |
+ const dataURL = canvas.toDataURL('image/png'); |
|
379 |
+ this.$router.push({ name: 'PhotoEdit', query: { image: encodeURIComponent(dataURL) } }); |
|
380 |
+ }; |
|
518 | 381 |
}, |
382 |
+ |
|
519 | 383 |
|
520 | 384 |
buttonSearch() { |
521 | 385 |
this.searchOpen = true; |
... | ... | @@ -526,298 +390,6 @@ |
526 | 390 |
closeBtn() { |
527 | 391 |
this.searchOpen = false; |
528 | 392 |
}, |
529 |
- capturePhoto() { |
|
530 |
- // 사진 촬영 기능 구현 |
|
531 |
- console.log("cam on"); |
|
532 |
- |
|
533 |
- if (!this.videoReady) return; // 비디오가 준비되지 않았으면 사진을 찍지 않음 |
|
534 |
- |
|
535 |
- const video = this.$refs.modalVideoElement; |
|
536 |
- const canvas = document.createElement('canvas'); |
|
537 |
- |
|
538 |
- canvas.width = video.videoWidth; |
|
539 |
- canvas.height = video.videoHeight; |
|
540 |
- this.canvasWidth = video.videoWidth; |
|
541 |
- this.canvasHeight = video.videoHeight; |
|
542 |
- const context = canvas.getContext('2d'); |
|
543 |
- context.translate(canvas.width, 0); |
|
544 |
- context.scale(-1, 1); |
|
545 |
- context.drawImage(video, 0, 0, canvas.width, canvas.height); |
|
546 |
- this.photo = canvas.toDataURL('image/png'); |
|
547 |
- this.photoTaken = true; |
|
548 |
- this.showPhotoModal = true; |
|
549 |
- console.log("PhotoModal open"); |
|
550 |
- this.$nextTick(() => { |
|
551 |
- console.log("canvas setup"); |
|
552 |
- // console.log("Photo data>>>>", this.photo); |
|
553 |
- this.setupCanvas(); |
|
554 |
- }); |
|
555 |
- |
|
556 |
- }, |
|
557 |
- setupCanvas() { |
|
558 |
- const canvas = this.$refs.canvas; |
|
559 |
- // const container = this.$refs.container; |
|
560 |
- if (!canvas) { |
|
561 |
- console.error("Canvas reference not found"); |
|
562 |
- resolve(); |
|
563 |
- return; |
|
564 |
- } |
|
565 |
- const context = canvas.getContext('2d'); |
|
566 |
- if (!context) { |
|
567 |
- console.error("Canvas context not found"); |
|
568 |
- return; |
|
569 |
- } |
|
570 |
- const image = new Image(); |
|
571 |
- image.src = this.photo; |
|
572 |
- // console.log("Photo data>>>>", image.src); |
|
573 |
- image.onload = () => { |
|
574 |
- console.log("Image loaded successfully"); |
|
575 |
- // this.canvasWidth = image.width; |
|
576 |
- // this.canvasHeight = image.height; |
|
577 |
- //이미지 크기가 캔버스와 안맞으면 이미지 불러오는데에 에러 남 |
|
578 |
- // container.style.width = this.canvasWidth; |
|
579 |
- // container.style.height = this.canvasHeight; |
|
580 |
- |
|
581 |
- canvas.width = this.canvasWidth; |
|
582 |
- canvas.height = this.canvasHeight; |
|
583 |
- |
|
584 |
- const rect = canvas.getBoundingClientRect(); |
|
585 |
- // 좌측 상단 좌표 |
|
586 |
- const topLeft = { |
|
587 |
- x: rect.left, |
|
588 |
- y: rect.top |
|
589 |
- }; |
|
590 |
- |
|
591 |
- // 우측 하단 좌표 |
|
592 |
- const bottomRight = { |
|
593 |
- x: rect.right, |
|
594 |
- y: rect.bottom |
|
595 |
- }; |
|
596 |
- |
|
597 |
- // 캔버스 크기 초기화 |
|
598 |
- this.updateCanvasRect(); |
|
599 |
- |
|
600 |
- // 윈도우 리사이즈 이벤트 리스너 추가 |
|
601 |
- window.addEventListener('resize', this.updateCanvasRect); |
|
602 |
- |
|
603 |
- // 클릭 이벤트 핸들러 추가 |
|
604 |
- this.$refs.canvas.addEventListener('click', this.handleCanvasClick); |
|
605 |
- |
|
606 |
- |
|
607 |
- // canvas.width = canvas.clientWidth; |
|
608 |
- // canvas.height = canvas.clientHeight; |
|
609 |
- // this.canvasWidth = canvas.clientWidth; |
|
610 |
- // this.canvasHeight = canvas.clientHeight; |
|
611 |
- |
|
612 |
- context.clearRect(0, 0, canvas.width, canvas.height); // 이전 이미지 있으면 초기화 |
|
613 |
- context.drawImage(image, 0, 0, this.canvasWidth, this.canvasHeight); |
|
614 |
- this.addCanvasEventListeners(); //추가해야함 |
|
615 |
- }; |
|
616 |
- image.onerror = (error) => { |
|
617 |
- console.error("Error loading image: ", error); |
|
618 |
- }; |
|
619 |
- }, |
|
620 |
- |
|
621 |
- addCanvasEventListeners() { |
|
622 |
- const canvas = this.$refs.canvas; |
|
623 |
- canvas.addEventListener('mousedown', this.onMouseDown); |
|
624 |
- canvas.addEventListener('mouseup', this.onMouseUp); |
|
625 |
- canvas.addEventListener('mousemove', this.onMouseMove); |
|
626 |
- canvas.addEventListener('click', this.onCanvasClick); |
|
627 |
- }, |
|
628 |
- setTool(tool) { |
|
629 |
- this.tool = tool; |
|
630 |
- }, |
|
631 |
- updateBrushSize() { |
|
632 |
- // 펜 굵기 변경 로직 |
|
633 |
- if (this.tool === 'draw') { |
|
634 |
- this.setBrushSize(this.brushSize); |
|
635 |
- } |
|
636 |
- }, |
|
637 |
- setBrushSize(size) { |
|
638 |
- this.brushSize = size; |
|
639 |
- const context = this.$refs.canvas.getContext('2d'); |
|
640 |
- context.lineWidth = size; |
|
641 |
- }, |
|
642 |
- // 캔버스 크기 갱신 함수 |
|
643 |
- updateCanvasRect() { |
|
644 |
- const rect = this.$refs.canvas.getBoundingClientRect(); |
|
645 |
- this.canvasRect = { |
|
646 |
- topLeft: { x: rect.left, y: rect.top }, |
|
647 |
- bottomRight: { x: rect.right, y: rect.bottom } |
|
648 |
- }; |
|
649 |
- console.log(">>>>>>>>>2222", rect.left); |
|
650 |
- }, |
|
651 |
- getCanvasPosition(event) { |
|
652 |
- |
|
653 |
- const rect = this.canvasRect; |
|
654 |
- console.log(">>>>>>>>>", this.canvasRect); |
|
655 |
- this.updateCanvasRect(); |
|
656 |
- |
|
657 |
- // 윈도우 리사이즈 이벤트 리스너 추가 |
|
658 |
- window.addEventListener('resize', this.updateCanvasRect); |
|
659 |
- |
|
660 |
- // 클릭 이벤트 핸들러 추가 |
|
661 |
- this.$refs.canvas.addEventListener('click', this.handleCanvasClick); |
|
662 |
- |
|
663 |
- // // 좌측 상단 좌표 |
|
664 |
- // const topLeft = { |
|
665 |
- // x: rect.left, |
|
666 |
- // y: rect.top |
|
667 |
- // }; |
|
668 |
- |
|
669 |
- // // 우측 하단 좌표 |
|
670 |
- // const bottomRight = { |
|
671 |
- // x: rect.right, |
|
672 |
- // y: rect.bottom |
|
673 |
- // }; |
|
674 |
- |
|
675 |
- // console.log(this.scrollLeft) |
|
676 |
- |
|
677 |
- const x = event.clientX - rect.topLeft.x |
|
678 |
- const y = event.clientY - rect.topLeft.y |
|
679 |
- |
|
680 |
- |
|
681 |
- console.log(`클릭한 좌표: x=${event.clientX}, y=${event.clientY}`); |
|
682 |
- console.log(`계산베이스 좌표: x=${rect.topLeft.x}, y=${rect.topLeft.y}`); |
|
683 |
- console.log(`계산베이스 좌표: x=${rect.topLeft.x}, y=${rect.topLeft.y}`); |
|
684 |
- console.log(`계산된 좌표: x=${x}, y=${y}`); |
|
685 |
- return { |
|
686 |
- x, y |
|
687 |
- }; |
|
688 |
- }, |
|
689 |
- onMouseDown(event) { |
|
690 |
- |
|
691 |
- // 캔버스 크기 초기화 |
|
692 |
- this.updateCanvasRect(); |
|
693 |
- |
|
694 |
- // 윈도우 리사이즈 이벤트 리스너 추가 |
|
695 |
- window.addEventListener('resize', this.updateCanvasRect); |
|
696 |
- |
|
697 |
- // 클릭 이벤트 핸들러 추가 |
|
698 |
- this.$refs.canvas.addEventListener('click', this.handleCanvasClick); |
|
699 |
- |
|
700 |
- const { x, y } = this.getCanvasPosition(event); |
|
701 |
- this.startX = x; |
|
702 |
- this.startY = y; |
|
703 |
- const context = this.$refs.canvas.getContext('2d'); |
|
704 |
- context.strokeStyle = this.color; |
|
705 |
- context.lineWidth = this.brushSize; // 브러시 크기 설정 |
|
706 |
- if (this.tool === 'draw') { |
|
707 |
- context.beginPath(); |
|
708 |
- context.moveTo(this.startX, this.startY); |
|
709 |
- this.nextLineId++; |
|
710 |
- } |
|
711 |
- this.isDrawing = true; |
|
712 |
- }, |
|
713 |
- onMouseUp(event) { |
|
714 |
- if (!this.isDrawing) return; |
|
715 |
- const { x, y } = this.getCanvasPosition(event); |
|
716 |
- const context = this.$refs.canvas.getContext('2d'); |
|
717 |
- context.strokeStyle = this.color; |
|
718 |
- context.lineWidth = this.brushSize; // 브러시 크기 설정 |
|
719 |
- if (this.tool === 'rectangle') { |
|
720 |
- context.strokeRect(this.startX, this.startY, x - this.startX, y - this.startY); |
|
721 |
- this.drawHistory.push({ type: 'rectangle', startX: this.startX, startY: this.startY, endX: x, endY: y, color: this.color }); |
|
722 |
- } else if (this.tool === 'circle') { |
|
723 |
- context.beginPath(); |
|
724 |
- const radius = Math.sqrt(Math.pow((x - this.startX), 2) + Math.pow((y - this.startY), 2)); |
|
725 |
- context.arc(this.startX, this.startY, radius, 0, 2 * Math.PI); |
|
726 |
- context.stroke(); |
|
727 |
- this.drawHistory.push({ type: 'circle', startX: this.startX, startY: this.startY, radius, color: this.color }); |
|
728 |
- } else if (this.tool === 'draw') { |
|
729 |
- context.lineTo(x, y); |
|
730 |
- context.stroke(); |
|
731 |
- this.tempLines.push({ id: this.nextLineId, startX: this.startX, startY: this.startY, endX: x, endY: y, color: this.color }); |
|
732 |
- } |
|
733 |
- this.isDrawing = false; |
|
734 |
- }, |
|
735 |
- onMouseMove(event) { |
|
736 |
- if (!this.isDrawing || this.tool !== 'draw') return; |
|
737 |
- const { x, y } = this.getCanvasPosition(event); |
|
738 |
- const context = this.$refs.canvas.getContext('2d'); |
|
739 |
- context.strokeStyle = this.color; |
|
740 |
- context.lineWidth = this.brushSize; // 브러시 크기 설정 |
|
741 |
- context.lineTo(x, y); |
|
742 |
- context.stroke(); |
|
743 |
- this.tempLines.push({ id: this.nextLineId, startX: this.startX, startY: this.startY, endX: x, endY: y, color: this.color }); |
|
744 |
- this.startX = x; |
|
745 |
- this.startY = y; |
|
746 |
- }, |
|
747 |
- onCanvasClick(event) { |
|
748 |
- if (this.tool === 'eraser') { |
|
749 |
- const { x, y } = this.getCanvasPosition(event); |
|
750 |
- this.eraseDrawing(x, y); |
|
751 |
- } |
|
752 |
- }, |
|
753 |
- eraseDrawing(x, y) { |
|
754 |
- const eraserRadius = 10; |
|
755 |
- this.drawHistory = this.drawHistory.filter(item => { |
|
756 |
- if (item.type === 'rectangle') { |
|
757 |
- return !(x >= item.startX && x <= item.endX && y >= item.startY && y <= item.endY); |
|
758 |
- } else if (item.type === 'circle') { |
|
759 |
- const distance = Math.sqrt(Math.pow((x - item.startX), 2) + Math.pow((y - item.startY), 2)); |
|
760 |
- return !(distance <= item.radius); |
|
761 |
- } |
|
762 |
- }); |
|
763 |
- const linesToDelete = this.tempLines.filter(line => { |
|
764 |
- const distanceToLine = this.distanceToLineSegment(line.startX, line.startY, line.endX, line.endY, x, y); |
|
765 |
- return distanceToLine <= 10; |
|
766 |
- }).map(line => line.id); |
|
767 |
- this.tempLines = this.tempLines.filter(line => !linesToDelete.includes(line.id)); |
|
768 |
- this.redraw(); |
|
769 |
- }, |
|
770 |
- distanceToLineSegment(x1, y1, x2, y2, px, py) { |
|
771 |
- const lengthSquared = Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2); |
|
772 |
- if (lengthSquared === 0) return Math.sqrt(Math.pow(px - x1, 2) + Math.pow(py - y1, 2)); |
|
773 |
- const t = Math.max(0, Math.min(1, ((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1)) / lengthSquared)); |
|
774 |
- const projX = x1 + t * (x2 - x1); |
|
775 |
- const projY = y1 + t * (y2 - y1); |
|
776 |
- return Math.sqrt(Math.pow(px - projX, 2) + Math.pow(py - projY, 2)); |
|
777 |
- }, |
|
778 |
- clearAll() { |
|
779 |
- this.drawHistory = []; |
|
780 |
- this.stickers = []; |
|
781 |
- this.tempLines = []; |
|
782 |
- this.redraw(); |
|
783 |
- }, |
|
784 |
- redraw() { |
|
785 |
- const canvas = this.$refs.canvas; |
|
786 |
- const context = canvas.getContext('2d'); |
|
787 |
- const image = new Image(); |
|
788 |
- image.src = this.photo; |
|
789 |
- image.onload = () => { |
|
790 |
- context.clearRect(0, 0, this.canvasWidth, this.canvasHeight); |
|
791 |
- context.drawImage(image, 0, 0, this.canvasWidth, this.canvasHeight); |
|
792 |
- this.drawHistory.forEach(item => { |
|
793 |
- context.strokeStyle = item.color; |
|
794 |
- if (item.type === 'draw') { |
|
795 |
- context.beginPath(); |
|
796 |
- context.moveTo(item.startX, item.startY); |
|
797 |
- context.lineTo(item.endX, item.endY); |
|
798 |
- context.stroke(); |
|
799 |
- } else if (item.type === 'rectangle') { |
|
800 |
- context.strokeRect(item.startX, item.startY, item.endX - item.startX, item.endY - item.startY); |
|
801 |
- } else if (item.type === 'circle') { |
|
802 |
- context.beginPath(); |
|
803 |
- context.arc(item.startX, item.startY, item.radius, 0, 2 * Math.PI); |
|
804 |
- context.stroke(); |
|
805 |
- } |
|
806 |
- }); |
|
807 |
- this.tempLines.forEach(line => { |
|
808 |
- context.strokeStyle = line.color; |
|
809 |
- context.beginPath(); |
|
810 |
- context.moveTo(line.startX, line.startY); |
|
811 |
- context.lineTo(line.endX, line.endY); |
|
812 |
- context.stroke(); |
|
813 |
- }); |
|
814 |
- this.stickers.forEach((sticker, index) => { |
|
815 |
- context.drawImage(sticker.img, sticker.x, sticker.y, sticker.width, sticker.height); |
|
816 |
- }); |
|
817 |
- }; |
|
818 |
- }, |
|
819 |
- |
|
820 |
- |
|
821 | 393 |
}, |
822 | 394 |
components: { |
823 | 395 |
SvgIcon, |
... | ... | @@ -825,17 +397,17 @@ |
825 | 397 |
mounted() { |
826 | 398 |
console.log('main mounted'); |
827 | 399 |
|
400 |
+ this.onVideoLoaded(); |
|
828 | 401 |
this.fetchImage(); |
402 |
+ |
|
403 |
+ if (this.$route.query.reCapture == 'true') { |
|
404 |
+ this.openCameraModal() |
|
405 |
+ } |
|
829 | 406 |
|
830 | 407 |
}, |
831 | 408 |
computed() { |
832 | 409 |
|
833 | 410 |
}, |
834 |
- beforeDestroy() { |
|
835 |
- // 컴포넌트가 파괴되기 전에 리스너 제거 |
|
836 |
- window.removeEventListener('resize', this.updateCanvasRect); |
|
837 |
- this.$refs.canvas.removeEventListener('click', this.handleCanvasClick); |
|
838 |
- } |
|
839 | 411 |
} |
840 | 412 |
</script> |
841 | 413 |
|
... | ... | @@ -929,4 +501,11 @@ |
929 | 501 |
.rabbit-end { |
930 | 502 |
cursor: pointer; |
931 | 503 |
} |
504 |
+ |
|
505 |
+.camera-rabbit { |
|
506 |
+ position: absolute; |
|
507 |
+ right: 0; |
|
508 |
+ bottom: 0; |
|
509 |
+ width: 40%; |
|
510 |
+} |
|
932 | 511 |
</style>(파일 끝에 줄바꿈 문자 없음) |
--- client/views/pages/main/PhotoEdit.vue
+++ client/views/pages/main/PhotoEdit.vue
... | ... | @@ -10,9 +10,9 @@ |
10 | 10 |
|
11 | 11 |
</div> |
12 | 12 |
<div class="btn-wrap flex justify-center mt40" style="gap: 40px;"> |
13 |
- <button class="login-btn" @click="goToPage('PhotoDesign')"> |
|
13 |
+ <button class="login-btn" @click="recapture()"> |
|
14 | 14 |
<img src="../../../resources/img/btn07_s.png" alt=""> |
15 |
- <p>수정하기</p> |
|
15 |
+ <p>다시 찍기</p> |
|
16 | 16 |
</button> |
17 | 17 |
|
18 | 18 |
<button class="login-btn" type="submit" @click="insertPhoto()"><img src="../../../resources/img/btn07_s.png" |
... | ... | @@ -27,6 +27,7 @@ |
27 | 27 |
|
28 | 28 |
<script> |
29 | 29 |
import axios from 'axios'; |
30 |
+ |
|
30 | 31 |
export default { |
31 | 32 |
data() { |
32 | 33 |
return { |
... | ... | @@ -43,6 +44,10 @@ |
43 | 44 |
} |
44 | 45 |
}, |
45 | 46 |
methods: { |
47 |
+ recapture() { |
|
48 |
+ // this.$router.push({ name: 'Dashboard', query: { reCapture: 'true', unit_id, book_id } }); |
|
49 |
+ this.$router.push({ name: 'AIDashboard', query: { reCapture: 'true' } }); |
|
50 |
+ }, |
|
46 | 51 |
async fetchImageAsFile(imageUrl, filename = "image.jpg") { |
47 | 52 |
try { |
48 | 53 |
const response = await fetch(imageUrl); |
... | ... | @@ -115,19 +120,6 @@ |
115 | 120 |
goToPage(page) { |
116 | 121 |
this.$router.push({ name: page }); |
117 | 122 |
}, |
118 |
- startTimer() { |
|
119 |
- if (this.intervalId) { |
|
120 |
- clearInterval(this.intervalId); |
|
121 |
- } |
|
122 |
- this.timer = 5; |
|
123 |
- this.intervalId = setInterval(() => { |
|
124 |
- if (this.timer > 0) { |
|
125 |
- this.timer--; |
|
126 |
- } else { |
|
127 |
- clearInterval(this.intervalId); |
|
128 |
- } |
|
129 |
- }, 1000); |
|
130 |
- } |
|
131 | 123 |
}, |
132 | 124 |
watch: { |
133 | 125 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?