ocpview-plus 1.3.14 → 1.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/README.md +55 -43
  2. package/dist/ocpviewplus.min.esm.js +574 -482
  3. package/dist/ocpviewplus.min.js +9 -9
  4. package/dist/style.css +1 -1
  5. package/dist/styles/efviewplus.css +1 -1
  6. package/package.json +146 -146
  7. package/src/components/base/ContractPrintMixins.js +30 -30
  8. package/src/components/base/controlbase.vue +190 -190
  9. package/src/components/base/controlbox.vue +102 -102
  10. package/src/components/base/index.js +2 -2
  11. package/src/components/base/load.js +19 -19
  12. package/src/components/base/probase.js +220 -220
  13. package/src/components/base/size.js +78 -78
  14. package/src/components/billbox/billbox.vue +67 -67
  15. package/src/components/billbox/index.js +1 -1
  16. package/src/components/cascaderbox/cascaderbox.vue +184 -184
  17. package/src/components/cascaderbox/index.js +2 -2
  18. package/src/components/checkbox/checkbox.vue +75 -75
  19. package/src/components/checkbox/checkgroupbox.vue +103 -103
  20. package/src/components/checkbox/index.js +2 -2
  21. package/src/components/colorbox/colorbox.vue +43 -43
  22. package/src/components/colorbox/index.js +1 -1
  23. package/src/components/combobox/combobox.vue +219 -219
  24. package/src/components/combobox/index.js +1 -1
  25. package/src/components/conditionbox/conditionbase.vue +194 -194
  26. package/src/components/conditionbox/conditionbox.vue +62 -62
  27. package/src/components/conditionbox/conditionfilterbox.vue +479 -479
  28. package/src/components/conditionbox/conditionselectorbox.vue +237 -237
  29. package/src/components/conditionbox/index.js +4 -4
  30. package/src/components/conditionbox/queryconditionbox.vue +25 -25
  31. package/src/components/conditionbox/queryconditionboxbase.vue +123 -123
  32. package/src/components/conditionbox/searchconditionbox.vue +113 -113
  33. package/src/components/conditionbox/searchgrid.vue +391 -391
  34. package/src/components/datebox/DateBoxV1.vue +22 -22
  35. package/src/components/datebox/datebox.vue +129 -129
  36. package/src/components/datebox/daterangebox.vue +154 -154
  37. package/src/components/datebox/index.js +5 -5
  38. package/src/components/form/baseform.vue +676 -676
  39. package/src/components/form/detailsbox.vue +487 -487
  40. package/src/components/form/formbox.vue +28 -28
  41. package/src/components/form/formcardbox.vue +267 -267
  42. package/src/components/form/formcardbox2.vue +228 -228
  43. package/src/components/form/formcardgroupbox.vue +251 -251
  44. package/src/components/form/formcompro.js +18 -18
  45. package/src/components/form/formdetail.vue +128 -128
  46. package/src/components/form/formdetailtwo.vue +302 -302
  47. package/src/components/form/index.js +9 -9
  48. package/src/components/form/toolanchor.js +45 -45
  49. package/src/components/form/workform.vue +167 -167
  50. package/src/components/grid/basegrid.vue +1062 -1062
  51. package/src/components/grid/editgrid.vue +51 -51
  52. package/src/components/grid/editgridbase.vue +1062 -1062
  53. package/src/components/grid/editgridcard.vue +193 -193
  54. package/src/components/grid/expandrow.vue +137 -137
  55. package/src/components/grid/index.js +5 -5
  56. package/src/components/grid/viewgrid.vue +121 -121
  57. package/src/components/grid/viewgridbase.vue +1286 -1286
  58. package/src/components/icon/common-icon.vue +53 -53
  59. package/src/components/icon/eicon.vue +28 -28
  60. package/src/components/icon/icons.vue +42 -42
  61. package/src/components/icon/index.js +1 -1
  62. package/src/components/label/index.js +2 -2
  63. package/src/components/label/showtext.vue +94 -94
  64. package/src/components/load/loadcartoon.vue +227 -227
  65. package/src/components/map/index.js +1 -1
  66. package/src/components/map/mapbox.vue +348 -348
  67. package/src/components/masterplate/RewriteBillListDetails/BillInfoPanel.vue +184 -184
  68. package/src/components/masterplate/RewriteBillListDetails/BillInfoPanelEditTable.vue +838 -838
  69. package/src/components/masterplate/RewriteBillListDetails/BillInfoPanelEditTableControlbox.vue +126 -126
  70. package/src/components/masterplate/RewriteBillListDetails/BillInfoPanelEditTableControlboxNumberbox.vue +27 -27
  71. package/src/components/masterplate/RewriteBillListDetails/BillListPanel.vue +126 -126
  72. package/src/components/masterplate/RewriteBillListDetails/BillListPanelQueryBar.vue +280 -280
  73. package/src/components/masterplate/RewriteBillListDetails/BillListPanelTable.vue +346 -346
  74. package/src/components/masterplate/RewriteBillListDetails/index.vue +325 -325
  75. package/src/components/masterplate/RewriteBillListDetails/mixins/useVxeGridEditTypeKeydownEventHook.js +251 -251
  76. package/src/components/masterplate/RewriteListdetails/BillListPanelV2.vue +115 -115
  77. package/src/components/masterplate/RewriteListdetails/BillListPanelV2QueryBar.vue +24 -24
  78. package/src/components/masterplate/RewriteListdetails/BillListPanelV3.vue +121 -121
  79. package/src/components/masterplate/RewriteListdetails/BillListPanelV3QueryBar.vue +275 -275
  80. package/src/components/masterplate/RewriteListdetails/indexV2.vue +320 -320
  81. package/src/components/masterplate/RewriteListdetails/indexV3.vue +331 -331
  82. package/src/components/masterplate/appendix.vue +586 -586
  83. package/src/components/masterplate/approval.vue +863 -863
  84. package/src/components/masterplate/base.vue +1028 -1028
  85. package/src/components/masterplate/billasyncimport.vue +614 -614
  86. package/src/components/masterplate/billconditionbox.vue +223 -223
  87. package/src/components/masterplate/billconditionsbox.vue +427 -427
  88. package/src/components/masterplate/billdetailform.vue +1028 -1028
  89. package/src/components/masterplate/billimport.vue +301 -301
  90. package/src/components/masterplate/billquerygrid.vue +391 -391
  91. package/src/components/masterplate/billsinglegrid.vue +234 -234
  92. package/src/components/masterplate/birtreport.vue +185 -185
  93. package/src/components/masterplate/contractappendix.vue +688 -688
  94. package/src/components/masterplate/detailbtntoolbar.vue +311 -311
  95. package/src/components/masterplate/detailsbox.vue +386 -386
  96. package/src/components/masterplate/editgridcard.vue +292 -292
  97. package/src/components/masterplate/editgridcard2.vue +127 -127
  98. package/src/components/masterplate/formcard.vue +105 -105
  99. package/src/components/masterplate/formcardgroupbox.vue +167 -167
  100. package/src/components/masterplate/formdetailtwo.vue +366 -366
  101. package/src/components/masterplate/gridcolset.vue +226 -226
  102. package/src/components/masterplate/index.js +54 -54
  103. package/src/components/masterplate/layouttemplate.vue +51 -51
  104. package/src/components/masterplate/leftlistrightdetails.vue +581 -581
  105. package/src/components/masterplate/leftlistrightlist.vue +464 -464
  106. package/src/components/masterplate/lefttreerightdetails.vue +636 -636
  107. package/src/components/masterplate/levelreport.vue +510 -510
  108. package/src/components/masterplate/listbtntoolbar.vue +276 -276
  109. package/src/components/masterplate/listdetails.vue +768 -768
  110. package/src/components/masterplate/operlog.vue +272 -272
  111. package/src/components/masterplate/options.vue +110 -110
  112. package/src/components/masterplate/page.vue +102 -102
  113. package/src/components/masterplate/promptmessage.vue +73 -73
  114. package/src/components/masterplate/querybar.vue +490 -490
  115. package/src/components/masterplate/report.vue +357 -357
  116. package/src/components/masterplate/rowbtntoolbar.vue +126 -126
  117. package/src/components/masterplate/simpletree.vue +137 -137
  118. package/src/components/masterplate/simpleviewgrid.vue +144 -144
  119. package/src/components/mychart/bar/bar.vue +201 -201
  120. package/src/components/mychart/basechart.vue +190 -190
  121. package/src/components/mychart/complexmychart/barline.vue +153 -153
  122. package/src/components/mychart/gauge/gauge.vue +82 -82
  123. package/src/components/mychart/index.js +8 -8
  124. package/src/components/mychart/line/line.vue +201 -201
  125. package/src/components/mychart/liquidfill/liquidfill.vue +108 -108
  126. package/src/components/mychart/pie/pie.vue +95 -95
  127. package/src/components/mychart/radar/radar.vue +121 -121
  128. package/src/components/mychart/scatter/scatter.vue +75 -75
  129. package/src/components/numberbox/NumberBoxV1.vue +39 -39
  130. package/src/components/numberbox/append.js +11 -11
  131. package/src/components/numberbox/index.js +4 -4
  132. package/src/components/numberbox/numberbox.vue +302 -302
  133. package/src/components/numberbox/numberrangebox.vue +422 -422
  134. package/src/components/picturebox/filebox.vue +369 -369
  135. package/src/components/picturebox/index.js +2 -2
  136. package/src/components/picturebox/picturebox.vue +541 -541
  137. package/src/components/picturebox/uploadbox.vue +164 -164
  138. package/src/components/poptagbox/index.js +1 -1
  139. package/src/components/poptagbox/poptagbox.vue +388 -388
  140. package/src/components/poptextbox/index.js +1 -1
  141. package/src/components/poptextbox/poptextbox.vue +624 -624
  142. package/src/components/radiobox/index.js +1 -1
  143. package/src/components/radiobox/radiogroupbox.vue +75 -75
  144. package/src/components/richtextbox/editor.vue +150 -150
  145. package/src/components/richtextbox/index.js +1 -1
  146. package/src/components/richtextbox/richtextbox.vue +448 -448
  147. package/src/components/textbox/index.js +1 -1
  148. package/src/components/textbox/textbox.vue +97 -97
  149. package/src/components/timebox/index.js +1 -1
  150. package/src/components/timebox/timebox.vue +75 -75
  151. package/src/components/toolbar/ebutton.vue +169 -169
  152. package/src/components/toolbar/index.js +3 -3
  153. package/src/components/toolbar/toolbar.vue +445 -445
  154. package/src/components/tree/CompatTree.vue +297 -297
  155. package/src/components/tree/basetree.vue +1098 -1098
  156. package/src/components/tree/index.js +2 -2
  157. package/src/components/tree/treedata.vue +53 -53
  158. package/src/components/tree/treedatabase.vue +189 -189
  159. package/src/components/upload/billimport.vue +233 -233
  160. package/src/components/upload/index.js +1 -1
  161. package/src/components/videobox/index.js +1 -1
  162. package/src/components/videobox/uploadbox.vue +148 -148
  163. package/src/components/videobox/videobox.vue +503 -503
  164. package/src/components/wrichtextbox/editor.vue +219 -219
  165. package/src/components/wrichtextbox/index.js +1 -1
  166. package/src/components/wrichtextbox/wrichtextbox.vue +62 -62
  167. package/src/index.js +231 -231
  168. package/src/locale/format.js +51 -51
  169. package/src/locale/index.js +63 -63
  170. package/src/locale/lang/zh-CN.js +123 -123
  171. package/src/locale/lang/zh-TW.js +114 -114
  172. package/src/locale/lang/zh-UG.js +115 -115
  173. package/src/locale/lang.js +15 -15
  174. package/src/method/case/case.js +1274 -1274
  175. package/src/method/config/queryconfig.js +24 -24
  176. package/src/method/const/const.js +815 -815
  177. package/src/method/index.js +7 -7
  178. package/src/plugins/theme/theme-variable.css +114 -114
  179. package/src/plugins/vxeTable/index.js +241 -241
  180. package/src/plugins/vxeTable/renderer/components/TableFilterInput.vue +51 -51
  181. package/src/plugins/vxeTable/renderer/filter.js +32 -32
  182. package/src/static/excel/exportexcel.js +626 -626
  183. package/src/static/iview/coustom.js +462 -462
  184. package/src/store/index.js +18 -18
  185. package/src/store/modules/app.js +53 -53
  186. package/src/styles/README.md +3 -3
  187. package/src/styles/common.less +80 -80
  188. package/src/styles/components/anchor.less +74 -74
  189. package/src/styles/components/approval.less +135 -135
  190. package/src/styles/components/button.less +208 -208
  191. package/src/styles/components/card.less +51 -51
  192. package/src/styles/components/content.less +38 -38
  193. package/src/styles/components/font.less +313 -313
  194. package/src/styles/components/form.less +71 -71
  195. package/src/styles/components/iconfont/fonts/iconfont.less +1384 -1384
  196. package/src/styles/components/iconfont/fonts/iconfont.svg +703 -703
  197. package/src/styles/components/index.less +16 -16
  198. package/src/styles/components/input.less +290 -290
  199. package/src/styles/components/modal.less +203 -203
  200. package/src/styles/components/page.less +340 -340
  201. package/src/styles/components/select.less +361 -361
  202. package/src/styles/components/steps.less +367 -367
  203. package/src/styles/components/table.less +544 -544
  204. package/src/styles/components/tabs.less +249 -249
  205. package/src/styles/components/upload.less +82 -82
  206. package/src/styles/custom.less +67 -67
  207. package/src/styles/index.less +6 -6
  208. package/src/styles/pack.less +6 -6
  209. package/src/utils/EfuMessenger.js +155 -155
  210. package/src/utils/assist.js +353 -353
  211. package/src/utils/index.js +1 -1
  212. package/src/utils/random_str.js +10 -10
  213. package/src/components/masterplate/detailgridbox.vue +0 -386
@@ -1,627 +1,627 @@
1
- /* eslint-disable */
2
- import * as XLSX from "xlsx"
3
- import * as XLSXS from "xlsx-style-vite"
4
- import {saveAs} from 'file-saver'
5
-
6
- (function (view) {
7
- "use strict";
8
-
9
- view.URL = view.URL || view.webkitURL;
10
-
11
- if (view.Blob && view.URL) {
12
- try {
13
- new Blob;
14
- return;
15
- } catch (e) {}
16
- }
17
-
18
- // Internally we use a BlobBuilder implementation to base Blob off of
19
- // in order to support older browsers that only have BlobBuilder
20
- var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) {
21
- var
22
- get_class = function(object) {
23
- return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
24
- }
25
- , FakeBlobBuilder = function BlobBuilder() {
26
- this.data = [];
27
- }
28
- , FakeBlob = function Blob(data, type, encoding) {
29
- this.data = data;
30
- this.size = data.length;
31
- this.type = type;
32
- this.encoding = encoding;
33
- }
34
- , FBB_proto = FakeBlobBuilder.prototype
35
- , FB_proto = FakeBlob.prototype
36
- , FileReaderSync = view.FileReaderSync
37
- , FileException = function(type) {
38
- this.code = this[this.name = type];
39
- }
40
- , file_ex_codes = (
41
- "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
42
- + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
43
- ).split(" ")
44
- , file_ex_code = file_ex_codes.length
45
- , real_URL = view.URL || view.webkitURL || view
46
- , real_create_object_URL = real_URL.createObjectURL
47
- , real_revoke_object_URL = real_URL.revokeObjectURL
48
- , URL = real_URL
49
- , btoa = view.btoa
50
- , atob = view.atob
51
-
52
- , ArrayBuffer = view.ArrayBuffer
53
- , Uint8Array = view.Uint8Array
54
- ;
55
- FakeBlob.fake = FB_proto.fake = true;
56
- while (file_ex_code--) {
57
- FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
58
- }
59
- if (!real_URL.createObjectURL) {
60
- URL = view.URL = {};
61
- }
62
- URL.createObjectURL = function(blob) {
63
- var
64
- type = blob.type
65
- , data_URI_header
66
- ;
67
- if (type === null) {
68
- type = "application/octet-stream";
69
- }
70
- if (blob instanceof FakeBlob) {
71
- data_URI_header = "data:" + type;
72
- if (blob.encoding === "base64") {
73
- return data_URI_header + ";base64," + blob.data;
74
- } else if (blob.encoding === "URI") {
75
- return data_URI_header + "," + decodeURIComponent(blob.data);
76
- } if (btoa) {
77
- return data_URI_header + ";base64," + btoa(blob.data);
78
- } else {
79
- return data_URI_header + "," + encodeURIComponent(blob.data);
80
- }
81
- } else if (real_create_object_URL) {
82
- return real_create_object_URL.call(real_URL, blob);
83
- }
84
- };
85
- URL.revokeObjectURL = function(object_URL) {
86
- if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
87
- real_revoke_object_URL.call(real_URL, object_URL);
88
- }
89
- };
90
- FBB_proto.append = function(data/*, endings*/) {
91
- var bb = this.data;
92
- // decode data to a binary string
93
- if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
94
- var
95
- str = ""
96
- , buf = new Uint8Array(data)
97
- , i = 0
98
- , buf_len = buf.length
99
- ;
100
- for (; i < buf_len; i++) {
101
- str += String.fromCharCode(buf[i]);
102
- }
103
- bb.push(str);
104
- } else if (get_class(data) === "Blob" || get_class(data) === "File") {
105
- if (FileReaderSync) {
106
- var fr = new FileReaderSync;
107
- bb.push(fr.readAsBinaryString(data));
108
- } else {
109
- // async FileReader won't work as BlobBuilder is sync
110
- throw new FileException("NOT_READABLE_ERR");
111
- }
112
- } else if (data instanceof FakeBlob) {
113
- if (data.encoding === "base64" && atob) {
114
- bb.push(atob(data.data));
115
- } else if (data.encoding === "URI") {
116
- bb.push(decodeURIComponent(data.data));
117
- } else if (data.encoding === "raw") {
118
- bb.push(data.data);
119
- }
120
- } else {
121
- if (typeof data !== "string") {
122
- data += ""; // convert unsupported types to strings
123
- }
124
- // decode UTF-16 to binary string
125
- bb.push(unescape(encodeURIComponent(data)));
126
- }
127
- };
128
- FBB_proto.getBlob = function(type) {
129
- if (!arguments.length) {
130
- type = null;
131
- }
132
- return new FakeBlob(this.data.join(""), type, "raw");
133
- };
134
- FBB_proto.toString = function() {
135
- return "[object BlobBuilder]";
136
- };
137
- FB_proto.slice = function(start, end, type) {
138
- var args = arguments.length;
139
- if (args < 3) {
140
- type = null;
141
- }
142
- return new FakeBlob(
143
- this.data.slice(start, args > 1 ? end : this.data.length)
144
- , type
145
- , this.encoding
146
- );
147
- };
148
- FB_proto.toString = function() {
149
- return "[object Blob]";
150
- };
151
- FB_proto.close = function() {
152
- this.size = this.data.length = 0;
153
- };
154
- return FakeBlobBuilder;
155
- }(view));
156
-
157
- view.Blob = function Blob(blobParts, options) {
158
- var type = options ? (options.type || "") : "";
159
- var builder = new BlobBuilder();
160
- if (blobParts) {
161
- for (var i = 0, len = blobParts.length; i < len; i++) {
162
- builder.append(blobParts[i]);
163
- }
164
- }
165
- return builder.getBlob(type);
166
- };
167
- }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));
168
-
169
- function generateArray(table) {
170
- var out = [];
171
- var rows = table.querySelectorAll('tr');
172
- var ranges = [];
173
- for (var R = 0; R < rows.length; ++R) {
174
- var outRow = [];
175
- var row = rows[R];
176
- var columns = row.querySelectorAll('td');
177
- for (var C = 0; C < columns.length; ++C) {
178
- var cell = columns[C];
179
- var colspan = cell.getAttribute('colspan');
180
- var rowspan = cell.getAttribute('rowspan');
181
- var cellValue = cell.innerText;
182
- if (cellValue !== "" && cellValue == +cellValue) cellValue = +cellValue;
183
-
184
- //Skip ranges
185
- ranges.forEach(function (range) {
186
- if (R >= range.s.r && R <= range.e.r && outRow.length >= range.s.c && outRow.length <= range.e.c) {
187
- for (var i = 0; i <= range.e.c - range.s.c; ++i) outRow.push(null);
188
- }
189
- });
190
-
191
- //Handle Row Span
192
- if (rowspan || colspan) {
193
- rowspan = rowspan || 1;
194
- colspan = colspan || 1;
195
- ranges.push({s: {r: R, c: outRow.length}, e: {r: R + rowspan - 1, c: outRow.length + colspan - 1}});
196
- }
197
- ;
198
-
199
- //Handle Value
200
- outRow.push(cellValue !== "" ? cellValue : null);
201
-
202
- //Handle Colspan
203
- if (colspan) for (var k = 0; k < colspan - 1; ++k) outRow.push(null);
204
- }
205
- out.push(outRow);
206
- }
207
- return [out, ranges];
208
- };
209
-
210
- function datenum(v, date1904) {
211
- if (date1904) v += 1462;
212
- var epoch = Date.parse(v);
213
- return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
214
- }
215
-
216
- function sheet_from_array_of_arrays(data, opts) {
217
- var ws = {};
218
- var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}};
219
- for (var R = 0; R != data.length; ++R) {
220
- for (var C = 0; C != data[R].length; ++C) {
221
- if (range.s.r > R) range.s.r = R;
222
- if (range.s.c > C) range.s.c = C;
223
- if (range.e.r < R) range.e.r = R;
224
- if (range.e.c < C) range.e.c = C;
225
- var cell = {v: data[R][C]};
226
- if (cell.v == null) continue;
227
- var cell_ref = XLSX.utils.encode_cell({c: C, r: R});
228
-
229
- if (typeof cell.v === 'number') cell.t = 'n';
230
- else if (typeof cell.v === 'boolean') cell.t = 'b';
231
- else if (cell.v instanceof Date) {
232
- cell.t = 'n';
233
- cell.z = XLSX.SSF._table[14];
234
- cell.v = datenum(cell.v);
235
- }
236
- else cell.t = 's';
237
-
238
- ws[cell_ref] = cell;
239
- }
240
- }
241
- if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
242
- return ws;
243
- }
244
-
245
- function Workbook() {
246
- if (!(this instanceof Workbook)) return new Workbook();
247
- this.SheetNames = [];
248
- this.Sheets = {};
249
- }
250
-
251
- function s2ab(s) {
252
- var buf = new ArrayBuffer(s.length);
253
- var view = new Uint8Array(buf);
254
- for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
255
- return buf;
256
- }
257
-
258
- export function export_table_to_excel(id) {
259
- var theTable = document.getElementById(id);
260
- console.log('a')
261
- var oo = generateArray(theTable);
262
- var ranges = oo[1];
263
-
264
- /* original data */
265
- var data = oo[0];
266
- var ws_name = "SheetJS";
267
- console.log(data);
268
-
269
- var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
270
-
271
- /* add ranges to worksheet */
272
- // ws['!cols'] = ['apple', 'banan'];
273
- ws['!merges'] = ranges;
274
-
275
- /* add worksheet to workbook */
276
- wb.SheetNames.push(ws_name);
277
- wb.Sheets[ws_name] = ws;
278
-
279
- var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
280
-
281
- saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx")
282
- }
283
-
284
- function formatJson(names,jsonData) {
285
- return jsonData.map(v => names.map(j =>v[j]));
286
- }
287
-
288
- export function exportExcel(config, jsonData, sheetName, defaultTitle) {
289
- /* original data */
290
- var th = [];
291
- var names = [];
292
- config.forEach(el => {
293
- if (el.label) {
294
- th.push(el.label);
295
- } else {
296
- th.push(el.name);
297
- }
298
- names.push(el.name);
299
- })
300
-
301
- var data = formatJson(names,jsonData);
302
- data.unshift(th);
303
- var ws_name = "SheetJS";
304
- if (sheetName) {
305
- ws_name = sheetName;
306
- }
307
- var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
308
-
309
- /* add worksheet to workbook */
310
- wb.SheetNames.push(ws_name);
311
- wb.Sheets[ws_name] = ws;
312
-
313
- var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
314
- var title = defaultTitle || '列表'
315
- saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx")
316
- }
317
-
318
- export function exportMultiSheetExcel(obj, defaultTitle) {
319
- var wb = new Workbook();
320
- var th = [];
321
- var names = [];
322
- var ws_name = "";
323
- obj.forEach((tmp, index) => {
324
- th = [];
325
- names = [];
326
- tmp.config.forEach(el => {
327
- if (el.label) {
328
- th.push(el.label);
329
- } else {
330
- th.push(el.name);
331
- }
332
- names.push(el.name);
333
- });
334
-
335
- var data = formatJson(names,tmp.data);
336
- data.unshift(th);
337
- ws_name = "SheetJS" + index;
338
- if (tmp.sheetName) {
339
- ws_name = tmp.sheetName;
340
- }
341
- wb.SheetNames.push(ws_name);
342
- wb.Sheets[ws_name] = sheet_from_array_of_arrays(data);
343
- });
344
- var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
345
- var title = defaultTitle || '列表';
346
- saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx");
347
- }
348
-
349
- function getExcelCellConfig(config) {
350
- let pro = {};
351
- pro.alignment = {
352
- vertical: 'center',
353
- wrapText: true
354
- };
355
- if (config.type === 'NumberBox') {
356
- pro.alignment.horizontal = 'right';
357
- if (config.format && config.format.length > 1) {
358
- let numType = config.format[0];
359
- let precisionNum = config.format[1];
360
- let excelstyle = '0';
361
- if (numType === 'n' || numType === 'p') {
362
- excelstyle = '0';
363
- } else if (numType === 'c') {
364
- excelstyle = '¥#,##0';
365
- }
366
- let tempStyle = '';
367
- if (Number(precisionNum) > 0) {
368
- for (let i = 0; i < Number(precisionNum); i++) {
369
- tempStyle = tempStyle + '0';
370
- }
371
- }
372
- if (tempStyle) {
373
- excelstyle = excelstyle + '.'+ tempStyle;
374
- }
375
- if (numType === 'p') {
376
- excelstyle = excelstyle + '%';
377
- }
378
- pro.numFmt = excelstyle;
379
- }
380
- pro.t = 'n';
381
- } else if (config.type === 'DataBox') {
382
- pro.alignment.horizontal = 'center';
383
- let excelstyle = 'yyyy年m月d日';
384
- if (config.vtype === 'datetime') {
385
- excelstyle = 'yyyy年m月d日 h:mm:ss';
386
- }
387
- pro.numFmt = excelstyle;
388
- pro.t = 'd';
389
- } else {
390
- pro.alignment.horizontal = 'left';
391
- pro.numFmt='@';
392
- pro.t = 's';
393
- }
394
- return pro;
395
- }
396
-
397
-
398
- function getHeadPro(names, heads, excelData, mergelist) {
399
- let sIndex = 0;
400
- for (let i=0;i<heads.length;i++) {
401
- let temp = new Array(names.length).fill('');
402
- sIndex = 0;
403
-
404
- let preFsIndes = '';
405
- for (let j=0;j<heads[i].length;j++) {
406
- if (heads[i][j].fIndex || heads[i][j].fIndex === 0) {
407
- let findex = i- 1;
408
- let fsIndex = heads[findex][heads[i][j].fIndex].sIndex;
409
- if (preFsIndes !== fsIndex) {
410
- sIndex = fsIndex;
411
- preFsIndes = fsIndex;
412
- }
413
- }
414
- temp[sIndex] = heads[i][j].label;
415
- heads[i][j].sIndex = sIndex;
416
- let tempMerge = {};
417
- tempMerge.s = {};
418
- tempMerge.s.r = i;
419
- tempMerge.s.c = sIndex;
420
- tempMerge.e = {};
421
- tempMerge.e.r = tempMerge.s.r;
422
- sIndex = sIndex + heads[i][j].num;
423
- if (heads[i][j].num === 1) {
424
- if (i === 0) {
425
- tempMerge.e.r = heads.length -1;
426
- tempMerge.e.c = tempMerge.s.c;
427
- }
428
- } else {
429
- tempMerge.e.c = sIndex - 1;
430
- }
431
- if (i !== heads.length -1) {
432
- mergelist.push(tempMerge);
433
- }
434
- }
435
- excelData.push(temp);
436
- }
437
- }
438
- function getExportConfig (config, head, n, names, fIndex) {
439
- if (config instanceof Array) {
440
- config.forEach(el => {
441
- getExportConfig(el,head, n, names, fIndex);
442
- });
443
- } else {
444
- if (config.visible !== false) {
445
- let obj = {};
446
- obj.label = config.label;
447
- obj.num = 1;
448
- let childRenNum = 0;
449
- let tempIndex = head[n].length;
450
- if (config.children && config.children.length > 0) {
451
- config.children.forEach(el => {
452
- let num = getExportConfig(el, head, n+1, names, tempIndex);
453
- childRenNum = childRenNum + num;
454
- });
455
- obj.num = childRenNum;
456
- } else {
457
- if (config.name) {
458
- obj.name = config.name;
459
- let width = 100;
460
- if (config.width) {
461
- if (config.width > 100) {
462
- width = config.width;
463
- }
464
- } else if (config.maxWidth) {
465
- if (config.maxWidth > 100) {
466
- width = config.maxWidth;
467
- }
468
- } else if (config.minWidth) {
469
- if (config.minWidth > 100) {
470
- width = config.minWidth;
471
- }
472
- }
473
- obj.width = width;
474
- obj.excelPro = getExcelCellConfig(config);
475
- names.push(obj);
476
- }
477
- }
478
- if (fIndex||fIndex === 0) {
479
- if (n !== 0) {
480
- obj.fIndex = fIndex;
481
- }
482
- }
483
- head[n].push(obj);
484
- return obj.num;
485
- } else {
486
- return 0;
487
- }
488
- }
489
- }
490
-
491
- export function exportExcelStyle(config, data, headNum, filename) {
492
- let head = [];
493
- for (let i=0;i<headNum; i++) {
494
- head.push([]);
495
- }
496
- let num = 0;
497
- let names = [];
498
- getExportConfig(config,head,num,names);
499
- let mergeslist = [];
500
- // 需要导出的数据
501
- let excelData = [];
502
- getHeadPro(names, head, excelData, mergeslist);
503
- let widthCol = [];
504
- names.forEach(el => {
505
- widthCol.push({wpx: el.width});
506
- });
507
- data.forEach(el => {
508
- let temp = [];
509
- names.forEach(el2 => {
510
- if (el2.excelPro.t === 'n') {
511
- temp.push(Number(el[el2.name]));
512
- } else if (el2.excelPro.t === 'd') {
513
- let value = datenum(new Date(el[el2.name]));
514
- temp.push(value);
515
- el2.excelPro.t = 'n';
516
- } else {
517
- temp.push(el[el2.name]);
518
- }
519
- })
520
- excelData.push(temp);
521
- });
522
- let namesNum = names.length;
523
-
524
-
525
- let defaultHeadCellStyle = {
526
- // 字体
527
- font: {
528
- name: '宋体',
529
- sz: 9,
530
- bold: true
531
- },
532
- border: {
533
- top: {
534
- style: 'thin'
535
- },
536
- bottom: {
537
- style: 'thin'
538
- },
539
- left: {
540
- style: 'thin'
541
- },
542
- right: {
543
- style: 'thin'
544
- }
545
- },
546
- alignment: {
547
- horizontal: 'center',
548
- vertical: 'center',
549
- wrapText: true
550
- }
551
- }
552
- let defaultCellStyle = {
553
- // 字体
554
- font: {
555
- name: '宋体',
556
- sz: 9
557
- },
558
- border: {
559
- top: {
560
- style: 'thin'
561
- },
562
- bottom: {
563
- style: 'thin'
564
- },
565
- left: {
566
- style: 'thin'
567
- },
568
- right: {
569
- style: 'thin'
570
- }
571
- }
572
- };
573
-
574
- // 导出的excel文件名
575
- let tempfilename = 'example.xlsx'
576
- if (filename) {
577
- tempfilename = filename;
578
- }
579
-
580
- // Excel第一个sheet的名称
581
- const ws_name = 'Sheet1'
582
- const wb = XLSX.utils.book_new();
583
- const ws = XLSX.utils.aoa_to_sheet(excelData)
584
- XLSX.utils.book_append_sheet(wb, ws, ws_name) // 将数据添加到工作薄
585
-
586
-
587
- // 设置标题行单元格合并
588
- // s即start, e即end, r即row, c即column
589
- // 合并从--0行0列开始,到0行3列
590
- if (mergeslist.length > 0) {
591
- ws['!merges'] = mergeslist
592
- }
593
- let x=0;
594
- // 可以遍历全部单元格,进行样式设置
595
- for (let i in ws) {
596
- if (i === '!merges' || i === '!ref' || i === '!cols') continue;
597
- ws[i].s = defaultHeadCellStyle
598
- if (x < namesNum*headNum) {
599
- ws[i].s = defaultHeadCellStyle
600
- } else {
601
- let pro =Object.assign({},{},defaultCellStyle);
602
- let num = x%namesNum;
603
- Object.assign(pro,names[num].excelPro);
604
- ws[i].s = pro
605
- }
606
- x++;
607
-
608
- }
609
-
610
- // 设置单元格宽度
611
- ws['!cols'] = widthCol;
612
-
613
-
614
- // 导出Excel, 注意这里用到的是XLSXS对象
615
- let wbout = XLSXS.write(wb, {
616
- bookType: 'xlsx',
617
- bookSST: false,
618
- type: 'binary'
619
- })
620
- saveAs(
621
- new Blob([s2ab(wbout)], {
622
- type: 'application/octet-stream'
623
- }),
624
- tempfilename
625
- )
626
- }
1
+ /* eslint-disable */
2
+ import * as XLSX from "xlsx"
3
+ import * as XLSXS from "xlsx-style-vite"
4
+ import {saveAs} from 'file-saver'
5
+
6
+ (function (view) {
7
+ "use strict";
8
+
9
+ view.URL = view.URL || view.webkitURL;
10
+
11
+ if (view.Blob && view.URL) {
12
+ try {
13
+ new Blob;
14
+ return;
15
+ } catch (e) {}
16
+ }
17
+
18
+ // Internally we use a BlobBuilder implementation to base Blob off of
19
+ // in order to support older browsers that only have BlobBuilder
20
+ var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) {
21
+ var
22
+ get_class = function(object) {
23
+ return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
24
+ }
25
+ , FakeBlobBuilder = function BlobBuilder() {
26
+ this.data = [];
27
+ }
28
+ , FakeBlob = function Blob(data, type, encoding) {
29
+ this.data = data;
30
+ this.size = data.length;
31
+ this.type = type;
32
+ this.encoding = encoding;
33
+ }
34
+ , FBB_proto = FakeBlobBuilder.prototype
35
+ , FB_proto = FakeBlob.prototype
36
+ , FileReaderSync = view.FileReaderSync
37
+ , FileException = function(type) {
38
+ this.code = this[this.name = type];
39
+ }
40
+ , file_ex_codes = (
41
+ "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
42
+ + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
43
+ ).split(" ")
44
+ , file_ex_code = file_ex_codes.length
45
+ , real_URL = view.URL || view.webkitURL || view
46
+ , real_create_object_URL = real_URL.createObjectURL
47
+ , real_revoke_object_URL = real_URL.revokeObjectURL
48
+ , URL = real_URL
49
+ , btoa = view.btoa
50
+ , atob = view.atob
51
+
52
+ , ArrayBuffer = view.ArrayBuffer
53
+ , Uint8Array = view.Uint8Array
54
+ ;
55
+ FakeBlob.fake = FB_proto.fake = true;
56
+ while (file_ex_code--) {
57
+ FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
58
+ }
59
+ if (!real_URL.createObjectURL) {
60
+ URL = view.URL = {};
61
+ }
62
+ URL.createObjectURL = function(blob) {
63
+ var
64
+ type = blob.type
65
+ , data_URI_header
66
+ ;
67
+ if (type === null) {
68
+ type = "application/octet-stream";
69
+ }
70
+ if (blob instanceof FakeBlob) {
71
+ data_URI_header = "data:" + type;
72
+ if (blob.encoding === "base64") {
73
+ return data_URI_header + ";base64," + blob.data;
74
+ } else if (blob.encoding === "URI") {
75
+ return data_URI_header + "," + decodeURIComponent(blob.data);
76
+ } if (btoa) {
77
+ return data_URI_header + ";base64," + btoa(blob.data);
78
+ } else {
79
+ return data_URI_header + "," + encodeURIComponent(blob.data);
80
+ }
81
+ } else if (real_create_object_URL) {
82
+ return real_create_object_URL.call(real_URL, blob);
83
+ }
84
+ };
85
+ URL.revokeObjectURL = function(object_URL) {
86
+ if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
87
+ real_revoke_object_URL.call(real_URL, object_URL);
88
+ }
89
+ };
90
+ FBB_proto.append = function(data/*, endings*/) {
91
+ var bb = this.data;
92
+ // decode data to a binary string
93
+ if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
94
+ var
95
+ str = ""
96
+ , buf = new Uint8Array(data)
97
+ , i = 0
98
+ , buf_len = buf.length
99
+ ;
100
+ for (; i < buf_len; i++) {
101
+ str += String.fromCharCode(buf[i]);
102
+ }
103
+ bb.push(str);
104
+ } else if (get_class(data) === "Blob" || get_class(data) === "File") {
105
+ if (FileReaderSync) {
106
+ var fr = new FileReaderSync;
107
+ bb.push(fr.readAsBinaryString(data));
108
+ } else {
109
+ // async FileReader won't work as BlobBuilder is sync
110
+ throw new FileException("NOT_READABLE_ERR");
111
+ }
112
+ } else if (data instanceof FakeBlob) {
113
+ if (data.encoding === "base64" && atob) {
114
+ bb.push(atob(data.data));
115
+ } else if (data.encoding === "URI") {
116
+ bb.push(decodeURIComponent(data.data));
117
+ } else if (data.encoding === "raw") {
118
+ bb.push(data.data);
119
+ }
120
+ } else {
121
+ if (typeof data !== "string") {
122
+ data += ""; // convert unsupported types to strings
123
+ }
124
+ // decode UTF-16 to binary string
125
+ bb.push(unescape(encodeURIComponent(data)));
126
+ }
127
+ };
128
+ FBB_proto.getBlob = function(type) {
129
+ if (!arguments.length) {
130
+ type = null;
131
+ }
132
+ return new FakeBlob(this.data.join(""), type, "raw");
133
+ };
134
+ FBB_proto.toString = function() {
135
+ return "[object BlobBuilder]";
136
+ };
137
+ FB_proto.slice = function(start, end, type) {
138
+ var args = arguments.length;
139
+ if (args < 3) {
140
+ type = null;
141
+ }
142
+ return new FakeBlob(
143
+ this.data.slice(start, args > 1 ? end : this.data.length)
144
+ , type
145
+ , this.encoding
146
+ );
147
+ };
148
+ FB_proto.toString = function() {
149
+ return "[object Blob]";
150
+ };
151
+ FB_proto.close = function() {
152
+ this.size = this.data.length = 0;
153
+ };
154
+ return FakeBlobBuilder;
155
+ }(view));
156
+
157
+ view.Blob = function Blob(blobParts, options) {
158
+ var type = options ? (options.type || "") : "";
159
+ var builder = new BlobBuilder();
160
+ if (blobParts) {
161
+ for (var i = 0, len = blobParts.length; i < len; i++) {
162
+ builder.append(blobParts[i]);
163
+ }
164
+ }
165
+ return builder.getBlob(type);
166
+ };
167
+ }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));
168
+
169
+ function generateArray(table) {
170
+ var out = [];
171
+ var rows = table.querySelectorAll('tr');
172
+ var ranges = [];
173
+ for (var R = 0; R < rows.length; ++R) {
174
+ var outRow = [];
175
+ var row = rows[R];
176
+ var columns = row.querySelectorAll('td');
177
+ for (var C = 0; C < columns.length; ++C) {
178
+ var cell = columns[C];
179
+ var colspan = cell.getAttribute('colspan');
180
+ var rowspan = cell.getAttribute('rowspan');
181
+ var cellValue = cell.innerText;
182
+ if (cellValue !== "" && cellValue == +cellValue) cellValue = +cellValue;
183
+
184
+ //Skip ranges
185
+ ranges.forEach(function (range) {
186
+ if (R >= range.s.r && R <= range.e.r && outRow.length >= range.s.c && outRow.length <= range.e.c) {
187
+ for (var i = 0; i <= range.e.c - range.s.c; ++i) outRow.push(null);
188
+ }
189
+ });
190
+
191
+ //Handle Row Span
192
+ if (rowspan || colspan) {
193
+ rowspan = rowspan || 1;
194
+ colspan = colspan || 1;
195
+ ranges.push({s: {r: R, c: outRow.length}, e: {r: R + rowspan - 1, c: outRow.length + colspan - 1}});
196
+ }
197
+ ;
198
+
199
+ //Handle Value
200
+ outRow.push(cellValue !== "" ? cellValue : null);
201
+
202
+ //Handle Colspan
203
+ if (colspan) for (var k = 0; k < colspan - 1; ++k) outRow.push(null);
204
+ }
205
+ out.push(outRow);
206
+ }
207
+ return [out, ranges];
208
+ };
209
+
210
+ function datenum(v, date1904) {
211
+ if (date1904) v += 1462;
212
+ var epoch = Date.parse(v);
213
+ return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
214
+ }
215
+
216
+ function sheet_from_array_of_arrays(data, opts) {
217
+ var ws = {};
218
+ var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}};
219
+ for (var R = 0; R != data.length; ++R) {
220
+ for (var C = 0; C != data[R].length; ++C) {
221
+ if (range.s.r > R) range.s.r = R;
222
+ if (range.s.c > C) range.s.c = C;
223
+ if (range.e.r < R) range.e.r = R;
224
+ if (range.e.c < C) range.e.c = C;
225
+ var cell = {v: data[R][C]};
226
+ if (cell.v == null) continue;
227
+ var cell_ref = XLSX.utils.encode_cell({c: C, r: R});
228
+
229
+ if (typeof cell.v === 'number') cell.t = 'n';
230
+ else if (typeof cell.v === 'boolean') cell.t = 'b';
231
+ else if (cell.v instanceof Date) {
232
+ cell.t = 'n';
233
+ cell.z = XLSX.SSF._table[14];
234
+ cell.v = datenum(cell.v);
235
+ }
236
+ else cell.t = 's';
237
+
238
+ ws[cell_ref] = cell;
239
+ }
240
+ }
241
+ if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
242
+ return ws;
243
+ }
244
+
245
+ function Workbook() {
246
+ if (!(this instanceof Workbook)) return new Workbook();
247
+ this.SheetNames = [];
248
+ this.Sheets = {};
249
+ }
250
+
251
+ function s2ab(s) {
252
+ var buf = new ArrayBuffer(s.length);
253
+ var view = new Uint8Array(buf);
254
+ for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
255
+ return buf;
256
+ }
257
+
258
+ export function export_table_to_excel(id) {
259
+ var theTable = document.getElementById(id);
260
+ console.log('a')
261
+ var oo = generateArray(theTable);
262
+ var ranges = oo[1];
263
+
264
+ /* original data */
265
+ var data = oo[0];
266
+ var ws_name = "SheetJS";
267
+ console.log(data);
268
+
269
+ var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
270
+
271
+ /* add ranges to worksheet */
272
+ // ws['!cols'] = ['apple', 'banan'];
273
+ ws['!merges'] = ranges;
274
+
275
+ /* add worksheet to workbook */
276
+ wb.SheetNames.push(ws_name);
277
+ wb.Sheets[ws_name] = ws;
278
+
279
+ var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
280
+
281
+ saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx")
282
+ }
283
+
284
+ function formatJson(names,jsonData) {
285
+ return jsonData.map(v => names.map(j =>v[j]));
286
+ }
287
+
288
+ export function exportExcel(config, jsonData, sheetName, defaultTitle) {
289
+ /* original data */
290
+ var th = [];
291
+ var names = [];
292
+ config.forEach(el => {
293
+ if (el.label) {
294
+ th.push(el.label);
295
+ } else {
296
+ th.push(el.name);
297
+ }
298
+ names.push(el.name);
299
+ })
300
+
301
+ var data = formatJson(names,jsonData);
302
+ data.unshift(th);
303
+ var ws_name = "SheetJS";
304
+ if (sheetName) {
305
+ ws_name = sheetName;
306
+ }
307
+ var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
308
+
309
+ /* add worksheet to workbook */
310
+ wb.SheetNames.push(ws_name);
311
+ wb.Sheets[ws_name] = ws;
312
+
313
+ var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
314
+ var title = defaultTitle || '列表'
315
+ saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx")
316
+ }
317
+
318
+ export function exportMultiSheetExcel(obj, defaultTitle) {
319
+ var wb = new Workbook();
320
+ var th = [];
321
+ var names = [];
322
+ var ws_name = "";
323
+ obj.forEach((tmp, index) => {
324
+ th = [];
325
+ names = [];
326
+ tmp.config.forEach(el => {
327
+ if (el.label) {
328
+ th.push(el.label);
329
+ } else {
330
+ th.push(el.name);
331
+ }
332
+ names.push(el.name);
333
+ });
334
+
335
+ var data = formatJson(names,tmp.data);
336
+ data.unshift(th);
337
+ ws_name = "SheetJS" + index;
338
+ if (tmp.sheetName) {
339
+ ws_name = tmp.sheetName;
340
+ }
341
+ wb.SheetNames.push(ws_name);
342
+ wb.Sheets[ws_name] = sheet_from_array_of_arrays(data);
343
+ });
344
+ var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
345
+ var title = defaultTitle || '列表';
346
+ saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx");
347
+ }
348
+
349
+ function getExcelCellConfig(config) {
350
+ let pro = {};
351
+ pro.alignment = {
352
+ vertical: 'center',
353
+ wrapText: true
354
+ };
355
+ if (config.type === 'NumberBox') {
356
+ pro.alignment.horizontal = 'right';
357
+ if (config.format && config.format.length > 1) {
358
+ let numType = config.format[0];
359
+ let precisionNum = config.format[1];
360
+ let excelstyle = '0';
361
+ if (numType === 'n' || numType === 'p') {
362
+ excelstyle = '0';
363
+ } else if (numType === 'c') {
364
+ excelstyle = '¥#,##0';
365
+ }
366
+ let tempStyle = '';
367
+ if (Number(precisionNum) > 0) {
368
+ for (let i = 0; i < Number(precisionNum); i++) {
369
+ tempStyle = tempStyle + '0';
370
+ }
371
+ }
372
+ if (tempStyle) {
373
+ excelstyle = excelstyle + '.'+ tempStyle;
374
+ }
375
+ if (numType === 'p') {
376
+ excelstyle = excelstyle + '%';
377
+ }
378
+ pro.numFmt = excelstyle;
379
+ }
380
+ pro.t = 'n';
381
+ } else if (config.type === 'DataBox') {
382
+ pro.alignment.horizontal = 'center';
383
+ let excelstyle = 'yyyy年m月d日';
384
+ if (config.vtype === 'datetime') {
385
+ excelstyle = 'yyyy年m月d日 h:mm:ss';
386
+ }
387
+ pro.numFmt = excelstyle;
388
+ pro.t = 'd';
389
+ } else {
390
+ pro.alignment.horizontal = 'left';
391
+ pro.numFmt='@';
392
+ pro.t = 's';
393
+ }
394
+ return pro;
395
+ }
396
+
397
+
398
+ function getHeadPro(names, heads, excelData, mergelist) {
399
+ let sIndex = 0;
400
+ for (let i=0;i<heads.length;i++) {
401
+ let temp = new Array(names.length).fill('');
402
+ sIndex = 0;
403
+
404
+ let preFsIndes = '';
405
+ for (let j=0;j<heads[i].length;j++) {
406
+ if (heads[i][j].fIndex || heads[i][j].fIndex === 0) {
407
+ let findex = i- 1;
408
+ let fsIndex = heads[findex][heads[i][j].fIndex].sIndex;
409
+ if (preFsIndes !== fsIndex) {
410
+ sIndex = fsIndex;
411
+ preFsIndes = fsIndex;
412
+ }
413
+ }
414
+ temp[sIndex] = heads[i][j].label;
415
+ heads[i][j].sIndex = sIndex;
416
+ let tempMerge = {};
417
+ tempMerge.s = {};
418
+ tempMerge.s.r = i;
419
+ tempMerge.s.c = sIndex;
420
+ tempMerge.e = {};
421
+ tempMerge.e.r = tempMerge.s.r;
422
+ sIndex = sIndex + heads[i][j].num;
423
+ if (heads[i][j].num === 1) {
424
+ if (i === 0) {
425
+ tempMerge.e.r = heads.length -1;
426
+ tempMerge.e.c = tempMerge.s.c;
427
+ }
428
+ } else {
429
+ tempMerge.e.c = sIndex - 1;
430
+ }
431
+ if (i !== heads.length -1) {
432
+ mergelist.push(tempMerge);
433
+ }
434
+ }
435
+ excelData.push(temp);
436
+ }
437
+ }
438
+ function getExportConfig (config, head, n, names, fIndex) {
439
+ if (config instanceof Array) {
440
+ config.forEach(el => {
441
+ getExportConfig(el,head, n, names, fIndex);
442
+ });
443
+ } else {
444
+ if (config.visible !== false) {
445
+ let obj = {};
446
+ obj.label = config.label;
447
+ obj.num = 1;
448
+ let childRenNum = 0;
449
+ let tempIndex = head[n].length;
450
+ if (config.children && config.children.length > 0) {
451
+ config.children.forEach(el => {
452
+ let num = getExportConfig(el, head, n+1, names, tempIndex);
453
+ childRenNum = childRenNum + num;
454
+ });
455
+ obj.num = childRenNum;
456
+ } else {
457
+ if (config.name) {
458
+ obj.name = config.name;
459
+ let width = 100;
460
+ if (config.width) {
461
+ if (config.width > 100) {
462
+ width = config.width;
463
+ }
464
+ } else if (config.maxWidth) {
465
+ if (config.maxWidth > 100) {
466
+ width = config.maxWidth;
467
+ }
468
+ } else if (config.minWidth) {
469
+ if (config.minWidth > 100) {
470
+ width = config.minWidth;
471
+ }
472
+ }
473
+ obj.width = width;
474
+ obj.excelPro = getExcelCellConfig(config);
475
+ names.push(obj);
476
+ }
477
+ }
478
+ if (fIndex||fIndex === 0) {
479
+ if (n !== 0) {
480
+ obj.fIndex = fIndex;
481
+ }
482
+ }
483
+ head[n].push(obj);
484
+ return obj.num;
485
+ } else {
486
+ return 0;
487
+ }
488
+ }
489
+ }
490
+
491
+ export function exportExcelStyle(config, data, headNum, filename) {
492
+ let head = [];
493
+ for (let i=0;i<headNum; i++) {
494
+ head.push([]);
495
+ }
496
+ let num = 0;
497
+ let names = [];
498
+ getExportConfig(config,head,num,names);
499
+ let mergeslist = [];
500
+ // 需要导出的数据
501
+ let excelData = [];
502
+ getHeadPro(names, head, excelData, mergeslist);
503
+ let widthCol = [];
504
+ names.forEach(el => {
505
+ widthCol.push({wpx: el.width});
506
+ });
507
+ data.forEach(el => {
508
+ let temp = [];
509
+ names.forEach(el2 => {
510
+ if (el2.excelPro.t === 'n') {
511
+ temp.push(Number(el[el2.name]));
512
+ } else if (el2.excelPro.t === 'd') {
513
+ let value = datenum(new Date(el[el2.name]));
514
+ temp.push(value);
515
+ el2.excelPro.t = 'n';
516
+ } else {
517
+ temp.push(el[el2.name]);
518
+ }
519
+ })
520
+ excelData.push(temp);
521
+ });
522
+ let namesNum = names.length;
523
+
524
+
525
+ let defaultHeadCellStyle = {
526
+ // 字体
527
+ font: {
528
+ name: '宋体',
529
+ sz: 9,
530
+ bold: true
531
+ },
532
+ border: {
533
+ top: {
534
+ style: 'thin'
535
+ },
536
+ bottom: {
537
+ style: 'thin'
538
+ },
539
+ left: {
540
+ style: 'thin'
541
+ },
542
+ right: {
543
+ style: 'thin'
544
+ }
545
+ },
546
+ alignment: {
547
+ horizontal: 'center',
548
+ vertical: 'center',
549
+ wrapText: true
550
+ }
551
+ }
552
+ let defaultCellStyle = {
553
+ // 字体
554
+ font: {
555
+ name: '宋体',
556
+ sz: 9
557
+ },
558
+ border: {
559
+ top: {
560
+ style: 'thin'
561
+ },
562
+ bottom: {
563
+ style: 'thin'
564
+ },
565
+ left: {
566
+ style: 'thin'
567
+ },
568
+ right: {
569
+ style: 'thin'
570
+ }
571
+ }
572
+ };
573
+
574
+ // 导出的excel文件名
575
+ let tempfilename = 'example.xlsx'
576
+ if (filename) {
577
+ tempfilename = filename;
578
+ }
579
+
580
+ // Excel第一个sheet的名称
581
+ const ws_name = 'Sheet1'
582
+ const wb = XLSX.utils.book_new();
583
+ const ws = XLSX.utils.aoa_to_sheet(excelData)
584
+ XLSX.utils.book_append_sheet(wb, ws, ws_name) // 将数据添加到工作薄
585
+
586
+
587
+ // 设置标题行单元格合并
588
+ // s即start, e即end, r即row, c即column
589
+ // 合并从--0行0列开始,到0行3列
590
+ if (mergeslist.length > 0) {
591
+ ws['!merges'] = mergeslist
592
+ }
593
+ let x=0;
594
+ // 可以遍历全部单元格,进行样式设置
595
+ for (let i in ws) {
596
+ if (i === '!merges' || i === '!ref' || i === '!cols') continue;
597
+ ws[i].s = defaultHeadCellStyle
598
+ if (x < namesNum*headNum) {
599
+ ws[i].s = defaultHeadCellStyle
600
+ } else {
601
+ let pro =Object.assign({},{},defaultCellStyle);
602
+ let num = x%namesNum;
603
+ Object.assign(pro,names[num].excelPro);
604
+ ws[i].s = pro
605
+ }
606
+ x++;
607
+
608
+ }
609
+
610
+ // 设置单元格宽度
611
+ ws['!cols'] = widthCol;
612
+
613
+
614
+ // 导出Excel, 注意这里用到的是XLSXS对象
615
+ let wbout = XLSXS.write(wb, {
616
+ bookType: 'xlsx',
617
+ bookSST: false,
618
+ type: 'binary'
619
+ })
620
+ saveAs(
621
+ new Blob([s2ab(wbout)], {
622
+ type: 'application/octet-stream'
623
+ }),
624
+ tempfilename
625
+ )
626
+ }
627
627