可拖拽组件

This commit is contained in:
simple321vip
2022-10-26 10:24:00 +08:00
parent 01652a527d
commit bf00737dd9
2 changed files with 88 additions and 53 deletions
+14 -4
View File
@@ -65,22 +65,32 @@ const putBlog = (postData: Object) => {
}) })
} }
const updateContent = (postData: Object) => { const updateContent = (post_data: Object) => {
return service({ return service({
url: '/auth/api/v1/author/blog/content', url: '/auth/api/v1/author/blog/content',
method: 'POST', method: 'POST',
headers: headers, headers: headers,
data: postData data: post_data
}) })
} }
const deleteContent = (bid: string) => { const deleteContent = (bid: string, delete_data: Object) => {
return service({ return service({
url: '/auth/api/v1/author/blog/' + bid, url: '/auth/api/v1/author/blog/' + bid,
method: 'DELETE', method: 'DELETE',
headers: headers, headers: headers,
data: delete_data
})
}
const sortBlogs = (data: Object, btId: string) => {
return service({
url: '/auth/api/v1/author/blogs/' + btId,
method: 'POST',
headers: headers,
data: data
}) })
} }
export { listAll, updateBtName, putBlogType, removeBlogType, sortBlogTypes, getContent, putBlog, updateContent, deleteContent } export { listAll, updateBtName, putBlogType, removeBlogType, sortBlogTypes, getContent, putBlog, updateContent, deleteContent, sortBlogs }
+71 -46
View File
@@ -1,47 +1,16 @@
<template> <template>
<div class="blog_editer" v-if="isReady"> <div class="blog_editer" v-if="isReady">
<div class="bt_section" :style="btWholeStyle"> <div class="bt_section" :style="btWholeStyle">
<table class="tb"> <el-button class="bt-input" @click="contentDialogVisible = true">增加一个分类</el-button>
<thead> <draggable :list="blogTypes" ghost-class="ghost" handle=".move" animation="300" :force-fallback="true"
<draggable v-model="state.headers" animation="200" tag="tr" :item-key="(key: string) => key"> filter=".forbid" chosen-class="chosenClass" :fallback-class="true" :fallback-on-body="true"
<template #item="{ element: header }"> :touch-start-threshold="50" :fallback-tolerance="50" @start="onStart" @end="onEnd" group="group1">
<th class="move">
增加分类
</th>
</template>
</draggable>
</thead>
<!-- <draggable :list="blogTypes" handle=".move" animation="300" @start="onStart" @end="onEnd" tag="tbody" -->
<draggable :list="blogTypes" handle=".move" animation="300" @start="onStart" @end="onEnd" tag="tbody"
item-key="name">
<template #item="{ element }"> <template #item="{ element }">
<tr> <div :class="element.disabledMove ? 'forbid item' : 'item'">
<td class="move" v-for="(header, index) in state.headers" :key="header"> <label class="move">{{ element.btName }}</label>
<el-icon v-show="checkedBlogIndex == element.order"> </div>
<edit />
</el-icon>
{{ element.btName }}
</td>
</tr>
</template> </template>
</draggable> </draggable>
</table>
<!-- <el-button class="bt-input" @click="contentDialogVisible = true">增加一个分类</el-button>
<el-button class="bt-input" v-for="(value, key) of blogTypes" :key="key" @click="onclickTypeTab(value.order)">
<el-dropdown trigger="click">
<el-icon v-show="checkedBlogIndex == value.order">
<edit />
</el-icon>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="dialogVisible = true">修改</el-dropdown-item>
<el-dropdown-item @click="btdeleteDialogVisible = true">删除</el-dropdown-item>
<el-dropdown-item @click="true">退出</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
{{ value.btName }}
</el-button> -->
</div> </div>
<div class="b_section" :style="bWholeStyle"> <div class="b_section" :style="bWholeStyle">
@@ -138,7 +107,8 @@ import {
getContent, getContent,
putBlog, putBlog,
deleteContent, deleteContent,
sortBlogTypes sortBlogTypes,
sortBlogs
} from '../../api/blog' } from '../../api/blog'
import draggable from "vuedraggable" import draggable from "vuedraggable"
@@ -180,9 +150,11 @@ animation="300" //动画效果
@end="onEnd" //拖拽结束的事件 @end="onEnd" //拖拽结束的事件
*/ */
const state = reactive({ const state = reactive({
//列的名称 modules: {
headers: ["blogType"], group1: [
//需要拖拽的数据,拖拽后数据的顺序也会变化
]
},
}) })
// 関数定義 // 関数定義
@@ -296,7 +268,7 @@ const saveContent = () => {
} }
/** /**
* Blogタイプ名称修正 * btName modify
*/ */
const saveType = () => { const saveType = () => {
const query = { const query = {
@@ -306,7 +278,6 @@ const saveType = () => {
updateBtName(query).then(response => { updateBtName(query).then(response => {
dialogVisible.value = false dialogVisible.value = false
}) })
} }
/** /**
@@ -360,8 +331,11 @@ const insertBlog = () => {
*/ */
const deleteBlog = () => { const deleteBlog = () => {
if (btName.value == "删除") { if (btName.value == "删除") {
deleteContent(checkedIndex.value).then(response => { let delete_data = {
if (response.status == 200) { btId: blogTypes[checkedBlogIndex.value].btId
}
deleteContent(checkedIndex.value, delete_data).then(response => {
if (response.data.process_status) {
const deleteKey = checkedIndex.value const deleteKey = checkedIndex.value
checkedIndex.value = blogTypes[checkedBlogIndex.value].blogs.keys().next().value checkedIndex.value = blogTypes[checkedBlogIndex.value].blogs.keys().next().value
blogTypes[checkedBlogIndex.value].blogs.delete(deleteKey) blogTypes[checkedBlogIndex.value].blogs.delete(deleteKey)
@@ -445,6 +419,21 @@ const sortBlogType = () => {
}).catch() }).catch()
} }
const sortBlog = () => {
const sortData: any[] = []
blogTypes[checkedBlogIndex.value].blogs.forEach((blog: Blog) => {
sortData.push({
bid: blog.btId,
order: blog.order
})
})
sortBlogs(sortData, blogTypes[checkedBlogIndex.value].btId).then(response => {
}).catch()
}
// Created 段階の関数呼び出す処理 // Created 段階の関数呼び出す処理
getTestData() getTestData()
@@ -570,4 +559,40 @@ table.tb td {
table.tb td:nth-of-type(1) { table.tb td:nth-of-type(1) {
text-align: center; text-align: center;
} }
.item {
border: solid 1px #ddd;
padding: 0px;
text-align: left;
background-color: #fff;
margin-bottom: 10px;
display: flex;
flex-direction: column;
min-height: 100px;
user-select: none;
}
.item>label {
border-bottom: solid 1px #ddd;
padding: 6px 10px;
color: #333;
}
.item>label:hover {
cursor: move;
}
.item>p {
padding: 6px 10px;
color: #666;
}
.chosenClass {
opacity: 1;
border: solid 1px red;
}
.ghost {
border: solid 1px rgb(19, 41, 239) !important;
}
</style> </style>