
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
<template>
<div class="content">
<div class="sub-title-area mb-30">
<h2>사진 기록물</h2>
<div class="breadcrumb-list">
<ul>
<li>
<img :src="homeicon" alt="Home Icon">
<p>기록물</p>
</li>
<li><img :src="righticon" alt=""></li>
<li>사진 기록물</li>
</ul>
</div>
</div>
<form class="gallery-form mb-40" @submit.prevent>
<dl class="mb-20">
<dd>
<p>{{ findResult.sj }}</p>
<div class="date flex align-center">
<img :src="calendaricon" alt="">
<span>{{ $dotFormatDate(findResult.rgsde) }}</span>
</div>
</dd>
</dl>
<div class="img-view">
<div class="current-img-wrap">
<img :src="currentImg.filePath" :alt="currentImg.fileNm" />
</div>
<div class="thumb-view">
<div class="download-btn txt-right mb-20">
<button class="btn all-down select-down" @click="fnDownload('all')">전체 다운로드</button>
</div>
<div class="thumbnails">
<div class="download-btn">
<div v-for="(item, idx) of findResult.files" :key="idx" class="thumbnail-wrap">
<figure class="thumbnail" @click="onchangeImg(item)">
<img :src="item.filePath" :alt="item.fileNm" />
</figure>
<div class="float-div">
<button type="button" class="btn_sm red" @click="fnDownload('single', item)"></button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<h3>내용</h3>
<form class="info-form mb-50" @submit.prevent>
<dl>
<dd>
<ViewerComponent :content="findResult.cn" />
</dd>
</dl>
</form>
<h3>기본정보</h3>
<form class="info-form mb-50" @submit.prevent>
<dl>
<dd class="mb-20">
<img :src="addressicon" alt="">
<span>주소</span>
<p>{{ findResult.adres }}</p>
</dd>
<dd class="mb-20">
<img :src="yearicon" alt="">
<span>생산연도</span>
<p>{{ $dotFormatDate(findResult.prdctnYear) }}</p>
</dd>
<dd>
<img :src="categoryicon" alt="">
<span>카테고리</span>
<ul class="category">
<li v-for="(item, idx) of findResult.ctgrys" :key="idx" class="category">{{ item.ctgryNm }}</li>
</ul>
</dd>
</dl>
</form>
<div class="btn-group flex-center">
<button v-if="isRegister" class="red-line " type="button" @click="fnDelete">삭제</button>
<button v-if="isRegister" class="blue-line " type="button" @click="fnMoveTo('edit', pageId)">수정</button>
<button class="gray-line-bg " type="button" @click="fnMoveTo('list')">목록</button>
</div>
</div>
</template>
<script>
// COMPONENT
import ViewerComponent from '@/views/component/editor/ViewerComponent.vue';
// API
import uploadProgressStore from '@/resources/js/uploadProgressStore';
import { findDcryProc, deleteDcryProc } from '@/resources/api/dcry';
import { fileDownloadProc, multiFileDownloadProc } from '@/resources/api/file';
export default {
components: {
ViewerComponent,
},
data() {
return {
// ICON
calendaricon: 'client/resources/images/icon/calendaricon.png',
homeicon: 'client/resources/images/icon/home.png',
erroricon: 'client/resources/images/icon/error.png',
righticon: 'client/resources/images/icon/right.png',
addressicon: 'client/resources/images/icon/addressicon.png',
yearicon: 'client/resources/images/icon/yearicon.png',
categoryicon: 'client/resources/images/icon/categoryicon.png',
pageId: null,
findResult: {},
selectedFiles: [],
loading: false,
activeIndex: 0,
currentImg: {
fileNm: "기본이미지",
filePath: "client/resources/images/no_img.png",
},
isRegister: false,
};
},
created() {
this.pageId = this.$route.query.id;
if (this.$isEmpty(this.pageId)) {
alert("게시물 존재하지 않습니다.");
this.fnMoveTo('list');
}
},
mounted() {
this.fnFindDcry(); // 상세 조회
},
methods: {
onchangeImg(img) {
this.currentImg = img;
},
// 상세 조회
async fnFindDcry() {
try {
const response = await findDcryProc(this.pageId);
this.findResult = response.data.data.dcry;
if (this.findResult.ty !== 'P') {
alert('올바른 접근이 아닙니다.');
this.fnMoveTo('list'); // 목록으로 이동
}
this.currentImg = this.findResult.files[0];
this.isRegister = this.$registerChk(this.findResult.register);
} catch (error) {
alert('조회중 오류가 발생했습니다.');
this.fnMoveTo('list');
if (error.response) {
alert(error.response.data.message);
}
console.error(error.message);
}
},
// 파일 다운로드
async fnDownload(type, file) {
let url = null;
let link = null;
try {
let fileList = [];
if (type === 'single') {
fileList.push(file);
} else if (type === 'all') {
fileList = this.findResult.files;
}
let isMultiple = fileList.length > 1;
let files = isMultiple ? fileList : fileList[0];
const response = isMultiple ? await multiFileDownloadProc(files) : await fileDownloadProc(files);
let filename;
if (type === 'single') {
filename = fileList[0].fileNm;
} else if (type === 'all') {
const contentDisposition = response.headers['content-disposition'];
if (contentDisposition) {
const filenameRegex = /file[Nn]ame[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
const matches = filenameRegex.exec(contentDisposition);
if (matches != null && matches[1]) {
let extractedName = matches[1].replace(/['"]/g, '');
try {
filename = decodeURIComponent(extractedName.replace(/\+/g, ' '));
} catch (e) {
console.warn('파일명 디코딩 실패:', e);
filename = extractedName.replace(/\+/g, ' ');
}
}
}
}
// 파일 다운로드 생성
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
uploadProgressStore.closeModal();
} catch (error) {
alert('파일 다운로드 중 오류가 발생했습니다.');
uploadProgressStore.closeModal();
} finally {
// 리소스 정리
setTimeout(() => {
if (url) {
window.URL.revokeObjectURL(url);
}
if (link && link.parentNode) {
document.body.removeChild(link);
}
}, 100);
}
},
// 삭제
async fnDelete() {
let isCheck = confirm("해당 페이지를 삭제하시겠습니까?");
if (!isCheck) {
return;
}
try {
const response = await deleteDcryProc(this.pageId);
alert('해당 페이지를 삭제했습니다.');
this.fnMoveTo('list');
} catch (error) {
if (error.response) {
alert(error.response.data.message);
}
console.error(error.message);
}
},
// 페이지 이동
fnMoveTo(type, id) {
const routes = {
'list': { name: 'PicHistorySearch' },
'view': { name: 'PicHistoryDetail', query: { id } },
'edit': { name: 'PicHistoryInsert', query: this.$isEmpty(id) ? {} : { id } },
};
if (routes[type]) {
this.$router.push(routes[type]);
} else {
alert("올바르지 않은 경로를 요청하여 목록으로 이동합니다.");
this.$router.push(routes['list']);
}
},
},
};
</script>