|
@@ -1,6 +1,6 @@
|
|
|
// 屏幕适配 mixin 函数
|
|
// 屏幕适配 mixin 函数
|
|
|
|
|
|
|
|
-// * 默认缩放值
|
|
|
|
|
|
|
+/*// * 默认缩放值
|
|
|
const scale = {
|
|
const scale = {
|
|
|
width: '1',
|
|
width: '1',
|
|
|
height: '1',
|
|
height: '1',
|
|
@@ -11,7 +11,7 @@ const baseWidth = 1920
|
|
|
const baseHeight = 1080
|
|
const baseHeight = 1080
|
|
|
|
|
|
|
|
// * 需保持的比例(默认1.77778)
|
|
// * 需保持的比例(默认1.77778)
|
|
|
-const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5))
|
|
|
|
|
|
|
+const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5))*/
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
data() {
|
|
data() {
|
|
@@ -21,7 +21,12 @@ export default {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
mounted () {
|
|
mounted () {
|
|
|
- this.calcRate()
|
|
|
|
|
|
|
+ this.$nextTick(()=>{
|
|
|
|
|
+ this.calcRate()
|
|
|
|
|
+ /*setTimeout(() => {
|
|
|
|
|
+ this.calcRate()
|
|
|
|
|
+ }, 5000);*/
|
|
|
|
|
+ })
|
|
|
window.addEventListener('resize', this.resize)
|
|
window.addEventListener('resize', this.resize)
|
|
|
},
|
|
},
|
|
|
beforeDestroy () {
|
|
beforeDestroy () {
|
|
@@ -31,20 +36,17 @@ export default {
|
|
|
calcRate () {
|
|
calcRate () {
|
|
|
const appRef = this.$refs["appRef"]
|
|
const appRef = this.$refs["appRef"]
|
|
|
if (!appRef) return
|
|
if (!appRef) return
|
|
|
- // 当前宽高比
|
|
|
|
|
- const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(5))
|
|
|
|
|
|
|
+ const newWidth = window.innerWidth;
|
|
|
|
|
+ const newHeight = window.innerHeight;
|
|
|
|
|
+
|
|
|
if (appRef) {
|
|
if (appRef) {
|
|
|
- if (currentRate > baseProportion) {
|
|
|
|
|
- // 表示更宽
|
|
|
|
|
- scale.width = ((window.innerHeight * baseProportion) / baseWidth).toFixed(5)
|
|
|
|
|
- scale.height = (window.innerHeight / baseHeight).toFixed(5)
|
|
|
|
|
- appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
|
|
|
|
|
- } else {
|
|
|
|
|
- // 表示更高
|
|
|
|
|
- scale.height = ((window.innerWidth / baseProportion) / baseHeight).toFixed(5)
|
|
|
|
|
- scale.width = (window.innerWidth / baseWidth).toFixed(5)
|
|
|
|
|
- appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ let newScaleX = newWidth / 1920;
|
|
|
|
|
+ let newScaleY = newHeight / 1080;
|
|
|
|
|
+
|
|
|
|
|
+ let newTranslateX = ((1920 - newWidth) / 2 / newWidth * 100).toFixed(5) + '%';
|
|
|
|
|
+ let newTranslateY = ((1080 - newHeight) / 2 / newHeight * 100).toFixed(5) + '%';
|
|
|
|
|
+ appRef.style.transform = `scale(${newScaleX.toFixed(5)}, ${newScaleY.toFixed(5)}) translate(-${newTranslateX}, -${newTranslateY})`
|
|
|
|
|
+ console.log(`scale(${newScaleX.toFixed(5)}, ${newScaleY.toFixed(5)}) translate(-${newTranslateX}, -${newTranslateY})`)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
resize () {
|
|
resize () {
|
|
@@ -61,7 +63,7 @@ export default {
|
|
|
}
|
|
}
|
|
|
this.drawTiming = setTimeout(() => {
|
|
this.drawTiming = setTimeout(() => {
|
|
|
this.calcRate()
|
|
this.calcRate()
|
|
|
- }, 10000)
|
|
|
|
|
|
|
+ }, 1000)
|
|
|
},
|
|
},
|
|
|
fullScreen(){
|
|
fullScreen(){
|
|
|
var docElm = document.documentElement; //若要全屏页面中div,var element= document.getElementById("divID");
|
|
var docElm = document.documentElement; //若要全屏页面中div,var element= document.getElementById("divID");
|