flag.vue
2.13 KB
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
<template>
<div class="flag-box" v-if="flag">
<div class="box" :style="{'top': setPosition(position.top) + 'px', 'left': setPosition(position.left) + 'px', 'right': setPosition(position.right) + 'px', 'bottom': setPosition(position.bottom) + 'px'}">
<img :src="flag" class="flag-img" :style="{'width': setWidth(width) + 'px'}" mode="widthFix" />
</div>
</div>
</template>
<script>
export default {
data: function () {
return {
}
},
// props: ["flag", "position"]
props: {
flag: {
required: true
},
position: {
type: Object,
default: () => ({
top: -6,
left: 10,
right: 0,
bottom: 0
})
},
width: {
type: Number,
default: 46
}
},
computed: {
/**
* 计算flag定位
* @param {int} x [待转换定位值]
*/
setPosition() {
return (x) => {
// 判断参数冲突,调增返回
if (this.position.right && this.position.right != 0) {
this.$set(this.position, "left", undefined);
}
if (this.position.bottom && this.position.bottom != 0) {
this.$set(this.position, "top", undefined);
}
return x * ((document.documentElement.clientWidth || document.body.clientWidth) / 750);
}
},
/**
* 计算flag宽度
* @param {int} w [flag宽度]
*/
setWidth() {
return (w) => {
return w * ((document.documentElement.clientWidth || document.body.clientWidth) / 750);
}
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less" scoped>
@import './flag';
</style>