383 lines
9.2 KiB
Vue
383 lines
9.2 KiB
Vue
<template>
|
|
<div>
|
|
<v-toolbar dark>
|
|
<v-spacer />
|
|
<v-toolbar-title>공지사항</v-toolbar-title>
|
|
<v-spacer />
|
|
</v-toolbar>
|
|
|
|
<br>
|
|
|
|
<v-container>
|
|
<v-row>
|
|
<v-col cols="10" />
|
|
<v-col>
|
|
<v-btn
|
|
block
|
|
color="#9970ff"
|
|
dark
|
|
depressed
|
|
@click="showWriteDialog"
|
|
>
|
|
공지사항 등록
|
|
</v-btn>
|
|
</v-col>
|
|
</v-row>
|
|
<v-row>
|
|
<v-col>
|
|
<v-simple-table
|
|
class="elevation-10"
|
|
dark
|
|
>
|
|
<template>
|
|
<thead>
|
|
<tr>
|
|
<th class="text-center">
|
|
NO
|
|
</th>
|
|
<th class="text-left">
|
|
제목
|
|
</th>
|
|
<th class="text-center">
|
|
등록일
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr
|
|
v-for="item in notices"
|
|
:key="item.id"
|
|
@click="clickNotice(item)"
|
|
>
|
|
<td>
|
|
{{ item.id }}
|
|
</td>
|
|
<td class="text-left">
|
|
{{ item.title }}
|
|
</td>
|
|
<td>
|
|
{{ item.date }}
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</template>
|
|
</v-simple-table>
|
|
</v-col>
|
|
</v-row>
|
|
<v-row class="text-center">
|
|
<v-col>
|
|
<v-pagination
|
|
v-model="page"
|
|
:length="total_page"
|
|
circle
|
|
@input="next"
|
|
/>
|
|
</v-col>
|
|
</v-row>
|
|
</v-container>
|
|
<v-row>
|
|
<v-dialog
|
|
v-model="show_write_dialog"
|
|
max-width="1000px"
|
|
persistent
|
|
>
|
|
<v-card>
|
|
<v-card-text />
|
|
<v-card-text>
|
|
<v-text-field
|
|
v-model="notice.title"
|
|
label="제목"
|
|
/>
|
|
</v-card-text>
|
|
<v-card-text>
|
|
<VueEditor
|
|
v-model="notice.content"
|
|
:editor-toolbar="customToolbar"
|
|
/>
|
|
</v-card-text>
|
|
<v-card-actions v-show="!is_loading">
|
|
<v-btn
|
|
v-show="is_modify"
|
|
color="blue darken-1"
|
|
text
|
|
@click="deleteConfirm"
|
|
>
|
|
삭제
|
|
</v-btn>
|
|
<v-spacer />
|
|
<v-btn
|
|
color="blue darken-1"
|
|
text
|
|
@click="cancel"
|
|
>
|
|
취소
|
|
</v-btn>
|
|
<v-btn
|
|
v-show="!is_modify"
|
|
color="blue darken-1"
|
|
text
|
|
@click="submit"
|
|
>
|
|
등록
|
|
</v-btn>
|
|
<v-btn
|
|
v-show="is_modify"
|
|
color="blue darken-1"
|
|
text
|
|
@click="modify"
|
|
>
|
|
수정
|
|
</v-btn>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</v-dialog>
|
|
</v-row>
|
|
<v-row>
|
|
<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="deleteNotice"
|
|
>
|
|
확인
|
|
</v-btn>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</v-dialog>
|
|
</v-row>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import {VueEditor} from "vue2-editor";
|
|
import * as api from '@/api/notice'
|
|
|
|
export default {
|
|
name: "NoticeView",
|
|
|
|
components: {
|
|
VueEditor,
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
is_loading: false,
|
|
is_modify: false,
|
|
page: 1,
|
|
total_page: 0,
|
|
notices: [],
|
|
notice: {},
|
|
show_write_dialog: false,
|
|
show_delete_confirm_dialog: false,
|
|
customToolbar: [
|
|
[{header: [false, 1, 2, 3, 4, 5, 6]}],
|
|
["bold", "italic", "underline"],
|
|
[
|
|
{align: ""},
|
|
{align: "center"},
|
|
{align: "right"},
|
|
{align: "justify"}
|
|
],
|
|
[{list: "ordered"}, {list: "bullet"}],
|
|
[{color: []}, {background: []}],
|
|
]
|
|
}
|
|
},
|
|
|
|
async created() {
|
|
await this.getNotices()
|
|
},
|
|
|
|
methods: {
|
|
notifyError(message) {
|
|
this.$dialog.notify.error(message)
|
|
},
|
|
|
|
notifySuccess(message) {
|
|
this.$dialog.notify.success(message)
|
|
},
|
|
|
|
async next() {
|
|
await this.getNotices()
|
|
},
|
|
|
|
async getNotices() {
|
|
this.is_loading = true
|
|
|
|
try {
|
|
const res = await api.getNotices(this.page)
|
|
if (res.status === 200 && res.data.success === true) {
|
|
const data = res.data.data
|
|
|
|
const total_page = Math.ceil(data.totalCount / 20)
|
|
this.notices = res.data.data.noticeList
|
|
|
|
if (total_page <= 0)
|
|
this.total_page = 1
|
|
else
|
|
this.total_page = total_page
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
}
|
|
},
|
|
|
|
showWriteDialog() {
|
|
this.show_write_dialog = true
|
|
},
|
|
|
|
clickNotice(item) {
|
|
this.is_modify = true
|
|
this.notice.id = item.id;
|
|
this.notice.title = item.title;
|
|
this.notice.content = item.content;
|
|
this.show_write_dialog = true
|
|
},
|
|
|
|
cancel() {
|
|
this.is_modify = false
|
|
this.notice = {}
|
|
this.show_write_dialog = false
|
|
},
|
|
|
|
validate() {
|
|
if (this.notice.title == null || this.notice.title.trim().length === 0) {
|
|
this.notifyError("제목을 입력하세요.")
|
|
return false;
|
|
}
|
|
|
|
if (this.notice.content == null || this.notice.content.trim().length === 0) {
|
|
this.notifyError("내용을 입력하세요.")
|
|
return false;
|
|
}
|
|
|
|
return true
|
|
},
|
|
|
|
async submit() {
|
|
if (!this.validate()) return;
|
|
if (this.is_loading) return;
|
|
|
|
this.is_loading = true
|
|
|
|
try {
|
|
const res = await api.save(this.notice.title, this.notice.content)
|
|
if (res.status === 200 && res.data.success === true) {
|
|
this.show_write_dialog = false
|
|
this.notifySuccess('등록되었습니다.')
|
|
this.page = 1
|
|
await this.getNotices()
|
|
this.notice = {}
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
}
|
|
},
|
|
|
|
async modify() {
|
|
if (!this.validate()) return;
|
|
if (this.is_loading) return;
|
|
|
|
this.is_loading = true
|
|
|
|
try {
|
|
const res = await api.modify(this.notice.id, this.notice.title, this.notice.content)
|
|
if (res.status === 200 && res.data.success === true) {
|
|
this.show_write_dialog = false
|
|
this.notifySuccess('수정되었습니다.')
|
|
this.page = 1
|
|
await this.getNotices()
|
|
this.notice = {}
|
|
this.is_modify = false
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
}
|
|
},
|
|
|
|
deleteConfirm() {
|
|
this.show_delete_confirm_dialog = true
|
|
},
|
|
|
|
deleteCancel() {
|
|
this.show_delete_confirm_dialog = false
|
|
},
|
|
|
|
async deleteNotice() {
|
|
if (this.is_loading) return;
|
|
this.is_loading = true
|
|
|
|
try {
|
|
const res = await api.deleteNotice(this.notice.id)
|
|
if (res.status === 200 && res.data.success === true) {
|
|
this.show_write_dialog = false
|
|
this.show_delete_confirm_dialog = false
|
|
this.notifySuccess('삭제되었습니다.')
|
|
this.page = 1
|
|
await this.getNotices()
|
|
this.notice = {}
|
|
this.is_modify = false
|
|
} else {
|
|
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
}
|
|
} catch (e) {
|
|
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
|
} finally {
|
|
this.is_loading = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
table {
|
|
width: 100%;
|
|
border-top: 1px solid #444444;
|
|
border-collapse: collapse;
|
|
}
|
|
|
|
th, td {
|
|
border-left: 1px solid #444444;
|
|
padding: 10px;
|
|
}
|
|
|
|
th:first-child, th:last-child {
|
|
width: 20%
|
|
}
|
|
|
|
th:first-child, td:first-child {
|
|
border-left: none;
|
|
}
|
|
</style>
|