download-top.vue
2 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<template>
<div class="download" v-if="visible">
</div>
</template>
<script>
export default {
name: 'download',
data() {
return {
visible: true
};
},
mounted() {
this.getDownloadElem((elem) => {
const newElem = this.handleElem(elem.cloneNode(true));
// elem.parentNode.removeChild(elem);
this.$el.appendChild(newElem);
});
},
methods: {
getDownloadElem(found) {
let vm = this;
function checkForDownload() {
vm.$download = document.getElementById('top-downloadbar');
if (vm.$download) {
found(vm.$download);
} else {
setTimeout(checkForDownload, 50);
}
}
checkForDownload();
},
handleElem(elem) {
const vm = this;
const miniElem = elem.querySelector('#mini-app-open');
if (miniElem) {
elem.removeChild(miniElem);
}
elem.addEventListener('click', function(e) {
let target = e.target;
switch (target.className.toLowerCase()) {
case 'download-close': {
// 点击关闭
vm.$emit('close');
vm.visible = false;
break;
}
case 'download-go': {
// 尝试打开app
vm.$openApp().then(() => {
vm.$links.toDownloadApp();
});
e.stopPropagation();
e.preventDefault();
break;
}
case 'download-go-wechat': {
// 尝试打开app
vm.$openApp().then(() => {
vm.$links.toDownloadApp();
});
e.stopPropagation();
e.preventDefault();
break;
}
default: {
// pass
}
}
});
const downloadGo = elem.querySelector('#download-go');
if (downloadGo) {
downloadGo.innerText = '下载APP';
}
return elem;
}
}
};
</script>
<style lang="scss" scoped>
.download {
width: 100%;
height: 110px;
}
</style>