- 생성·수정 폼에 KO/JA/EN 언어 select 추가 (신규 기본값 KO, 수정은 저장된 lang 유지) - multipart request JSON 파트에 정규 대문자 lang 을 항상 포함해 전송 - 목록에 언어 열 추가, lang 누락 응답은 KO 로 간주하지 않고 계약 미충족 안내 - EN 은 현재 앱 공개 국가 매핑에서 미노출됨을 폼에 안내 - 400 등 4xx 거부 시 입력값·선택 파일·날짜를 보존하고 재전송을 막지 않도록 처리 - 언어 관련 focused test 추가
678 lines
22 KiB
Vue
678 lines
22 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 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">
|
|
언어
|
|
</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>{{ langText(item) }}</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="9"
|
|
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">
|
|
<label for="sub-banner-lang">언어</label>
|
|
</v-col>
|
|
<v-col cols="8">
|
|
<v-select
|
|
id="sub-banner-lang"
|
|
v-model="sub_banner.lang"
|
|
:items="langs"
|
|
item-text="text"
|
|
item-value="value"
|
|
label="언어 선택"
|
|
:error-messages="form_errors.lang"
|
|
/>
|
|
</v-col>
|
|
</v-row>
|
|
<v-row>
|
|
<v-col class="guide-text">
|
|
영어(EN)는 저장과 목록 조회는 가능하지만 현재 앱 공개 국가 매핑(JP → 일본어, 그 외 → 한국어)에서는 노출되지 않습니다.
|
|
배너 소재 언어와 연결된 이벤트 언어는 운영자가 직접 맞춰 주세요.
|
|
</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,
|
|
langLabel,
|
|
scheduleStatus,
|
|
SUB_BANNER_LANGS,
|
|
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,
|
|
langs: SUB_BANNER_LANGS,
|
|
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)
|
|
},
|
|
|
|
// 400 등 4xx 는 ApiResponse 가 아닌 표준 Spring Boot body 일 수 있어 단정하지 않는다.
|
|
clientErrorMessage(error) {
|
|
const response = error && error.response
|
|
if (!response || response.status < 400 || response.status >= 500) return null
|
|
|
|
const body = response.data
|
|
const message = body && typeof body === 'object' ? (body.message || body.error) : null
|
|
return 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)
|
|
},
|
|
|
|
langText(subBanner) {
|
|
// lang 이 없는 응답을 KO 로 간주하지 않는다.
|
|
return langLabel(subBanner.lang) || '-'
|
|
},
|
|
|
|
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) {
|
|
const clientError = this.clientErrorMessage(e)
|
|
if (clientError !== null) {
|
|
// 서버가 확실히 거부했으므로 입력값·선택 파일·날짜를 그대로 두고 재전송도 막지 않는다.
|
|
this.notifyError(clientError)
|
|
} else {
|
|
// 결과가 불명확하므로 자동 재시도 없이 중복 전송을 막고 목록으로 상태를 확인한다.
|
|
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) {
|
|
const clientError = this.clientErrorMessage(e)
|
|
if (clientError !== null) {
|
|
this.notifyError(clientError)
|
|
} else {
|
|
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 : []
|
|
|
|
// 응답에 lang 이 없으면 KO 로 간주하지 않고 계약 미충족을 알린다.
|
|
if (this.sub_banners.some((item) => !item || item.lang === undefined)) {
|
|
this.notifyError('목록 응답에 lang 이 없습니다. 언어 계약이 적용된 서버인지 확인해 주세요.')
|
|
}
|
|
} 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>
|