1 | import Light from "light";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | function printQRCode(hashpath) {
|
7 |
|
8 | let path = location.pathname;
|
9 | let env = __ENV__;
|
10 |
|
11 | if (path === "/"){
|
12 | path = "/index.html";
|
13 | }
|
14 |
|
15 | print(path);
|
16 |
|
17 | if(env.plugins && env.plugins.toString().indexOf("miniapp")>-1 && (!Light.onlyFor || Light.onlyFor === "miniapp")) {
|
18 | if(path === "/index.html"){
|
19 | print("/app.miniapp.js");
|
20 | }else{
|
21 | print(path.replace(/\.html/ig, ".miniapp.js"));
|
22 | }
|
23 | }
|
24 | if(env.plugins && env.plugins.toString().indexOf("jsnative")>-1 && (!Light.onlyFor || Light.onlyFor === "jsn")){
|
25 | if(path === "/index.html"){
|
26 | print("/app.native.js");
|
27 | }else{
|
28 | print(path.replace(/\.html/ig, ".miniapp.js"));
|
29 | }
|
30 | }
|
31 |
|
32 |
|
33 | function print(path) {
|
34 | if(navigator.onLine){
|
35 | let urlToScan = `http://${location.host}${path}${location.search}#${hashpath}`;
|
36 | Light.ajax({
|
37 | url:`https://fs-api.lightyy.com/service/utils/qrcode?url=${encodeURIComponent(urlToScan)}`,
|
38 | type:"get",
|
39 | dataType:"json",
|
40 | success(data){
|
41 | console.log("LightView 扫码 URL: " + urlToScan);
|
42 |
|
43 | console.log("%c ", "padding:75px 80px 75px;background:url(" + data.data + ") no-repeat;background-size:150px");
|
44 | }
|
45 | })
|
46 | }
|
47 | }
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function countNodes(node) {
|
56 | let count = 1;
|
57 | if(node.hasChildNodes()) {
|
58 | let cnodes = node.childNodes;
|
59 | for(let i=0; i<cnodes.length; i++) {
|
60 | count = count + countNodes(cnodes.item(i))
|
61 | }
|
62 | }
|
63 | return count;
|
64 | }
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | function countLevels(node) {
|
71 | if(node.hasChildNodes()) {
|
72 | let cnodes = node.childNodes;
|
73 |
|
74 | let levels = [];
|
75 | cnodes.forEach(function (n) {
|
76 | levels.push( 1 + countLevels(n))
|
77 | })
|
78 | return Math.max(...levels)
|
79 | }else{
|
80 | return 1;
|
81 | }
|
82 | }
|
83 |
|
84 | Light.filter("route", function (from, to, next) {
|
85 | try {
|
86 | next();
|
87 | printQRCode(to.fullPath);
|
88 |
|
89 |
|
90 | setTimeout(function () {
|
91 | let count = countNodes(document.body);
|
92 | let level = countLevels(document.body);
|
93 | console.log(`当前视图的DOM节点总数为:${count},最深的DOM节点层次为:${level}`);
|
94 | },1000)
|
95 | }catch (e) {
|
96 | console.log(e)
|
97 | }
|
98 | });
|
99 |
|
100 |
|
101 | console.log(`%c查看编译资源详情请点击链接:http://${location.host}/stats.html`,"font-size:15px;color:red;font-weight:bolder");
|