tools.vue
7.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<template>
<view>
<subTitleBar
:isOpen="isShowSetting"
@click="changeStatus('isShowSetting')"
title="DevTools扩展配置项"
/>
<template v-if="isShowSetting">
<!-- #ifdef APP-PLUS || H5 -->
<view class="settingItem">
<view class="settingHead">
<text class="settingTitle">页面自动注入Eruda调试工具</text>
<text class="settingSubtitle">(强大的节点选择等工具;重启APP后生效)</text>
</view>
<switch
:checked="isInjectEruda"
@change="switchChange($event, 'isInjectEruda')"
color="#ff2d55"
/>
</view>
<view class="settingItem">
<view class="settingHead">
<text class="settingTitle">页面自动注入vConsole调试工具</text>
<text class="settingSubtitle">(腾讯开源的h5调试工具;重启APP后生效)</text>
</view>
<switch
:checked="isInjectVConsole"
@change="switchChange($event, 'isInjectVConsole')"
color="#ff2d55"
/>
</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="settingItem">
<view class="settingHead">
<text class="settingTitle">小程序VConsole开关</text>
<text class="settingSubtitle">设置是否打开调试开关。此开关对正式版也能生效。</text>
</view>
<switch
:checked="isOpenMpDevTag"
@change="switchChange($event, 'isOpenMpDevTag')"
color="#ff2d55"
/>
</view>
<!-- #endif -->
</template>
<subTitleBar
:isOpen="isShowBtnPanel"
@click="changeStatus('isShowBtnPanel')"
title="常用工具"
/>
<view
v-if="isShowBtnPanel"
class="btnPanel"
>
<!-- #ifdef APP-PLUS || H5 -->
<view
class="btnItem btn-def"
@click="restart"
>
<text class="btnText">重启APP</text>
</view>
<!-- #endif -->
<view
class="btnItem btn-def"
@click="goPage"
>
<text class="btnText">跳转指定页面</text>
</view>
<view
class="btnItem btn-def"
@click="$emit('goOpenRequest')"
>
<text class="btnText">发起网络请求</text>
</view>
<view
class="btnItem btn-def"
@click="delLocalStorage"
>
<text class="btnText">清空localStorage缓存</text>
</view>
</view>
<subTitleBar
:isOpen="isShowDiyTools"
@click="changeStatus('isShowDiyTools')"
title="自定义Tools"
/>
<tools
v-if="isShowDiyTools"
ref="tools"
/>
</view>
</template>
<script>
import tools from "../../../tools.vue";
import subTitleBar from "../ui/subTitleBar.vue";
export default {
components: {
tools,
subTitleBar,
},
data() {
return {
/**
* 是否显示系统工具栏
*/
isShowSetting: false,
/**
* 是否自动注入Eruda
*/
isInjectEruda: uni.getStorageSync("devTools_isInjectEruda") == "yes",
/**
* 是否自动注入vConsole
*/
isInjectVConsole: uni.getStorageSync("devTools_isInjectVConsole") == "yes",
/**
* 是否显示 用户自定义tools
*/
isShowDiyTools: true,
/**
* 是否打开小程序调试工具
*/
isOpenMpDevTag: uni.getStorageSync("devTools_isOpenMpDevTag") == "yes",
/**
* 常用工具栏开关
*/
isShowBtnPanel: true,
};
},
methods: {
/**
* 更改选中状态
*/
changeStatus(key) {
this[key] = !this[key];
},
/**
* 开关选择器改变事件
*/
switchChange(e, key) {
let status = e.detail.value;
this[key] = status;
uni.setStorageSync("devTools_" + key, status ? "yes" : "no");
if (key == "isOpenMpDevTag") {
wx.setEnableDebug({
enableDebug: status,
});
}
},
/**
* 重启APP
*/
restart() {
// #ifdef APP-PLUS
plus.runtime.restart();
// #endif
// #ifdef H5
location.href = "/";
// #endif
},
/**
* 跳转指定页面
*/
goPage() {
uni.$emit("devTools_showRouteDialog");
},
/**
* 清空LocalStorage
*/
delLocalStorage() {
uni.showModal({
title: "操作确认",
content: "是否确认清空LocalStorage缓存?",
success(res) {
if (res.confirm) {
// #ifdef APP-PLUS
let keys = plus.storage.getAllKeys();
for (let i = 0; i < keys.length; i++) {
const key = String(keys[i]);
if (key.indexOf("devTools_") == 0) {
continue;
}
uni.removeStorageSync(key);
}
// #endif
// #ifdef H5
for (let i = 0; i < localStorage.length; i++) {
let key = String(localStorage.key(i));
if (key.indexOf("devTools_") == 0) {
continue;
}
setTimeout(() => {
localStorage.removeItem(key);
}, i * 2 + 1);
}
// #endif
// #ifdef MP
let keyList = devCache.get("storage");
if (!keyList) keyList = [];
for (let i = 0; i < keyList.length; i++) {
const key = keyList[i];
if (key.indexOf("devTools_") == 0) {
continue;
}
uni.removeStorageSync(key);
}
// #endif
uni.showToast({
icon: "success",
title: "清空成功!",
});
}
},
});
},
},
};
</script>
<style lang="scss" scoped>
.padding-sm {
padding: 20rpx;
}
.settingItem:active {
background-color: rgba(0, 0, 0, 0.05);
}
.settingItem {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 750rpx;
padding: 15rpx 0;
padding-right: 15rpx;
.settingHead {
display: flex;
flex-direction: column;
margin-left: 20rpx;
.settingTitle {
font-size: 24rpx;
line-height: 28rpx;
color: #333;
}
.settingSubtitle {
margin-top: 4rpx;
font-size: 20rpx;
line-height: 26rpx;
color: #777;
}
}
}
.btnPanel {
display: flex;
flex-direction: row;
flex-wrap: wrap;
padding-left: 20rpx;
padding-right: 20rpx;
padding-top: 20rpx;
.btnItem {
margin-right: 20rpx;
margin-bottom: 20rpx;
border-radius: 10rpx;
/* #ifndef APP-PLUS */
min-width: 120rpx;
/* #endif */
height: 60rpx;
border: 1px solid rgba(0, 0, 0, 0.1);
background-color: rgba(0, 0, 0, 0.04);
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
padding: 0 15rpx;
.btnText {
font-size: 20rpx;
line-height: 30rpx;
color: #333;
}
}
.btn-red:active {
background-color: rgba(255, 45, 85, 0.5);
}
.btn-red {
border: 1px solid rgba(255, 45, 85, 1);
background-color: rgba(255, 45, 85, 1);
.btnText {
color: #fff;
}
}
.btn-def:active {
background-color: rgba(0, 0, 0, 0.1);
}
.btn-def {
border: 1px solid rgba(0, 0, 0, 0.1);
background-color: rgba(0, 0, 0, 0.04);
.btnText {
color: #333;
}
}
}
</style>