一级导航/二级内容拖拽排序
2023-04-18 15:55:13 时间
虽互不曾谋面,但希望能和您成为笔尖下的朋友
以读书,技术,生活为主,偶尔撒点鸡汤
不作,不敷衍,意在真诚吐露,用心分享
背景
在一些后台管理系统里,有时候需要对一级导航拖拽排序,也要对一级导航下的二级内容进行拖拽排序,那这个是怎么实现的呢
实例效果
具体实现
<template>
<div class="tag-relation-wrap">
<div class="tag-tab">
<ul class="tag-tab-ul">
<draggable v-model="firstTabLists" animation="1000">
<transition-group>
<li v-for="(item) in firstTabLists"
:key="item.id"
class="tab-ul-li"
:class="{selectTab:curTab==item.id}"
@click="handleLevel1TagLi(item.id)"
>
{{item.title}}
</li>
</transition-group>
</draggable>
</ul>
<div class="second-tag-content">
<draggable v-model="secondTagLists" class="draggable" @start="handleOnStart" @end="handleOnEnd" animation="1000">
<transition-group>
<div class="second-tag-list" v-for="(item) in secondTagLists" :key="item.id">
<div v-if="curTab == item.parent.id">
<div>
<img :src="item.logo" width="150" height="100" style="margin-right:10px;" alt="">
</div>
<div>{{item.title}}({{item.img_count}})</div>
</div>
</div>
</transition-group>
</draggable>
</div>
</div>
</div>
</template>
<script>
import draggable from 'vuedraggable'
export default {
name: 'levelDraw',
components: {
draggable
},
data() {
return {
curTab: 0,
drag: false,
firstTabLists: [],
secondTagLists: [
{
id: "111",
logo: "https://t7.baidu.com/it/u=2604797219,1573897854&fm=193&f=GIF",
title: "自然风景",
img_count: "4",
parent: {
id: "0"
}
},
{
id: "112",
logo: "https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00607-2747.jpg",
title: "城市风光",
img_count: "5",
parent: {
id: "0",
}
},
{
id: "113",
logo: "https://img1.baidu.com/it/u=3359541483,3941166536&fm=26&fmt=auto",
title: "蓝天白云",
img_count: "6",
parent: {
id: "0",
}
},
{
id: "114",
logo: "https://img2.baidu.com/it/u=1986005730,948348151&fm=26&fmt=auto",
title: "浪漫大海",
img_count: "7",
parent: {
id: "0",
}
},
{
id: "115",
logo: "https://img1.baidu.com/it/u=4096324645,3052151476&fm=26&fmt=auto",
title: "幽静森林",
img_count: "8",
parent: {
id: "0",
}
},
{
id: "116",
logo: "https://img0.baidu.com/it/u=986567382,3731968355&fm=26&fmt=auto",
title: "风景",
img_count: "8",
parent: {
id: "1",
}
},
{
id: "117",
logo: "https://img2.baidu.com/it/u=3493136389,1353360279&fm=26&fmt=auto",
title: "人文",
img_count: "5",
parent: {
id: "1",
}
},
{
id: "118",
logo: "https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00237-960.jpg",
title: "植物",
img_count: "9",
parent: {
id: "1",
}
},
{
id: "119",
logo: "https://img1.baidu.com/it/u=3108395991,3014709597&fm=26&fmt=auto",
title: "动物",
img_count: "6",
parent: {
id: "1",
}
},
{
id: "120",
logo: "https://img2.baidu.com/it/u=2629675476,1507451532&fm=26&fmt=auto",
title: "绿色护眼",
img_count: "6",
parent: {
id: "2",
}
},
{
id: "121",
logo: "https://img1.baidu.com/it/u=2985957268,45475772&fm=26&fmt=auto",
title: "清新淡雅",
img_count: "6",
parent: {
id: "2",
}
},
{
id: "122",
logo: "https://img1.baidu.com/it/u=2433542901,3786348763&fm=15&fmt=auto",
title: "艺术作品",
img_count: "7",
parent: {
id: "3",
}
},
{
id: "123",
logo: "https://img0.baidu.com/it/u=3147964452,2678650339&fm=26&fmt=auto",
title: "二次元",
img_count: "8",
parent: {
id: "3",
}
},
{
id: "124",
logo: "https://img0.baidu.com/it/u=251703063,4193365027&fm=26&fmt=auto",
title: "打工人",
img_count: "8",
parent: {
id: "3",
}
}
],
}
},
mounted() {
this.mockFirstTabList();
},
methods: {
handleLevel1TagLi(id) {
console.log(id);
this.curTab = id;
},
mockFirstTabList() {
let firstLevelTitle = ["风景","摄影","花草","插画","影视","美女","汽车","简约"];
for(let i = 0;i<=firstLevelTitle.length;i++) {
this.firstTabLists.push({
id: i,
title: firstLevelTitle[i]
})
}
},
// 开始拖拽
handleOnStart() {
this.drag = true;
},
// 结束拖拽
handleOnEnd() {
this.drag = false;
},
}
}
</script>
<style lang="scss" scoped>
.tag-relation-wrap {
display: flex;
justify-content: space-between;
.tag-tab {
flex: 1;
margin-top: 20px;
.second-tag-content {
margin-top: 10px;
.draggable {
span {
display: flex;
flex-wrap: wrap;
.second-tag-list {
display:flex;
flex-direction: column;
align-items: center;
// margin-right: 10px;
margin-bottom: 10px;
cursor: move;
text-align: center;
}
}
}
}
.tag-tab-ul {
display: flex;
span{
display: flex;
}
.tab-ul-li {
margin-right: 25px;
}
.selectTab {
color: #409EFF;
cursor: move;
border-bottom: 2px solid #409EFF;
}
}
}
/deep/ .el-tabs__nav-wrap::after {
display:none;
}
}
</style>
温馨提示
这里的拖拽主要借助vuedraggable
组件实现,而tab切换,主要是根据一级导航与二级导航相关联的id,实现控制一级导航对应内容的显示和隐藏
在具体的实现拖拽排序中,这是要请求接口的,把位置顺序传给后端,保存到数据库当中,就可以了的
相关文章
- 本地调试小程序的webview的两个方案
- 微信小程序--P2P消息收发模式(MQTT)
- Android App开发语音处理之系统自带的语音引擎、文字转语音、语音识别的讲解及实战(超详细 附源码)
- 2、mac上安装配置git
- RK3568 Android固件介绍、固件烧录、开机进系统
- OkHttp原理分析总结
- 使用docker-compose部署达梦DEM管理工具,mac m1系列适用
- Adb找不到设备解决方法
- Android Studio安装详细教程(从下载到安装,保姆级教程)
- 从Github上下载的项目导入安卓项目步骤(仅针对AndroidStudio,保证靠谱):
- 原生小程序实现视频监控(m3u8格式)
- 在MacBook上安装Ubuntu20.04双系统
- 【小程序-开篇】国内IT技术圈的技能树貌似点歪了?
- Android/Linux 子系统Graphics图形栈入门普法介绍
- 使用小程序+C#实现人脸、手势双重识别认证
- 【小程序项目开发 --- 京东商城】 启航篇之uni-app项目搭建
- 移动应用开发期末复习(自用复习勿转)
- 小程序页面之间数据传递的四种方法
- 【Flutter】【Unity】使用 Flutter + Unity 构建(AR 体验工具包)
- mac的node版本安装及升降级