From 1ec55506b2193b0bc8dd98a44a444f2a3e5a7eaa Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Fri, 30 Oct 2026 23:22:05 +0900 Subject: [PATCH] =?UTF-8?q?feat(notice):=20=EA=B4=80=EB=A6=AC=EC=9E=90=20?= =?UTF-8?q?=EA=B3=B5=EC=A7=80=20=EC=98=88=EC=95=BD=20=EA=B3=B5=EA=B0=9C(pu?= =?UTF-8?q?blishAt)=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 생성 요청에 선택적 publishAt 추가(생략/null 은 즉시 공개) - 수정 요청은 undefined 면 publishAt 생략해 기존 예약 보존, 명시적 null 만 즉시 공개 전환으로 전송 - 목록 조회를 GET /api/v2/admin/notices 로 변경하고 timezone 파라미터 제거 - 작성/수정 다이얼로그에 예약 공개 입력과 미래 시각 검증 추가, 표시 날짜는 KST 문자열 그대로 사용 --- src/api/notice.js | 25 ++++-- src/views/Support/NoticeView.vue | 136 ++++++++++++++++++++++++++++++- 2 files changed, 151 insertions(+), 10 deletions(-) diff --git a/src/api/notice.js b/src/api/notice.js index 8eabcf2..5af58cc 100644 --- a/src/api/notice.js +++ b/src/api/notice.js @@ -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" ) } diff --git a/src/views/Support/NoticeView.vue b/src/views/Support/NoticeView.vue index 8e02dcc..db5995f 100644 --- a/src/views/Support/NoticeView.vue +++ b/src/views/Support/NoticeView.vue @@ -56,7 +56,7 @@ {{ item.title }} - {{ item.date }} + {{ displayDate(item) }} @@ -95,6 +95,33 @@ :editor-toolbar="customToolbar" /> + + + + +
+ 이미 공개된 공지는 공개 시각을 변경할 수 없습니다. +
+
"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 || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.') -- 2.54.0