This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
TabMain.vue
97 lines (92 loc) · 1.82 KB
/
TabMain.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
87
88
89
90
91
92
93
94
95
96
97
<template>
<div
v-show="isActive"
:class="$style.wrap"
>
<tab-header
v-if="isActive"
:item="item"
:can-go-back="webviewData.canGoBack"
:can-go-forward="webviewData.canGoForward"
@doReload="reloadTab"
@goToHome="goToHome"
@goBack="goBack"
@goForward="goForward"
@toggleDevTools="toggleDevTools"
/>
<tab-webview
ref="webview"
:item="item"
:is-active="isActive"
/>
</div>
</template>
<script>
import TabHeader from '@/components/TabHeader.vue';
import TabWebview from '@/components/TabWebview.vue';
export default {
components: {
TabHeader,
TabWebview,
},
props: {
item: {
type: Object,
default: () => ({}),
},
},
data() {
return {
webviewData: {},
webviewEl: {},
};
},
computed: {
isActive() {
const { params, name } = this.$route;
return params.id === this.item.id && name === 'tabs';
},
},
watch: {
isActive(isActive) {
if (isActive) {
this.$store.commit('Pages/setState', {
tabId: this.item.id,
data: { hasNotificationBadge: false },
});
this.webviewEl.focus();
}
},
},
mounted() {
this.webviewData = this.$refs.webview;
this.webviewEl = this.webviewData.webview;
},
methods: {
goToHome() {
this.webviewEl.loadURL(this.item.url);
},
goBack() {
this.webviewEl.goBack();
},
goForward() {
this.webviewEl.goForward();
},
reloadTab() {
this.webviewEl.reload();
},
toggleDevTools() {
if (this.webviewEl.isDevToolsOpened()) {
this.webviewEl.closeDevTools();
} else {
this.webviewEl.openDevTools();
}
},
},
};
</script>
<style lang="postcss" module>
.wrap {
@apply flex flex-1 flex-col;
}
</style>