feat(sub-banner): 가로형 서브 배너 관리 화면 추가

홈/콘텐츠 placement별 가로형 서브 배너의 목록·생성·수정·삭제 UI를 추가한다.

- 관리자 API(/admin/sub-banners) 호출 모듈 추가
- 주소 trim/blank→null 정규화, 최소 1개 주소 및 scheme 검증
- KST yyyy-MM-dd HH:mm 분 단위 기간 직렬화(생략 보존, 명시적 null 해제)
- 수정 시 image 생략으로 기존 이미지 유지, 실패 시 입력·이미지 상태 보존
- 라우터/사이드 메뉴 항목 및 test:sub-banner 스크립트 등록
This commit is contained in:
Yu Sung
2026-10-30 01:02:08 +09:00
parent 63f16091fa
commit abb6481bfc
7 changed files with 1524 additions and 0 deletions
+615
View File
@@ -0,0 +1,615 @@
<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 align="center">
<v-col cols="9">
<v-radio-group
v-model="selected_placement"
row
@change="getSubBanners"
>
<v-radio
v-for="placement in placements"
:key="placement.value"
:label="placement.text"
:value="placement.value"
/>
</v-radio-group>
</v-col>
<v-spacer />
<v-col>
<v-btn
block
color="#3BB9F1"
dark
depressed
v-bind="attrs"
v-on="on"
@click="showCreateDialog"
>
배너 등록
</v-btn>
<v-btn
block
class="mt-2"
depressed
:disabled="is_loading"
@click="getSubBanners"
>
목록 새로고침
</v-btn>
</v-col>
</v-row>
<v-row>
<v-col>
<v-simple-table class="elevation-10">
<template>
<thead>
<tr>
<th class="text-center">
번호
</th>
<th class="text-center">
이미지
</th>
<th class="text-center">
웹 URL
</th>
<th class="text-center">
Android 딥링크
</th>
<th class="text-center">
iOS 딥링크
</th>
<th class="text-center">
노출 기간 (KST)
</th>
<th class="text-center">
상태
</th>
<th class="text-center">
관리
</th>
</tr>
</thead>
<tbody>
<tr
v-for="item in sub_banners"
:key="item.id"
>
<td>{{ item.id }}</td>
<td>
<img
:src="item.imageUrl"
alt=""
class="list-image"
>
</td>
<td>{{ item.webUrl || '-' }}</td>
<td>{{ item.androidDeepLink || '-' }}</td>
<td>{{ item.iosDeepLink || '-' }}</td>
<td>{{ scheduleRangeText(item) }}</td>
<td>{{ statusText(item) }}</td>
<td>
<v-btn
text
@click="showModifyDialog(item)"
>
수정
</v-btn>
<v-btn
text
@click="deleteConfirm(item)"
>
삭제
</v-btn>
</td>
</tr>
<tr v-if="sub_banners.length === 0">
<td
colspan="8"
class="text-center"
>
등록된 배너가 없습니다.
</td>
</tr>
</tbody>
</template>
</v-simple-table>
</v-col>
</v-row>
</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="sub_banner.placement"
row
>
<v-radio
v-for="placement in placements"
:key="placement.value"
:label="placement.text"
:value="placement.value"
/>
</v-radio-group>
</v-col>
</v-row>
</v-card-text>
<v-card-text>
<v-row align="center">
<v-col cols="4">
웹 URL
</v-col>
<v-col cols="8">
<v-text-field
v-model="sub_banner.web_url"
label="https://example.com/promo"
:error-messages="form_errors.web_url"
/>
</v-col>
</v-row>
<v-row align="center">
<v-col cols="4">
Android 딥링크
</v-col>
<v-col cols="8">
<v-text-field
v-model="sub_banner.android_deep_link"
label="sampleapp://promo"
:error-messages="form_errors.android_deep_link"
/>
</v-col>
</v-row>
<v-row align="center">
<v-col cols="4">
iOS 딥링크
</v-col>
<v-col cols="8">
<v-text-field
v-model="sub_banner.ios_deep_link"
label="sampleapp://promo"
:error-messages="form_errors.ios_deep_link"
/>
</v-col>
</v-row>
<v-row>
<v-col class="guide-text">
웹 URL, Android 딥링크, iOS 딥링크 중 최소 한 개는 입력해야 합니다. 비워둔 주소는 null 로 저장되어 해제됩니다.
</v-col>
</v-row>
</v-card-text>
<v-card-text>
<v-row align="center">
<v-col cols="4">
노출 기간 (한국 시간 KST 기준)
</v-col>
<v-col cols="4">
<v-text-field
v-model="sub_banner.start_date"
type="datetime-local"
label="시작 일시 (KST, 선택)"
:error-messages="form_errors.start_date"
clearable
@click:clear="sub_banner.start_date = ''"
/>
</v-col>
<v-col cols="4">
<v-text-field
v-model="sub_banner.end_date"
type="datetime-local"
label="종료 일시 (KST, 선택)"
:error-messages="form_errors.end_date"
clearable
@click:clear="sub_banner.end_date = ''"
/>
</v-col>
</v-row>
<v-row>
<v-col class="guide-text">
입력한 시간은 한국 시간(KST) 분 단위로 저장됩니다. 비워두면 해당 경계의 기간 제한이 없습니다.
(시작만 있으면 시작 분의 :00 부터, 종료만 있으면 종료 분의 :59 까지 노출)
</v-col>
</v-row>
</v-card-text>
<div class="image-select">
<label for="image">
배너 이미지 등록
</label>
<v-file-input
id="image"
v-model="sub_banner.image"
accept="image/*"
@change="imageAdd"
/>
</div>
<img
v-if="sub_banner.image_url"
:src="sub_banner.image_url"
alt=""
class="image-preview"
>
<v-card-text
v-if="is_modify === true"
class="guide-text"
>
이미지를 새로 등록하지 않으면 기존 이미지가 그대로 유지됩니다.
</v-card-text>
<v-card-text
v-if="submit_blocked === true"
class="guide-text"
>
응답을 받지 못해 저장 여부를 알 수 없습니다. 중복 저장을 막기 위해 다시 보내지 않습니다. 목록에서 결과를 확인한 뒤 진행해 주세요.
</v-card-text>
<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
:disabled="is_loading || submit_blocked"
@click="modify"
>
수정
</v-btn>
<v-btn
v-else
color="blue darken-1"
text
:disabled="is_loading || submit_blocked"
@click="submit"
>
등록
</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
:disabled="is_loading"
@click="deleteSubBanner"
>
확인
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</div>
</template>
<script>
import * as api from "@/api/sub_banner"
import {
appendSubBannerRequestPart,
buildSubBannerCreateRequest,
buildSubBannerUpdateRequest,
createSubBannerForm,
formatScheduleRange,
scheduleStatus,
SUB_BANNER_PLACEMENTS,
validateSubBannerForm
} from "@/utils/sub_banner"
export default {
name: "SubBannerView",
data() {
return {
is_loading: false,
is_modify: false,
submit_blocked: false,
show_write_dialog: false,
show_delete_confirm_dialog: false,
placements: SUB_BANNER_PLACEMENTS,
selected_placement: SUB_BANNER_PLACEMENTS[0].value,
sub_banners: [],
selected_sub_banner: {},
sub_banner: createSubBannerForm(),
form_errors: {}
}
},
async created() {
await this.getSubBanners()
},
methods: {
notifyError(message) {
this.$dialog.notify.error(message)
},
notifySuccess(message) {
this.$dialog.notify.success(message)
},
imageAdd(payload) {
const file = payload
if (!file) {
// 새 이미지를 해제하면 기존 이미지 상태로 되돌린다.
this.sub_banner.image = null
this.sub_banner.image_url = this.selected_sub_banner.imageUrl || null
return
}
this.sub_banner.image = file
this.sub_banner.image_url = URL.createObjectURL(file)
},
showCreateDialog() {
this.is_modify = false
this.selected_sub_banner = {}
this.sub_banner = createSubBannerForm({placement: this.selected_placement})
this.form_errors = {}
this.submit_blocked = false
this.show_write_dialog = true
},
showModifyDialog(subBanner) {
// 별도 상세 조회가 없으므로 목록의 전체 객체로 form 을 채운다.
this.is_modify = true
this.selected_sub_banner = subBanner
this.sub_banner = createSubBannerForm(subBanner)
this.form_errors = {}
this.submit_blocked = false
this.show_write_dialog = true
},
cancel() {
this.is_modify = false
this.show_write_dialog = false
this.show_delete_confirm_dialog = false
this.selected_sub_banner = {}
this.sub_banner = createSubBannerForm({placement: this.selected_placement})
this.form_errors = {}
this.submit_blocked = false
},
scheduleRangeText(subBanner) {
return formatScheduleRange(subBanner.startDate, subBanner.endDate)
},
statusText(subBanner) {
return scheduleStatus(subBanner)
},
validate() {
const errors = validateSubBannerForm(
this.sub_banner,
this.is_modify === true ? this.selected_sub_banner : null
)
this.form_errors = errors
const messages = Object.keys(errors).map((key) => errors[key])
if (messages.length > 0) {
this.notifyError(messages[0])
return false
}
if (this.is_modify !== true && !this.sub_banner.image) {
this.notifyError('배너 이미지를 등록하세요.')
return false
}
return true
},
deleteConfirm(subBanner) {
this.selected_sub_banner = subBanner
this.show_delete_confirm_dialog = true
},
deleteCancel() {
this.show_delete_confirm_dialog = false
this.selected_sub_banner = {}
},
async submit() {
if (this.is_loading === true || this.submit_blocked === true) return
if (!this.validate()) return
this.is_loading = true
try {
const formData = new FormData()
formData.append("image", this.sub_banner.image)
appendSubBannerRequestPart(formData, buildSubBannerCreateRequest(this.sub_banner))
const res = await api.saveSubBanner(formData)
if (res.status === 200 && res.data.success === true) {
this.selected_placement = this.sub_banner.placement
this.cancel()
this.notifySuccess('등록되었습니다.')
await this.getSubBanners()
} else {
// 실패 시 입력값과 기존 이미지 상태를 그대로 보존한다.
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
}
} catch (e) {
// 결과가 불명확하므로 자동 재시도 없이 중복 전송을 막고 목록으로 상태를 확인한다.
this.submit_blocked = true
this.notifyError('응답을 받지 못했습니다. 등록 여부를 목록에서 확인해 주세요.')
} finally {
this.is_loading = false
}
if (this.submit_blocked === true) {
await this.getSubBanners()
}
},
async modify() {
if (this.is_loading === true || this.submit_blocked === true) return
if (!this.validate()) return
this.is_loading = true
try {
const formData = new FormData()
// 이미지를 새로 선택하지 않으면 image 파트를 생략해 기존 이미지를 유지한다.
if (this.sub_banner.image) {
formData.append("image", this.sub_banner.image)
}
appendSubBannerRequestPart(
formData,
buildSubBannerUpdateRequest(this.sub_banner, this.selected_sub_banner)
)
const res = await api.modifySubBanner(this.sub_banner.id, formData)
if (res.status === 200 && res.data.success === true) {
this.selected_placement = this.sub_banner.placement
this.cancel()
this.notifySuccess('수정되었습니다.')
await this.getSubBanners()
} else {
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
}
} catch (e) {
this.submit_blocked = true
this.notifyError('응답을 받지 못했습니다. 수정 여부를 목록에서 확인해 주세요.')
} finally {
this.is_loading = false
}
if (this.submit_blocked === true) {
await this.getSubBanners()
}
},
async deleteSubBanner() {
if (this.is_loading === true) return
this.is_loading = true
try {
const res = await api.deleteSubBanner(this.selected_sub_banner.id)
if (res.status === 200 && res.data.success === true) {
this.cancel()
this.notifySuccess('삭제되었습니다.')
await this.getSubBanners()
} else {
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
}
} catch (e) {
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
} finally {
this.is_loading = false
}
},
async getSubBanners() {
this.is_loading = true
try {
const res = await api.getSubBanners(this.selected_placement)
if (res.status === 200 && res.data.success === true) {
// 서버가 id 오름차순으로 내려주므로 재정렬하지 않고 전부 표시한다.
this.sub_banners = Array.isArray(res.data.data) ? res.data.data : []
} else {
// 조회 실패를 빈 목록으로 오인하지 않는다.
this.notifyError(res.data.message || '목록을 불러오지 못했습니다. 다시 시도해 주세요.')
}
} catch (e) {
this.notifyError('목록을 불러오지 못했습니다. 다시 시도해 주세요.')
} 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;
}
.guide-text {
font-size: 12px;
color: #666;
}
.list-image {
width: 160px;
object-fit: cover;
}
.image-preview {
max-width: 100%;
width: 320px;
object-fit: cover;
margin-top: 10px;
}
</style>