App.vue
3.91 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<template>
<el-tabs>
<el-tab-pane label="Debugger Apps">
<div class="app-list">
<template v-for="(app, key) in debuggerApps" :key="key">
<div class="app-list-item">
<div class="app-list-item__content">
<el-input placeholder="子应用名称" v-model="app.name"> </el-input>
<el-input placeholder="子应用地址" v-model="app.entry"></el-input>
</div>
<div class="app-list-item__btn">
<el-button
v-if="app.debugging"
type=""
@click="handleDebugging(key)"
>
<VideoPause style="width: 1em; height: 1em" />
</el-button>
<el-button v-else type="" @click="handleDebugging(key)">
<VideoPlay style="width: 1em; height: 1em" />
</el-button>
<el-button type="" @click="deleteItem(key)">-</el-button>
<el-button
v-if="key === debuggerApps.length - 1"
type=""
@click="add"
>+</el-button
>
</div>
</div>
</template>
</div>
<div class="btn">
<el-button @click="start(true)"
><Refresh style="width: 1em; height: 1em" />
</el-button>
<el-button v-if="debuggerStatus" @click="end">
<VideoPause style="width: 1em; height: 1em; margin-right: 8px" />
结束调试
</el-button>
<el-button v-else @click="start"
><VideoPlay style="width: 1em; height: 1em; margin-right: 8px" />
开启调试</el-button
>
</div>
</el-tab-pane>
</el-tabs>
</template>
<script setup>
import { reactive, ref, computed, watchEffect } from "vue";
const defaultApps = [{ name: "", entry: "", debugging: false }];
const { sessionStorage } =
chrome.extension.getBackgroundPage().backgroundState || {};
const debuggerApps = ref(
JSON.parse(
window.localStorage.getItem("qx-debugger-apps") ||
JSON.stringify(defaultApps)
)
);
const debuggerStatus = ref(
JSON.parse(window.localStorage.getItem("qx-debugger-status") || "false")
);
const filterDebuggerApps = computed(() =>
debuggerApps.value.filter((app) => app.name && app.entry && app.debugging)
);
watchEffect(() => {
window.localStorage.setItem(
"qx-debugger-apps",
JSON.stringify(debuggerApps.value || defaultApps)
);
chrome.runtime.sendMessage({
type: "setSessionStorage",
key: "QX_DEBUG_APPS",
value: JSON.stringify(filterDebuggerApps.value),
});
});
const DEVELOPER_MODE = ref(sessionStorage.DEVELOPER_MODE === "1");
function add() {
debuggerApps.value.push(defaultApps[0]);
}
function deleteItem(index) {
debuggerApps.value.splice(index, 1);
if (index == 0 && !debuggerApps.length) {
debuggerApps.value.push({ name: "", entry: "" });
}
}
async function start() {
chrome.runtime.sendMessage({ type: "reload" });
debuggerStatus.value = true;
window.localStorage.setItem("qx-debugger-status", "true");
chrome.runtime.sendMessage({
type: "setSessionStorage",
key: "QX_DEBUG_APPS",
value: JSON.stringify(filterDebuggerApps.value),
});
}
async function end() {
debuggerStatus.value = false;
window.localStorage.setItem("qx-debugger-status", "false");
chrome.runtime.sendMessage({
type: "removeSessionStorage",
key: "QX_DEBUG_APPS",
});
chrome.runtime.sendMessage({ type: "reload" });
}
function handleDebugging(index) {
debuggerApps.value[index].debugging = !debuggerApps.value[index].debugging;
chrome.runtime.sendMessage({ type: "reload" });
}
</script>
<style>
.app-list {
}
.app-list-item {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.app-list-item__content {
width: 30%;
display: flex;
align-items: center;
justify-content: space-between;
}
.app-list-item__btn {
margin-left: 10px;
}
.el-input {
width: calc(50% - 5px);
}
</style>