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

vue3实现可视化大屏布局

实现功能:
1 实现4x3宫格布局,
2 自定义设置跨行,跨列自动隐藏对应列,比如setAreaSpanAndUpdateVisibility(2, 3, 2); 表示设置区域2,跨3行,跨2列,然后区域3,6,7,10,11自动隐藏
3 内容自动剧中

1 效果图

在这里插入图片描述

代码

<template><div class="visual-root big-data-bg-qjg-v1"><div class="top-bar">数据可视化大屏 - 顶部区域</div><div class="grid-area"><template v-for="(item, _idx) in gridItems" :key="item.id"><div class="grid-cell" v-if="item.visible" :style="getGridStyle(item)"><div class="cell-title"><div class="title-bg"></div><span>{{ item.id }}-{{ item.title }}</span></div><divclass="cell-content" :style="getContentSpanStyle(item)"><div v-if="item.component === 'ChartCell'"><ChartCell></ChartCell></div><div v-else-if="item.component === 'TableCell'"><TableCell></TableCell></div><div v-else-if="item.component === 'TextCell'"><TextCell></TextCell></div></div></div></template></div><!-- <button class="test-btn" @click="testSpan">测试区域122</button> --></div>
</template><script setup lang="ts">
import GridCell from "./components/GridCell.vue.vue";
import ChartCell from "./components/ChartCell.vue";
import TableCell from "./components/TableCell.vue";
import TextCell from "./components/TextCell.vue";
import { onMounted, ref } from "vue";const gridItems = ref([{id: 1,title: "区域1",color: "#4fdcff",visible: true,row: 1,col: 1,rowspan: 1,colspan: 1,component: "ChartCell",},{id: 2,title: "区域2",color: "#ffe066",visible: true,row: 1,col: 2,rowspan: 1,colspan: 1,component: "TableCell",},{id: 3,title: "区域3",color: "#ff8c66",visible: true,row: 1,col: 3,rowspan: 1,colspan: 1,component: "TextCell",},{id: 4,title: "区域4",color: "#6fff8f",visible: true,row: 1,col: 4,rowspan: 1,colspan: 1,component: "TextCell",},{id: 5,title: "区域5",color: "#a066ff",visible: true,row: 2,col: 1,rowspan: 1,colspan: 1,component: "TextCell",},{id: 6,title: "区域6",color: "#ff66c4",visible: true,row: 2,col: 2,rowspan: 1,colspan: 1,component: "TextCell",},{id: 7,title: "区域7",color: "#66e0ff",visible: true,row: 2,col: 3,rowspan: 1,colspan: 1,component: "TextCell",},{id: 8,title: "区域8",color: "#ffb366",visible: true,row: 2,col: 4,rowspan: 1,colspan: 1,component: "TextCell",},{id: 9,title: "区域9",color: "#b3ff66",visible: true,row: 3,col: 1,rowspan: 1,colspan: 1,component: "TextCell",},{id: 10,title: "区域10",color: "#ff6666",visible: true,row: 3,col: 2,rowspan: 1,colspan: 1,component: "TextCell",},{id: 11,title: "区域11",color: "#66ffb3",visible: true,row: 3,col: 3,rowspan: 1,colspan: 1,component: "TextCell",},{id: 12,title: "区域12",color: "#668cff",visible: true,row: 3,col: 4,rowspan: 1,colspan: 1,component: "TextCell",},
]);function setAreaSpanAndUpdateVisibility(areaId: number,rowspan: number,colspan: number,
) {const area = gridItems.value.find((item) => item.id === areaId);if (!area) return;area.rowspan = rowspan;area.colspan = colspan;// gridItems.value.forEach(item => { item.visible = true })for (let r = 0; r < rowspan; r++) {for (let c = 0; c < colspan; c++) {if (r === 0 && c === 0) continue;const coverRow = area.row + r;const coverCol = area.col + c;const coveredItem = gridItems.value.find((item) => item.row === coverRow && item.col === coverCol,);if (coveredItem) coveredItem.visible = false;}}
}function getGridStyle(item: any) {return {gridRow: `${item.row} / span ${item.rowspan || 1}`,gridColumn: `${item.col} / span ${item.colspan || 1}`,background: item.color,};
}
function getContentSpanStyle(item: any) {return;const style: any = {};if (item.rowspan > 1)style.height = `calc(100% * ${item.rowspan} + ${(item.rowspan - 1) * 18}px)`;if (item.colspan > 1)style.width = `calc(100% * ${item.colspan} + ${(item.colspan - 1) * 18}px)`;return style;
}onMounted(() => {setAreaSpanAndUpdateVisibility(2, 3, 2);
});
</script><style scoped>
.visual-root {width: 100vw;height: 100vh;min-width: 800px;min-height: 600px;background: linear-gradient(120deg, rgba(10, 26, 42, 0.8) 60%, rgba(24, 60, 90, 0.8) 100%), url('@/assets/imgs/background.jpg');background-size: cover;background-position: center;background-repeat: no-repeat;overflow: hidden;font-family: "Microsoft YaHei", Arial, sans-serif;color: #fff;display: flex;flex-direction: column;
}
.top-bar {width: 100%;height: 100px;background: linear-gradient(90deg, #1e2a3a 60%, #223c5a 100%);color: #4fdcff;font-size: 36px;font-weight: bold;letter-spacing: 8px;text-align: center;line-height: 100px;box-shadow: 0 2px 12px #0008;z-index: 10;flex-shrink: 0;
}
.grid-area {flex: 1;width: 100%;display: grid;grid-template-columns: repeat(4, 1fr);grid-template-rows: repeat(3, 1fr);gap: 18px;padding: 28px 32px 32px 32px;box-sizing: border-box;align-items: stretch;justify-items: stretch;
}
.grid-cell {border-radius: 18px;box-shadow: 0 0 18px #0004;display: flex;flex-direction: column;min-width: 0;min-height: 0;overflow: hidden;position: relative;transition: box-shadow 0.2s;background: var(--cell-color, #4fdcff);
}
.grid-cell:hover {box-shadow:0 0 32px #fff8,0 2px 12px #0008;z-index: 2;
}
.cell-title {position: relative;font-size: 22px;font-weight: bold;padding: 0;color: #fff;text-shadow: 0 0 8px #000a;height: 48px;display: flex;align-items: center;z-index: 1;
}
.cell-title .title-bg {position: absolute;left: 0;top: 0;right: 0;bottom: 0;z-index: 0;background:url("https://img.alicdn.com/imgextra/i2/O1CN01Qw6QwB1wQw6QwB1wQw6QwB1wQw.png")no-repeat center/cover,linear-gradient(90deg, #0008 0%, #fff2 100%);opacity: 0.18;border-bottom: 2px solid #fff2;border-radius: 0 0 16px 16px;
}
.cell-title span {position: relative;z-index: 1;padding: 0 18px;line-height: 48px;
}
.cell-content {flex: 1;padding: 18px;overflow: auto;font-size: 18px;color: #fff;background: rgba(0, 0, 0, 0.04);transition: width 0.3s, height 0.3s;display: flex;align-items: center;justify-content: center;
}
.cell-content-hide {display: none;
}
</style>
http://www.dtcms.com/a/289965.html

相关文章:

  • 数组习题及答案
  • f4硬件配置spi
  • 一维DP深度解析
  • 三菱A1SJ PLC以太网模块:上位机与触摸屏高效通讯解决方案
  • 深入解析:如何在Kafka中配置Source和Sink连接器构建高效数据管道
  • 金仓数据库:融合进化,智领未来——2025年数据库技术革命的深度解析
  • 【Linux指南】Linux系统 -权限全面解析
  • Windows下编译libarchive
  • JavaWeb笔记四
  • 深入详解随机森林在医学图像质量评估中的应用与实现细节
  • OCR 身份识别:让身份信息录入场景更高效安全
  • PHP反序列化漏洞详解
  • 第十八节:第七部分:java高级:注解的应用场景:模拟junit框架
  • 【c++】leetcode5 最长回文子串
  • 【Project】ELK 7.17.16 日志分析系统部署
  • Day07_网络编程20250721(网络编程考试试卷)
  • 关于 URL 中 “+“ 号变成空格的问题
  • CentOS 7安装 FFmpeg问题可以按照以下步骤进行安装
  • Spring Boot 3核心技术面试指南:从迁移升级到云原生实战,9轮技术攻防(含架构解析)
  • Django实战:基于Django和openpyxl实现Excel导入导出功能
  • 基于python django的BOSS直聘网站计算机岗位数据分析与可视化系统,包括薪酬预测及岗位推荐,推荐算法为融合算法
  • 智能体性能优化:延迟、吞吐量与成本控制
  • django filter按两个属性 去重
  • JAVA面试宝典 -《 架构演进:从单体到 Service Mesh》
  • Go从入门到精通(26) - 一个简单web项目-实现服务注册
  • Go语言实战案例-读取CSV文件并打印
  • python 正则表达式
  • 借助 Amazon SageMaker Catalog 功能,简化从数据到洞察的路径
  • FastLLVE:实时低光视频增强新突破
  • 大端小端:数据存储的核心密码