
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
<template>
<div class="notice-wrap">
<div class="content-box">
<div class="title-wrap">
<div class="flex-start">
<img src="../../../../resources/jpg/notic-logo-img.png" alt="공지사항 아이콘" class="title-icon">
<h2 class="main-title">공지사항</h2>
</div>
</div>
<div class="content-wrap NoticeInsert">
<table class="insert-table">
<tbody>
<tr>
<th>제목</th>
<td><input type="text" name="" id="newsTitle" v-model="post.post_title"></td>
</tr>
<tr>
<th>게시물 상단고정 사용여부</th>
<td><input type="checkbox" v-model="post.notice_yn" true-value="Y" false-value="N"><label>사용</label></td>
</tr>
<tr>
<th>내용</th>
<td><textarea name="smart" id="smart" style="width:100%"></textarea></td>
</tr>
<tr>
<th>첨부파일</th>
<td>
<div class="btn-upload" @click="openFileInput">파일 업로드</div>
<input type="file" name="file" id="file" ref="fileInput" style="display: none"
@change="fileUpload()">
<ul v-for="(file, idx) in fileList" :key="idx" class="file-list">
<li> {{ file.name }} <button @click="fileRemove(idx)" class="aclose-btn">X</button></li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="btn-wrap">
<button class="dark-gray-btn" @click="postSelectListPage()">이전</button>
<button class="blue-btn" @click="postInsertCheck()">등록</button>
</div>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
import COMMON_UTIL from '../../../../resources/js/commonUtil.js';
export default {
data() {
return {
post: {
bbs_id: '2',
post_title: null,
post_content: null,
// 카테고리가 없는 게시판에서는 null로 설정 부탁합니다!
ctgry_nm: null,
notice_yn: 'N',
},
fileList: [],
filecount: 0,
oEditors: [], // oEditors는 스마트에디터용
};
},
methods: {
//게시글 및 첨부파일 등록
postInsert: function () {
const vm = this;
let formData = new FormData();
if (vm.fileList.length > 0) {
for (let i = 0; i < vm.fileList.length; i++) {
formData.append('file', vm.fileList[i]);
}
formData.append("post", JSON.stringify(vm.post));
axios({
url: '/post/postFileInsert.file',
method: 'post',
headers: {
'Content-Type': 'multipart/form-data',
},
data: formData
}).then(function (response) {
let result = response.data;
if (result > 0) {
alert("등록을 완료하였습니다.");
vm.postSelectListPage()
} else {
alert("등록 실패, 관리자에게 문의해주세요.");
}
}).catch(function (error) {
console.log("qnaInsert - error : ", error);
alert("등록 오류, 관리자에게 문의해주세요.");
});
} else {
axios({
url: '/post/postInsert.json',
method: 'post',
headers: {
'Content-Type': "application/json; charset=UTF-8",
},
data: vm.post
}).then(function (response) {
let result = response.data;
if (result > 0) {
alert("등록을 완료하였습니다.");
vm.postSelectListPage()
} else {
alert("등록 실패, 관리자에게 문의해주세요.");
}
}).catch(function (error) {
console.log("noticeInsert - error : ", error);
alert("등록 오류, 관리자에게 문의해주세요.");
});
}
},
//등록 유효성 검사
postInsertCheck: function () {
const oEditors = this.oEditors;
oEditors.getById["smart"].exec("UPDATE_CONTENTS_FIELD", []);
// 스마트에디터의 iframe에 있는 내용을 textarea로.
this.post.post_content = document.getElementById("smart").value;
if (COMMON_UTIL.isEmpty(this.post.post_title) === false) {
alert("제목을 입력해주세요.");
return false;
}
if (COMMON_UTIL.isEmpty(this.post.post_content) === false || this.post.post_content === "<p><br></p>") {
alert("내용을 입력해주세요.");
return false;
}
this.postInsert();
},
//파일업로드
fileUpload: function () {
this.fileList[this.filecount] = this.$refs.fileInput.files[0]
this.filecount += 1
},
//파일업로드 중 업로드 파일 삭제
fileRemove(idx) {
this.fileList.splice(idx, 1);
this.filecount = this.fileList.length;
},
//게시글 리스트로 이동
postSelectListPage: function () {
this.$router.push({ path: '/adm/noticeSelectList.page' });
},
// 파일 업로드 커스텀을 위한 함수
openFileInput: function () {
this.$refs.fileInput.click(); // 파일 업로드 input 요소를 클릭
}
},
watch: {},
computed: {},
components: {},
mounted() {
// 스마트 에디터 적용
const oEditors = this.oEditors;
nhn.husky.EZCreator.createInIFrame({
oAppRef: oEditors,
elPlaceHolder: "smart",
sSkinURI: "/client/smarteditor2-2.8.2.3/SmartEditor2Skin.html",
htParams: {
bUseToolbar: true, // 툴바 사용 여부 (true:사용/ false:사용하지 않음)
bSkipXssFilter: true,
bUseVerticalResizer: true,
bUseModeChanger: true
},
fCreator: "createSEditor2"
});
}
};
</script>