当前位置: 首页 > news >正文

vue 实战 区域内小组件元素拖拽 示例

<template><div><el-button type="primary" @click="showDialog = true">快捷布局</el-button><el-dialog title="快捷布局配置" :visible.sync="showDialog"><el-row :gutter="20"><el-col><el-card class="box-card" header="开始面板引流区"><draggable tag="div" class="buttons-container" v-model="drainComponents" ><el-button v-for="component in drainComponents" :key="component.comId" class="button" :style="{ backgroundColor: component.color }"><div class="button-content"><div>{{ component.name }}</div><div class="component-id">{{ component.comId }}</div></div></el-button></draggable></el-card></el-col><el-col><el-card class="box-card" header="开始面板数据区"><draggable tag="div" class="buttons-container" v-model="dataComponents" ><el-button v-for="component in dataComponents" :key="component.comId" class="button" :style="{ backgroundColor: component.color }"><div class="button-content"><div>{{ component.name }}</div><div class="component-id">{{ component.comId }}</div></div></el-button></draggable></el-card></el-col><el-col><el-card class="box-card" header="生活中默认区域"><draggable tag="div" class="buttons-container" v-model="liveComponents" ><el-button v-for="component in liveComponents" :key="component.comId" class="button" :style="{ backgroundColor: component.color }"><div class="button-content"><div>{{ component.name }}</div><div class="component-id">{{ component.comId }}</div></div></el-button></draggable></el-card></el-col></el-row><span slot="footer" class="dialog-footer"><el-button @click="showDialog = false">取消</el-button><el-button type="primary" @click="saveLayout">确定</el-button></span></el-dialog></div></template><script>import draggable from 'vuedraggable';// 生成柔和颜色的函数const generateSoftColor = () => {const hue = Math.floor(Math.random() * 360);const saturation = 60 + Math.random() * 20; // 饱和度在60%-80%之间const lightness = 70 + Math.random() * 20; // 亮度在70%-90%之间return `hsl(${hue}, ${saturation}%, ${lightness}%)`;};// 通用的转换函数const convertDataList = (dataList) => {return dataList.map(item => ({comId: item.comId,name: item.name,weight: item.weight,color: generateSoftColor()}));};const sortedDataList = (dataList) => {return dataList.slice().sort((a, b) => b.weight - a.weight);}// 数据列表const dataList1 = [{ comId: '1000009', name: '对方如果', property: 0, type: 0, weight: 4 },{ comId: '1000004', name: '辅导费人', property: 0, type: 0, weight: 1 },{ comId: '1000010', name: '电电风扇', property: 0, type: 0, weight: 2 },{ comId: '1000006', name: '小组件', property: 0, type: 0, weight: 3 },{ comId: '1000007', name: '飒飒飒飒', property: 0, type: 0, weight: 5 },{ comId: '1000011', name: '你说的分手', property: 0, type: 0, weight: 6 },{ comId: '1000012', name: '大润发儿童', property: 0, type: 0, weight: 9 },{ comId: '1000013', name: '大方的发过的', property: 0, type: 0, weight: 8 }];const dataList2 = [{ comId: '1000001', name: '哈哈哈', property: 0, type: 1, weight: 2 },{ comId: '1000005', name: '测试组件名称', property: 0, type: 1, weight: 2 },{ comId: '1000002', name: '啦啦啦', property: 1, type: 0, weight: 0 }];const dataList3 = [{ comId: '1000017', name: 'GV地方大幅度', property: 0, type: 0, weight: 3 },{ comId: '1000016', name: '奋斗奋斗发的', property: 0, type: 0, weight: 2 },{ comId: '1000008', name: '大幅度发', property: 0, type: 0, weight: 1 },{ comId: '1000003', name: '似懂非懂发', property: 1, type: 1, weight: 0 },{ comId: '1000014', name: '个人发一个发帖人', property: 0, type: 0, weight: 0 },{ comId: '1000015', name: '会更好多说点', property: 0, type: 0, weight: 0 }];export default {components: { draggable },data() {return {showDialog: false,drainComponents: convertDataList(sortedDataList(dataList1)),dataComponents: convertDataList(sortedDataList(dataList2)),liveComponents: convertDataList(sortedDataList(dataList3))};},methods: {generateSoftColor,convertDataList,removeColorSet(data) {for(let i=0;i<data.length;i++){delete data[i].color;}return data},updateWeights(data) {for(let i=0;i<data.length;i++) {data[i].weight = data.length - i;}return data},saveLayout() {this.showDialog = false;this.drainComponents = this.updateWeights(this.drainComponents)this.dataComponents = this.updateWeights(this.dataComponents)this.liveComponents = this.updateWeights(this.liveComponents)this.printComponentVal();// Remove 'color' field from each dictionary// this.drainComponents = this.removeColorSet(this.drainComponents)// console.log("this.drainComponents", this.drainComponents)// this.dataComponents = this.removeColorSet(this.dataComponents)// console.log("this.dataComponents", this.dataComponents)// this.liveComponents = this.removeColorSet(this.liveComponents)// console.log("this.liveComponents", this.liveComponents)},printComponentVal() {console.log("this.drainComponents", this.drainComponents)console.log("this.dataComponents", this.dataComponents)console.log("this.liveComponents", this.liveComponents)},}};</script><style scoped>.box-card {margin-bottom: 20px;}.buttons-container {display: flex;flex-wrap: wrap;}.button {margin: 5px;flex: 0 1 auto;display: flex;flex-direction: column;align-items: center;justify-content: center;}.button-content {text-align: center;}.component-id {font-size: 0.8em;color: #666;}.buttons-container .button:first-child {margin-left: 10px;}</style>

http://www.lryc.cn/news/407411.html

相关文章:

  • C++多线程编程中的锁详解
  • van-dialog 组件调用报错
  • 【Django】在vscode中运行调试Django项目(命令及图形方式)
  • 麦田物语第十三天
  • 【Git多人协作开发】不同的分支下的多人协作开发模式
  • Lua 复数计算器
  • 深入MySQL中的IF和IFNULL函数
  • AI多模态实战教程:面壁智能MiniCPM-V多模态大模型问答交互、llama.cpp模型量化和推理
  • Docker 搭建Elasticsearch详细步骤
  • mysql中提供的函数
  • 加速下载,揭秘Internet Download Manager2024下载器的威力!
  • oracle 宽表设计
  • winrar安装好后,鼠标右键没有弹出解压的选项
  • 数字图像处理笔记(一)---- 图像数字化与显示
  • Unity UGUI 之 事件接口
  • Hadoop、HDFS、MapReduce 大数据解决方案
  • Dubbo SPI 之负载均衡
  • 规范:前后端接口规范
  • Python --NumPy库基础方法(2)
  • 音视频入门基础:H.264专题(15)——FFmpeg源码中通过SPS属性获取视频帧率的实现
  • 【C++高阶】哈希之美:探索位图与布隆过滤器的应用之旅
  • 文件包涵条件竞争(ctfshow82)
  • 通信原理-思科实验三:无线局域网实验
  • *算法训练(leetcode)第三十一天 | 1049. 最后一块石头的重量 II、494. 目标和、474. 一和零
  • mac中如何使用obs推流以及使用vlc播放
  • shopee虾皮 java后端 一面面经 整体感觉不难
  • HydraRPC: RPC in the CXL Era——论文阅读
  • pve笔记
  • typecho仿某度响应式主题Xaink
  • springcloud RocketMQ 客户端是怎么走到消费业务逻辑的 - debug step by step