vue: board
This commit is contained in:
+116
-46
@@ -18,56 +18,61 @@
|
|||||||
type="text"
|
type="text"
|
||||||
maxlength="250"
|
maxlength="250"
|
||||||
placeholder="제목"
|
placeholder="제목"
|
||||||
|
v-model="newArticle.title"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="bg1">내용</th>
|
<th class="bg1">내용</th>
|
||||||
<td class="boardArticle">
|
<td class="boardArticle">
|
||||||
<textarea class="contentInput autosize" placeholder="내용"></textarea>
|
<textarea
|
||||||
|
class="contentInput autosize"
|
||||||
|
ref="newArticleTextForm"
|
||||||
|
placeholder="내용"
|
||||||
|
v-model="newArticle.text"
|
||||||
|
@input="autoResizeTextarea"
|
||||||
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<button type="button" id="submitArticle">등록</button>
|
<button type="button" id="submitArticle" @click="submitArticle">
|
||||||
|
등록
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div id="board">
|
<div id="board">
|
||||||
<!--<suspense>
|
<template v-if="articles && articles.length">
|
||||||
<template #default>-->
|
<board-article
|
||||||
<board-article
|
v-for="article in articles"
|
||||||
v-for="article in articles"
|
:key="article.no"
|
||||||
:key="article.no"
|
:article="article"
|
||||||
:article="article"
|
@submit-comment="reloadArticles"
|
||||||
/>
|
/>
|
||||||
<!--</template>
|
</template>
|
||||||
<template #fallback>
|
<template v-else> 게시물이 없습니다. </template>
|
||||||
<span>불러오는 중입니다...</span>
|
|
||||||
</template>
|
|
||||||
</suspense>-->
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, PropType, reactive, toRef } from "vue";
|
|
||||||
import "../scss/bootstrap5.scss";
|
import "../scss/bootstrap5.scss";
|
||||||
import "../scss/inheritPoint.scss";
|
import "../scss/inheritPoint.scss";
|
||||||
import "../scss/game_bg.scss";
|
import "../scss/game_bg.scss";
|
||||||
|
import "../../css/config.css";
|
||||||
|
|
||||||
|
import { defineComponent, onMounted, reactive, ref } from "vue";
|
||||||
import TopBackBar from "./components/TopBackBar.vue";
|
import TopBackBar from "./components/TopBackBar.vue";
|
||||||
import BoardArticle from "./components/BoardArticle.vue";
|
import BoardArticle from "./components/BoardArticle.vue";
|
||||||
import _, { isArray } from "lodash";
|
|
||||||
import { ref } from "vue";
|
|
||||||
import axios from "axios";
|
|
||||||
import { convertFormData } from "./util/convertFormData";
|
import { convertFormData } from "./util/convertFormData";
|
||||||
|
import axios from "axios";
|
||||||
import { InvalidResponse } from "./defs";
|
import { InvalidResponse } from "./defs";
|
||||||
import { delay } from "./util/delay";
|
import { autoResizeTextarea } from "./util/autoResizeTextarea";
|
||||||
declare const isSecretBoard: boolean;
|
import { unwrap } from "./util/unwrap";
|
||||||
|
|
||||||
export type BoardResponse = {
|
export type BoardResponse = {
|
||||||
result: true;
|
result: true;
|
||||||
articles: Record<number, BoardArticleItem>;
|
articles: Record<number, BoardArticleItem>;
|
||||||
@@ -103,36 +108,101 @@ export default defineComponent({
|
|||||||
TopBackBar,
|
TopBackBar,
|
||||||
BoardArticle,
|
BoardArticle,
|
||||||
},
|
},
|
||||||
async setup() {
|
props: {
|
||||||
let boardResponse: BoardResponse;
|
isSecretBoard: {
|
||||||
|
type: Boolean,
|
||||||
try {
|
required: true,
|
||||||
const response = await axios({
|
},
|
||||||
url: "j_board_get_articles.php",
|
},
|
||||||
responseType: "json",
|
data() {
|
||||||
method: "post",
|
return {
|
||||||
data: convertFormData({
|
title: this.isSecretBoard ? "기밀실" : "회의실",
|
||||||
isSecret: isSecretBoard,
|
newArticle: {
|
||||||
}),
|
title: "",
|
||||||
});
|
text: "",
|
||||||
const result: InvalidResponse | BoardResponse = response.data;
|
},
|
||||||
if (!result.result) {
|
};
|
||||||
throw result.reason;
|
},
|
||||||
|
methods: {
|
||||||
|
autoResizeTextarea,
|
||||||
|
async submitArticle() {
|
||||||
|
const { title, text } = this.newArticle;
|
||||||
|
if (!title && !text) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
boardResponse = result;
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
alert(`에러: ${e}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//const articles = reactive();
|
let result: InvalidResponse;
|
||||||
console.log(boardResponse);
|
|
||||||
const articles:BoardResponse['articles'] = isArray(boardResponse.articles)?{}:boardResponse;
|
try {
|
||||||
|
const response = await axios({
|
||||||
|
url: "j_board_article_add.php",
|
||||||
|
method: "post",
|
||||||
|
responseType: "json",
|
||||||
|
data: convertFormData({
|
||||||
|
isSecret: this.isSecretBoard,
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
result = response.data;
|
||||||
|
if (!result.result) {
|
||||||
|
throw result.reason;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
alert(`실패했습니다. :${e}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.newArticle = { title: "", text: "" };
|
||||||
|
const newArticleTextForm = unwrap(this.newArticleTextForm);
|
||||||
|
newArticleTextForm.style.height = 'auto';
|
||||||
|
|
||||||
|
await this.reloadArticles();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
setup(props) {
|
||||||
|
const newArticleTextForm = ref<HTMLInputElement>();
|
||||||
|
const articles = reactive<BoardArticleItem[]>([]);
|
||||||
|
|
||||||
|
const reloadArticles = async () => {
|
||||||
|
let boardResponse: BoardResponse;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios({
|
||||||
|
url: "j_board_get_articles.php",
|
||||||
|
responseType: "json",
|
||||||
|
method: "post",
|
||||||
|
data: convertFormData({
|
||||||
|
isSecret: props.isSecretBoard,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const result: InvalidResponse | BoardResponse = response.data;
|
||||||
|
if (!result.result) {
|
||||||
|
throw result.reason;
|
||||||
|
}
|
||||||
|
boardResponse = result;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
alert(`에러: ${e}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
articles.length = 0;
|
||||||
|
articles.push(...Object.values(boardResponse.articles));
|
||||||
|
articles.reverse();
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await reloadArticles();
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: isSecretBoard ? "기밀실" : "회의실",
|
newArticleTextForm,
|
||||||
articles,
|
articles,
|
||||||
|
reloadArticles,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,15 +2,22 @@
|
|||||||
<table class="articleFrame bg0">
|
<table class="articleFrame bg0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="bg1">
|
<tr class="bg1">
|
||||||
<th class="authorName"></th>
|
<th class="authorName">{{ article.author }}</th>
|
||||||
<th class="articleTitle"></th>
|
<th class="articleTitle">{{ article.title }}</th>
|
||||||
<th class="date"></th>
|
<th class="date">{{ article.date }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td><img class="authorIcon generalIcon" width="64" height="64" /></td>
|
<td>
|
||||||
<td class="text" colspan="2"></td>
|
<img
|
||||||
|
class="authorIcon generalIcon"
|
||||||
|
width="64"
|
||||||
|
height="64"
|
||||||
|
:src="article.author_icon"
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
<td class="text" colspan="2">{{ article.text }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
<tbody class="commentList">
|
<tbody class="commentList">
|
||||||
@@ -29,19 +36,26 @@
|
|||||||
type="text"
|
type="text"
|
||||||
maxlength="250"
|
maxlength="250"
|
||||||
placeholder="새 댓글 내용"
|
placeholder="새 댓글 내용"
|
||||||
:value="newCommentText"
|
v-model.trim="newCommentText"
|
||||||
|
@keyup.enter="submitComment"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td><button type="button" class="submitComment">등록</button></td>
|
<td>
|
||||||
|
<button type="button" class="submitComment" @click="submitComment">
|
||||||
|
등록
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { BoardArticleItem } from "board.vue";
|
import { BoardArticleItem } from "../Board.vue";
|
||||||
import BoardComment from "./BoardComment.vue";
|
import BoardComment from "./BoardComment.vue";
|
||||||
import { defineComponent, PropType } from "vue";
|
import { defineComponent, PropType } from "vue";
|
||||||
|
import axios from "axios";
|
||||||
|
import { convertFormData } from "../util/convertFormData";
|
||||||
|
import { InvalidResponse } from "../defs";
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "BoardArticle",
|
name: "BoardArticle",
|
||||||
components: {
|
components: {
|
||||||
@@ -58,15 +72,47 @@ export default defineComponent({
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
emits: ["submit-comment"],
|
||||||
methods: {
|
methods: {
|
||||||
submitComment() {
|
async submitComment() {
|
||||||
console.log(this.newCommentText);
|
const comment = this.newCommentText;
|
||||||
|
if (!comment) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const articleNo = this.article.no;
|
||||||
|
|
||||||
|
let result: InvalidResponse;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios({
|
||||||
|
url: "j_board_comment_add.php",
|
||||||
|
method: "post",
|
||||||
|
responseType: "json",
|
||||||
|
data: convertFormData({
|
||||||
|
articleNo: articleNo,
|
||||||
|
text: comment,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
result = response.data;
|
||||||
|
if (!result.result) {
|
||||||
|
throw result.reason;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
alert(`실패했습니다: ${e}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.newCommentText = "";
|
||||||
|
|
||||||
|
this.$emit("submit-comment");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/*
|
|
||||||
setup(props) {
|
|
||||||
toRef(props, "article");
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
td.text {
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { BoardCommentItem } from "board.vue";
|
import { BoardCommentItem } from "../Board.vue";
|
||||||
import { defineComponent, PropType } from "vue";
|
import { defineComponent, PropType } from "vue";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { unwrap } from "./unwrap";
|
||||||
|
|
||||||
|
export function autoResizeTextarea(e: InputEvent): void {
|
||||||
|
const el = unwrap(e.target) as HTMLInputElement;
|
||||||
|
el.style.height = 'auto';
|
||||||
|
el.style.height = `${el.scrollHeight + 1}px`;
|
||||||
|
}
|
||||||
+6
-1
@@ -2,5 +2,10 @@ import { createApp } from 'vue'
|
|||||||
import Board from './Board.vue';
|
import Board from './Board.vue';
|
||||||
import { setAxiosXMLHttpRequest } from './util/setAxiosXMLHttpRequest';
|
import { setAxiosXMLHttpRequest } from './util/setAxiosXMLHttpRequest';
|
||||||
|
|
||||||
|
declare const isSecretBoard: boolean;
|
||||||
|
|
||||||
|
|
||||||
setAxiosXMLHttpRequest();
|
setAxiosXMLHttpRequest();
|
||||||
createApp(Board).mount('#app')
|
createApp(Board, {
|
||||||
|
isSecretBoard
|
||||||
|
}).mount('#app')
|
||||||
+3
-3
@@ -45,9 +45,9 @@ $boardName = $isSecretBoard ? '기밀실' : '회의실';
|
|||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=1024" />
|
<meta name="viewport" content="width=1024" />
|
||||||
<?= WebUtil::printCSS('dist_css/common_vue.css') ?>
|
<?= WebUtil::printCSS('dist_css/common_vue.css') ?>
|
||||||
<?= ""??WebUtil::printCSS('dist_css/v_board.css') ?>
|
<?= WebUtil::printCSS('dist_css/v_board.css') ?>
|
||||||
<?= WebUtil::printJS('../d_shared/common_path.js') ?>
|
<?= WebUtil::printJS('../d_shared/common_path.js', true) ?>
|
||||||
<?= WebUtil::printJS('dist_js/vendors_vue.js') ?>
|
<?= WebUtil::printJS('dist_js/vendors_vue.js', true) ?>
|
||||||
<?= WebUtil::printJS('dist_js/v_board.js', true) ?>
|
<?= WebUtil::printJS('dist_js/v_board.js', true) ?>
|
||||||
<?= WebUtil::printStaticValues([
|
<?= WebUtil::printStaticValues([
|
||||||
'isSecretBoard' => $isSecretBoard,
|
'isSecretBoard' => $isSecretBoard,
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ foreach (array_keys(General::INHERITANCE_KEY) as $key) {
|
|||||||
<meta name="viewport" content="width=1024" />
|
<meta name="viewport" content="width=1024" />
|
||||||
<?= WebUtil::printCSS('dist_css/common_vue.css') ?>
|
<?= WebUtil::printCSS('dist_css/common_vue.css') ?>
|
||||||
<?= WebUtil::printCSS('dist_css/v_inheritPoint.css') ?>
|
<?= WebUtil::printCSS('dist_css/v_inheritPoint.css') ?>
|
||||||
<?= WebUtil::printJS('../d_shared/common_path.js') ?>
|
<?= WebUtil::printJS('../d_shared/common_path.js', true) ?>
|
||||||
<?= WebUtil::printJS('dist_js/vendors_vue.js') ?>
|
<?= WebUtil::printJS('dist_js/vendors_vue.js', true) ?>
|
||||||
<?= WebUtil::printJS('dist_js/v_inheritPoint.js', true) ?>
|
<?= WebUtil::printJS('dist_js/v_inheritPoint.js', true) ?>
|
||||||
<?= WebUtil::printStaticValues([
|
<?= WebUtil::printStaticValues([
|
||||||
'items' => $items
|
'items' => $items
|
||||||
|
|||||||
Reference in New Issue
Block a user