基于Vue3+ECharts5+datav的疫情数据可视化大屏/地图项目

news/2024/7/5 11:25:38

本项目是一个基于Vue3+ECharts5+datav打造的一个每日疫情数据大屏可视化开源项目;通过nginx部署在阿里云服务器上

效果展示

在线预览地址:http://lj520zz.top/
请大家动动手点点star
项目前台源码地址:https://github.com/qdfudimo/vue3-screen
项目后台源码地址:https://github.com/qdfudimo/serve-screen
图片效果展示
在这里插入图片描述

技术栈添加链接描述

前台技术栈

  1. vue3

  2. vite

  3. echarts5 官方社区停用 以下几个社区链接
    社区链接 http://www.ppchart.com/#/
    https://www.isqqw.com/#/homepage
    http://chart.majh.top/
    http://analysis.datains.cn/finance-admin/index.html#/chartLib/all
    https://www.isqqw.com/

  4. datav datav组件库地址

大屏适配方案

案例中采用了css3的缩放transform: scale(X,y)属性,改变分辨率时,scale的值是变化的。 通过获取当前屏幕大小screen和当前窗口大小,我们只要监听浏览器窗口大的小,同时控制变化的比例就可以了。
项目中通过创建一个ScaleBox缩放组件包裹住所有组件
在这里插入图片描述
scalebox组件采用css3的缩放transform: scale(X,y)

const { width, height } = screen
 const w = window.innerWidth / width
 const h = window.innerHeight / height
this.style.transform = 'scale(' + x +"," + y ') translate(-50%, -50%)'

后续添加了屏幕宽度小于800高度小于600时的完整显示

let getScale = () => {
    // const wh = window.innerHeight / height;
    // const ww = window.innerWidth / width;
    // return [wh,ww];
    const w = window.innerWidth / width
    const h = window.innerHeight / height
    if (window.innerWidth <= 800 || window.innerHeight <= 600) {
        let scale = w < h ? w : h;
        return [scale, scale]
    }
    return [h, w]
}
let setScale = (e) => {
    // 缩放比
    scale.h = getScale()[0];
    scale.w = getScale()[1];
}
let reCalc = debounce(setScale)
onMounted(() => {
    setScale();
    window.addEventListener("resize", reCalc);
})
onUnmounted(() => {
    window.removeEventListener("resize", reCalc)
})

在这里插入图片描述
在这里插入图片描述

也可以使用vue3的css样式绑定 https://cn.vuejs.org/api/sfc-css-features.html#v-bind-in-css

<script setup>
const theme = {
  color: 'red'
}
</script>
<style scoped>
p {
  color: v-bind('theme.color');
}
</style>

也使用了阿里的字体图标
通过vite-plugin-svg-icons 使用SVG图片

  1. 安装 vite-plugin-svg-icons
npm i vite-plugin-svg-icons -D
// 或者
yarn add vite-plugin-svg-icons -D
  1. main.js引入
import 'virtual:svg-icons-register';
  1. 创建svg图片文件夹
    在这里插入图片描述
  2. 在vite.config.js中配置
import {
  createSvgIconsPlugin
} from 'vite-plugin-svg-icons'
import path from 'path'
defineConfig({
  server: {
  //反向代理
    proxy: {
      // 选项写法
      // '/api': {
      //   target: 'http://jsonplaceholder.typicode.com',
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/api/, '')
      // },
      // // 选项写法
      [config.VITE_API_BASE_URL]: {
        target: config.VITE_APP_BASE_SERVER,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
      // Proxying websockets or socket.io
      // '/socket.io': {
      //   target: 'ws://localhost:3000',
      //   ws: true
      // }
    }
  },
  plugins: [
    createSvgIconsPlugin({
      // Specify the icon folder to be cached
      iconDirs: [path.resolve(process.cwd(), 'src/icons')],
      // Specify symbolId format
      symbolId: 'icon-[dir]-[name]',
    })
  ],
})

5.新建svg组件

<template>
    <svg :class="svgClass" v-bind="$attrs">
        <use :xlink:href="iconName"></use>
    </svg>
</template>

<script setup lang="ts">
import { computed } from 'vue'
const props = defineProps({
    name: {
        type: String,
        required: true
    },
    color: {
        type: String,
        default: '#e6e6e6'
    }
})
const iconName = computed(() => `#icon-${props.name}`)
const svgClass = computed(() => {
    if (props.name) return `svg-icon icon-${props.name}`
    return 'svg-icon'
})
</script>

<style scoped>
.svg-icon {
    width: 1em;
    height: 1em;
    fill: currentColor;
    vertical-align: middle;
}
</style>
  1. main.js全局引入使用
import SvgIcon from '@/components/SvgIcon.vue'
const app = createApp(App)
app.component("svg-icon",SvgIcon)

组件中使用

//name svg文件名
<svg-icon name="empty" style="fontSize:120px"></svg-icon>

后台数据

koa2+axios 将爬取网易新闻的每日接口
通过定时任务每日爬取网易新闻的接口数据,保存为json文件,然后读取文件数据,请求数据时返回给前台。
每天定时下午先判断今日是否有数据,有则删除前一日的json数据,无则不删除

const schedule = require('node-schedule');
const {
    getData
} = require("../api")
const {
    formatBeforetTime,
    formatTime
} = require("../util/moment")
const {
    checkDirFile,
    emptyDir,
} = require("../util/index")
/**
 * 定时任务调接口
 */
function scheduleCronstyle() {
    schedule.scheduleJob('30 0 10 * * *', function () {
        console.log('scheduleCronstyle:' + new Date());
        getData()
    });
    schedule.scheduleJob('30 0 14 * * *', function () {
        console.log('scheduleCronstyle:' + new Date());
        getData()
    });
}
/**
 * 定时任务删除上一天json文件
 */
function scheduleDelFile() {
    schedule.scheduleJob('30 3 16 * * *', function () {
        let fileName = formatBeforetTime();
        let fileNamepre = formatTime();
        if (checkDirFile("areaData", fileNamepre) && checkDirFile("areaData", fileName)) {
            emptyDir("areaData", fileName)
            console.log(`删除文件areaData${fileName}`);
        }else {
            console.log(`没有删除文件areaData`);
        }
        if (checkDirFile("chinaData", fileNamepre) && checkDirFile("chinaData", fileName)) {
            emptyDir("chinaData", fileName)
            console.log(`删除文件chinaData${fileName}`);
        }

    });

http://lihuaxi.xjx100.cn/news/76858.html

相关文章

FreeSWITCH 1.10 源码阅读(3)-sofia 模块原理及其呼入处理流程

文章目录1. 前言2. 源码分析2.1 sofia 模块的加载2.2 呼入的处理流程1. 前言 SIP(Session Initiation Protocol) 是应用层的信令控制协议&#xff0c;有许多开源的协议栈实现&#xff0c;其中就包括 Sofia-SIP。FreeSWITCH 中的 sofia模块 就是对底层 Sofia-SIP 协议栈的使用封…

泰勒公式专题 拉格朗日余项与佩亚诺余项,麦克劳林公式

泰勒公式专题 拉格朗日余项与佩亚诺余项,麦克劳林公式 文章目录1. 泰勒公式原理2. 具有 拉格朗日余项 的 泰勒公式。3. 具有 佩亚诺余项 的 泰勒公式4. 麦克劳林公式1. 泰勒公式原理 泰勒公式&#xff0c;也即泰勒展开式。在进行数学计算时&#xff0c;给定一个函数f(x)f(x)f(…

使用git时出现的一些问题整理

目录 一、解决fatal: detected dubious ownership in repository at D:/resource/git项目 二、解决error: failed to push some refs to https://gitee.com/yantianzi/roadlinkhint: Updates were rejected because the remote contains work that you do 一、解决fatal: det…

网络技术大讲堂:什么是IPv6+?

Pv6以IPv6海量地址为基础&#xff0c;包括以SRv6、网络切片、IFIT、BIERv6等协议创新&#xff0c;和以网络分析、自动调优等网络智能化为代表的技术创新。 IPv6在智能、安全、超宽、广联接、确定性和低时延六个维度全面提升IP网络能力&#xff0c;助力打造无处不在的智能IP联接…

前端开发规范:CSS 代码规范指南

CSS 代码规范指南 代码风格 代码格式化 样式书写一般有两种&#xff1a;一种是紧凑格式 (Compact) .web{ display: block;width: 50px;}一种是展开格式&#xff08;Expanded&#xff09; .web {display: block;width: 50px; }团队约定: 统一使用展开格式书写样式 代码大小…

Go基础 数组 切片 Map

数组 数组介绍 数组可以存放多个同一类型数据 数组也是一种数据类型 在Go 中数组是指类型 案例 package mainimport "fmt"func main() {// 计算 6个人 平均体重 以及体重总和var person [6]float64person[0] 98person[1] 90person[2] 91person[3] 3person[4]…

MPLS 配置LDP本地会话实验 详解

MPLS 配置LDP本地会话 组网需求 在如图1所示&#xff0c;LSRA、LSRC为IP/MPLS骨干网的PE设备。LSRA和LSRC上需要部署MPLS L2VPN或L3VPN业务来实现VPN站点的互联&#xff0c;因此LSR间需要配置本地LDP会话来建立LDP LSP&#xff0c;实现承载VPN业务。 图1 配置LDP本地会话组网…

C/C++函数传参详解

问题引出 在编码过程中&#xff0c;新手经常会遇到的一个问题是&#xff0c;我明明在函数中交换了数据&#xff0c;为什么函数外面显示的不对&#xff0c;最常见的例子就是swap()函数。先看两个代码&#xff1a; 代码一&#xff1a; #include <stdio.h> void swap(int…