当前位置:网站首页>长沙大屏开发
长沙大屏开发
2022-07-20 08:11:00 【小曲曲】
原定想使用使用DataV提供的全局容器
全局容器不起作用,我猜是因为只有使用dataV的组件,可以保证他的组件适配,而我们都是自己写的,所以不起作用吧
- header使用定高141px,下面内容使用
height: calc(100vh - 141px);
- 内容区域横向使用 flex 布局,宽度相加为100%,间距使用每块padding撑开
- 内容部分纵向相加为 100% ,间距使用padding撑开
- 无需考虑分辨率的问题,任何分辨率下全屏显示
- 每个图表使用独立组件,随着尺寸变化自动刷新,mixins文件夹下 resize.js文件
- 字体及边距的适配:使用flexible.js做字体适配,将所有px转为rem
- 公共样式例如 size-20 的适配:新建一个rem.scss文件,将px转为rem单位
- echarts图表里字体大小,线宽度等的适配:封装一个方法,放在mixin里,在组件中直接调用this.fontSize(实际大小/100)
- 通过webSocket获取所有大屏数据,将数据传递给子组件。实时传递新数据,子组件需要监听数据变化重新渲染
6、mixins文件夹下 resize.js文件
// screen/components/mixins/resize.js
import {
debounce } from '@/utils'
export default {
data() {
return {
$_sidebarElm: null,
$_resizeHandler: null
}
},
mounted() {
this.initListener()
},
activated() {
if (!this.$_resizeHandler) {
// avoid duplication init
this.initListener()
}
// when keep-alive chart activated, auto resize
this.resize()
},
beforeDestroy() {
this.destroyListener()
},
deactivated() {
this.destroyListener()
},
methods: {
// use $_ for mixins properties
// https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
$_sidebarResizeHandler(e) {
if (e.propertyName === 'width') {
this.$_resizeHandler()
}
},
initListener() {
this.$_resizeHandler = debounce(() => {
this.resize()
}, 100)
window.addEventListener('resize', this.$_resizeHandler)
this.$_sidebarElm = document.getElementsByClassName('sidebar-container')[0]
this.$_sidebarElm && this.$_sidebarElm.addEventListener('transitionend', this.$_sidebarResizeHandler)
},
destroyListener() {
window.removeEventListener('resize', this.$_resizeHandler)
this.$_resizeHandler = null
this.$_sidebarElm && this.$_sidebarElm.removeEventListener('transitionend', this.$_sidebarResizeHandler)
},
resize() {
const {
chart } = this
chart && chart.resize()
}
}
}
// utils/index.js
/** * @param {Function} func * @param {number} wait * @param {boolean} immediate * @return {*} */
export function debounce(func, wait, immediate) {
let timeout, args, context, timestamp, result;
const later = function () {
// 据上一次触发时间间隔
const last = +new Date() - timestamp;
// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
if (last < wait && last > 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
if (!immediate) {
result = func.apply(context, args);
if (!timeout) context = args = null;
}
}
};
return function (...args) {
context = this;
timestamp = +new Date();
const callNow = immediate && !timeout;
// 如果延时不存在,重新设定延时
if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
}
8. 新建一个rem.scss文件,将px转为rem单位,144 = 分辨率/24 = 3456 / 24
@for $value from 1 through 100 {
.pd-#{
$value}, .ptb-#{
$value}, .pt-#{
$value} {
padding-top: $value/144 * 1rem;
}
.pd-#{
$value}, .ptb-#{
$value}, .pb-#{
$value} {
padding-bottom: $value/144 * 1rem;
}
.pd-#{
$value}, .plr-#{
$value}, .pl-#{
$value} {
padding-left: $value/144 * 1rem;
}
.pd-#{
$value}, .plr-#{
$value}, .pr-#{
$value} {
padding-right: $value/144 * 1rem;
}
.mg-#{
$value}, .mtb-#{
$value}, .mt-#{
$value} {
margin-top: $value/144 * 1rem;
}
.mg-#{
$value}, .mtb-#{
$value}, .mb-#{
$value} {
margin-bottom: $value/144 * 1rem;
}
.mg-#{
$value}, .mlr-#{
$value}, .ml-#{
$value} {
margin-left: $value/144 * 1rem;
}
.mg-#{
$value}, .mlr-#{
$value}, .mr-#{
$value} {
margin-right: $value/144 * 1rem;
}
}
@for $value from 10 through 40 {
.size-#{
$value} {
font-size: $value/144 * 1rem;
}
}
*{
box-sizing: border-box;
}
.s-yellow{
color: #FFC300;
}
.s-red{
color: #CB272C;
}
.s-blue{
color: #00CDCF;
}
.s-gray{
color: #979797;
}
.line-1 {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
9. echarts图表里字体大小,线宽度等的适配,封装一个方法,放在mixin里,在组件中直接调用this.fontSize(实际大小/100)
fontSize(res) {
let docEl = document.documentElement,
clientWidth =
window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
if (!clientWidth) return;
console.log(clientWidth);
let fontSize = 100 * (clientWidth / 3456);
return res * fontSize;
},
// 使用
//坐标值标注
axisLabel: {
formatter: "{value} %", //右侧Y轴文字显示
textStyle: {
color: "#fff",
fontSize: this.fontSize(0.16),
},
},
10、子组件监听数据变化实时刷新图表
props: ["list"],
watch: {
list: {
handler(val) {
// 深度监听没有旧值
this.month = val.map((item) => {
return item.month + "月";
});
this.orderNum = val.map((item) => {
return item.orderCount;
});
this.oldNum = val.map((item) => {
return item.servedCount;
});
this.goodRate = val.map((item) => {
return item.favorableRate;
});
let option = {
xAxis: [
{
data: this.month,
},
],
series: [
{
data: this.orderNum, // 订单量
},
{
data: this.oldNum, // 服务人数
},
{
data: this.goodRate, //折线图数据
},
],
};
this.chart.setOption(option);
},
// 这里是关键,代表递归监听的变化
deep: true,
},
},
边栏推荐
- Two ways of QT multithreading implementation thread implementation
- Study json parse(JSON.stringify(obj))
- Introduction to Lua scripting language
- Spack作业分析
- What is ethanol?
- R语言世界价值观调查作业
- Routing of upper layer loops in VRRP
- @Retryable @Backoff @Recover 重试注解的使用
- Use r to delete rows with empty cells from Excel
- 文件上传下载
猜你喜欢
Request和Response
Detailed explanation of x509 digital certificate
[hbuilder runs to the problem that Mumu simulator cannot install the base, and it has been stuck in the installation base...]
6.0 取消会员注册验证码
Program yuan sent an article lamenting unemployment, which attracted program apes from various industries to comfort, laughing in the comment area
Drawing multi group Y-axis truncation graph with R language
Node JS processes pictures asynchronously and JSON text asynchronously
Filebeat 的学习笔记
BardecodeFiler拆分和重命名 TIF 文档
【Verilog数字系统设计(夏宇闻)----Verilog的基础知识1】
随机推荐
CTFShow-MISC入门篇
TP5.1 分页(带参数传递)
Use r to delete rows with empty cells from Excel
go 方法集
R语言世界价值观调查作业
R语言求微分
微信、QQ、电话下单,在线订货系统助企业走出困局
Spack作业分析
Reducing Participation Costs via Incremental Verification for Ledger Systems学习笔记
Simple use of Supervisor
Happens-Before规则详解
ASP.NET CORE 自定义中间件
利用yaml定义卷积网络【附代码】
R language optimization problem
node-js 异步处理图片,异步处理json文本
R language RMD output has Chinese, how to remove Chinese
JUC包下的常见类
两种常见的Vlan间通信的方式
File upload and download
经典网络学习-ResNet代码实现