1 | <!DOCTYPE html>
|
2 |
|
3 | <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
4 | <head>
|
5 | <meta charset="utf-8" />
|
6 | <title>解析</title>
|
7 | <script src="https://lib.baomitu.com/jszip/3.1.4/jszip.min.js"></script>
|
8 | <script src="https://lib.baomitu.com/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
|
9 | </head>
|
10 | <body>
|
11 |
|
12 | <script>
|
13 | var sp = {
|
14 |
|
15 | source: {
|
16 |
|
17 | word: "/src/data/word.json",
|
18 |
|
19 | ci: "/src/data/ci.json",
|
20 |
|
21 | idiom: "/src/data/idiom.json"
|
22 | },
|
23 | out: {
|
24 | complete: 0,
|
25 | word: {
|
26 | rows: 30,
|
27 | keys: [],
|
28 | pagedata: []
|
29 | },
|
30 | ci: {
|
31 | rows: 600,
|
32 | keys: [],
|
33 | pagedata: []
|
34 | },
|
35 | idiom: {
|
36 | rows: 150,
|
37 | keys: [],
|
38 | pagedata: []
|
39 | }
|
40 | },
|
41 | zip: null,
|
42 | down: function () {
|
43 | sp.zip.generateAsync({ type: "blob" }).then(function (content) {
|
44 | saveAs(content, "zidian.zip");
|
45 | });
|
46 | },
|
47 | spword: function () {
|
48 | fetch(sp.source.word).then(x => x.json()).then(function (res) {
|
49 | res.forEach(function (item, index) {
|
50 | sp.out.word.keys.push(item.word);
|
51 | var pi = Math.ceil((index + 1) / sp.out.word.rows) - 1;
|
52 | var arr = sp.out.word.pagedata[pi] || [];
|
53 | arr.push(item);
|
54 | sp.out.word.pagedata[pi] = arr;
|
55 | })
|
56 |
|
57 | sp.zip = sp.zip || new JSZip();
|
58 |
|
59 | var text = JSON.stringify(sp.out.word.keys);
|
60 | sp.zip.file("word/00.json", text);
|
61 |
|
62 | sp.out.word.pagedata.forEach(function (pd, pi) {
|
63 | var text = JSON.stringify(pd);
|
64 | sp.zip.file("word/" + pi + ".json", text);
|
65 | });
|
66 |
|
67 | if (++sp.out.complete == 3) {
|
68 | sp.down();
|
69 | }
|
70 | })
|
71 | },
|
72 | spci: function () {
|
73 | fetch(sp.source.ci).then(x => x.json()).then(function (res) {
|
74 | res.forEach(function (item, index) {
|
75 | sp.out.ci.keys.push(item.ci);
|
76 | var pi = Math.ceil((index + 1) / sp.out.ci.rows) - 1;
|
77 | var arr = sp.out.ci.pagedata[pi] || [];
|
78 | arr.push(item);
|
79 | sp.out.ci.pagedata[pi] = arr;
|
80 | })
|
81 |
|
82 | sp.zip = sp.zip || new JSZip();
|
83 |
|
84 | var text = JSON.stringify(sp.out.ci.keys);
|
85 | sp.zip.file("ci/00.json", text);
|
86 |
|
87 | sp.out.ci.pagedata.forEach(function (pd, pi) {
|
88 | var text = JSON.stringify(pd);
|
89 | sp.zip.file("ci/" + pi + ".json", text);
|
90 | });
|
91 |
|
92 | if (++sp.out.complete == 3) {
|
93 | sp.down();
|
94 | }
|
95 | })
|
96 | },
|
97 | spidiom: function () {
|
98 | fetch(sp.source.idiom).then(x => x.json()).then(function (res) {
|
99 | res.forEach(function (item, index) {
|
100 | sp.out.idiom.keys.push(item.word);
|
101 | var pi = Math.ceil((index + 1) / sp.out.idiom.rows) - 1;
|
102 | var arr = sp.out.idiom.pagedata[pi] || [];
|
103 | arr.push(item);
|
104 | sp.out.idiom.pagedata[pi] = arr;
|
105 | })
|
106 |
|
107 | sp.zip = sp.zip || new JSZip();
|
108 |
|
109 | var text = JSON.stringify(sp.out.idiom.keys);
|
110 | sp.zip.file("idiom/00.json", text);
|
111 |
|
112 | sp.out.idiom.pagedata.forEach(function (pd, pi) {
|
113 | var text = JSON.stringify(pd);
|
114 | sp.zip.file("idiom/" + pi + ".json", text);
|
115 | });
|
116 |
|
117 | if (++sp.out.complete == 3) {
|
118 | sp.down();
|
119 | }
|
120 | })
|
121 | },
|
122 | }
|
123 |
|
124 | sp.spword();
|
125 | sp.spci();
|
126 | sp.spidiom();
|
127 |
|
128 | </script>
|
129 | </body>
|
130 | </html> |
\ | No newline at end of file |