first commit
This commit is contained in:
438
src/views/Explorer/ExplorerSectionView.vue
Normal file
438
src/views/Explorer/ExplorerSectionView.vue
Normal file
@@ -0,0 +1,438 @@
|
||||
<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-data-table
|
||||
:headers="headers"
|
||||
:items="explorer_sections"
|
||||
:loading="isLoading"
|
||||
:items-per-page="20"
|
||||
item-key="id"
|
||||
class="elevation-1"
|
||||
hide-default-footer
|
||||
>
|
||||
<template v-slot:body="props">
|
||||
<draggable
|
||||
v-model="props.items"
|
||||
tag="tbody"
|
||||
@end="onDropCallback(props.items)"
|
||||
>
|
||||
<tr
|
||||
v-for="(item, index) in props.items"
|
||||
:key="index"
|
||||
>
|
||||
<td>{{ item.title }}</td>
|
||||
<td>{{ item.coloredTitle }}</td>
|
||||
<td>#{{ item.color }}</td>
|
||||
<td>{{ item.tags.map((tag) => '#' + tag).join(' ') }}</td>
|
||||
<td>
|
||||
<span v-if="item.isAdult">
|
||||
O
|
||||
</span>
|
||||
<span v-else>
|
||||
X
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span v-if="item.isActive">
|
||||
O
|
||||
</span>
|
||||
<span v-else>
|
||||
X
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<v-btn
|
||||
:disabled="isLoading"
|
||||
@click="showModifyDialog(item)"
|
||||
>
|
||||
수정
|
||||
</v-btn>
|
||||
</td>
|
||||
</tr>
|
||||
</draggable>
|
||||
</template>
|
||||
</v-data-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-title>탐색 섹션 등록</v-card-title>
|
||||
<v-card-text>
|
||||
<v-text-field
|
||||
v-model="title"
|
||||
label="제목"
|
||||
required
|
||||
/>
|
||||
</v-card-text>
|
||||
<v-card-text>
|
||||
<v-text-field
|
||||
v-model="colored_title"
|
||||
label="제목에 컬러를 변경할 단어(선택)"
|
||||
required
|
||||
/>
|
||||
</v-card-text>
|
||||
<v-card-text>
|
||||
<v-text-field
|
||||
v-model="color"
|
||||
label="컬러(ex > 00ff00)(선택)"
|
||||
required
|
||||
/>
|
||||
</v-card-text>
|
||||
<v-card-text>
|
||||
관심사(최소 1개 이상)<br><br>
|
||||
----------------
|
||||
<v-row align="center">
|
||||
<v-col
|
||||
v-for="tag in creator_tags"
|
||||
:key="tag.id"
|
||||
cols="3"
|
||||
>
|
||||
<input
|
||||
v-model="selected_tags"
|
||||
:value="tag.tag"
|
||||
type="checkbox"
|
||||
>
|
||||
{{ tag.tag }}
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
----------------<br><br>
|
||||
<v-card-text>
|
||||
<v-row align="center">
|
||||
<v-col>
|
||||
<input
|
||||
v-model="is_adult"
|
||||
type="checkbox"
|
||||
> 19금
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
<v-card-text v-if="selected_explorer_section != null">
|
||||
<v-row align="center">
|
||||
<v-col>
|
||||
<input
|
||||
v-model="is_active"
|
||||
type="checkbox"
|
||||
> 활성화
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
<v-card-actions v-show="!isLoading">
|
||||
<v-spacer />
|
||||
<v-btn
|
||||
color="blue darken-1"
|
||||
text
|
||||
@click="cancel"
|
||||
>
|
||||
취소
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-if="selected_explorer_section != null"
|
||||
color="blue darken-1"
|
||||
text
|
||||
@click="modify"
|
||||
>
|
||||
수정
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-else
|
||||
color="blue darken-1"
|
||||
text
|
||||
@click="validate"
|
||||
>
|
||||
등록
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as api from "@/api/explorer"
|
||||
import * as creatorTagApi from "@/api/counselor_tag";
|
||||
import Draggable from "vuedraggable";
|
||||
|
||||
export default {
|
||||
name: "ExplorerSectionView",
|
||||
|
||||
components: {Draggable},
|
||||
|
||||
data() {
|
||||
return {
|
||||
isLoading: false,
|
||||
show_write_dialog: false,
|
||||
page: 1,
|
||||
total_page: 0,
|
||||
creator_tags: [],
|
||||
selected_tags: [],
|
||||
explorer_sections: [],
|
||||
selected_explorer_section: null,
|
||||
title: null,
|
||||
colored_title: null,
|
||||
color: null,
|
||||
is_adult: false,
|
||||
is_active: true,
|
||||
headers: [
|
||||
{
|
||||
text: '제목',
|
||||
align: 'center',
|
||||
sortable: false,
|
||||
value: 'title',
|
||||
},
|
||||
{
|
||||
text: '제목에 컬러를 변경할 단어',
|
||||
align: 'center',
|
||||
sortable: false,
|
||||
value: 'coloredTitle',
|
||||
},
|
||||
{
|
||||
text: '컬러',
|
||||
align: 'center',
|
||||
sortable: false,
|
||||
value: 'color',
|
||||
},
|
||||
{
|
||||
text: '관심사',
|
||||
align: 'center',
|
||||
sortable: false,
|
||||
value: 'tags',
|
||||
},
|
||||
{
|
||||
text: '19금',
|
||||
align: 'center',
|
||||
sortable: false,
|
||||
value: 'isAdult',
|
||||
},
|
||||
{
|
||||
text: '사용여부',
|
||||
align: 'center',
|
||||
sortable: false,
|
||||
value: 'isActive',
|
||||
},
|
||||
{
|
||||
text: '관리',
|
||||
align: 'center',
|
||||
sortable: false,
|
||||
value: 'management'
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
async created() {
|
||||
await this.getCreatorTags()
|
||||
await this.getExplorerSections()
|
||||
},
|
||||
|
||||
methods: {
|
||||
notifyError(message) {
|
||||
this.$dialog.notify.error(message)
|
||||
},
|
||||
|
||||
notifySuccess(message) {
|
||||
this.$dialog.notify.success(message)
|
||||
},
|
||||
|
||||
validate() {
|
||||
if (this.title === null || this.title.trim().length <= 0) {
|
||||
this.notifyError("제목을 입력하세요.")
|
||||
} else if (
|
||||
this.selected_tags === null ||
|
||||
this.selected_tags.length <= 0
|
||||
) {
|
||||
this.notifyError("관심사를 선택하세요.")
|
||||
} else {
|
||||
this.submit()
|
||||
}
|
||||
},
|
||||
|
||||
async submit() {
|
||||
if (this.is_loading) return;
|
||||
this.isLoading = true
|
||||
|
||||
const res = await api.createExplorerSection({
|
||||
"title": this.title,
|
||||
"isAdult": this.is_adult,
|
||||
"tagList": this.selected_tags,
|
||||
"coloredTitle": this.colored_title,
|
||||
"color": this.color
|
||||
})
|
||||
|
||||
if (res.status === 200 && res.data.success === true) {
|
||||
this.cancel()
|
||||
this.notifySuccess('등록되었습니다.')
|
||||
this.page = 1
|
||||
await this.getExplorerSections()
|
||||
} else {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
}
|
||||
|
||||
this.is_loading = false
|
||||
},
|
||||
|
||||
async modify() {
|
||||
if (this.is_loading) return;
|
||||
this.isLoading = true
|
||||
|
||||
const res = await api.updateExplorerSection({
|
||||
"id": this.selected_explorer_section.id,
|
||||
"title": this.title !== this.selected_explorer_section.title ? this.title : null,
|
||||
"isAdult": this.is_adult !== this.selected_explorer_section.isAdult ? this.is_adult : null,
|
||||
"isActive": this.is_active !== this.selected_explorer_section.isActive ? this.is_active : null,
|
||||
"tagList": this.selected_tags !== this.selected_explorer_section.tags ? this.selected_tags : null,
|
||||
"coloredTitle": this.colored_title !== this.selected_explorer_section.coloredTitle ? this.colored_title : null,
|
||||
"color": this.color !== this.selected_explorer_section.color ? this.color : null
|
||||
})
|
||||
|
||||
if (res.status === 200 && res.data.success === true) {
|
||||
this.cancel()
|
||||
this.notifySuccess(res.data.message || '수정되었습니다.')
|
||||
this.page = 1
|
||||
await this.getExplorerSections()
|
||||
this.is_loading = false
|
||||
} else {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
this.is_loading = false
|
||||
}
|
||||
},
|
||||
|
||||
async next() {
|
||||
await this.getExplorerSections()
|
||||
},
|
||||
|
||||
async getExplorerSections() {
|
||||
this.isLoading = true
|
||||
|
||||
try {
|
||||
const res = await api.getExplorerSections(this.page)
|
||||
|
||||
if (res.status === 200 && res.data.success === true) {
|
||||
const data = res.data.data
|
||||
|
||||
const totalPage = Math.ceil(data.totalCount / 20)
|
||||
this.explorer_sections = data.explorerSectionItemList;
|
||||
|
||||
if (totalPage <= 0)
|
||||
this.total_page = 1
|
||||
else
|
||||
this.total_page = totalPage
|
||||
} else {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
}
|
||||
} catch (e) {
|
||||
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
} finally {
|
||||
this.isLoading = false
|
||||
}
|
||||
},
|
||||
|
||||
async getCreatorTags() {
|
||||
this.isLoading = true
|
||||
|
||||
try {
|
||||
const res = await creatorTagApi.getTags()
|
||||
|
||||
if (res.status === 200 && res.data.success === true) {
|
||||
this.creator_tags = res.data.data;
|
||||
} else {
|
||||
this.notifyError(res.data.message || '알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
}
|
||||
} catch (e) {
|
||||
this.notifyError('알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.')
|
||||
} finally {
|
||||
this.isLoading = false
|
||||
}
|
||||
},
|
||||
|
||||
showWriteDialog() {
|
||||
this.show_write_dialog = true
|
||||
},
|
||||
|
||||
showModifyDialog(item) {
|
||||
this.selected_explorer_section = item;
|
||||
this.title = item.title;
|
||||
this.colored_title = item.coloredTitle;
|
||||
this.color = item.color;
|
||||
this.selected_tags = item.tags;
|
||||
this.is_adult = item.isAdult;
|
||||
this.is_active = item.isActive;
|
||||
this.show_write_dialog = true
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.show_write_dialog = false
|
||||
this.selected_explorer_section = null
|
||||
this.selected_tags = []
|
||||
this.title = null
|
||||
this.colored_title = null
|
||||
this.color = null
|
||||
this.is_adult = false
|
||||
this.is_active = true
|
||||
},
|
||||
|
||||
async onDropCallback(items) {
|
||||
this.explorer_sections = items
|
||||
|
||||
const ids = items.map((item) => {
|
||||
return item.id
|
||||
})
|
||||
|
||||
const firstOrders = (this.page - 1) * 20 + 1
|
||||
|
||||
const res = await api.updateExplorerSectionsOrders(firstOrders, ids)
|
||||
if (res.status === 200 && res.data.success === true) {
|
||||
this.notifySuccess(res.data.message)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user