index.js
4.05 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
import drawView from "./core/libs/drawView";
import logReport from "./core/libs/logReport";
import errorReport from "./core/libs/errorReport";
import devOptions from "./core/libs/devOptions";
import createH5Bubble from "./core/libs/createH5Bubble";
import vueMixin from "./core/proxy/vueMixin";
import devToolsProxyInstall from "./core/proxy/index";
import pageLinkList from "./core/libs/pageLinkList";
/**
* @type {Vue}
*/
let that;
const devTools = {
options: null,
/**
* 挂载安装APP页面
*/
install(vm, options) {
try {
that = vm;
let _this = this;
if (vm && vm.config && vm.config.globalProperties) {
vm.config.globalProperties.$logReport = logReport;
} else {
vm.prototype.$logReport = logReport;
}
//! 初始化配置项
devOptions.setOptions(options)
options = devOptions.getOptions()
_this.options = options;
if (!options || !options.status) {
return console.log("%c devTools 调试工具未运行!", 'padding: 4px;background-color: red;color: #fff;font-size: 15px;');
}
//! 挂载dev工具
if (vm && vm.config && vm.config.globalProperties) {
vm.config.globalProperties.$devTools = devTools;
} else {
vm.prototype.$devTools = devTools;
}
if (options.error.status) {
//! 挂载vue报错
vm.config.errorHandler = (err, vm, trace) => {
errorReport(err, trace, "ve")
};
//! 挂载vue警告
vm.config.warnHandler = (err, vm, trace) => {
errorReport(err, trace, "vw")
}
}
//!混入生命周期监听器
vm.mixin(vueMixin)
//!绘制环境变量小标签
// #ifdef APP-PLUS
drawView(options, devTools)
// #endif
// #ifdef H5
createH5Bubble(options, devTools)
// #endif
//!调试工具全局拦截器挂载
devToolsProxyInstall(options)
//! 注册dev弹窗打开事件
uni.$on("devTools_showDialog", () => {
_this.show()
})
//! 注册dev弹窗关闭事件
uni.$on("devTools_closeDialog", (options) => {
_this.hide(options)
})
//! 挂载uni对象
uni.$dev = {
show() {
_this.show()
},
hide() {
_this.hide()
},
errorReport,
logReport,
}
//! 注册jsRunner执行事件
uni.$on("devTools_jsRunner", (code) => {
let result = undefined;
try {
let fun = (("ev" + "__混淆__" + "al").replace("__混淆__", ""));
result = globalThis[fun](code);
// result = eval(code);
} catch (error) {
if (error && error.message) {
result = error.message;
}
}
uni.$emit("devTools_jsRunnerCallback", result)
})
// ! 页面路由列表
pageLinkList.install()
} catch (error) {
console.log("devTools install error", error);
}
},
/**
* 打开调试弹窗
*/
show() {
let pages = getCurrentPages();
//! 已经打开了调试工具,不要重复显示
if (pages[pages.length - 1].route == this.options.devRoute) {
return false;
}
uni.navigateTo({
url: this.options.route,
animationType: 'none',
animationDuration: 0,
})
},
/**
* 隐藏调试弹窗
*/
hide(options) {
// #ifdef APP-PLUS
uni.$emit("devTools_closeDevToolsPanel")
let isBack = false;
uni.$once("devTools_panelHideSuccess", () => {
if (!isBack) {
isBack = true;
uni.navigateBack();
}
})
setTimeout(() => {
if (!isBack) {
isBack = true;
uni.navigateBack();
}
}, 500);
// #endif
// #ifndef APP-PLUS
uni.navigateBack()
// #endif
if (options && options.navigateToUrl) {
let t = 600;
// #ifndef APP-PLUS
t = 200;
// #endif
setTimeout(() => {
uni.navigateTo({
url: options.navigateToUrl,
})
}, t);
}
},
errorReport,
logReport,
}
export default devTools;