-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBigDataRapidPlaceholder.vue
86 lines (83 loc) · 1.98 KB
/
BigDataRapidPlaceholder.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
<div class="CockpitLayout" :class="{isDev:isDev}">
<img class="CockpitLayoutBj" ref="img" :src="src">
<slot :getStyle="getStyle"></slot>
</div>
</template>
<script>
export default {
name: "CockpitLayout",
props:{
src:{type:String, default:null},
width:{type:Number, default:null},
height:{type:Number, default:null},
},
data(){
return {
ratio_w:0,
ratio_h:0,
}
},
computed:{
isDev(){
return process.env.NODE_ENV !== 'production'
}
},
mounted(){
this.init()
window.addEventListener("resize",()=>{
this.init();
})
},
methods:{
init(){
if(this.width && this.height){
this.ratio_w = window.innerWidth / this.width;
this.ratio_h = window.innerHeight / this.height;
}else {
const img = new Image();
img.src = this.src;
img.onload = ()=>{
this.ratio_w = window.innerWidth / img.width;
this.ratio_h = window.innerHeight / img.height;
}
}
},
getStyle({left,top, width, height}){
const unit = "px";
return {
left:(left * this.ratio_w) + unit,
top:(top * this.ratio_h) + unit,
width:width * this.ratio_w + unit,
height:height * this.ratio_h + unit,
}
}
}
}
</script>
<style scoped lang="less">
.CockpitLayout {
position: fixed;
left: 0;
top: 0;
height: 100%;
width: 100%;
.CockpitLayoutBj{
position: fixed;
left: 0;
top: 0;
height: 100%;
width: 100%;
}
&>div{
cursor: pointer;
position: fixed;
display: flex;
}
&.isDev{
&>div{
border:1px dashed rgba(253, 255, 53, 0.1);
}
}
}
</style>