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

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,390 @@
1
+ // import { createCellPos } from './translateNumToLetter'
2
+ const Excel = require('exceljs')
3
+
4
+ import FileSaver from 'file-saver'
5
+ export var testaaa = function (){
6
+ console.log("...");
7
+ }
8
+ export var exportExcel = function(luckysheet, value) {
9
+ // 参数为luckysheet.getluckysheetfile()获取的对象
10
+ // 1.创建工作簿,可以为工作簿添加属性
11
+ const workbook = new Excel.Workbook()
12
+ // 2.创建表格,第二个参数可以配置创建什么样的工作表
13
+ if (Object.prototype.toString.call(luckysheet) === '[object Object]') {
14
+ luckysheet = [luckysheet]
15
+ }
16
+ luckysheet.forEach(function(table) {
17
+ if (table.data.length === 0) return true
18
+ // ws.getCell('B2').fill = fills.
19
+ const worksheet = workbook.addWorksheet(table.name)
20
+ const merge = (table.config && table.config.merge) || {}
21
+ const borderInfo = (table.config && table.config.borderInfo) || {}
22
+ // 3.设置单元格合并,设置单元格边框,设置单元格样式,设置值
23
+ setStyleAndValue(table.data, worksheet)
24
+ setMerge(merge, worksheet)
25
+ setBorder(borderInfo, worksheet)
26
+ return true
27
+ })
28
+
29
+ // return
30
+ // 4.写入 buffer
31
+ const buffer = workbook.xlsx.writeBuffer().then(data => {
32
+ // console.log('data', data)
33
+ const blob = new Blob([data], {
34
+ type: 'application/vnd.ms-excel;charset=utf-8'
35
+ })
36
+ console.log("导出成功!")
37
+ FileSaver.saveAs(blob, `${value}.xlsx`)
38
+ })
39
+ return buffer
40
+ }
41
+
42
+ export var generateExcelBlob = function(luckysheet, fileName) {
43
+ // 参数为luckysheet.getluckysheetfile()获取的对象,返回Blob对象
44
+ // 1.创建工作簿,可以为工作簿添加属性
45
+ const workbook = new Excel.Workbook()
46
+ // 2.创建表格,第二个参数可以配置创建什么样的工作表
47
+ if (Object.prototype.toString.call(luckysheet) === '[object Object]') {
48
+ luckysheet = [luckysheet]
49
+ }
50
+ luckysheet.forEach(function(table) {
51
+ if (table.data.length === 0) return true
52
+ const worksheet = workbook.addWorksheet(table.name)
53
+ const merge = (table.config && table.config.merge) || {}
54
+ const borderInfo = (table.config && table.config.borderInfo) || {}
55
+ // 3.设置单元格合并,设置单元格边框,设置单元格样式,设置值
56
+ setStyleAndValue(table.data, worksheet)
57
+ setMerge(merge, worksheet)
58
+ setBorder(borderInfo, worksheet)
59
+ return true
60
+ })
61
+
62
+ // 4.写入 buffer 并返回 Blob 对象
63
+ return workbook.xlsx.writeBuffer().then(data => {
64
+ const blob = new Blob([data], {
65
+ type: 'application/vnd.ms-excel;charset=utf-8'
66
+ })
67
+ // 如果提供了文件名,设置文件名属性
68
+ if (fileName) {
69
+ blob.name = `${fileName}.xlsx`
70
+ }
71
+ return blob
72
+ })
73
+ }
74
+
75
+ export var generateExcelFile = function(luckysheet, fileName) {
76
+ // 参数为luckysheet.getluckysheetfile()获取的对象,返回File对象
77
+ return generateExcelBlob(luckysheet, fileName).then(blob => {
78
+ const file = new File([blob], `${fileName || 'export'}.xlsx`, {
79
+ type: 'application/vnd.ms-excel;charset=utf-8'
80
+ })
81
+ return file
82
+ })
83
+ }
84
+
85
+ var setMerge = function(luckyMerge = {}, worksheet) {
86
+ const mergearr = Object.values(luckyMerge)
87
+ mergearr.forEach(function(elem) {
88
+ // elem格式:{r: 0, c: 0, rs: 1, cs: 2}
89
+ // 按开始行,开始列,结束行,结束列合并(相当于 K10:M12)
90
+ worksheet.mergeCells(
91
+ elem.r + 1,
92
+ elem.c + 1,
93
+ elem.r + elem.rs,
94
+ elem.c + elem.cs
95
+ )
96
+ })
97
+ }
98
+
99
+ var setBorder = function(luckyBorderInfo, worksheet) {
100
+ if (!Array.isArray(luckyBorderInfo)) return
101
+ // console.log('luckyBorderInfo', luckyBorderInfo)
102
+ luckyBorderInfo.forEach(function(elem) {
103
+ // 现在只兼容到borderType 为range的情况
104
+ // console.log('ele', elem)
105
+ if (elem.rangeType === 'range') {
106
+ let border = borderConvert(elem.borderType, elem.style, elem.color)
107
+ let rang = elem.range[0]
108
+ // console.log('range', rang)
109
+ let row = rang.row
110
+ let column = rang.column
111
+ for (let i = row[0] + 1; i < row[1] + 2; i++) {
112
+ for (let y = column[0] + 1; y < column[1] + 2; y++) {
113
+ worksheet.getCell(i, y).border = border
114
+ }
115
+ }
116
+ }
117
+ if (elem.rangeType === 'cell') {
118
+ // col_index: 2
119
+ // row_index: 1
120
+ // b: {
121
+ // color: '#d0d4e3'
122
+ // style: 1
123
+ // }
124
+ const { col_index, row_index } = elem.value
125
+ const borderData = Object.assign({}, elem.value)
126
+ delete borderData.col_index
127
+ delete borderData.row_index
128
+ let border = addborderToCell(borderData, row_index, col_index)
129
+ // console.log('bordre', border, borderData)
130
+ worksheet.getCell(row_index + 1, col_index + 1).border = border
131
+ }
132
+ // console.log(rang.column_focus + 1, rang.row_focus + 1)
133
+ // worksheet.getCell(rang.row_focus + 1, rang.column_focus + 1).border = border
134
+ })
135
+ }
136
+ var setStyleAndValue = function(cellArr, worksheet) {
137
+ if (!Array.isArray(cellArr)) return
138
+ cellArr.forEach(function(row, rowid) {
139
+ row.every(function(cell, columnid) {
140
+ if (!cell) return true
141
+ let fill = fillConvert(cell.bg)
142
+
143
+ let font = fontConvert(
144
+ cell.ff,
145
+ cell.fc,
146
+ cell.bl,
147
+ cell.it,
148
+ cell.fs,
149
+ cell.cl,
150
+ cell.ul
151
+ )
152
+ let alignment = alignmentConvert(cell.vt, cell.ht, cell.tb, cell.tr)
153
+ let value = ''
154
+
155
+ if (cell.f) {
156
+ value = { formula: cell.f, result: cell.v }
157
+ } else if (!cell.v && cell.ct && cell.ct.s) {
158
+ // xls转为xlsx之后,内部存在不同的格式,都会进到富文本里,即值不存在与cell.v,而是存在于cell.ct.s之后
159
+ // value = cell.ct.s[0].v
160
+ cell.ct.s.forEach(arr => {
161
+ value += arr.v
162
+ })
163
+ } else {
164
+ value = cell.v
165
+ }
166
+ // style 填入到_value中可以实现填充色
167
+ let letter = createCellPos(columnid)
168
+ let target = worksheet.getCell(letter + (rowid + 1))
169
+ // console.log('1233', letter + (rowid + 1))
170
+ for (const key in fill) {
171
+ target.fill = fill
172
+ break
173
+ }
174
+ target.font = font
175
+ target.alignment = alignment
176
+ target.value = value
177
+
178
+ return true
179
+ })
180
+ })
181
+ }
182
+
183
+ var fillConvert = function(bg) {
184
+ if (!bg) {
185
+ return {}
186
+ }
187
+ // const bgc = bg.replace('#', '')
188
+ let fill = {
189
+ type: 'pattern',
190
+ pattern: 'solid',
191
+ fgColor: { argb: bg.replace('#', '') }
192
+ }
193
+ return fill
194
+ }
195
+
196
+ var fontConvert = function(
197
+ ff = 0,
198
+ fc = '#000000',
199
+ bl = 0,
200
+ it = 0,
201
+ fs = 10,
202
+ cl = 0,
203
+ ul = 0
204
+ ) {
205
+ // luckysheet:ff(样式), fc(颜色), bl(粗体), it(斜体), fs(大小), cl(删除线), ul(下划线)
206
+ const luckyToExcel = {
207
+ 0: '微软雅黑',
208
+ 1: '宋体(Song)',
209
+ 2: '黑体(ST Heiti)',
210
+ 3: '楷体(ST Kaiti)',
211
+ 4: '仿宋(ST FangSong)',
212
+ 5: '新宋体(ST Song)',
213
+ 6: '华文新魏',
214
+ 7: '华文行楷',
215
+ 8: '华文隶书',
216
+ 9: 'Arial',
217
+ 10: 'Times New Roman ',
218
+ 11: 'Tahoma ',
219
+ 12: 'Verdana',
220
+ num2bl: function(num) {
221
+ return num === 0 ? false : true
222
+ }
223
+ }
224
+ // 出现Bug,导入的时候ff为luckyToExcel的val
225
+
226
+ let font = {
227
+ name: typeof ff === 'number' ? luckyToExcel[ff] : ff,
228
+ family: 1,
229
+ size: fs,
230
+ color: { argb: fc.replace('#', '') },
231
+ bold: luckyToExcel.num2bl(bl),
232
+ italic: luckyToExcel.num2bl(it),
233
+ underline: luckyToExcel.num2bl(ul),
234
+ strike: luckyToExcel.num2bl(cl)
235
+ }
236
+
237
+ return font
238
+ }
239
+
240
+ var alignmentConvert = function(
241
+ vt = 'default',
242
+ ht = 'default',
243
+ tb = 'default',
244
+ tr = 'default'
245
+ ) {
246
+ // luckysheet:vt(垂直), ht(水平), tb(换行), tr(旋转)
247
+ const luckyToExcel = {
248
+ vertical: {
249
+ 0: 'middle',
250
+ 1: 'top',
251
+ 2: 'bottom',
252
+ default: 'top'
253
+ },
254
+ horizontal: {
255
+ 0: 'center',
256
+ 1: 'left',
257
+ 2: 'right',
258
+ default: 'left'
259
+ },
260
+ wrapText: {
261
+ 0: false,
262
+ 1: false,
263
+ 2: true,
264
+ default: false
265
+ },
266
+ textRotation: {
267
+ 0: 0,
268
+ 1: 45,
269
+ 2: -45,
270
+ 3: 'vertical',
271
+ 4: 90,
272
+ 5: -90,
273
+ default: 0
274
+ }
275
+ }
276
+
277
+ let alignment = {
278
+ vertical: luckyToExcel.vertical[vt],
279
+ horizontal: luckyToExcel.horizontal[ht],
280
+ wrapText: luckyToExcel.wrapText[tb],
281
+ textRotation: luckyToExcel.textRotation[tr]
282
+ }
283
+ return alignment
284
+ }
285
+
286
+ var borderConvert = function(borderType, style = 1, color = '#000') {
287
+ // 对应luckysheet的config中borderinfo的的参数
288
+ if (!borderType) {
289
+ return {}
290
+ }
291
+ const luckyToExcel = {
292
+ type: {
293
+ 'border-all': 'all',
294
+ 'border-top': 'top',
295
+ 'border-right': 'right',
296
+ 'border-bottom': 'bottom',
297
+ 'border-left': 'left'
298
+ },
299
+ style: {
300
+ 0: 'none',
301
+ 1: 'thin',
302
+ 2: 'hair',
303
+ 3: 'dotted',
304
+ 4: 'dashDot', // 'Dashed',
305
+ 5: 'dashDot',
306
+ 6: 'dashDotDot',
307
+ 7: 'double',
308
+ 8: 'medium',
309
+ 9: 'mediumDashed',
310
+ 10: 'mediumDashDot',
311
+ 11: 'mediumDashDotDot',
312
+ 12: 'slantDashDot',
313
+ 13: 'thick'
314
+ }
315
+ }
316
+ let template = {
317
+ style: luckyToExcel.style[style],
318
+ color: { argb: color.replace('#', '') }
319
+ }
320
+ let border = {}
321
+ if (luckyToExcel.type[borderType] === 'all') {
322
+ border['top'] = template
323
+ border['right'] = template
324
+ border['bottom'] = template
325
+ border['left'] = template
326
+ } else {
327
+ border[luckyToExcel.type[borderType]] = template
328
+ }
329
+ // console.log('border', border)
330
+ return border
331
+ }
332
+
333
+ function addborderToCell(borders, row_index, col_index) {
334
+ let border = {}
335
+ const luckyExcel = {
336
+ type: {
337
+ l: 'left',
338
+ r: 'right',
339
+ b: 'bottom',
340
+ t: 'top'
341
+ },
342
+ style: {
343
+ 0: 'none',
344
+ 1: 'thin',
345
+ 2: 'hair',
346
+ 3: 'dotted',
347
+ 4: 'dashDot', // 'Dashed',
348
+ 5: 'dashDot',
349
+ 6: 'dashDotDot',
350
+ 7: 'double',
351
+ 8: 'medium',
352
+ 9: 'mediumDashed',
353
+ 10: 'mediumDashDot',
354
+ 11: 'mediumDashDotDot',
355
+ 12: 'slantDashDot',
356
+ 13: 'thick'
357
+ }
358
+ }
359
+ // console.log('borders', borders)
360
+ for (const bor in borders) {
361
+ // console.log(bor)
362
+ if (borders[bor].color.indexOf('rgb') === -1) {
363
+ border[luckyExcel.type[bor]] = {
364
+ style: luckyExcel.style[borders[bor].style],
365
+ color: { argb: borders[bor].color.replace('#', '') }
366
+ }
367
+ } else {
368
+ border[luckyExcel.type[bor]] = {
369
+ style: luckyExcel.style[borders[bor].style],
370
+ color: { argb: borders[bor].color }
371
+ }
372
+ }
373
+ }
374
+
375
+ return border
376
+ }
377
+
378
+ function createCellPos(n) {
379
+ let ordA = 'A'.charCodeAt(0)
380
+
381
+ let ordZ = 'Z'.charCodeAt(0)
382
+ let len = ordZ - ordA + 1
383
+ let s = ''
384
+ while (n >= 0) {
385
+ s = String.fromCharCode((n % len) + ordA) + s
386
+
387
+ n = Math.floor(n / len) - 1
388
+ }
389
+ return s
390
+ }
@@ -1,9 +1,6 @@
1
1
  import Vue from 'vue';
2
2
  import dialogComponent from './dialog.vue';
3
-
4
- export { default as univerSheet } from "./univerSheet.vue";
5
- export { default as asuniverDialog } from "./dialog.vue";
6
- export { default as asuniverButton } from "./button.vue";
3
+ export {default as luckysheetDialog } from './dialog.vue';
7
4
 
8
5
  /**
9
6
  * 打开univerDialog对话框
@@ -17,15 +14,10 @@ export { default as asuniverButton } from "./button.vue";
17
14
  * @param {Function} options.onClose - 关闭回调函数
18
15
  * @returns {Object} 对话框实例,包含close方法
19
16
  */
20
- export function openUniverSheetDialog(options = {}) {
17
+ export function openLuckysheetDialog(options = {}) {
18
+ let visiable = true;
21
19
  const {
22
- visiable = true,
23
- data = '',
24
- title = 'excel',
25
- readonly = false,
26
- onConfirm,
27
20
  onClose,
28
- univerConfig = {},
29
21
  } = options;
30
22
 
31
23
  // 创建组件实例
@@ -33,10 +25,7 @@ export function openUniverSheetDialog(options = {}) {
33
25
  const instance = new DialogConstructor({
34
26
  propsData: {
35
27
  visiable,
36
- data,
37
- title,
38
- readonly,
39
- univerConfig: univerConfig,
28
+ options: options,
40
29
  }
41
30
  });
42
31
 
@@ -57,18 +46,6 @@ export function openUniverSheetDialog(options = {}) {
57
46
  }, 300);
58
47
  };
59
48
 
60
- // 监听确认事件
61
- if (onConfirm) {
62
- instance.$on('confirm', (result) => {
63
- onConfirm(result);
64
- // 确认后也需要销毁
65
- destroyDialog();
66
- });
67
- } else {
68
- // 如果没有传入onConfirm,也要确保确认后销毁
69
- instance.$on('confirm', destroyDialog);
70
- }
71
-
72
49
  // 监听关闭事件
73
50
  if (onClose) {
74
51
  instance.$on('update:visiable', (value) => {