- 전역 단일 카테고리 선택 제거 → 각 태그 그룹에 사용 게시판 체크박스(커뮤니티/짠테크/재테크 팁) - 저장 시 boards 함께 전송, 선택 없으면 전체 게시판 - 글쓰기 화면은 현재 게시판에 매핑된 그룹 태그만 노출(boardApi.tagGroups(category)) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -38,8 +38,8 @@ export const boardApi = {
|
||||
tags() {
|
||||
return http.get('/board/tags')
|
||||
},
|
||||
tagGroups() {
|
||||
return http.get('/board/tag-groups')
|
||||
tagGroups(category) {
|
||||
return http.get('/board/tag-groups', { params: { category: category || undefined } })
|
||||
},
|
||||
addComment(id, content) {
|
||||
return http.post(`/board/posts/${id}/comments`, { content })
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { adminApi } from '@/api/adminApi'
|
||||
import { useDialog } from '@/composables/dialog'
|
||||
import { BOARDS } from '@/constants/boards'
|
||||
import IconBtn from '@/components/ui/IconBtn.vue'
|
||||
|
||||
const dialog = useDialog()
|
||||
@@ -11,18 +12,17 @@ const error = ref(null)
|
||||
|
||||
const newCategoryName = ref('')
|
||||
const newTag = reactive({}) // { [categoryId]: '입력값' }
|
||||
const boardCategoryId = ref('') // 게시판에서 사용할 카테고리 ('' = 제한 없음)
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
categories.value = await adminApi.categories()
|
||||
categories.value.forEach((c) => {
|
||||
const list = await adminApi.categories()
|
||||
list.forEach((c) => {
|
||||
if (!Array.isArray(c.boards)) c.boards = []
|
||||
if (newTag[c.id] === undefined) newTag[c.id] = ''
|
||||
})
|
||||
const setting = await adminApi.getBoardSetting()
|
||||
boardCategoryId.value = setting.tagCategoryId ?? ''
|
||||
categories.value = list
|
||||
} catch (e) {
|
||||
error.value = e.response?.data?.message || '불러오지 못했습니다.'
|
||||
} finally {
|
||||
@@ -30,21 +30,18 @@ async function load() {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveBoardSetting() {
|
||||
try {
|
||||
const id = boardCategoryId.value === '' ? null : Number(boardCategoryId.value)
|
||||
await adminApi.setBoardSetting(id)
|
||||
alert('게시판 사용 카테고리를 저장했습니다.')
|
||||
} catch (e) {
|
||||
alert(e.response?.data?.message || '저장 실패')
|
||||
}
|
||||
// 카테고리의 게시판 매핑 토글
|
||||
function toggleBoard(cat, key) {
|
||||
const i = cat.boards.indexOf(key)
|
||||
if (i >= 0) cat.boards.splice(i, 1)
|
||||
else cat.boards.push(key)
|
||||
}
|
||||
|
||||
async function addCategory() {
|
||||
const name = newCategoryName.value.trim()
|
||||
if (!name) return
|
||||
try {
|
||||
await adminApi.createCategory({ name, sortOrder: categories.value.length })
|
||||
await adminApi.createCategory({ name, sortOrder: categories.value.length, boards: [] })
|
||||
newCategoryName.value = ''
|
||||
await load()
|
||||
} catch (e) {
|
||||
@@ -56,7 +53,8 @@ async function saveCategory(cat) {
|
||||
const name = (cat.name || '').trim()
|
||||
if (!name) return
|
||||
try {
|
||||
await adminApi.updateCategory(cat.id, { name, sortOrder: cat.sortOrder })
|
||||
await adminApi.updateCategory(cat.id, { name, sortOrder: cat.sortOrder, boards: cat.boards })
|
||||
alert('저장했습니다.')
|
||||
await load()
|
||||
} catch (e) {
|
||||
alert(e.response?.data?.message || '카테고리 수정 실패')
|
||||
@@ -100,15 +98,7 @@ onMounted(load)
|
||||
|
||||
<template>
|
||||
<section class="tag-admin">
|
||||
<div class="board-setting">
|
||||
<label>게시판 사용 카테고리</label>
|
||||
<select v-model="boardCategoryId">
|
||||
<option value="">전체 허용 (제한 없음)</option>
|
||||
<option v-for="c in categories" :key="c.id" :value="c.id">{{ c.name }}</option>
|
||||
</select>
|
||||
<IconBtn icon="check" title="저장" variant="primary" @click="saveBoardSetting" />
|
||||
<span class="hint">선택 시 글쓰기에서 해당 카테고리의 태그만 사용할 수 있습니다.</span>
|
||||
</div>
|
||||
<p class="page-hint">각 태그 그룹을 사용할 게시판을 지정하세요. 선택한 게시판의 글쓰기에서만 그 그룹 태그가 노출됩니다. (선택 없으면 전체 게시판)</p>
|
||||
|
||||
<form class="new-category" @submit.prevent="addCategory">
|
||||
<input v-model="newCategoryName" type="text" placeholder="새 카테고리 이름 (예: 게시판, 게시판2)" />
|
||||
@@ -121,10 +111,19 @@ onMounted(load)
|
||||
<div v-for="cat in categories" :key="cat.id" class="category-card">
|
||||
<div class="cat-head">
|
||||
<input v-model="cat.name" class="cat-name" @keyup.enter="saveCategory(cat)" />
|
||||
<IconBtn icon="check" title="이름 저장" @click="saveCategory(cat)" />
|
||||
<IconBtn icon="check" title="저장" @click="saveCategory(cat)" />
|
||||
<IconBtn icon="trash" title="카테고리 삭제" variant="danger" @click="removeCategory(cat)" />
|
||||
</div>
|
||||
|
||||
<div class="board-map">
|
||||
<span class="bm-label">사용 게시판</span>
|
||||
<label v-for="b in BOARDS" :key="b.key" class="bm-check">
|
||||
<input type="checkbox" :checked="cat.boards.includes(b.key)" @change="toggleBoard(cat, b.key)" />
|
||||
{{ b.label }}
|
||||
</label>
|
||||
<span v-if="!cat.boards.length" class="bm-all">전체</span>
|
||||
</div>
|
||||
|
||||
<div class="tag-list">
|
||||
<span v-for="t in cat.tags" :key="t.id" class="tag-chip">
|
||||
{{ t.name }}
|
||||
@@ -171,31 +170,40 @@ button.danger {
|
||||
border-color: #c0392b;
|
||||
color: #c0392b;
|
||||
}
|
||||
.board-setting {
|
||||
.page-hint {
|
||||
font-size: 0.85rem;
|
||||
opacity: 0.7;
|
||||
margin-bottom: 1rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.board-map {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
padding: 0.75rem;
|
||||
margin-bottom: 1.25rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background: var(--color-background-soft);
|
||||
padding: 0.5rem 0 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
border-bottom: 1px dashed var(--color-border);
|
||||
}
|
||||
.board-setting label {
|
||||
.bm-label {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
opacity: 0.8;
|
||||
}
|
||||
.board-setting select {
|
||||
padding: 0.4rem 0.6rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 4px;
|
||||
background: var(--color-background);
|
||||
color: var(--color-text);
|
||||
.bm-check {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
font-size: 0.85rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.board-setting .hint {
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.65;
|
||||
flex-basis: 100%;
|
||||
.bm-check input {
|
||||
width: auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
.bm-all {
|
||||
font-size: 0.78rem;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.new-category {
|
||||
display: flex;
|
||||
|
||||
@@ -37,7 +37,7 @@ function toggleTag(id) {
|
||||
|
||||
async function loadTagGroups() {
|
||||
try {
|
||||
tagGroups.value = await boardApi.tagGroups()
|
||||
tagGroups.value = await boardApi.tagGroups(category)
|
||||
} catch {
|
||||
tagGroups.value = []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user