cloud-web-corejs 1.0.54-dev.542 → 1.0.54-dev.544

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.
@@ -0,0 +1,298 @@
1
+ <template>
2
+ <div style="height: 100%">
3
+ <div
4
+ :id="containerId"
5
+ :key="containerId"
6
+ style="
7
+ margin: 0px;
8
+ padding: 0px;
9
+ height: 100%;
10
+ width: 100%;
11
+ left: 0px;
12
+ top: 30px;
13
+ bottom: 0px;
14
+ "
15
+ ></div>
16
+ <div
17
+ v-show="isMaskShow"
18
+ style="
19
+ position: absolute;
20
+ z-index: 1000000;
21
+ left: 0px;
22
+ top: 0px;
23
+ bottom: 0px;
24
+ right: 0px;
25
+ background: rgba(255, 255, 255, 0.8);
26
+ text-align: center;
27
+ font-size: 40px;
28
+ align-items: center;
29
+ justify-content: center;
30
+ display: flex;
31
+ "
32
+ >
33
+ Downloading
34
+ </div>
35
+ </div>
36
+ </template>
37
+
38
+ <script>
39
+ import LuckyExcel from "luckyexcel";
40
+ //导入库export.js 这个文件是es6的,不能在普通的HTML文件直接引入js文件(虽然都是js文件,但是有区别,具体请百度es6与es5)!需要把es6转es5才可以直接引入使用!
41
+ import { exportExcel, generateExcelFile } from "./export";
42
+ import { saveAs } from "file-saver";
43
+
44
+ export default {
45
+ name: "luckysheet",
46
+ props: {
47
+ options: {
48
+ type: Object,
49
+ default: () => {},
50
+ },
51
+ data: {
52
+ type: Array,
53
+ default: () => [],
54
+ },
55
+ },
56
+ data() {
57
+ return {
58
+ selected: "",
59
+ /* itemOptions: [
60
+ {
61
+ text: "Money Manager.xlsx",
62
+ value: "https://minio.cnbabylon.com/public/luckysheet/money-manager-2.xlsx",
63
+ },
64
+ {
65
+ text: "Activity costs tracker.xlsx",
66
+ value:
67
+ "https://minio.cnbabylon.com/public/luckysheet/Activity%20costs%20tracker.xlsx",
68
+ },
69
+ {
70
+ text: "House cleaning checklist.xlsx",
71
+ value:
72
+ "https://minio.cnbabylon.com/public/luckysheet/House%20cleaning%20checklist.xlsx",
73
+ },
74
+ {
75
+ text: "Student assignment planner.xlsx",
76
+ value:
77
+ "https://minio.cnbabylon.com/public/luckysheet/Student%20assignment%20planner.xlsx",
78
+ },
79
+ {
80
+ text: "Credit card tracker.xlsx",
81
+ value:
82
+ "https://minio.cnbabylon.com/public/luckysheet/Credit%20card%20tracker.xlsx",
83
+ },
84
+ {
85
+ text: "Blue timesheet.xlsx",
86
+ value: "https://minio.cnbabylon.com/public/luckysheet/Blue%20timesheet.xlsx",
87
+ },
88
+ {
89
+ text: "Student calendar (Mon).xlsx",
90
+ value:
91
+ "https://minio.cnbabylon.com/public/luckysheet/Student%20calendar%20%28Mon%29.xlsx",
92
+ },
93
+ {
94
+ text: "Blue mileage and expense report.xlsx",
95
+ value:
96
+ "https://minio.cnbabylon.com/public/luckysheet/Blue%20mileage%20and%20expense%20report.xlsx",
97
+ },
98
+ ], */
99
+ isMaskShow: false,
100
+ // 生成随机ID,避免多个组件实例之间的ID冲突
101
+ containerId: "luckysheet-" + Math.random().toString(36).substr(2, 9),
102
+ };
103
+ },
104
+ beforeDestroy() {
105
+ if (luckysheet) {
106
+ // luckysheet.destroy();
107
+ }
108
+ },
109
+ mounted() {
110
+ // In some cases, you need to use $nextTick
111
+ // this.$nextTick(() => {
112
+ let config = this.options.config || {};
113
+ let data = this.data.length > 0 ? this.data : null;
114
+ if (!data) {
115
+ data = [
116
+ {
117
+ name: "Sheet1",
118
+ color: "",
119
+ status: "1",
120
+ order: "0",
121
+ data: [],
122
+ config: {},
123
+ index: 0,
124
+ },
125
+ ];
126
+ }
127
+ luckysheet.create({
128
+ container: this.containerId,
129
+ lang: "zh",
130
+ showinfobar: false,
131
+ data: data,
132
+ ...config,
133
+ });
134
+
135
+ // });
136
+ },
137
+ methods: {
138
+ generateExcelFile(callback) {
139
+ // 检查luckysheet是否存在
140
+ if (!luckysheet) {
141
+ console.error("luckysheet未初始化");
142
+ return;
143
+ }
144
+
145
+ try {
146
+ // 获取luckysheet数据
147
+ if (luckysheet.getLuckysheetfile) {
148
+ const excelData = luckysheet.getLuckysheetfile();
149
+ console.log("获取Excel数据成功", excelData);
150
+
151
+ // 生成Excel文件对象
152
+ generateExcelFile(excelData, "测试文件")
153
+ .then((file) => {
154
+ callback && callback(file);
155
+ // console.log("生成Excel文件对象成功", file);
156
+ // console.log("文件名:", file.name);
157
+ // console.log("文件大小:", file.size);
158
+ // console.log("文件类型:", file.type);
159
+
160
+ // 这里可以使用file对象进行上传等操作
161
+ // 例如:uploadFile(file);
162
+ // const fileName = `电子表格_${new Date().getTime()}.xlsx`;
163
+ // saveAs(file, fileName);
164
+ })
165
+ .catch((error) => {
166
+ console.error("生成Excel文件对象失败:", error);
167
+ });
168
+ } else {
169
+ console.error("luckysheet不支持getLuckysheetfile方法");
170
+ }
171
+ } catch (error) {
172
+ console.error("生成Excel文件对象失败:", error);
173
+ }
174
+ },
175
+ uploadExcel(evt) {
176
+ const files = evt.target.files;
177
+ if (files == null || files.length == 0) {
178
+ alert("No files wait for import");
179
+ return;
180
+ }
181
+
182
+ let name = files[0].name;
183
+ let suffixArr = name.split("."),
184
+ suffix = suffixArr[suffixArr.length - 1];
185
+ if (suffix != "xlsx") {
186
+ alert("Currently only supports the import of xlsx files");
187
+ return;
188
+ }
189
+ const self = this;
190
+ LuckyExcel.transformExcelToLucky(files[0], function (exportJson, luckysheetfile) {
191
+ if (exportJson.sheets == null || exportJson.sheets.length == 0) {
192
+ alert(
193
+ "Failed to read the content of the excel file, currently does not support xls files!"
194
+ );
195
+ return;
196
+ }
197
+ luckysheet.destroy();
198
+
199
+ luckysheet.create({
200
+ container: self.containerId, //使用当前组件的容器ID
201
+ showinfobar: false,
202
+ data: exportJson.sheets,
203
+ title: exportJson.info.name,
204
+ userInfo: exportJson.info.name.creator,
205
+ });
206
+ });
207
+ },
208
+ getValue() {
209
+ luckysheet.exitEditMode();
210
+ let sheetData = luckysheet.getluckysheetfile();
211
+ return sheetData;
212
+ // return this.getJson().data;
213
+ },
214
+ /* selectExcel(evt) {
215
+ const value = this.selected;
216
+ const name = evt.target.itemOptions[evt.target.selectedIndex].innerText;
217
+
218
+ if (value == "") {
219
+ return;
220
+ }
221
+ this.isMaskShow = true;
222
+
223
+ LuckyExcel.transformExcelToLuckyByUrl(value, name, (exportJson, luckysheetfile) => {
224
+ if (exportJson.sheets == null || exportJson.sheets.length == 0) {
225
+ alert(
226
+ "Failed to read the content of the excel file, currently does not support xls files!"
227
+ );
228
+ return;
229
+ }
230
+
231
+ this.isMaskShow = false;
232
+ window.luckysheet.destroy();
233
+
234
+ window.luckysheet.create({
235
+ container: "luckysheet", //luckysheet is the container id
236
+ showinfobar: false,
237
+ data: exportJson.sheets,
238
+ title: exportJson.info.name,
239
+ userInfo: exportJson.info.name.creator,
240
+ });
241
+ });
242
+ }, */
243
+ downloadExcel() {
244
+ // const value = this.selected;;
245
+ //
246
+ // if(value.length==0){
247
+ // alert("Please select a demo file");
248
+ // return;
249
+ // }
250
+ //
251
+ // var elemIF = document.getElementById("Lucky-download-frame");
252
+ // if(elemIF==null){
253
+ // elemIF = document.createElement("iframe");
254
+ // elemIF.style.display = "none";
255
+ // elemIF.id = "Lucky-download-frame";
256
+ // document.body.appendChild(elemIF);
257
+ // }
258
+ // elemIF.src = value;
259
+ exportExcel(luckysheet.getAllSheets(), "下载");
260
+ // testaaa();
261
+ },
262
+ getJson() {
263
+ /* const cell = document.querySelector(".luckysheet-cell.luckysheet-cell-selected");
264
+ if (cell) {
265
+ cell.focus();
266
+ } */
267
+ // luckysheet.exitEditMode();
268
+ luckysheet.exitEditMode();
269
+ let json = luckysheet.toJson();
270
+ // luckysheet.enterEditMode();
271
+ return json;
272
+ },
273
+ },
274
+ };
275
+ </script>
276
+
277
+ <!-- Add "scoped" attribute to limit CSS to this component only -->
278
+ <style scoped>
279
+ h3 {
280
+ margin: 40px 0 0;
281
+ }
282
+ ul {
283
+ list-style-type: none;
284
+ padding: 0;
285
+ }
286
+ li {
287
+ display: inline-block;
288
+ margin: 0 10px;
289
+ }
290
+ a {
291
+ color: #42b983;
292
+ }
293
+ </style>
294
+ <style>
295
+ #luckysheet-icon-morebtn-div {
296
+ z-index: 10030 !important;
297
+ }
298
+ </style>