대시보드와 주간보고 기능 업데이트
This commit is contained in:
@@ -12,31 +12,12 @@
|
||||
<div class="card mb-4">
|
||||
<div class="card-header"><strong>보고 주차</strong></div>
|
||||
<div class="card-body">
|
||||
<div class="row align-items-end">
|
||||
<div class="col-auto">
|
||||
<div class="input-group">
|
||||
<button type="button" class="btn btn-outline-secondary" @click="changeWeek(-1)">
|
||||
<i class="bi bi-chevron-left"></i>
|
||||
</button>
|
||||
<span class="input-group-text bg-white" style="min-width: 160px;">
|
||||
<strong>{{ form.reportYear }}년 {{ form.reportWeek }}주차</strong>
|
||||
</span>
|
||||
<button type="button" class="btn btn-outline-secondary" @click="changeWeek(1)">
|
||||
<i class="bi bi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<div class="input-group">
|
||||
<input type="date" class="form-control" v-model="form.weekStartDate" @change="updateWeekFromDate" />
|
||||
<span class="input-group-text">~</span>
|
||||
<input type="date" class="form-control" v-model="form.weekEndDate" readonly />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="button" class="btn btn-outline-primary btn-sm" @click="setLastWeek">지난주</button>
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm ms-1" @click="setThisWeek">이번주</button>
|
||||
</div>
|
||||
<div class="d-flex align-items-center">
|
||||
<h5 class="mb-0">
|
||||
<i class="bi bi-calendar-week me-2 text-primary"></i>
|
||||
<strong>{{ form.reportYear }}년 {{ form.reportWeek }}주차</strong>
|
||||
<span class="text-muted ms-2">({{ form.weekStartDate }} ~ {{ form.weekEndDate }})</span>
|
||||
</h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -45,9 +26,14 @@
|
||||
<div class="card mb-4">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<strong><i class="bi bi-folder me-2"></i>프로젝트별 실적/계획</strong>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" @click="showProjectModal = true">
|
||||
<i class="bi bi-plus"></i> 프로젝트 추가
|
||||
</button>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-sm btn-outline-success" @click="showAiModal = true">
|
||||
<i class="bi bi-robot me-1"></i>AI 자동채우기
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" @click="showProjectModal = true">
|
||||
<i class="bi bi-plus"></i> 프로젝트 추가
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div v-if="projectGroups.length === 0" class="text-center text-muted py-4">
|
||||
@@ -88,7 +74,8 @@
|
||||
{{ task.isCompleted ? '완료' : '진행' }}
|
||||
</label>
|
||||
</div>
|
||||
<textarea class="form-control form-control-sm" v-model="task.description" rows="2" placeholder="작업 내용"></textarea>
|
||||
<textarea class="form-control form-control-sm auto-resize" v-model="task.description" rows="1"
|
||||
placeholder="작업 내용" @input="autoResize"></textarea>
|
||||
<div class="text-nowrap">
|
||||
<input type="number" class="form-control form-control-sm text-end mb-1" style="width: 70px;"
|
||||
v-model.number="task.hours" min="0" step="0.5" placeholder="h" />
|
||||
@@ -114,7 +101,8 @@
|
||||
</div>
|
||||
<div v-for="(task, tIdx) in getPlanTasks(group.projectId)" :key="'plan-'+tIdx" class="mb-2">
|
||||
<div class="d-flex gap-2 align-items-start">
|
||||
<textarea class="form-control form-control-sm" v-model="task.description" rows="2" placeholder="계획 내용"></textarea>
|
||||
<textarea class="form-control form-control-sm auto-resize" v-model="task.description" rows="1"
|
||||
placeholder="계획 내용" @input="autoResize"></textarea>
|
||||
<div class="text-nowrap">
|
||||
<input type="number" class="form-control form-control-sm text-end mb-1" style="width: 70px;"
|
||||
v-model.number="task.hours" min="0" step="0.5" placeholder="h" />
|
||||
@@ -205,11 +193,269 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-backdrop fade show" v-if="showProjectModal" @click="showProjectModal = false"></div>
|
||||
|
||||
<!-- 이전 계획 로드 확인 모달 -->
|
||||
<div class="modal fade" :class="{ show: showLoadConfirmModal }" :style="{ display: showLoadConfirmModal ? 'block' : 'none' }">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
<i class="bi bi-clipboard-check me-2"></i>이전 계획 불러오기
|
||||
</h5>
|
||||
<button type="button" class="btn-close" @click="showLoadConfirmModal = false"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="mb-0">
|
||||
지난주에 작성된 주간보고 내용이 없습니다.<br>
|
||||
최근에 작성한 <strong>{{ recentReportInfo?.reportYear }}년 {{ recentReportInfo?.reportWeek }}주차</strong> 계획을 불러오시겠습니까?
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" @click="showLoadConfirmModal = false">취소</button>
|
||||
<button type="button" class="btn btn-primary" @click="confirmLoadRecentPlan">
|
||||
<i class="bi bi-download me-1"></i>불러오기
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-backdrop fade show" v-if="showLoadConfirmModal" @click="showLoadConfirmModal = false"></div>
|
||||
|
||||
<!-- 기존 보고서 존재 확인 모달 -->
|
||||
<div class="modal fade" :class="{ show: showExistingReportModal }" :style="{ display: showExistingReportModal ? 'block' : 'none' }">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
<i class="bi bi-exclamation-circle me-2 text-warning"></i>주간보고 존재
|
||||
</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="mb-0">
|
||||
<strong>{{ existingReportInfo?.reportYear }}년 {{ existingReportInfo?.reportWeek }}주차</strong>에 작성된 주간보고가 이미 존재합니다.<br>
|
||||
수정화면으로 이동합니다.
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" @click="goToList">취소</button>
|
||||
<button type="button" class="btn btn-primary" @click="goToExistingReport">
|
||||
<i class="bi bi-pencil me-1"></i>확인
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-backdrop fade show" v-if="showExistingReportModal"></div>
|
||||
|
||||
<!-- AI 자동채우기 모달 -->
|
||||
<div class="modal fade" :class="{ show: showAiModal }" :style="{ display: showAiModal ? 'block' : 'none' }">
|
||||
<div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">
|
||||
<i class="bi bi-robot me-2"></i>AI 자동채우기
|
||||
<span v-if="aiStep === 'matching'" class="badge bg-primary ms-2">프로젝트 매칭</span>
|
||||
</h5>
|
||||
<button type="button" class="btn-close" @click="closeAiModal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<!-- Step 1: 입력 -->
|
||||
<template v-if="aiStep === 'input'">
|
||||
<!-- 입력 방식 탭 -->
|
||||
<ul class="nav nav-tabs mb-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" :class="{ active: aiInputMode === 'text' }" href="#" @click.prevent="aiInputMode = 'text'">
|
||||
<i class="bi bi-fonts me-1"></i>텍스트
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" :class="{ active: aiInputMode === 'image' }" href="#" @click.prevent="aiInputMode = 'image'">
|
||||
<i class="bi bi-image me-1"></i>이미지
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- 텍스트 입력 -->
|
||||
<div v-if="aiInputMode === 'text'">
|
||||
<textarea
|
||||
class="form-control font-monospace"
|
||||
v-model="aiRawText"
|
||||
rows="12"
|
||||
placeholder="주간보고 내용을 붙여넣으세요.
|
||||
|
||||
예시:
|
||||
- PIMS 고도화: API 개발 완료 (8시간), UI 수정 (4시간)
|
||||
- 차주: 테스트 진행 예정 (16시간)
|
||||
- 이슈: 서버 메모리 부족
|
||||
- 휴가: 1/10(금) 연차"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<!-- 이미지 입력 -->
|
||||
<div v-if="aiInputMode === 'image'">
|
||||
<div
|
||||
class="upload-zone p-5 text-center border rounded"
|
||||
:class="{ 'border-primary bg-light': isDragging }"
|
||||
tabindex="0"
|
||||
@dragover.prevent="isDragging = true"
|
||||
@dragleave.prevent="isDragging = false"
|
||||
@drop.prevent="handleAiDrop"
|
||||
@paste="handleAiPaste"
|
||||
@click="($refs.aiFileInput as HTMLInputElement).click()"
|
||||
>
|
||||
<input
|
||||
ref="aiFileInput"
|
||||
type="file"
|
||||
multiple
|
||||
accept="image/*"
|
||||
class="d-none"
|
||||
@change="handleAiFileSelect"
|
||||
/>
|
||||
<i class="bi bi-cloud-arrow-up display-4 text-muted"></i>
|
||||
<p class="mt-2 mb-0 text-muted">
|
||||
이미지를 드래그하거나 클릭해서 업로드<br>
|
||||
<small>또는 <strong>Ctrl+V</strong>로 붙여넣기 (최대 10장)</small>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-if="aiUploadedImages.length > 0" class="mt-3">
|
||||
<label class="form-label small">업로드된 이미지 ({{ aiUploadedImages.length }}장)</label>
|
||||
<div class="d-flex flex-wrap gap-2">
|
||||
<div v-for="(img, idx) in aiUploadedImages" :key="idx" class="position-relative">
|
||||
<img :src="img" class="rounded border" style="width: 100px; height: 100px; object-fit: cover;" />
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm btn-danger position-absolute top-0 end-0 rounded-circle"
|
||||
style="transform: translate(30%, -30%); width: 20px; height: 20px; padding: 0; font-size: 10px;"
|
||||
@click="aiUploadedImages.splice(idx, 1)"
|
||||
>
|
||||
<i class="bi bi-x"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-info mt-3 mb-0 small">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
AI가 분석한 내용은 기존에 작성된 내용과 <strong>병합</strong>됩니다.
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Step 2: 프로젝트 매칭 -->
|
||||
<template v-if="aiStep === 'matching' && aiParsedResult">
|
||||
<div class="alert alert-warning small mb-3">
|
||||
<i class="bi bi-exclamation-triangle me-1"></i>
|
||||
AI가 분석한 프로젝트를 기존 프로젝트와 매칭해주세요.
|
||||
</div>
|
||||
|
||||
<div v-for="(proj, pIdx) in aiParsedResult.projects" :key="pIdx" class="card mb-3">
|
||||
<div class="card-header bg-light">
|
||||
<div class="row align-items-center">
|
||||
<div class="col">
|
||||
<small class="text-muted">AI 분석 결과:</small>
|
||||
<strong class="ms-1">{{ proj.originalName }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-bold">매칭할 프로젝트 선택</label>
|
||||
<select class="form-select" v-model="proj.matchedProjectId">
|
||||
<option :value="null" class="text-muted">-- 선택하세요 (미선택시 제외) --</option>
|
||||
<option v-for="p in allProjects" :key="p.projectId" :value="p.projectId">
|
||||
{{ p.projectCode }} - {{ p.projectName }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- 태스크 미리보기 -->
|
||||
<div class="row">
|
||||
<div class="col-md-6" v-if="proj.workTasks.length > 0">
|
||||
<label class="form-label small text-primary fw-bold">
|
||||
<i class="bi bi-check2-square me-1"></i>금주 실적 ({{ proj.workTasks.length }}건)
|
||||
</label>
|
||||
<ul class="list-unstyled small mb-0">
|
||||
<li v-for="(task, tIdx) in proj.workTasks" :key="'w'+tIdx" class="text-truncate mb-1">
|
||||
<i class="bi bi-dot"></i>{{ task.description }}
|
||||
<span v-if="task.hours" class="text-muted">({{ task.hours }}h)</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-6" v-if="proj.planTasks.length > 0">
|
||||
<label class="form-label small text-success fw-bold">
|
||||
<i class="bi bi-calendar-check me-1"></i>차주 계획 ({{ proj.planTasks.length }}건)
|
||||
</label>
|
||||
<ul class="list-unstyled small mb-0">
|
||||
<li v-for="(task, tIdx) in proj.planTasks" :key="'p'+tIdx" class="text-truncate mb-1">
|
||||
<i class="bi bi-dot"></i>{{ task.description }}
|
||||
<span v-if="task.hours" class="text-muted">({{ task.hours }}h)</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 공통사항 미리보기 -->
|
||||
<div v-if="aiParsedResult.issueDescription || aiParsedResult.vacationDescription || aiParsedResult.remarkDescription"
|
||||
class="card">
|
||||
<div class="card-header bg-light">
|
||||
<strong><i class="bi bi-chat-text me-1"></i>공통사항</strong>
|
||||
</div>
|
||||
<div class="card-body small">
|
||||
<div v-if="aiParsedResult.issueDescription" class="mb-2">
|
||||
<span class="badge bg-danger me-1">이슈</span>{{ aiParsedResult.issueDescription }}
|
||||
</div>
|
||||
<div v-if="aiParsedResult.vacationDescription" class="mb-2">
|
||||
<span class="badge bg-info me-1">휴가</span>{{ aiParsedResult.vacationDescription }}
|
||||
</div>
|
||||
<div v-if="aiParsedResult.remarkDescription">
|
||||
<span class="badge bg-secondary me-1">기타</span>{{ aiParsedResult.remarkDescription }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<!-- Step 1: 입력 -->
|
||||
<template v-if="aiStep === 'input'">
|
||||
<button type="button" class="btn btn-secondary" @click="closeAiModal">취소</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
@click="runAiParse"
|
||||
:disabled="isAiParsing || (aiInputMode === 'text' ? !aiRawText.trim() : aiUploadedImages.length === 0)"
|
||||
>
|
||||
<span v-if="isAiParsing" class="spinner-border spinner-border-sm me-1"></span>
|
||||
<i v-else class="bi bi-robot me-1"></i>
|
||||
AI 분석
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<!-- Step 2: 매칭 -->
|
||||
<template v-if="aiStep === 'matching'">
|
||||
<button type="button" class="btn btn-outline-secondary" @click="aiStep = 'input'">
|
||||
<i class="bi bi-arrow-left me-1"></i>이전
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary" @click="applyAiResult" :disabled="!hasMatchedProjects">
|
||||
<i class="bi bi-check-lg me-1"></i>적용하기
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-backdrop fade show" v-if="showAiModal" @click="closeAiModal"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
const { fetchCurrentUser } = useAuth()
|
||||
const route = useRoute()
|
||||
const { getWeekInfo, getWeekDates, getLastWeekInfo, getActualCurrentWeekInfo, getMonday, changeWeek: calcChangeWeek } = useWeekCalc()
|
||||
const router = useRouter()
|
||||
|
||||
interface TaskItem {
|
||||
@@ -230,6 +476,37 @@ const allProjects = ref<any[]>([])
|
||||
const showProjectModal = ref(false)
|
||||
const isSaving = ref(false)
|
||||
|
||||
// 이전 계획 로드 확인 모달
|
||||
const showLoadConfirmModal = ref(false)
|
||||
const recentReportInfo = ref<{ reportId: number; reportYear: number; reportWeek: number } | null>(null)
|
||||
|
||||
// 기존 보고서 존재 확인 모달
|
||||
const showExistingReportModal = ref(false)
|
||||
const existingReportInfo = ref<{ reportId: number; reportYear: number; reportWeek: number } | null>(null)
|
||||
|
||||
// AI 자동채우기 모달
|
||||
const showAiModal = ref(false)
|
||||
const aiStep = ref<'input' | 'matching'>('input')
|
||||
const aiInputMode = ref<'text' | 'image'>('text')
|
||||
const aiRawText = ref('')
|
||||
const aiUploadedImages = ref<string[]>([])
|
||||
const isAiParsing = ref(false)
|
||||
const isDragging = ref(false)
|
||||
|
||||
// AI 분석 결과 (매칭 전 임시 저장)
|
||||
interface AiParsedProject {
|
||||
originalName: string
|
||||
matchedProjectId: number | null
|
||||
workTasks: { description: string; hours: number; isCompleted: boolean }[]
|
||||
planTasks: { description: string; hours: number }[]
|
||||
}
|
||||
const aiParsedResult = ref<{
|
||||
projects: AiParsedProject[]
|
||||
issueDescription: string | null
|
||||
vacationDescription: string | null
|
||||
remarkDescription: string | null
|
||||
} | null>(null)
|
||||
|
||||
const form = ref({
|
||||
reportYear: new Date().getFullYear(),
|
||||
reportWeek: 1,
|
||||
@@ -266,7 +543,7 @@ const totalPlanHours = computed(() =>
|
||||
form.value.tasks.filter(t => t.taskType === 'PLAN').reduce((sum, t) => sum + (t.hours || 0), 0)
|
||||
)
|
||||
|
||||
const canSubmit = computed(() => form.value.tasks.some(t => t.description.trim()))
|
||||
const canSubmit = computed(() => form.value.tasks.some(t => t.description?.trim()))
|
||||
|
||||
onMounted(async () => {
|
||||
const user = await fetchCurrentUser()
|
||||
@@ -276,9 +553,60 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
await loadProjects()
|
||||
setLastWeek()
|
||||
await setDefaultWeek(user.employeeId)
|
||||
|
||||
// 이번 주차에 이미 작성한 보고서가 있는지 확인
|
||||
const existingReport = await checkExistingReport(user.employeeId)
|
||||
if (existingReport) {
|
||||
// 이미 작성한 보고서가 있으면 모달로 확인
|
||||
existingReportInfo.value = {
|
||||
reportId: existingReport.reportId,
|
||||
reportYear: form.value.reportYear,
|
||||
reportWeek: form.value.reportWeek
|
||||
}
|
||||
showExistingReportModal.value = true
|
||||
return
|
||||
}
|
||||
|
||||
await loadLastWeekPlan(user.employeeId)
|
||||
initAutoResize()
|
||||
})
|
||||
|
||||
// tasks 변경 시 textarea 높이 조절
|
||||
watch(() => form.value.tasks, () => {
|
||||
initAutoResize()
|
||||
}, { deep: true })
|
||||
|
||||
// 이번 주차에 이미 작성한 보고서 확인
|
||||
async function checkExistingReport(userId: number) {
|
||||
try {
|
||||
const res = await $fetch<any>(`/api/report/weekly/list?year=${form.value.reportYear}&week=${form.value.reportWeek}&authorId=${userId}`)
|
||||
if (res.reports && res.reports.length > 0) {
|
||||
return res.reports[0]
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('기존 보고서 확인 실패:', e)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// 기존 보고서 모달 - 확인 (수정화면으로 이동)
|
||||
function goToExistingReport() {
|
||||
if (existingReportInfo.value) {
|
||||
router.replace(`/report/weekly/${existingReportInfo.value.reportId}`)
|
||||
}
|
||||
}
|
||||
|
||||
// 기존 보고서 모달 - 취소 (목록으로 이동)
|
||||
function goToList() {
|
||||
// 쿼리 파라미터가 있으면 해당 주차 목록으로 이동
|
||||
if (route.query.year && route.query.week) {
|
||||
router.replace(`/report/weekly?year=${route.query.year}&week=${route.query.week}`)
|
||||
} else {
|
||||
router.replace('/report/weekly')
|
||||
}
|
||||
}
|
||||
|
||||
async function loadProjects() {
|
||||
try {
|
||||
const res = await $fetch<any>('/api/project/list')
|
||||
@@ -288,67 +616,150 @@ async function loadProjects() {
|
||||
}
|
||||
}
|
||||
|
||||
// 주차 관련 함수들
|
||||
function getMonday(date: Date): Date {
|
||||
const d = new Date(date)
|
||||
const day = d.getDay()
|
||||
const diff = d.getDate() - day + (day === 0 ? -6 : 1)
|
||||
d.setDate(diff)
|
||||
return d
|
||||
}
|
||||
|
||||
function getSunday(monday: Date): Date {
|
||||
const d = new Date(monday)
|
||||
d.setDate(d.getDate() + 6)
|
||||
return d
|
||||
}
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
return date.toISOString().split('T')[0]
|
||||
}
|
||||
|
||||
function getWeekNumber(date: Date): { year: number; week: number } {
|
||||
const d = new Date(date)
|
||||
d.setHours(0, 0, 0, 0)
|
||||
d.setDate(d.getDate() + 3 - (d.getDay() + 6) % 7)
|
||||
const week1 = new Date(d.getFullYear(), 0, 4)
|
||||
const weekNum = 1 + Math.round(((d.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7)
|
||||
return { year: d.getFullYear(), week: weekNum }
|
||||
}
|
||||
|
||||
function setWeekDates(monday: Date) {
|
||||
const sunday = getSunday(monday)
|
||||
const weekInfo = getWeekNumber(monday)
|
||||
|
||||
form.value.weekStartDate = formatDate(monday)
|
||||
form.value.weekEndDate = formatDate(sunday)
|
||||
form.value.reportYear = weekInfo.year
|
||||
form.value.reportWeek = weekInfo.week
|
||||
// 주차 관련 함수들 (useWeekCalc 사용)
|
||||
function setWeekFromInfo(info: { year: number; week: number; startDateStr: string; endDateStr: string }) {
|
||||
form.value.reportYear = info.year
|
||||
form.value.reportWeek = info.week
|
||||
form.value.weekStartDate = info.startDateStr
|
||||
form.value.weekEndDate = info.endDateStr
|
||||
}
|
||||
|
||||
function changeWeek(delta: number) {
|
||||
const currentMonday = new Date(form.value.weekStartDate)
|
||||
currentMonday.setDate(currentMonday.getDate() + (delta * 7))
|
||||
setWeekDates(currentMonday)
|
||||
const { year, week } = calcChangeWeek(form.value.reportYear, form.value.reportWeek, delta)
|
||||
const weekInfo = getWeekDates(year, week)
|
||||
setWeekFromInfo(weekInfo)
|
||||
}
|
||||
|
||||
function setLastWeek() {
|
||||
const today = new Date()
|
||||
const lastWeekMonday = getMonday(today)
|
||||
lastWeekMonday.setDate(lastWeekMonday.getDate() - 7)
|
||||
setWeekDates(lastWeekMonday)
|
||||
const lastWeek = getLastWeekInfo()
|
||||
setWeekFromInfo(lastWeek)
|
||||
}
|
||||
|
||||
function setThisWeek() {
|
||||
const today = new Date()
|
||||
const thisWeekMonday = getMonday(today)
|
||||
setWeekDates(thisWeekMonday)
|
||||
const thisWeek = getActualCurrentWeekInfo()
|
||||
setWeekFromInfo(thisWeek)
|
||||
}
|
||||
|
||||
async function setDefaultWeek(userId: number) {
|
||||
// 쿼리 파라미터가 있으면 해당 주차로 설정
|
||||
if (route.query.year && route.query.week) {
|
||||
const year = parseInt(route.query.year as string)
|
||||
const week = parseInt(route.query.week as string)
|
||||
const weekInfo = getWeekDates(year, week)
|
||||
setWeekFromInfo(weekInfo)
|
||||
return
|
||||
}
|
||||
|
||||
const now = new Date()
|
||||
const dayOfWeek = now.getDay() // 0=일, 1=월, ...
|
||||
const hour = now.getHours()
|
||||
|
||||
// 기본값: 이번 주
|
||||
const thisWeek = getActualCurrentWeekInfo()
|
||||
setWeekFromInfo(thisWeek)
|
||||
|
||||
// 월요일 9시 전인 경우, 지난주 보고서 확인
|
||||
if (dayOfWeek === 1 && hour < 9) {
|
||||
const lastWeek = getLastWeekInfo()
|
||||
|
||||
try {
|
||||
// 현재 사용자의 지난주 보고서가 있는지 확인
|
||||
const res = await $fetch<any>(`/api/report/weekly/list?year=${lastWeek.year}&week=${lastWeek.week}&authorId=${userId}`)
|
||||
const hasLastWeekReport = res.reports && res.reports.length > 0
|
||||
|
||||
// 지난주 보고서가 없으면 지난주로 설정
|
||||
if (!hasLastWeekReport) {
|
||||
setWeekFromInfo(lastWeek)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('지난주 보고서 확인 실패:', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 지난주 계획을 이번주 실적에 로드
|
||||
async function loadLastWeekPlan(userId: number) {
|
||||
try {
|
||||
// 작성하려는 주차
|
||||
const targetYear = form.value.reportYear
|
||||
const targetWeek = form.value.reportWeek
|
||||
|
||||
// 직전 주차 계산
|
||||
const prevWeek = calcChangeWeek(targetYear, targetWeek, -1)
|
||||
|
||||
// 작성하려는 주차 이전의 보고서만 조회 (최신순, 1건)
|
||||
const res = await $fetch<any>(`/api/report/weekly/list?authorId=${userId}&beforeYear=${targetYear}&beforeWeek=${targetWeek}&limit=1`)
|
||||
|
||||
if (!res.reports || res.reports.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const recent = res.reports[0]
|
||||
|
||||
if (recent.reportYear === prevWeek.year && recent.reportWeek === prevWeek.week) {
|
||||
// 직전 주차면 → 자동 로드
|
||||
await loadPlanFromReport(recent.reportId)
|
||||
} else {
|
||||
// 직전 주차가 아니면 → 모달로 물어봄
|
||||
recentReportInfo.value = {
|
||||
reportId: recent.reportId,
|
||||
reportYear: recent.reportYear,
|
||||
reportWeek: recent.reportWeek
|
||||
}
|
||||
showLoadConfirmModal.value = true
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('이전 계획 로드 실패:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 보고서에서 계획 로드 (공통 함수)
|
||||
async function loadPlanFromReport(reportId: number) {
|
||||
try {
|
||||
const detail = await $fetch<any>(`/api/report/weekly/${reportId}/detail`)
|
||||
|
||||
if (!detail.projects || detail.projects.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// 모든 프로젝트의 planTasks를 WORK로 변환
|
||||
const tasks: TaskItem[] = []
|
||||
for (const proj of detail.projects) {
|
||||
if (proj.planTasks && proj.planTasks.length > 0) {
|
||||
for (const t of proj.planTasks) {
|
||||
tasks.push({
|
||||
projectId: proj.projectId,
|
||||
projectCode: proj.projectCode || '',
|
||||
projectName: proj.projectName || '',
|
||||
taskType: 'WORK',
|
||||
description: t.description || '',
|
||||
hours: t.hours || 0,
|
||||
isCompleted: false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tasks.length > 0) {
|
||||
form.value.tasks = tasks
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('계획 로드 실패:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 모달에서 확인 클릭 시
|
||||
async function confirmLoadRecentPlan() {
|
||||
if (recentReportInfo.value) {
|
||||
await loadPlanFromReport(recentReportInfo.value.reportId)
|
||||
}
|
||||
showLoadConfirmModal.value = false
|
||||
}
|
||||
|
||||
function updateWeekFromDate() {
|
||||
const startDate = new Date(form.value.weekStartDate)
|
||||
const monday = getMonday(startDate)
|
||||
setWeekDates(monday)
|
||||
const weekInfo = getWeekInfo(startDate)
|
||||
setWeekFromInfo(weekInfo)
|
||||
}
|
||||
|
||||
// Task 관련 함수들
|
||||
@@ -464,10 +875,281 @@ async function handleSubmit() {
|
||||
isSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// === textarea 자동 높이 조절 ===
|
||||
function autoResize(e: Event) {
|
||||
const textarea = e.target as HTMLTextAreaElement
|
||||
textarea.style.height = 'auto'
|
||||
textarea.style.height = textarea.scrollHeight + 'px'
|
||||
}
|
||||
|
||||
// 초기 로드 시 모든 textarea 높이 조절
|
||||
function initAutoResize() {
|
||||
nextTick(() => {
|
||||
document.querySelectorAll('textarea.auto-resize').forEach((el) => {
|
||||
const textarea = el as HTMLTextAreaElement
|
||||
textarea.style.height = 'auto'
|
||||
textarea.style.height = textarea.scrollHeight + 'px'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// === AI 자동채우기 관련 ===
|
||||
function closeAiModal() {
|
||||
showAiModal.value = false
|
||||
aiStep.value = 'input'
|
||||
aiRawText.value = ''
|
||||
aiUploadedImages.value = []
|
||||
aiParsedResult.value = null
|
||||
}
|
||||
|
||||
function handleAiDrop(e: DragEvent) {
|
||||
isDragging.value = false
|
||||
const files = e.dataTransfer?.files
|
||||
if (files) processAiFiles(Array.from(files))
|
||||
}
|
||||
|
||||
function handleAiPaste(e: ClipboardEvent) {
|
||||
const items = e.clipboardData?.items
|
||||
if (!items) return
|
||||
|
||||
const imageFiles: File[] = []
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
if (items[i].type.startsWith('image/')) {
|
||||
const file = items[i].getAsFile()
|
||||
if (file) imageFiles.push(file)
|
||||
}
|
||||
}
|
||||
|
||||
if (imageFiles.length > 0) {
|
||||
e.preventDefault()
|
||||
processAiFiles(imageFiles)
|
||||
}
|
||||
}
|
||||
|
||||
function handleAiFileSelect(e: Event) {
|
||||
const input = e.target as HTMLInputElement
|
||||
if (input.files) processAiFiles(Array.from(input.files))
|
||||
}
|
||||
|
||||
function processAiFiles(files: File[]) {
|
||||
const maxFiles = 10 - aiUploadedImages.value.length
|
||||
const toProcess = files.slice(0, maxFiles)
|
||||
|
||||
toProcess.forEach(file => {
|
||||
if (!file.type.startsWith('image/')) return
|
||||
const reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
if (e.target?.result) {
|
||||
aiUploadedImages.value.push(e.target.result as string)
|
||||
}
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
})
|
||||
}
|
||||
|
||||
async function runAiParse() {
|
||||
isAiParsing.value = true
|
||||
try {
|
||||
let res: any
|
||||
if (aiInputMode.value === 'text') {
|
||||
res = await $fetch<any>('/api/ai/parse-my-report', {
|
||||
method: 'POST',
|
||||
body: { rawText: aiRawText.value }
|
||||
})
|
||||
} else {
|
||||
res = await $fetch<any>('/api/ai/parse-my-report-image', {
|
||||
method: 'POST',
|
||||
body: { images: aiUploadedImages.value }
|
||||
})
|
||||
}
|
||||
|
||||
console.log('=== AI 분석 응답 ===')
|
||||
console.log(res)
|
||||
|
||||
// 파싱 결과를 임시 저장하고 매칭 단계로 이동
|
||||
if (res.parsed?.projects?.length > 0) {
|
||||
aiParsedResult.value = {
|
||||
projects: res.parsed.projects.map((p: any) => ({
|
||||
originalName: p.projectName || '알 수 없음',
|
||||
matchedProjectId: p.matchedProjectId || null,
|
||||
workTasks: p.workTasks || [],
|
||||
planTasks: p.planTasks || []
|
||||
})),
|
||||
issueDescription: res.parsed.issueDescription,
|
||||
vacationDescription: res.parsed.vacationDescription,
|
||||
remarkDescription: res.parsed.remarkDescription
|
||||
}
|
||||
aiStep.value = 'matching'
|
||||
} else {
|
||||
alert('분석된 내용이 없습니다.')
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error('=== AI 분석 에러 ===', e)
|
||||
alert(e.data?.message || 'AI 분석에 실패했습니다.')
|
||||
} finally {
|
||||
isAiParsing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 매칭된 프로젝트가 있는지 확인
|
||||
const hasMatchedProjects = computed(() => {
|
||||
if (!aiParsedResult.value) return false
|
||||
return aiParsedResult.value.projects.some(p => p.matchedProjectId !== null)
|
||||
})
|
||||
|
||||
// 매칭 완료 후 적용
|
||||
function applyAiResult() {
|
||||
if (!aiParsedResult.value) return
|
||||
|
||||
const parsed = aiParsedResult.value
|
||||
|
||||
// 프로젝트별 태스크 병합
|
||||
for (const proj of parsed.projects) {
|
||||
const projectId = proj.matchedProjectId
|
||||
if (!projectId) continue // 미선택은 제외
|
||||
|
||||
// 금주 실적 추가
|
||||
for (const task of proj.workTasks) {
|
||||
if (task.description?.trim()) {
|
||||
form.value.tasks.push({
|
||||
projectId,
|
||||
taskType: 'WORK',
|
||||
description: task.description,
|
||||
hours: task.hours || 0,
|
||||
isCompleted: task.isCompleted !== false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 차주 계획 추가
|
||||
for (const task of proj.planTasks) {
|
||||
if (task.description?.trim()) {
|
||||
form.value.tasks.push({
|
||||
projectId,
|
||||
taskType: 'PLAN',
|
||||
description: task.description,
|
||||
hours: task.hours || 0,
|
||||
isCompleted: false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 공통사항 병합
|
||||
if (parsed.issueDescription) {
|
||||
form.value.issueDescription = form.value.issueDescription
|
||||
? form.value.issueDescription + '\n' + parsed.issueDescription
|
||||
: parsed.issueDescription
|
||||
}
|
||||
if (parsed.vacationDescription) {
|
||||
form.value.vacationDescription = form.value.vacationDescription
|
||||
? form.value.vacationDescription + '\n' + parsed.vacationDescription
|
||||
: parsed.vacationDescription
|
||||
}
|
||||
if (parsed.remarkDescription) {
|
||||
form.value.remarkDescription = form.value.remarkDescription
|
||||
? form.value.remarkDescription + '\n' + parsed.remarkDescription
|
||||
: parsed.remarkDescription
|
||||
}
|
||||
|
||||
closeAiModal()
|
||||
}
|
||||
|
||||
function mergeAiResult(parsed: any) {
|
||||
console.log('=== mergeAiResult 시작 ===')
|
||||
console.log('parsed:', parsed)
|
||||
console.log('allProjects:', allProjects.value)
|
||||
|
||||
// 프로젝트별 태스크 병합
|
||||
if (parsed.projects && Array.isArray(parsed.projects)) {
|
||||
for (const proj of parsed.projects) {
|
||||
console.log('처리 중인 프로젝트:', proj.projectName, 'matchedProjectId:', proj.matchedProjectId)
|
||||
|
||||
// 기존 프로젝트 찾기 (이름으로 매칭)
|
||||
const existingProject = allProjects.value.find(p =>
|
||||
p.projectName.toLowerCase().includes(proj.projectName?.toLowerCase()) ||
|
||||
proj.projectName?.toLowerCase().includes(p.projectName.toLowerCase())
|
||||
)
|
||||
|
||||
const projectId = proj.matchedProjectId || existingProject?.projectId
|
||||
|
||||
if (!projectId) {
|
||||
console.warn('매칭되는 프로젝트 없음:', proj.projectName)
|
||||
continue
|
||||
}
|
||||
|
||||
// 금주 실적 추가
|
||||
if (proj.workTasks && Array.isArray(proj.workTasks)) {
|
||||
for (const task of proj.workTasks) {
|
||||
if (task.description?.trim()) {
|
||||
form.value.tasks.push({
|
||||
projectId,
|
||||
taskType: 'WORK',
|
||||
description: task.description,
|
||||
hours: task.hours || 0,
|
||||
isCompleted: task.isCompleted !== false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 차주 계획 추가
|
||||
if (proj.planTasks && Array.isArray(proj.planTasks)) {
|
||||
for (const task of proj.planTasks) {
|
||||
if (task.description?.trim()) {
|
||||
form.value.tasks.push({
|
||||
projectId,
|
||||
taskType: 'PLAN',
|
||||
description: task.description,
|
||||
hours: task.hours || 0,
|
||||
isCompleted: true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 공통사항 병합 (기존 내용 + 새 내용)
|
||||
if (parsed.issueDescription) {
|
||||
form.value.issueDescription = form.value.issueDescription
|
||||
? form.value.issueDescription + '\n' + parsed.issueDescription
|
||||
: parsed.issueDescription
|
||||
}
|
||||
if (parsed.vacationDescription) {
|
||||
form.value.vacationDescription = form.value.vacationDescription
|
||||
? form.value.vacationDescription + '\n' + parsed.vacationDescription
|
||||
: parsed.vacationDescription
|
||||
}
|
||||
if (parsed.remarkDescription) {
|
||||
form.value.remarkDescription = form.value.remarkDescription
|
||||
? form.value.remarkDescription + '\n' + parsed.remarkDescription
|
||||
: parsed.remarkDescription
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.modal.show {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.upload-zone {
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
border-style: dashed !important;
|
||||
border-width: 2px !important;
|
||||
}
|
||||
|
||||
.upload-zone:hover {
|
||||
border-color: #0d6efd !important;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
textarea.auto-resize {
|
||||
overflow: hidden;
|
||||
resize: none;
|
||||
min-height: 32px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user