feat(notice): 관리자 공지 예약 공개(publishAt) 연동 #108
+18
-7
@@ -1,21 +1,33 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
async function save(title, content) {
|
||||
async function save(title, content, publishAt) {
|
||||
const request = {title: title, content: content}
|
||||
|
||||
// publishAt 생략 또는 null 은 즉시 공개
|
||||
if (publishAt != null) {
|
||||
request.publishAt = publishAt
|
||||
}
|
||||
|
||||
return Vue.axios.post("/notice", request)
|
||||
}
|
||||
|
||||
async function modify(id, title, content) {
|
||||
async function modify(id, title, content, publishAt) {
|
||||
const request = {id: id}
|
||||
|
||||
if (title.trim().length > 0) {
|
||||
if (title != null && title.trim().length > 0) {
|
||||
request.title = title
|
||||
}
|
||||
|
||||
if (content.trim().length > 0) {
|
||||
if (content != null && content.trim().length > 0) {
|
||||
request.content = content
|
||||
}
|
||||
|
||||
// undefined 는 기존 예약 상태 보존(생략),
|
||||
// null 은 사용자가 즉시 공개 전환을 명시한 경우에만 전송
|
||||
if (publishAt !== undefined) {
|
||||
request.publishAt = publishAt
|
||||
}
|
||||
|
||||
return Vue.axios.put("/notice", request)
|
||||
}
|
||||
|
||||
@@ -25,9 +37,8 @@ async function deleteNotice(id) {
|
||||
|
||||
async function getNotices(page) {
|
||||
return Vue.axios.get(
|
||||
"/notice?page=" + (page - 1) +
|
||||
"&size=20" +
|
||||
"&timezone=" + Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||
"/api/v2/admin/notices?page=" + (page - 1) +
|
||||
"&size=20"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
{{ item.title }}
|
||||
</td>
|
||||
<td>
|
||||
{{ item.date }}
|
||||
{{ displayDate(item) }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -95,6 +95,33 @@
|
||||
:editor-toolbar="customToolbar"
|
||||
/>
|
||||
</v-card-text>
|
||||
<v-card-text>
|
||||
<v-checkbox
|
||||
v-model="use_schedule"
|
||||
:disabled="is_modify && !can_change_publish_at"
|
||||
label="예약 공개"
|
||||
hide-details
|
||||
/>
|
||||
<v-text-field
|
||||
v-show="use_schedule"
|
||||
v-model="publish_at_input"
|
||||
:disabled="is_modify && !can_change_publish_at"
|
||||
label="공개 시각 (KST)"
|
||||
type="datetime-local"
|
||||
/>
|
||||
<v-checkbox
|
||||
v-show="is_modify && can_change_publish_at && !use_schedule"
|
||||
v-model="publish_now"
|
||||
label="지금 공개로 전환"
|
||||
hide-details
|
||||
/>
|
||||
<div
|
||||
v-show="is_modify && !can_change_publish_at"
|
||||
class="text-caption grey--text"
|
||||
>
|
||||
이미 공개된 공지는 공개 시각을 변경할 수 없습니다.
|
||||
</div>
|
||||
</v-card-text>
|
||||
<v-card-actions v-show="!is_loading">
|
||||
<v-btn
|
||||
v-show="is_modify"
|
||||
@@ -185,6 +212,11 @@ export default {
|
||||
total_page: 0,
|
||||
notices: [],
|
||||
notice: {},
|
||||
use_schedule: false,
|
||||
publish_now: false,
|
||||
publish_at_input: '',
|
||||
original_publish_at: null,
|
||||
can_change_publish_at: true,
|
||||
show_write_dialog: false,
|
||||
show_delete_confirm_dialog: false,
|
||||
customToolbar: [
|
||||
@@ -219,6 +251,44 @@ export default {
|
||||
await this.getNotices()
|
||||
},
|
||||
|
||||
// "yyyy-MM-dd HH:mm:ss"(KST) -> "yyyy-MM-ddTHH:mm" (시간대 변환 없이 문자열만 변환)
|
||||
toInputValue(publishAt) {
|
||||
if (!publishAt) return ''
|
||||
return publishAt.replace(' ', 'T').substring(0, 16)
|
||||
},
|
||||
|
||||
// "yyyy-MM-ddTHH:mm" -> "yyyy-MM-dd HH:mm:ss"(KST)
|
||||
toContractValue(input) {
|
||||
if (!input) return null
|
||||
const value = input.replace('T', ' ')
|
||||
if (value.length === 16) return value + ':00'
|
||||
return value.substring(0, 19)
|
||||
},
|
||||
|
||||
nowKstString() {
|
||||
const parts = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Asia/Seoul',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: false
|
||||
}).formatToParts(new Date()).reduce((acc, p) => {
|
||||
acc[p.type] = p.value
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}:${parts.second}`
|
||||
},
|
||||
|
||||
displayDate(item) {
|
||||
const source = (item.isScheduled === true && item.publishAt) ? item.publishAt : item.createdAt
|
||||
if (!source) return ''
|
||||
return source.substring(0, 10)
|
||||
},
|
||||
|
||||
async getNotices() {
|
||||
this.is_loading = true
|
||||
|
||||
@@ -245,6 +315,7 @@ export default {
|
||||
},
|
||||
|
||||
showWriteDialog() {
|
||||
this.resetPublishState()
|
||||
this.show_write_dialog = true
|
||||
},
|
||||
|
||||
@@ -253,12 +324,35 @@ export default {
|
||||
this.notice.id = item.id;
|
||||
this.notice.title = item.title;
|
||||
this.notice.content = item.content;
|
||||
|
||||
this.resetPublishState()
|
||||
this.original_publish_at = item.publishAt || null
|
||||
// 예약 공지이면서 공개 시각이 아직 도래하지 않은 경우에만 공개 시각 변경을 시도할 수 있다.
|
||||
// 공개 경계의 최종 판단은 API 응답을 따른다.
|
||||
this.can_change_publish_at = item.isScheduled === true &&
|
||||
!!item.publishAt &&
|
||||
item.publishAt > this.nowKstString()
|
||||
|
||||
if (this.can_change_publish_at) {
|
||||
this.use_schedule = true
|
||||
this.publish_at_input = this.toInputValue(item.publishAt)
|
||||
}
|
||||
|
||||
this.show_write_dialog = true
|
||||
},
|
||||
|
||||
resetPublishState() {
|
||||
this.use_schedule = false
|
||||
this.publish_now = false
|
||||
this.publish_at_input = ''
|
||||
this.original_publish_at = null
|
||||
this.can_change_publish_at = true
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.is_modify = false
|
||||
this.notice = {}
|
||||
this.resetPublishState()
|
||||
this.show_write_dialog = false
|
||||
},
|
||||
|
||||
@@ -273,9 +367,36 @@ export default {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.use_schedule) {
|
||||
if (this.publish_at_input == null || this.publish_at_input.trim().length === 0) {
|
||||
this.notifyError("공개 시각을 입력하세요.")
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.toContractValue(this.publish_at_input) <= this.nowKstString()) {
|
||||
this.notifyError("공개 시각은 현재보다 미래여야 합니다.")
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
|
||||
// 수정 요청에 담을 publishAt 산출
|
||||
// undefined: 생략(기존 예약 상태 보존), null: 지금 공개로 전환, 문자열: 재예약
|
||||
publishAtForModify() {
|
||||
if (!this.can_change_publish_at) return undefined
|
||||
|
||||
if (this.publish_now && !this.use_schedule) return null
|
||||
|
||||
if (this.use_schedule) {
|
||||
const publishAt = this.toContractValue(this.publish_at_input)
|
||||
if (publishAt !== this.original_publish_at) return publishAt
|
||||
}
|
||||
|
||||
return undefined
|
||||
},
|
||||
|
||||
async submit() {
|
||||
if (!this.validate()) return;
|
||||
if (this.is_loading) return;
|
||||
@@ -283,13 +404,15 @@ export default {
|
||||
this.is_loading = true
|
||||
|
||||
try {
|
||||
const res = await api.save(this.notice.title, this.notice.content)
|
||||
const publishAt = this.use_schedule ? this.toContractValue(this.publish_at_input) : null
|
||||
const res = await api.save(this.notice.title, this.notice.content, publishAt)
|
||||
if (res.status === 200 && res.data.success === true) {
|
||||
this.show_write_dialog = false
|
||||
this.notifySuccess('등록되었습니다.')
|
||||
this.page = 1
|
||||
await this.getNotices()
|
||||
this.notice = {}
|
||||
this.resetPublishState()
|
||||
} else {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
}
|
||||
@@ -307,13 +430,19 @@ export default {
|
||||
this.is_loading = true
|
||||
|
||||
try {
|
||||
const res = await api.modify(this.notice.id, this.notice.title, this.notice.content)
|
||||
const res = await api.modify(
|
||||
this.notice.id,
|
||||
this.notice.title,
|
||||
this.notice.content,
|
||||
this.publishAtForModify()
|
||||
)
|
||||
if (res.status === 200 && res.data.success === true) {
|
||||
this.show_write_dialog = false
|
||||
this.notifySuccess('수정되었습니다.')
|
||||
this.page = 1
|
||||
await this.getNotices()
|
||||
this.notice = {}
|
||||
this.resetPublishState()
|
||||
this.is_modify = false
|
||||
} else {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
@@ -346,6 +475,7 @@ export default {
|
||||
this.page = 1
|
||||
await this.getNotices()
|
||||
this.notice = {}
|
||||
this.resetPublishState()
|
||||
this.is_modify = false
|
||||
} else {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
|
||||
Reference in New Issue
Block a user