

231103 김성훈 자료집 insert 추가(진행중)
@878993c3839b87d29647cd8fb0942bf4c2d1cd6c
--- client/resources/js/commonUtil.js
+++ client/resources/js/commonUtil.js
... | ... | @@ -15,12 +15,12 @@ |
15 | 15 |
isEmpty: function (data) { |
16 | 16 |
if (data === undefined || data === null || data === "" || data.length === 0 || (data.constructor == Object && Object.keys(data).length === 0)) { |
17 | 17 |
if ((typeof data) === "number") { |
18 |
- return false |
|
18 |
+ return true |
|
19 | 19 |
} else { |
20 |
- return true; |
|
20 |
+ return false; |
|
21 | 21 |
} |
22 | 22 |
} else { |
23 |
- return false; |
|
23 |
+ return true; |
|
24 | 24 |
} |
25 | 25 |
}, |
26 | 26 |
|
--- client/smarteditor2-2.8.2.3/sample/photo_uploader/attach_photo.js
+++ client/smarteditor2-2.8.2.3/sample/photo_uploader/attach_photo.js
... | ... | @@ -334,7 +334,7 @@ |
334 | 334 |
var tempFile, |
335 | 335 |
sUploadURL; |
336 | 336 |
|
337 |
- sUploadURL= '/post/postImageUpload.file'; //upload URL |
|
337 |
+ sUploadURL= '/file/postImageUpload.file'; //upload URL |
|
338 | 338 |
|
339 | 339 |
//파일을 하나씩 보내고, 결과를 받음. |
340 | 340 |
for(var j=0, k=0; j < nImageInfoCnt; j++) { |
--- client/views/pages/admin/databook/DataInsert.vue
+++ client/views/pages/admin/databook/DataInsert.vue
... | ... | @@ -12,8 +12,8 @@ |
12 | 12 |
<tbody> |
13 | 13 |
<tr> |
14 | 14 |
<th>제목</th> |
15 |
- <td><input type="text" name="" id="newsTitle"></td> |
|
16 |
- </tr> |
|
15 |
+ <td><input type="text" name="" id="newsTitle" v-model = "post.post_title"></td> |
|
16 |
+ </tr> |
|
17 | 17 |
<tr> |
18 | 18 |
<th>내용</th> |
19 | 19 |
<td><textarea name="smart" id="smart"></textarea></td> |
... | ... | @@ -22,29 +22,138 @@ |
22 | 22 |
<th>첨부파일</th> |
23 | 23 |
<td> |
24 | 24 |
<div class="btn-upload" @click="openFileInput">파일 업로드하기</div> |
25 |
- <input type="file" name="file" id="file" ref="fileInput" style="display: none"> |
|
25 |
+ <input type="file" name="file" id="file" ref="fileInput" style="display: none" @change="fileUpload()"> |
|
26 |
+ <div v-for="(file, idx) in fileList" :key="idx"> |
|
27 |
+ <div> {{ file.name }} <button @click="fileRemove(idx)">삭제</button></div> |
|
28 |
+ </div> |
|
26 | 29 |
</td> |
27 | 30 |
</tr> |
28 | 31 |
</tbody> |
29 | 32 |
</table> |
30 | 33 |
<div class="btn-wrap"> |
31 |
- <button class="dark-gray-btn" @click="selectList">이전</button> |
|
32 |
- <button class="blue-btn">글쓰기</button> |
|
34 |
+ <button class="dark-gray-btn" @click="postSelectListPage()">이전</button> |
|
35 |
+ <button class="blue-btn" @click="postInsertCheck()">등록</button> |
|
33 | 36 |
</div> |
34 | 37 |
</div> |
35 | 38 |
</div> |
36 | 39 |
</div> |
37 | 40 |
</template> |
38 | 41 |
<script> |
42 |
+import axios from 'axios'; |
|
43 |
+import COMMON_UTIL from '../../../../resources/js/commonUtil'; |
|
39 | 44 |
|
40 | 45 |
export default { |
41 | 46 |
data() { |
42 | 47 |
return { |
48 |
+ post: { |
|
49 |
+ bbs_id: '0', |
|
50 |
+ post_title: null, |
|
51 |
+ post_content: null, |
|
52 |
+ link_url: null, |
|
53 |
+ }, |
|
54 |
+ fileList:[], |
|
55 |
+ filecount: 0, |
|
43 | 56 |
oEditors: [], // oEditors는 스마트에디터용 |
44 | 57 |
}; |
45 | 58 |
}, |
46 | 59 |
methods: { |
47 |
- selectList: function () { |
|
60 |
+ |
|
61 |
+ //게시글 및 첨부파일 등록 |
|
62 |
+ postInsert: function () { |
|
63 |
+ const vm = this; |
|
64 |
+ let formData = new FormData(); |
|
65 |
+ |
|
66 |
+ if (vm.fileList.length > 0) { |
|
67 |
+ for(let i = 0; i < vm.fileList.length; i++ ) { |
|
68 |
+ formData.append('file', vm.fileList[i]); |
|
69 |
+ console.log(formData.get('file')); |
|
70 |
+ } |
|
71 |
+ formData.append("post", JSON.stringify(vm.post)); |
|
72 |
+ |
|
73 |
+ axios({ |
|
74 |
+ url: '/post/postFileInsert.file', |
|
75 |
+ method: 'post', |
|
76 |
+ headers: { |
|
77 |
+ 'Content-Type': 'multipart/form-data', |
|
78 |
+ }, |
|
79 |
+ data: formData |
|
80 |
+ }).then(function (response) { |
|
81 |
+ console.log("qnaInsert - response : ", response); |
|
82 |
+ let result = response.data; |
|
83 |
+ if (result > 0) { |
|
84 |
+ alert("등록을 완료하였습니다."); |
|
85 |
+ vm.postSelectListPage() |
|
86 |
+ } else { |
|
87 |
+ alert("등록 실패, 관리자에게 문의해주세요."); |
|
88 |
+ } |
|
89 |
+ }).catch(function (error) { |
|
90 |
+ console.log("qnaInsert - error : ", error); |
|
91 |
+ alert("등록 오류, 관리자에게 문의해주세요."); |
|
92 |
+ }); |
|
93 |
+ } else { |
|
94 |
+ |
|
95 |
+ axios({ |
|
96 |
+ url: '/post/postInsert.json', |
|
97 |
+ method: 'post', |
|
98 |
+ headers: { |
|
99 |
+ 'Content-Type': "application/json; charset=UTF-8", |
|
100 |
+ }, |
|
101 |
+ data: vm.post |
|
102 |
+ }).then(function (response) { |
|
103 |
+ console.log("noticeInsert - response : ", response); |
|
104 |
+ let result = response.data; |
|
105 |
+ if (result > 0) { |
|
106 |
+ alert("등록을 완료하였습니다."); |
|
107 |
+ vm.postSelectListPage() |
|
108 |
+ } else { |
|
109 |
+ alert("등록 실패, 관리자에게 문의해주세요."); |
|
110 |
+ } |
|
111 |
+ }).catch(function (error) { |
|
112 |
+ console.log("noticeInsert - error : ", error); |
|
113 |
+ alert("등록 오류, 관리자에게 문의해주세요."); |
|
114 |
+ }); |
|
115 |
+ } |
|
116 |
+ }, |
|
117 |
+ |
|
118 |
+ //등록 유효성 검사 |
|
119 |
+ postInsertCheck: function () { |
|
120 |
+ const oEditors = this.oEditors; |
|
121 |
+ oEditors.getById["smart"].exec("UPDATE_CONTENTS_FIELD", []); |
|
122 |
+ // 스마트에디터의 iframe에 있는 내용을 textarea로. |
|
123 |
+ this.post.post_content = document.getElementById("smart").value; |
|
124 |
+ console.log(document.getElementById("smart").value); |
|
125 |
+ console.log(this.post.post_content); |
|
126 |
+ console.log(COMMON_UTIL.isEmpty(this.post.post_title)); |
|
127 |
+ |
|
128 |
+ if (COMMON_UTIL.isEmpty(this.post.post_title) === false) { |
|
129 |
+ alert("제목을 입력해주세요."); |
|
130 |
+ return false; |
|
131 |
+ } |
|
132 |
+ |
|
133 |
+ if (COMMON_UTIL.isEmpty(this.post.post_content) === false || this.post.post_content === "<p><br></p>") { |
|
134 |
+ alert("내용을 입력해주세요."); |
|
135 |
+ return false; |
|
136 |
+ } |
|
137 |
+ |
|
138 |
+ this.postInsert(); |
|
139 |
+ }, |
|
140 |
+ |
|
141 |
+ //파일업로드 |
|
142 |
+ fileUpload: function() { |
|
143 |
+ this.fileList[this.filecount] = this.$refs.fileInput.files[0] |
|
144 |
+ this.filecount += 1 |
|
145 |
+ console.log("file", this.fileList); |
|
146 |
+ }, |
|
147 |
+ |
|
148 |
+ //파일업로드 중 업로드 파일 삭제 |
|
149 |
+ fileRemove(idx) { |
|
150 |
+ this.fileList.splice(idx, 1); |
|
151 |
+ console.log("reMove_file", this.fileList); |
|
152 |
+ this.filecount = this.fileList.length; |
|
153 |
+ }, |
|
154 |
+ |
|
155 |
+ //게시글 리스트로 이동 |
|
156 |
+ postSelectListPage: function () { |
|
48 | 157 |
this.$router.push({ path: '/adm/dataSelectList.page' }); |
49 | 158 |
}, |
50 | 159 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?