当前位置:   article > 正文

vue3-实战-13-管理后台-数据大屏解决方案-顶部组件搭建-实时游客统计_vue数据大屏

vue数据大屏

目录

1-数据大屏解决方案vw和vh

2-数据大屏解决方案scale

3-数据大屏原型需求图

4-数据大屏顶部搭建

4.1-顶部原型需求

4.2-顶部模块父组件的结构和逻辑

4.3-顶部模块子组件结构和逻辑

5-数据大屏游客统计

5.1-原型需求图分析

5.2-结构样式逻辑开发


1-数据大屏解决方案vw和vh

       比如我们的显示器分辨率为1920*1080,1920=100vw,1080=100vh;如果我们的原型尺寸是100*100;我们需要计算尺寸换算成对应的vw和vh;每次需要动态计算,而且缺点是div盒子的文案和文字不能对应动态扩大和缩放。所以在实际项目中,我们一般采用下面的scale方案。
        比如div的尺寸是宽100*高100;换算成对应的是:             100/1920*100vw=5.208vw;100/1080*100=9.259vh;
 

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. .box {
  6. width:100vw;
  7. height:100vh;
  8. background: orange;
  9. }
  10. .top{
  11. width: 5.2vw;
  12. height: 9.26vh;
  13. background: red;
  14. margin-left: 2.6vw;
  15. }
  16. .bottom{
  17. width: 5.2vw;
  18. height: 9.26vh;
  19. background: skyblue;
  20. margin-left: 2.6vw;
  21. margin-top:9.26vh;
  22. }

2-数据大屏解决方案scale

scale解决方案的优点是:我们只需要确定屏幕尺寸,然后按照这个比例缩放就好。实际项目中一般采用scale这种缩放的解决方案。
结构核心代码如下:

  1. <head>
  2. <style>
  3. * {
  4. margin: 0;
  5. padding: 0;
  6. }
  7. .container {
  8. width: 100vw;
  9. height: 100vh;
  10. background: url(./bg.png) no-repeat;
  11. background-size: cover;
  12. }
  13. .box {
  14. position: fixed;
  15. width: 1920px;
  16. height: 1080px;
  17. background: red;
  18. transform-origin: left top;
  19. left: 50%;
  20. top: 50%;
  21. }
  22. .top {
  23. width: 100px;
  24. height: 100px;
  25. background: hotpink;
  26. margin-left: 50px;
  27. }
  28. .bottom {
  29. width: 100px;
  30. height: 100px;
  31. background: skyblue;
  32. margin-left: 50px;
  33. margin-top: 100px;
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <div class="container">
  39. <!-- 数据展示的区域 -->
  40. <div class="box">
  41. <div class="top">这是top区域</div>
  42. <div class="bottom">这是bottom区域</div>
  43. </div>
  44. </div>
  45. </body>

js逻辑的核心计算方法:

  1. //控制数据大屏放大与缩小
  2. let box = document.querySelector('.box');
  3. box.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
  4. //计算缩放的比例
  5. function getScale(w = 1920, h = 1080) {
  6. const ww = window.innerWidth / w;
  7. const wh = window.innerHeight / h;
  8. return ww < wh ? ww : wh;
  9. }
  10. window.onresize = () => {
  11. box.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
  12. }

3-数据大屏原型需求图

4-数据大屏顶部搭建

4.1-顶部原型需求

       数据大屏总体分为上下两部分;其中上部(顶部),顶部可以分为三部分,左中右三部分。我们先来分析和实现顶部的功能。 左中右三个盒子,先用三个div包起来,左边可以在div里面使用一个span,里面有个首页,点击要去到首页,需要绑定一个点击事件。中间就是一个div,显示文字,不过我们需要编写对应的样式。右边有个统计报告文案,目前没有任何事件,然后还需要显示当前时间,而且要定时刷新,组件销毁的时候,我们需要清除定时器。

4.2-顶部模块父组件的结构和逻辑

父组件在加载的时候,需要对适配大屏做出逻辑处理。进行相关的缩放操作。
文件父组件:src\views\screen\index.vue的代码结构实现:

文件父组件:src\views\screen\index.vue在挂载的时候,需要处理缩放相关逻辑:

  1. import { ref, onMounted } from "vue";
  2. //引入顶部的子组件
  3. import Top from './components/top/index.vue';
  4. //获取数据大屏展示内容盒子的DOM元素
  5. let screen = ref();
  6. onMounted(() => {
  7. screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
  8. });
  9. //定义大屏缩放比例
  10. function getScale(w = 1920, h = 1080) {
  11. const ww = window.innerWidth / w;
  12. const wh = window.innerHeight / h;
  13. return ww < wh ? ww : wh;
  14. }
  15. //监听视口变化
  16. window.onresize = () => {
  17. screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
  18. }

文件父组件:src\views\screen\index.vue中相关的样式代码:

  1. .container {
  2. width: 100vw;
  3. height: 100vh;
  4. background: url(./images/bg.png) no-repeat;
  5. background-size: cover;
  6. .screen {
  7. position: fixed;
  8. width: 1920px;
  9. height: 1080px;
  10. left: 50%;
  11. top: 50%;
  12. transform-origin: left top;
  13. .top {
  14. width: 100%;
  15. height: 40px;
  16. }
  17. }
  18. }

4.3-顶部模块子组件结构和逻辑

首先,组件加载的时候,我们需要加载一个定时器,定时去获取时间。点击首页的时候,我们还要跳转首页,需要使用到useRouter方法获取到$router。

顶部组件文件:src\views\screen\components\top\index.vue的页面结构如下:

顶部组件文件src\views\screen\components\top\index.vue;我们需要处理的相关业务逻辑核心代码如下:

  1. <script setup lang="ts">
  2. //@ts-ignore
  3. import moment from 'moment';
  4. //点击首页按钮回到首页
  5. import { useRouter } from 'vue-router';
  6. import { ref, onMounted, onBeforeUnmount } from 'vue';
  7. //获取路由器对象
  8. let $router = useRouter();
  9. //存储当前时间
  10. let time = ref(moment().format('YYYY年MM月DD日 HH:mm:ss'));
  11. let timer = ref(0);
  12. //按钮的点击回调
  13. const goHome = () => {
  14. $router.push('/home')
  15. }
  16. //组件挂载完毕更新当前的事件
  17. onMounted(() => {
  18. timer.value = setInterval(() => {
  19. time.value = moment().format('YYYY年MM月DD日 HH:mm:ss');
  20. }, 1000);
  21. });
  22. onBeforeUnmount(() => {
  23. clearInterval(timer.value);
  24. })
  25. </script>
  26. <script lang="ts">
  27. export default {
  28. name: 'Top',
  29. }
  30. </script>

顶部组件文件src\views\screen\components\top\index.vue;我们需要对页面进行相关的页面样式代码如下【在实际项目中,按照自己的原型图进行变更,这里没有做很精细的布局和优化】:

  1. <style scoped lang="scss">
  2. .top {
  3. width: 100%;
  4. height: 40px;
  5. display: flex;
  6. .left {
  7. flex: 1.5;
  8. background: url(../../images/dataScreen-header-left-bg.png) no-repeat;
  9. background-size: cover;
  10. .lbtn {
  11. width: 150px;
  12. height: 40px;
  13. float: right;
  14. background: url(../../images/dataScreen-header-btn-bg-l.png) no-repeat;
  15. background-size: 100% 100%;
  16. text-align: center;
  17. line-height: 40px;
  18. color: #29fcff;
  19. font-size: 20px;
  20. }
  21. }
  22. .center {
  23. flex: 2;
  24. .title {
  25. width: 100%;
  26. height: 74px;
  27. background: url(../../images/dataScreen-header-center-bg.png) no-repeat;
  28. background-size: 100% 100%;
  29. text-align: center;
  30. line-height: 74px;
  31. color: #29fcff;
  32. font-size: 30px;
  33. }
  34. }
  35. .right {
  36. flex: 1.5;
  37. background: url(../../images/dataScreen-header-left-bg.png) no-repeat;
  38. background-size: cover;
  39. display: flex;
  40. justify-content: space-between;
  41. align-items: center;
  42. .rbtn {
  43. width: 150px;
  44. height: 40px;
  45. background: url(../../images/dataScreen-header-btn-bg-r.png) no-repeat;
  46. background-size: 100% 100%;
  47. text-align: center;
  48. line-height: 40px;
  49. color: #29fcff;
  50. }
  51. .time {
  52. color: #29fcff;
  53. font-size: 20px;
  54. }
  55. }
  56. }
  57. </style>

5-数据大屏游客统计

5.1-原型需求图分析

       目前数据大屏的数据全部是静态数据,在实际项目中大家可以根据自己的项目实际,向服务端获取相关的动态数据进行数据展示和渲染就好。
       页面结构分三部分,上面的顶部需要展示实时游客统计和可预约的数量,中间部分需要展示目前的游客数量,下面部分需要用到echarts的扩展组件水球图echarts-liquidfill组件。

5.2-结构样式逻辑开发

组件src\views\screen\components\tourist\index.vue的页面结构如下图:

 组件src\views\screen\components\tourist\index.vue的核心处理逻辑:

  1. <script setup lang="ts">
  2. import 'echarts-liquidfill'
  3. import * as echarts from 'echarts';
  4. import { ref, onMounted } from 'vue';
  5. let people = ref('215908人');
  6. //水球图拓展插件
  7. //获取节点
  8. let charts = ref();
  9. onMounted(() => {
  10. //获取echarts类的实例
  11. let mycharts = echarts.init(charts.value);
  12. //设置实例的配置项
  13. mycharts.setOption({
  14. //标题组件
  15. title: {
  16. text: '水球图'
  17. },
  18. //x|y轴组件
  19. xAxis: {},
  20. yAxis: {},
  21. //系列:决定你展示什么样的图形图标
  22. series: {
  23. type: 'liquidFill',//系列
  24. data: [0.6, 0.4, 0.2],//展示的数据
  25. waveAnimation: true,//动画
  26. animationDuration: 3,
  27. animationDurationUpdate: 0,
  28. radius: '100%',//半径
  29. outline: {//外层边框颜色设置
  30. show: true,
  31. borderDistance: 8,
  32. itemStyle: {
  33. color: 'skyblue',
  34. borderColor: '#294D99',
  35. borderWidth: 8,
  36. shadowBlur: 20,
  37. shadowColor: 'rgba(0, 0, 0, 0.25)'
  38. }
  39. },
  40. },
  41. //布局组件
  42. grid: {
  43. left: 0,
  44. right: 0,
  45. top: 0,
  46. bottom: 0
  47. }
  48. })
  49. })
  50. </script>

组件src\views\screen\components\tourist\index.vue的样式核心代码:

  1. .box {
  2. background: url(../../images/dataScreen-main-lb.png) no-repeat;
  3. background-size: 100% 100%;
  4. margin-top: 10px;
  5. .top {
  6. margin-left: 20px;
  7. .title {
  8. color: white;
  9. font-size: 20px;
  10. }
  11. .bg {
  12. width: 68px;
  13. height: 7px;
  14. background: url(../../images/dataScreen-title.png) no-repeat;
  15. background-size: 100% 100%;
  16. margin-top: 10px;
  17. }
  18. .right {
  19. float: right;
  20. color: white;
  21. font-size: 20px;
  22. span {
  23. color: yellowgreen;
  24. }
  25. }
  26. }
  27. .number {
  28. padding: 10px;
  29. margin-top: 30px;
  30. display: flex;
  31. span {
  32. flex: 1;
  33. height: 40px;
  34. text-align: center;
  35. line-height: 40px;
  36. background: url(../../images/total.png) no-repeat;
  37. background-size: 100% 100%;
  38. color: #29fcff;
  39. }
  40. }
  41. .charts {
  42. width: 100%;
  43. height: 270px;
  44. }
  45. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/772055
推荐阅读
相关标签
  

闽ICP备14008679号