feat: 영수증 스캔 네이티브 카메라(@capacitor/camera)
CI / build (push) Failing after 15m10s

- 앱에서 촬영/갤러리 선택 프롬프트로 영수증 입력 (웹은 파일선택 폴백)
- AndroidManifest CAMERA 권한 추가

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ByungCheol
2026-06-03 16:50:54 +09:00
parent efbe298a1f
commit e1d2ec5bd7
6 changed files with 47 additions and 5 deletions
+28 -5
View File
@@ -3,6 +3,8 @@ import { computed, onMounted, reactive, ref } from 'vue'
import { accountApi } from '@/api/accountApi'
import IconBtn from '@/components/ui/IconBtn.vue'
import { scanReceipt } from '@/utils/receiptOcr'
import { Capacitor } from '@capacitor/core'
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'
const now = new Date()
const year = ref(now.getFullYear())
@@ -59,21 +61,42 @@ const receiptInput = ref(null)
const ocrRunning = ref(false)
const ocrProgress = ref(0)
const ocrResult = ref(null) // { amount, date, store }
function pickReceipt() {
async function pickReceipt() {
ocrResult.value = null
receiptInput.value?.click()
// 네이티브(앱): 카메라/갤러리 선택 프롬프트, 웹: 파일 선택
if (Capacitor.isNativePlatform()) {
try {
const photo = await Camera.getPhoto({
source: CameraSource.Prompt,
resultType: CameraResultType.DataUrl,
quality: 70,
correctOrientation: true,
promptLabelHeader: '영수증',
promptLabelPhoto: '갤러리에서 선택',
promptLabelPicture: '카메라로 촬영',
promptLabelCancel: '취소',
})
if (photo?.dataUrl) await runOcr(photo.dataUrl)
} catch {
// 사용자가 취소 → 무시
}
} else {
receiptInput.value?.click()
}
}
async function onReceiptFile(e) {
const file = e.target.files?.[0]
e.target.value = '' // 같은 파일 재선택 허용
if (!file) return
if (file) await runOcr(file)
}
async function runOcr(image) {
ocrRunning.value = true
ocrProgress.value = 0
ocrResult.value = null
formError.value = null
try {
const r = await scanReceipt(file, (p) => (ocrProgress.value = p))
// 추출값이 있을 때만 폼에 채움 (기존 입력 보존하되, 비어있으면 채움)
const r = await scanReceipt(image, (p) => (ocrProgress.value = p))
// 추출값이 있을 때만 폼에 채움 (메모는 비어있을 때만)
if (r.amount) form.amount = r.amount
if (r.date) form.entryDate = r.date
if (r.store && !form.memo) form.memo = r.store