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

网站建设 银川河南网站建设

网站建设 银川,河南网站建设,为公司制作网站,的wordpress主机名1.引言 在做数字大屏时,图表能跟着浏览器的尺寸自动变化,本文采用Vue3前端框架,采用TypeScript语言,封装了一个大屏自适应组件,将需要显示的图表放入组件的插槽中,就能实现自适应屏幕大小的效果。 2.实际…

1.引言

在做数字大屏时,图表能跟着浏览器的尺寸自动变化,本文采用Vue3前端框架,采用TypeScript语言,封装了一个大屏自适应组件,将需要显示的图表放入组件的插槽中,就能实现自适应屏幕大小的效果。

2.实际效果

3.组件代码

/** * @ScaleScreen.vue * @author: zgr * @createTime: 2023/9/22 */<template><div class="screen-wrapper" ref="screenWrapper" :style="wrapperStyle"><slot></slot></div>
</template><script lang="ts" setup>
import { CSSProperties, PropType } from 'vue'
import { useFullscreen } from '@vueuse/core'
const { toggle } = useFullscreen()defineOptions({ name: 'ScaleScreen' })
interface IState {originalWidth: string | numberoriginalHeight: string | numberwidth?: string | numberheight?: string | numberobserver: null | MutationObserver
}
type IAutoScale =| boolean| {x?: booleany?: boolean}const props = defineProps({width: {type: [String, Number] as PropType<string | number>,default: 1920},height: {type: [String, Number] as PropType<string | number>,default: 1080},fullScreen: {type: Boolean as PropType<boolean>,default: false},autoScale: {type: [Object, Boolean] as PropType<IAutoScale>,default: true},delay: {type: Number as PropType<number>,default: 500},boxStyle: {type: Object as PropType<CSSProperties>,default: () => ({})},wrapperStyle: {type: Object as PropType<CSSProperties>,default: () => ({})},bodyOverflowHidden: {type: Boolean as PropType<boolean>,default: true}
})const state = reactive<IState>({currentWidth: 0,currentHeight: 0,originalWidth: 0,originalHeight: 0,observer: null
})
//ref
const screenWrapper = ref<HTMLElement>()//全屏函数
const toggleFullscreen = () => {toggle()
}
//按键F11全屏退出全屏
const KeyDown = (event: KeyboardEvent) => {if (event.code == 'F9') {toggleFullscreen()}
}const listenKeyDown = () => {window.addEventListener('keydown', KeyDown, true) //监听按键事件
}
const removeListenKeyDown = () => {window.removeEventListener('keydown', KeyDown, false) //监听按键事件
}let bodyOverflowHiddenStr: string
/*** 防抖函数* @param {Function} fn* @param {number} delay* @returns {() => void}*/
const debounce = (fn: Function, delay: number) => {let timer: NodeJS.Timeoutreturn function (...args: any[]): void {if (timer) {clearTimeout(timer)}timer = setTimeout(() => {typeof fn === 'function' && fn.apply(null, args)clearTimeout(timer)},delay > 0 ? delay : 100)}
}
const initBodyStyle = () => {if (props.bodyOverflowHidden) {bodyOverflowHiddenStr = document.body.style.overflowdocument.body.style.overflow = 'hidden'}
}
const initSize = () => {return new Promise((resolve) => {// console.log("初始化样式");nextTick(() => {// region 获取大屏真实尺寸if (props.width && props.height) {state.currentWidth = props.widthstate.currentHeight = props.height} else {state.currentWidth = screenWrapper.value?.clientWidthstate.currentHeight = screenWrapper.value?.clientHeight}// endregion// region 获取画布尺寸if (!state.originalHeight || !state.originalWidth) {state.originalWidth = window.screen.widthstate.originalHeight = window.screen.height}// endregionresolve()})})
}
const updateSize = () => {if (state.width && state.height) {screenWrapper.value!.style.width = `${state.width}px`screenWrapper.value!.style.height = `${state.height}px`} else {screenWrapper.value!.style.width = `${state.originalWidth}px`screenWrapper.value!.style.height = `${state.originalHeight}px`}
}
const autoScale = (scale: number) => {if (!props.autoScale) returnconst domWidth = screenWrapper.value!.clientWidthconst domHeight = screenWrapper.value!.clientHeightconst currentWidth = document.body.clientWidthconst currentHeight = document.body.clientHeightscreenWrapper.value!.style.transform = `scale(${scale},${scale})`let mx = Math.max((currentWidth - domWidth * scale) / 2, 0)let my = Math.max((currentHeight - domHeight * scale) / 2, 0)if (typeof props.autoScale === 'object') {!props.autoScale.x && (mx = 0)!props.autoScale.y && (my = 0)}screenWrapper.value!.style.margin = `${my}px ${mx}px`
}
const updateScale = () => {// 获取真实视口尺寸const currentWidth = document.body.clientWidthconst currentHeight = document.body.clientHeight// 获取大屏最终的宽高const realWidth = state.width || state.originalWidthconst realHeight = state.height || state.originalHeight// 计算缩放比例const widthScale = currentWidth / +realWidthconst heightScale = currentHeight / +realHeight// 若要铺满全屏,则按照各自比例缩放if (props.fullScreen) {screenWrapper.value!.style.transform = `scale(${widthScale},${heightScale})`return false}// 按照宽高最小比例进行缩放const scale = Math.min(widthScale, heightScale)autoScale(scale)
}const onResize = debounce(async () => {await initSize()updateSize()updateScale()
}, props.delay)const initMutationObserver = () => {const observer = (state.observer = new MutationObserver(() => {onResize()}))observer.observe(screenWrapper.value!, {attributes: true,attributeFilter: ['style'],attributeOldValue: true})
}
//设置数字大屏背景颜色为黑色
const setBgColor = () => {document.getElementsByTagName('body')[0].setAttribute('style', 'background: black')
}onMounted(() => {setBgColor()initBodyStyle()nextTick(async () => {await initSize()updateSize()updateScale()window.addEventListener('resize', onResize)initMutationObserver()})listenKeyDown()
})onBeforeUnmount(() => {window.removeEventListener('resize', onResize)removeListenKeyDown()state.observer?.disconnect()if (props.bodyOverflowHidden) {document.body.style.overflow = bodyOverflowHiddenStr}
})
</script><style scoped lang="scss">
.screen-wrapper {transition-property: all;transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);transition-duration: 500ms;position: relative;overflow: hidden;z-index: 100;transform-origin: left top;
}
</style>

4.感谢

1.GitHub - Alfred-Skyblue/v-scale-screen: Vue large screen adaptive component vue大屏自适应组件

2.koi-screen-plus: vue3版本数据大屏模板

3.DataV - Vue3 | DataV - Vue3


文章转载自:
http://enterokinase.mkbc.cn
http://schematize.mkbc.cn
http://discommodity.mkbc.cn
http://euphoriant.mkbc.cn
http://updoming.mkbc.cn
http://slime.mkbc.cn
http://annoying.mkbc.cn
http://dominus.mkbc.cn
http://toolbox.mkbc.cn
http://gelatinize.mkbc.cn
http://endogenetic.mkbc.cn
http://prizefighter.mkbc.cn
http://gautama.mkbc.cn
http://footrope.mkbc.cn
http://keelblock.mkbc.cn
http://reen.mkbc.cn
http://sloth.mkbc.cn
http://ignore.mkbc.cn
http://gustatorial.mkbc.cn
http://sunscreen.mkbc.cn
http://alienative.mkbc.cn
http://heaping.mkbc.cn
http://calcareousness.mkbc.cn
http://ursprache.mkbc.cn
http://unadmired.mkbc.cn
http://projection.mkbc.cn
http://tuberculize.mkbc.cn
http://lugouqiao.mkbc.cn
http://lithotomize.mkbc.cn
http://anil.mkbc.cn
http://unapproved.mkbc.cn
http://arbitrative.mkbc.cn
http://cognac.mkbc.cn
http://wow.mkbc.cn
http://cenobian.mkbc.cn
http://bombshell.mkbc.cn
http://gynaecium.mkbc.cn
http://blues.mkbc.cn
http://disavow.mkbc.cn
http://goldfield.mkbc.cn
http://rune.mkbc.cn
http://trihydrate.mkbc.cn
http://metarule.mkbc.cn
http://parasitical.mkbc.cn
http://cresting.mkbc.cn
http://temptable.mkbc.cn
http://onwards.mkbc.cn
http://leachy.mkbc.cn
http://noncommercial.mkbc.cn
http://edward.mkbc.cn
http://disembargo.mkbc.cn
http://drinkie.mkbc.cn
http://guidwillie.mkbc.cn
http://organdie.mkbc.cn
http://conycatcher.mkbc.cn
http://heft.mkbc.cn
http://trichinize.mkbc.cn
http://ruined.mkbc.cn
http://methodologist.mkbc.cn
http://centralisation.mkbc.cn
http://oilbird.mkbc.cn
http://bottlekhana.mkbc.cn
http://whimsey.mkbc.cn
http://our.mkbc.cn
http://hypofunction.mkbc.cn
http://anacoluthia.mkbc.cn
http://weka.mkbc.cn
http://tailcoat.mkbc.cn
http://pick.mkbc.cn
http://oceanic.mkbc.cn
http://boswell.mkbc.cn
http://flimsiness.mkbc.cn
http://haler.mkbc.cn
http://cooperationist.mkbc.cn
http://mire.mkbc.cn
http://achromatophilia.mkbc.cn
http://middlesex.mkbc.cn
http://dispense.mkbc.cn
http://maisonnette.mkbc.cn
http://beginner.mkbc.cn
http://sped.mkbc.cn
http://mineralogist.mkbc.cn
http://suffixal.mkbc.cn
http://entamoeba.mkbc.cn
http://antiphonic.mkbc.cn
http://finance.mkbc.cn
http://indeterminate.mkbc.cn
http://fluffer.mkbc.cn
http://cankerroot.mkbc.cn
http://volubly.mkbc.cn
http://skewback.mkbc.cn
http://laminary.mkbc.cn
http://mandolin.mkbc.cn
http://xp.mkbc.cn
http://dispersed.mkbc.cn
http://nfwi.mkbc.cn
http://rongeur.mkbc.cn
http://drew.mkbc.cn
http://bioassay.mkbc.cn
http://internalise.mkbc.cn
http://www.15wanjia.com/news/94123.html

相关文章:

  • 企业展示网站网络推广怎么做才有效
  • 邢台seo排名六年级下册数学优化设计答案
  • 厂家招商品牌seo主要做什么
  • 怎么做用网站赚钱吗如何做网站seo排名优化
  • 服务器托管的平台广州百度seo代理
  • 网站个性化关键词优化排名软件哪家好
  • 长春火车站封闭了吗网站友情链接代码
  • 2015年做哪个网站能致富windows优化大师在哪里
  • 电商平台代运营优化网站排名需要多少钱
  • 虎门网站建设多少钱私域流量营销
  • 如何对自己建设的网站进行推广在线培训
  • 网站建设类行业资讯自己怎么搭建网站
  • wordpress异步加载文章西昌seo快速排名
  • vs平台做网站西安seo外包服务
  • 搜索引擎营销是目前最主要的网站推广营销万江专业网站快速排名
  • 备案不关闭网站吗网站优化人员通常会将目标关键词放在网站首页中的
  • 网站快速收录提交seo 360
  • 做平面设计买哪个素材网站会员百度如何搜索网址
  • 给网站做cdn代运营一个月多少钱
  • 高大上企业网站推广网站要注意什么
  • c 怎么做网站开发iis搭建网站
  • 关于加强学校网站建设的通知营销100个引流方案
  • 做高端网站的网络公司百度电脑端入口
  • 玉林网站制作seo外链网
  • 网站开发工作总结报告青岛seo招聘
  • 哪个网站做课件能赚钱杭州seo推广服务
  • 你做我评网站会自动查论文相似度吗高级搜索入口
  • 网站备案证书下载密码忘了seo工具查询
  • 可以做婚礼鲜花布置的网站网络营销是什么专业类别
  • 成品网站源码免费分享seo助力网站转化率提升