Files
sodalive-vuejs-admin/src/views/Content/ContentMainTopBanner.vue
T
Yu Sung 63f16091fa feat(content-banner): 콘텐츠 배너 예약 기간 적용
- 등록/수정 폼에 선택적 시작·종료 일시(datetime-local, KST) 추가
- 관리자 목록 카드에 저장된 예약 기간 표기
- 수정 시 미변경 필드 생략, 값 삭제 시 명시적 null 전송
- 역전 범위 저장 차단(같은 분 허용) 및 검증 유틸·테스트 추가
2026-10-27 21:18:06 +09:00

1057 lines
32 KiB
Vue

<template>
<div>
<v-toolbar dark>
<v-spacer />
<v-toolbar-title>콘텐츠 배너</v-toolbar-title>
<v-spacer />
</v-toolbar>
<br>
<v-dialog
v-model="show_write_dialog"
max-width="1000px"
persistent
>
<template v-slot:activator="{ on, attrs }">
<v-container>
<v-row>
<v-col cols="9">
<v-radio-group
v-model="selected_tab_id"
row
@change="getBanners"
>
<v-radio
v-for="tab in tabs"
:key="tab.tabId"
:label="tab.title"
:value="tab.tabId"
/>
</v-radio-group>
</v-col>
<v-spacer />
<v-col>
<v-btn
block
color="#3BB9F1"
dark
depressed
v-bind="attrs"
v-on="on"
>
배너 등록
</v-btn>
</v-col>
</v-row>
<draggable
v-model="banners"
class="row"
@end="onDropCallback(banners)"
>
<v-col
v-for="(item, i) in banners"
:key="i"
cols="3"
>
<v-card>
<v-card-title>
<v-spacer />
<v-img :src="item.thumbnailImageUrl" />
<v-spacer />
</v-card-title>
<v-card-subtitle class="text-center schedule-text">
{{ scheduleRangeText(item) }}
</v-card-subtitle>
<v-card-actions>
<v-spacer />
<v-btn
text
@click="showModifyBannerDialog(item)"
>
수정
</v-btn>
<v-btn
text
@click="deleteConfirm(item)"
>
삭제
</v-btn>
<v-spacer />
</v-card-actions>
</v-card>
</v-col>
</draggable>
</v-container>
</template>
<v-card>
<v-card-title v-if="is_modify === true">
배너 수정
</v-card-title>
<v-card-title v-else>
배너 등록
</v-card-title>
<v-card-text>
<v-row align="center">
<v-col cols="4">
메인 탭
</v-col>
<v-col cols="8">
<v-radio-group
v-model="banner.tab_id"
row
>
<v-radio
v-for="tab in tabs"
:key="tab.tabId"
:label="tab.title"
:value="tab.tabId"
/>
</v-radio-group>
</v-col>
</v-row>
</v-card-text>
<!-- 언어 선택: 등록 시에만 노출 (수정 시 비노출) -->
<v-card-text v-if="!is_modify">
<v-row align="center">
<v-col cols="4">
언어
</v-col>
<v-col cols="8">
<v-select
v-model="banner.lang"
:items="langItems"
item-text="text"
item-value="value"
label="언어 선택"
/>
</v-col>
</v-row>
</v-card-text>
<v-card-text>
<v-row align="center">
<v-col cols="4">
배너 타입
</v-col>
<v-col cols="8">
<v-radio-group
v-model="banner.type"
row
>
<v-radio
value="CREATOR"
label="크리에이터 채널"
/>
<v-radio
value="LINK"
label="외부링크"
/>
<v-radio
value="EVENT"
label="이벤트"
/>
<v-radio
value="SERIES"
label="시리즈"
/>
</v-radio-group>
</v-col>
</v-row>
</v-card-text>
<v-card-text v-if="banner.type === 'CREATOR'">
<v-row align="center">
<v-col cols="4">
크리에이터
</v-col>
<v-col cols="8">
<v-combobox
v-model="banner.creator_nickname"
:items="creators"
:loading="is_loading"
:search-input.sync="search_query_creator"
label="크리에이터를 검색하세요"
item-text="name"
item-value="value"
no-data-text="No results found"
hide-selected
clearable
@change="onSelect"
@update:search-input="onSearchUpdate"
/>
</v-col>
</v-row>
</v-card-text>
<v-card-text v-else-if="banner.type === 'LINK'">
<v-row align="center">
<v-col cols="4">
링크
</v-col>
<v-col cols="8">
<v-text-field
v-model="banner.link"
label="링크"
required
/>
</v-col>
</v-row>
</v-card-text>
<v-card-text v-else-if="banner.type === 'SERIES'">
<v-row align="center">
<v-col cols="4">
시리즈
</v-col>
<v-col cols="8">
<v-combobox
v-model="banner.series_title"
:items="series"
:loading="is_loading"
:search-input.sync="search_query_series"
label="시리즈를 검색하세요"
item-text="name"
item-value="value"
no-data-text="No results found"
hide-selected
clearable
@change="onSelectSeries"
@update:search-input="onSearchSeriesUpdate"
/>
</v-col>
</v-row>
</v-card-text>
<v-card-text v-else>
<v-row align="center">
<v-col cols="4">
이벤트
</v-col>
<v-col cols="8">
<v-select
v-model="banner.event_id"
:items="events"
item-text="title"
item-value="value"
label="이벤트 선택"
/>
</v-col>
</v-row>
</v-card-text>
<v-card-text>
<v-row>
<v-col cols="4">
19금
</v-col>
<v-col cols="8">
<input
v-model="banner.is_adult"
type="checkbox"
>
</v-col>
</v-row>
</v-card-text>
<v-card-text>
<v-row align="center">
<v-col cols="4">
노출 기간 (한국 시간 기준)
</v-col>
<v-col cols="4">
<v-text-field
v-model="banner.start_date"
type="datetime-local"
label="시작 일시 (선택)"
:error-messages="schedule_errors.start_date"
clearable
@click:clear="banner.start_date = ''"
/>
</v-col>
<v-col cols="4">
<v-text-field
v-model="banner.end_date"
type="datetime-local"
label="종료 일시 (선택)"
:error-messages="schedule_errors.end_date"
clearable
@click:clear="banner.end_date = ''"
/>
</v-col>
</v-row>
<v-row>
<v-col class="schedule-text">
비워두면 해당 경계의 예약 제한이 없습니다. 입력한 시간은 한국 시간(KST)으로 저장됩니다.
</v-col>
</v-row>
</v-card-text>
<div class="image-select">
<label for="image">
배너 이미지 등록
</label>
<v-file-input
id="image"
v-model="banner.thumbnail_image"
@change="imageAdd"
/>
</div>
<img
v-if="banner.thumbnail_image_url"
:src="banner.thumbnail_image_url"
alt=""
class="image-preview"
>
<v-card-actions v-show="!is_loading">
<v-spacer />
<v-btn
color="blue darken-1"
text
@click="cancel"
>
취소
</v-btn>
<v-btn
v-if="is_modify === true"
color="blue darken-1"
text
@click="modify"
>
수정
</v-btn>
<v-btn
v-else
color="blue darken-1"
text
@click="submit"
>
등록
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<!-- 이미지 크롭 다이얼로그 (CropperJS) -->
<v-dialog
v-model="show_crop_dialog"
max-width="900px"
persistent
>
<v-card class="cropper-card">
<v-card-title>
이미지 크롭 (1:1)
</v-card-title>
<v-card-text class="cropper-card-text">
<div class="cropper-canvas-wrap">
<img
v-if="crop_src"
ref="cropperImage"
:src="crop_src"
alt="crop"
class="cropper-dialog-img"
>
</div>
</v-card-text>
<v-card-actions v-show="!is_loading">
<v-spacer />
<v-btn
color="blue darken-1"
text
@click="handleCropCancel"
>
취소
</v-btn>
<v-btn
color="blue darken-1"
text
@click="handleCropConfirm"
>
확인
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog
v-model="show_delete_confirm_dialog"
max-width="400px"
persistent
>
<v-card>
<v-card-text />
<v-card-text>
삭제하시겠습니까?
</v-card-text>
<v-card-actions v-show="!is_loading">
<v-spacer />
<v-btn
color="blue darken-1"
text
@click="deleteCancel"
>
취소
</v-btn>
<v-btn
color="blue darken-1"
text
@click="deleteBanner"
>
확인
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script>
import Draggable from "vuedraggable";
import debounce from "lodash/debounce";
import Cropper from 'cropperjs'
import * as seriesApi from "@/api/audio_content_series"
import * as memberApi from "@/api/member";
import * as eventApi from "@/api/event";
import * as api from "@/api/audio_content"
import {
applyScheduleToModifyRequest,
applyScheduleToSaveRequest,
createBannerScheduleForm,
formatScheduleRange,
validateBannerSchedule
} from "@/utils/audio_content_banner"
export default {
name: "AudioContentMainTopBanner",
components: {Draggable},
data() {
return {
is_selecting: false,
is_loading: false,
is_modify: false,
show_write_dialog: false,
show_delete_confirm_dialog: false,
// 이미지 크롭용 상태
show_crop_dialog: false,
cropper: null,
crop_src: null,
selected_file_for_crop: null,
selected_banner: {},
banner: {type: 'CREATOR', tab_id: 1, lang: 'ko', ...createBannerScheduleForm()},
schedule_errors: {},
banners: [],
events: [],
creators: [],
series: [],
search_query_creator: '',
search_query_series: '',
tabs: [],
selected_tab_id: 1,
langItems: [
{ text: '한국어', value: 'ko' },
{ text: '일본어', value: 'ja' },
{ text: '영어', value: 'en' }
]
}
},
watch: {
search_query_creator() {
if (!this.is_selecting) {
this.debouncedSearch();
}
},
search_query_series() {
if (!this.is_selecting) {
this.debouncedSearchSeries();
}
}
},
async created() {
await this.getEvents()
await this.getAudioContentMainTabList()
},
mounted() {
this.debouncedSearch = debounce(this.searchCreator, 500);
this.debouncedSearchSeries = debounce(this.searchSeries, 500);
},
methods: {
async imageAdd(payload) {
const file = payload;
// 파일 해제 시 초기화
if (!file) {
if (this.banner.thumbnail_image_url) {
URL.revokeObjectURL(this.banner.thumbnail_image_url)
}
this.banner.thumbnail_image = null
this.banner.thumbnail_image_url = null
return
}
// CropperJS 다이얼로그 오픈 흐름
if (this.crop_src) {
URL.revokeObjectURL(this.crop_src)
}
this.selected_file_for_crop = file
this.crop_src = URL.createObjectURL(file)
this.show_crop_dialog = true
this.$nextTick(() => {
this.initCropper()
})
},
initCropper() {
const imageEl = this.$refs.cropperImage
if (!imageEl) return
// 기존 인스턴스 제거
if (this.cropper) {
this.cropper.destroy()
this.cropper = null
}
this.cropper = new Cropper(imageEl, {
aspectRatio: 1,
viewMode: 1,
autoCropArea: 1,
movable: true,
zoomable: true,
scalable: false,
rotatable: false,
responsive: true,
background: false,
})
},
destroyCropper() {
if (this.cropper) {
this.cropper.destroy()
this.cropper = null
}
},
async handleCropConfirm() {
if (!this.cropper || !this.selected_file_for_crop) return
try {
this.is_loading = true
const mime = this.selected_file_for_crop.type && /^image\//.test(this.selected_file_for_crop.type)
? this.selected_file_for_crop.type
: 'image/png'
const canvas = this.cropper.getCroppedCanvas()
await new Promise((resolve, reject) => {
canvas.toBlob((blob) => {
if (!blob) return reject(new Error('크롭된 이미지를 생성할 수 없습니다.'))
const croppedFile = new File([blob], this.selected_file_for_crop.name || 'image.png', { type: mime })
// 기존 미리보기 URL 해제
if (this.banner.thumbnail_image_url) {
URL.revokeObjectURL(this.banner.thumbnail_image_url)
}
this.banner.thumbnail_image = croppedFile
this.banner.thumbnail_image_url = URL.createObjectURL(croppedFile)
resolve()
}, mime)
})
this.show_crop_dialog = false
} catch (e) {
this.notifyError('이미지 크롭 중 오류가 발생했습니다. 다시 시도해 주세요.')
} finally {
this.is_loading = false
this.cleanupCropDialog()
}
},
handleCropCancel() {
this.show_crop_dialog = false
this.cleanupCropDialog()
},
cleanupCropDialog() {
this.destroyCropper()
if (this.crop_src) {
URL.revokeObjectURL(this.crop_src)
this.crop_src = null
}
this.selected_file_for_crop = null
},
cancel() {
this.is_modify = false
this.is_selecting = false
this.show_write_dialog = false
this.show_delete_confirm_dialog = false
this.banner = {type: 'CREATOR', tab_id: 1, lang: 'ko', ...createBannerScheduleForm()}
this.schedule_errors = {}
this.selected_banner = {}
this.search_query_creator = ''
this.search_query_series = ''
},
notifyError(message) {
this.$dialog.notify.error(message)
},
notifySuccess(message) {
this.$dialog.notify.success(message)
},
async getAudioContentMainTabList() {
this.is_loading = true
try {
const res = await api.getAudioContentMainTabList()
if (res.status === 200 && res.data.success === true) {
const data = res.data.data
this.tabs = data
this.selected_tab_id = data[0].tabId
await this.getBanners()
} else {
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
} finally {
this.is_loading = false
}
},
showModifyBannerDialog(banner) {
this.is_modify = true
this.selected_banner = banner
this.is_selecting = true; // 선택 중 플래그 활성화
this.banner.id = banner.id
this.banner.type = banner.type
this.banner.thumbnail_image_url = banner.thumbnailImageUrl
this.banner.event_id = banner.eventId
this.banner.event_thumbnail_image = banner.eventThumbnailImage
this.banner.creator_id = banner.creatorId
this.banner.creator_nickname = banner.creatorNickname
this.banner.series_id = banner.seriesId
this.banner.series_title = banner.seriesTitle
this.banner.link = banner.link
this.banner.is_adult = banner.isAdult
this.banner.tab_id = banner.tabId
const schedule = createBannerScheduleForm(banner)
this.banner.start_date = schedule.start_date
this.banner.end_date = schedule.end_date
this.schedule_errors = {}
// 수정 시 언어는 변경 불가하므로 UI를 표시하지 않음. 필요 시 내부 유지만 함 (기본값 또는 서버 값 사용)
if (banner.lang) {
this.banner.lang = banner.lang
}
setTimeout(() => {
this.is_selecting = false; // 선택 상태 해제
}, 1000);
this.show_write_dialog = true
},
validate() {
if (this.banner.type === 'EVENT' && (this.banner.event_id === null || this.banner.event_id === undefined)) {
this.notifyError("이벤트를 선택하세요")
return false;
}
if (
this.banner.type === 'CREATOR' &&
(this.banner.creator_id === null || this.banner.creator_id === undefined)) {
this.notifyError("크리에이터를 선택하세요")
return false;
}
if (
this.banner.type === 'SERIES' &&
(this.banner.series_id === null || this.banner.series_id === undefined)) {
this.notifyError("시리즈를 선택하세요")
return false;
}
if (
this.banner.type === 'LINK' &&
(this.banner.link === null || this.banner.link === undefined || this.banner.link.trim().length <= 0)
) {
this.notifyError("링크를 입력하세요")
return false;
}
if (this.banner.thumbnail_image == null) {
this.notifyError("썸네일 이미지를 등록하세요")
return false;
}
return this.validateSchedule()
},
validateSchedule() {
const errors = validateBannerSchedule(this.banner)
this.schedule_errors = errors
const messages = Object.keys(errors).map((key) => errors[key])
if (messages.length > 0) {
this.notifyError(messages[0])
return false;
}
return true
},
scheduleRangeText(banner) {
return formatScheduleRange(banner.startDate, banner.endDate)
},
deleteConfirm(banner) {
this.selected_banner = banner
this.show_delete_confirm_dialog = true
},
deleteCancel() {
this.show_delete_confirm_dialog = false
},
async submit() {
if (!this.validate()) return;
if (this.is_loading === true) return;
this.is_loading = true
try {
const formData = new FormData()
formData.append("image", this.banner.thumbnail_image)
let request = {
type: this.banner.type,
isAdult: this.banner.is_adult,
lang: this.banner.lang || 'ko'
}
if (this.banner.type === 'CREATOR') {
request.creatorId = this.banner.creator_id
} else if (this.banner.type === 'EVENT') {
request.eventId = this.banner.event_id
} else if (this.banner.type === 'LINK') {
request.link = this.banner.link
} else if (this.banner.type === 'SERIES') {
request.seriesId = this.banner.series_id
}
if (this.banner.tab_id !== 1) {
request.tabId = this.banner.tab_id
}
applyScheduleToSaveRequest(request, this.banner)
formData.append("request", JSON.stringify(request))
const res = await api.saveBanner(formData)
if (res.status === 200 && res.data.success === true) {
this.cancel()
this.notifySuccess('등록되었습니다.')
this.banners = []
await this.getBanners()
} else {
this.notifyError(res.data.message);
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
} finally {
this.is_loading = false
}
},
async modify() {
if (!this.validateSchedule()) return;
if (this.is_loading) return;
this.is_loading = true
try {
const formData = new FormData()
let request = {id: this.banner.id}
if (this.banner.thumbnail_image !== null) {
formData.append("image", this.banner.thumbnail_image)
}
if (
this.selected_banner.eventId !== this.banner.event_id &&
this.banner.event_id !== null &&
this.banner.event_id !== undefined
) {
request.type = this.banner.type
request.eventId = this.banner.event_id
}
if (
this.selected_banner.creator_id !== this.banner.creator_id &&
this.banner.creator_id !== null &&
this.banner.creator_id !== undefined
) {
request.type = this.banner.type
request.creatorId = this.banner.creator_id
}
if (
this.selected_banner.series_id !== this.banner.series_id &&
this.banner.series_id !== null &&
this.banner.series_id !== undefined
) {
request.type = this.banner.type
request.seriesId = this.banner.series_id
}
if (
this.selected_banner.link !== this.banner.link &&
this.banner.link !== null &&
this.banner.link !== undefined
) {
request.type = this.banner.type
request.link = this.banner.link
}
if (this.selected_banner.isAdult !== this.banner.is_adult) {
request.isAdult = this.banner.is_adult
}
if (this.selected_banner.tabId !== this.banner.tab_id) {
request.tabId = this.banner.tab_id
}
applyScheduleToModifyRequest(request, this.banner, this.selected_banner)
formData.append("request", JSON.stringify(request))
const res = await api.modifyBanner(formData)
if (res.status === 200 && res.data.success === true) {
this.cancel()
this.notifySuccess('수정되었습니다.')
this.banners = []
await this.getBanners()
} else {
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
} finally {
this.is_loading = false
}
},
async deleteBanner() {
if (this.is_loading) return;
this.is_loading = true
try {
const formData = new FormData()
formData.append("request", JSON.stringify({id: this.selected_banner.id, isActive: false}))
const res = await api.modifyBanner(formData)
if (res.status === 200 && res.data.success === true) {
this.show_delete_confirm_dialog = false
this.cancel()
this.notifySuccess('삭제되었습니다.')
this.banners = []
await this.getBanners()
} else {
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
} finally {
this.is_loading = false
}
},
async onDropCallback(items) {
const ids = items.map((item) => {
return item.id
})
const res = await api.updateBannerOrders(ids)
if (res.status === 200 && res.data.success === true) {
this.notifySuccess(res.data.message)
}
},
async searchCreator() {
if (this.search_query_creator === null || this.search_query_creator.length < 2) {
this.creators = [];
return;
}
this.is_loading = true;
try {
const res = await memberApi.searchCreator(this.search_query_creator, 1);
if (res.status === 200 && res.data.success === true) {
this.creators = res.data.data.items.map((item) => {
return {name: item.nickname, value: item.id}
})
} else {
this.creators = []
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
this.is_loading = false
} finally {
this.is_loading = false
}
},
onSelect(value) {
this.banner.creator_id = value.value
this.is_selecting = true; // 선택 중 플래그 활성화
setTimeout(() => {
this.is_selecting = false; // 선택 상태 해제
}, 0);
},
onSearchUpdate(value) {
if (!this.is_selecting) {
this.search_query_creator = value
}
},
async searchSeries() {
if (this.search_query_series === null || this.search_query_series.length < 2) {
this.series = [];
return;
}
this.is_loading = true;
try {
const res = await seriesApi.searchSeriesList(this.search_query_series);
if (res.status === 200 && res.data.success === true) {
this.series = res.data.data.map((item) => {
return {name: item.title, value: item.id}
})
} else {
this.series = []
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
this.is_loading = false
} finally {
this.is_loading = false
}
},
onSelectSeries(value) {
this.banner.series_id = value.value
this.is_selecting = true; // 선택 중 플래그 활성화
setTimeout(() => {
this.is_selecting = false; // 선택 상태 해제
}, 0);
},
onSearchSeriesUpdate(value) {
if (!this.is_selecting) {
this.search_query_series = value
}
},
async getEvents() {
this.is_loading = true
try {
const res = await eventApi.getEvents(1)
if (res.status === 200 && res.data.success === true) {
this.events = res.data.data.map((item) => {
return {title: item.title, value: item.id}
})
} else {
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
this.is_loading = false
} finally {
this.is_loading = false
}
},
async getBanners() {
this.is_loading = true
try {
const res = await api.getBannerList(this.selected_tab_id)
if (res.status === 200 && res.data.success === true) {
this.banners = res.data.data
} else {
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
this.is_loading = false
} finally {
this.is_loading = false
}
},
}
}
</script>
<style scoped>
.image-select label {
display: inline-block;
padding: 10px 20px;
background-color: #232d4a;
color: #fff;
vertical-align: middle;
font-size: 15px;
cursor: pointer;
border-radius: 5px;
}
.v-file-input {
position: absolute;
width: 0;
height: 0;
padding: 0;
overflow: hidden;
border: 0;
}
.schedule-text {
font-size: 12px;
color: #666;
}
.image-preview {
max-width: 100%;
width: 250px;
object-fit: cover;
margin-top: 10px;
}
</style>
<style>
/* CropperJS 기본 스타일 */
@import '~cropperjs/dist/cropper.css';
.cropper-card {
max-height: 80vh; /* 뷰포트 대비 제한하여 하단 버튼이 항상 보이도록 */
display: flex;
flex-direction: column;
}
.cropper-card-text {
flex: 1;
overflow: auto; /* 내부 스크롤로 이미지만 스크롤되게 함 */
}
.cropper-canvas-wrap {
width: 100%;
height: 60vh; /* 이미지 표시 영역 고정 */
}
.cropper-dialog-img {
max-width: 100%;
max-height: 100%;
display: block;
}
</style>