App.vue
3.3 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
<template>
<el-tabs>
<el-tab-pane label="Debugger Apps">
<div class="app-list">
<template v-for="(app, key) in QX_DEBUG_APPS" :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 type="" @click="deleteItem(key)">-</el-button>
<el-button
v-if="key === QX_DEBUG_APPS.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="DEVELOPER_MODE == 1 && filterDebuggerApps.length"
@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 } from "vue";
const { sessionStorage } =
chrome.extension.getBackgroundPage().backgroundState || {};
const defaultApps = '[{"name":"","entry":""}]';
const sessionDebuggerApps = JSON.parse(
sessionStorage.QX_DEBUG_APPS || defaultApps
);
const QX_DEBUG_APPS = reactive(
JSON.parse(sessionDebuggerApps.length ? sessionDebuggerApps : defaultApps)
);
const filterDebuggerApps = computed(() =>
QX_DEBUG_APPS.filter((item) => item.name && item.entry)
);
const DEVELOPER_MODE = ref(sessionStorage.DEVELOPER_MODE === "1");
console.log("sessionStorage", sessionStorage);
function add() {
QX_DEBUG_APPS.push({ name: "", entry: "" });
}
function deleteItem(index) {
QX_DEBUG_APPS.splice(index, 1);
if (index == 0 && !QX_DEBUG_APPS.length) {
QX_DEBUG_APPS.push({ name: "", entry: "" });
}
}
function validate(refresh) {
if (filterDebuggerApps.value.length || refresh) {
return true;
}
return false;
}
async function save() {
chrome.runtime.sendMessage({
type: "setSessionStorage",
key: "QX_DEBUG_APPS",
value: JSON.stringify(filterDebuggerApps.value),
});
}
async function start(refresh) {
if (validate(refresh)) {
DEVELOPER_MODE.value = "1";
save();
chrome.runtime.sendMessage({
type: "setSessionStorage",
key: "DEVELOPER_MODE",
value: "1",
});
chrome.runtime.sendMessage({ type: "reload" });
}
}
async function end() {
DEVELOPER_MODE.value = null;
chrome.runtime.sendMessage({
type: "removeSessionStorage",
key: "DEVELOPER_MODE",
});
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>