原有设计稿比例
baseWidth: 1920, // 设计稿尺寸
baseHeight: 1080, // 设计稿尺寸
baseProportion: 0, // 比例
缩放与改变
// 计算放大倍数
calcRate() {
const contentRef = this.$refs.contentRef;
if (!contentRef) return;
// 当前宽高比
const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(2));
if (currentRate > this.baseProportion) {
// 表示更宽
this.scale.width = ((window.innerHeight * this.baseProportion) / this.baseWidth).toFixed(2);
this.scale.height = (window.innerHeight / this.baseHeight).toFixed(2);
contentRef.style.transform = `scale(${this.scale.width}, ${this.scale.height}) translate(-50%, -50%)`;
} else {
// 表示更高
this.scale.height = ((window.innerWidth / this.baseProportion) / this.baseHeight).toFixed(2);
this.scale.width = (window.innerWidth / this.baseWidth).toFixed(2);
contentRef.style.transform = `scale(${this.scale.width}, ${this.scale.height}) translate(-50%, -50%)`;
}
},
// 屏幕大小改变更新倍数
resize() {
clearTimeout(this.scaleTime)
this.scaleTime = setTimeout(() => {
this.calcRate()
}, 0)
}
生命周期调用
mounted() {
this.calcRate()
this.resize()
window.addEventListener('resize', this.resize);
// window.addEventListener('keydown', this.toggleFullscreen, true)
},
盒子
<div class="trans-common" ref="contentRef">
<top-header />
<div class="main-content">
<div class="lr-box">
<content-left @toNews="toNews" :psDic="psDic"></content-left>
</div>
<div class="c-box">
<!-- 总控台 -->
<!-- <content-main @toTable="toTable" @toPeoInfo="toPeoInfo"></content-main> -->
<content-main @toTable="toTable" @toPeoInfo="toPeoInfo" @toGis="toGis"></content-main>
</div>
<div class="lr-box">
<content-right :psDic="psDic"></content-right>
</div>
<base-table :show="showTable" @toTable="toTable" @toPeoInfo="toPeoInfoSearch" @close="showTable = false">
</base-table>
<news v-if="showNews" :show="showNews" @close="showNews = false"></news>
<peo-info v-if="showPeoInfo" :show="showPeoInfo" @tomapList="tomapList" @close="showPeoInfo = false"></peo-info>
<info-gis v-if="showInfoGis" :show="showInfoGis" @close="showInfoGis = false"></info-gis>
<!-- <Map v-if="mapList" :show="mapList" @close="mapList = false"></Map> -->
<RouteMap v-if="routemapShow" :show="routemapShow" @close="mapShow = false"></RouteMap>
</div>
</div>