@@ -205,7 +205,7 @@ export default {
205
205
'customClass' : '' , //自定义样式
206
206
'duration' : 3000 , //显示时间毫秒
207
207
'show' : true //是否自动弹出
208
- } ;
208
+ } ;
209
209
dispatch ( 'pushMessage' , message , { root : true } ) ; //消息提醒
210
210
setTimeout ( ( ) => {
211
211
commit ( {
@@ -302,162 +302,175 @@ export default {
302
302
dispatch ( 'pushMessage' , message , { root : true } ) ; //消息提醒
303
303
return ;
304
304
}
305
- //导入开始
306
- commit ( {
307
- type : 'set' ,
308
- key :'downloading' ,
309
- downloading : true
310
- } ) ;
311
- commit ( {
312
- type : 'set' ,
313
- key :'download_progress' ,
314
- download_progress : 0
305
+ let datas = XLSX . utils . sheet_to_json ( workbook . Sheets [ workbook . SheetNames [ 0 ] ] ) ;
306
+ let title_desc = collect ( datas . shift ( ) ) . all ( ) ; //去掉表头
307
+ dispatch ( 'importExcelData' , {
308
+ datas :datas ,
309
+ title_desc :title_desc ,
310
+ import_per_page :parms . import_per_page ,
311
+ sheet :parms . sheet ,
312
+ callback :parms . callback ,
313
+ url :parms . url
315
314
} ) ;
315
+ } ;
<
9E88
td data-grid-cell-id="diff-37f534b0a9f7869c9a421de551bde084dfca972f4e71842aea6f48e9133bf5a8-315-316-1" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">316
+ }
317
+
318
+ reader . readAsBinaryString ( parms . file ) ;
319
+ } ,
320
+ importExcelData ( { state, commit, rootState, dispatch } , options ) {
321
+ let title_desc = options . title_desc ;
322
+ let url = rootState [ 'use_url' ] + options . url ;
323
+ //导入开始
324
+ commit ( {
325
+ type : 'set' ,
326
+ key :'downloading' ,
327
+ downloading : true
328
+ } ) ;
329
+ commit ( {
330
+ type : 'set' ,
331
+ key :'download_progress' ,
332
+ download_progress : 0
333
+ } ) ;
334
+ commit ( {
335
+ type : 'set' ,
336
+ key :'pauseing' ,
337
+ pauseing : false
338
+ } ) ;
339
+ commit ( {
340
+ type : 'set' ,
341
+ key :'model' ,
342
+ model : 1
343
+ } ) ;
344
+ let error_title = collect ( JSON . parse ( JSON . stringify ( title_desc ) ) ) ;
345
+ error_title . put ( 'error' , i18n . t ( 'Error message' ) ) ; //错误信息
346
+ let datas = collect ( options . datas ) . map ( ( item ) => {
347
+ collect ( title_desc ) . each ( ( name , key ) => {
348
+ if ( typeof item [ key ] == "undefined" ) {
349
+ item [ key ] = '' ;
350
+ } else if ( typeof ( item [ key ] ) == 'string' && ( ( item [ key ] . startsWith ( '{' ) && item [ key ] . endsWith ( '}' ) ) || ( item [ key ] . startsWith ( '[' ) && item [ key ] . endsWith ( ']' ) ) ) ) {
351
+ try {
352
+ let value = JSON . parse ( item [ key ] ) ;
353
+ item [ key ] = value ;
354
+ } catch ( e ) {
355
+ }
356
+ }
357
+ } ) ;
358
+ return item ;
359
+ } ) ;
360
+ let total = datas . count ( ) ;
361
+ datas = datas . chunk ( options . import_per_page || 200 ) ;
362
+ let count = datas . count ( ) || 1 ; //总请求数
363
+ data = datas . shift ( ) ; //第一组数据
364
+ if ( ! importCallback ) {
365
+ importFail = ( error ) => {
316
366
commit ( {
317
367
type : 'set' ,
318
368
key :'pauseing' ,
319
- pauseing : false
320
- } ) ;
321
- commit ( {
322
- type : 'set' ,
323
- key :'model' ,
324
- model : 1
369
+ pauseing : true
325
370
} ) ;
326
- let datas = collect ( XLSX . utils . sheet_to_json ( workbook . Sheets [ workbook . SheetNames [ 0 ] ] ) ) ;
327
- let title = collect ( datas . shift ( ) ) ; //去掉表头
328
- let error_title = collect ( JSON . parse ( JSON . stringify ( title . all ( ) ) ) ) ;
329
- error_title . put ( 'error' , i18n . t ( 'Error message' ) ) ; //错误信息
330
- datas = datas . map ( ( item ) => {
331
- collect ( title ) . each ( ( name , key ) => {
332
- if ( typeof item [ key ] == "undefined" ) {
333
- item [ key ] = '' ;
334
- } else if ( typeof ( item [ key ] ) == 'string' && ( ( item [ key ] . startsWith ( '{' ) && item [ key ] . endsWith ( '}' ) ) || ( item [ key ] . startsWith ( '[' ) && item [ key ] . endsWith ( ']' ) ) ) ) {
335
- try {
336
- let value = JSON . parse ( item [ key ] ) ;
337
- item [ key ] = value ;
338
- } catch ( e ) {
339
- }
340
- }
371
+ message . title = i18n . t ( 'Import error, import has been suspended' ) ; //'导入出错,已暂停导入!';
372
+ dispatch ( 'pushMessage' , message , { root : true } ) ; //消息提醒
373
+ datas . prepend ( data ) ; //将导入提交数据还原
374
+ } ;
375
+ importCallback = ( response ) => {
376
+ if ( response . status == 200 ) {
377
+ //进度
378
+ commit ( {
379
+ type : 'set' ,
380
+ key :'download_progress' ,
381
+ download_progress : Math . floor ( ( count - datas . count ( ) ) / count * 100 )
341
382
} ) ;
342
- return item ;
343
- } ) ;
344
- let total = datas . count ( ) ;
345
- datas = datas . chunk ( parms . import_per_page || 200 ) ;
346
- let count = datas . count ( ) || 1 ; //总请求数
347
- data = datas . shift ( ) ; //第一组数据
348
- if ( ! importCallback ) {
349
- importFail = ( error ) => {
350
- commit ( {
351
- type : 'set' ,
352
- key :'pauseing' ,
353
- pauseing : true
354
- } ) ;
355
- message . title = i18n . t ( 'Import error, import has been suspended' ) ; //'导入出错,已暂停导入!';
356
- dispatch ( 'pushMessage' , message , { root : true } ) ; //消息提醒
357
- datas . prepend ( data ) ; //将导入提交数据还原
358
- } ;
359
- importCallback = ( response ) => {
360
- if ( response . status == 200 ) {
361
- //进度
362
- commit ( {
363
- type : 'set' ,
364
- key :'download_progress' ,
365
- download_progress : Math . floor ( ( count - datas . count ( ) ) / count * 100 )
383
+ if ( typeof response . data . errors != "undefined" && response . data . errors . length ) {
384
+ errors = collect ( errors ) . merge ( collect ( response . data . errors ) . map ( function ( row ) {
385
+ //重新整理排序
386
+ let item = [ ] ;
387
+ error_title . each ( ( val , key ) => {
388
+ item [ item . length ] = row [ key ] ;
366
389
} ) ;
367
- if ( typeof response . data . errors != "undefined" && response . data . errors .
1241
length ) {
368
- errors = collect ( errors ) . merge ( collect ( response . data . errors ) . map ( function ( row ) {
369
- //重新整理排序
370
- let item = [ ] ;
371
- error_title . each ( ( val , key ) => {
372
- item [ item . length ] = row [ key ] ;
373
- } ) ;
374
- return item ;
375
- } ) . all ( ) ) . all ( ) ; //存放错误数据
376
- }
377
- } else {
378
- importFail ( ) ;
379
- return ;
380
- }
381
- if ( ! state . downloading || state . pauseing ) { //取消上传
382
- return ;
383
- }
384
- data = datas . shift ( ) ; //第一组数据
385
- if ( data && data . count ( ) ) {
386
- importChunk ( { datas :data . all ( ) } , url , importCallback , importFail ) ;
387
- } else {
388
- if ( errors . length ) { //错误数据导出
389
- commit ( 'set' , {
390
- key :'modal' ,
391
- modal :{
392
- title :'提示' ,
393
- type : 'warning' , //消息类型
394
- content : i18n . t ( 'Import {success_number} data successfully, import {error_number} data failed! Did you download wrong data' ,
395
- {
396
- success_number :total - errors . length ,
397
- error_number :errors . length
398
- } ) , //'成功导入'+(total-errors.length)+'条数据,导入失败'+errors.length+'数据!是否下载错误数据?',
399
- callback :( ) => {
400
- let data = collect ( errors )
401
- . prepend ( error_title . values ( ) . all ( ) )
402
- . prepend ( error_title . keys ( ) . all ( ) ) . all ( ) ;
403
- exportExcel ( data , parms . sheet , i18n . t ( 'Wrong data' ) ) ; //错误数据
404
- errors = [ ] ;
405
- if ( typeof parms . callback == "function" ) {
406
- parms . callback ( ) ;
407
- }
408
- } ,
409
- cancel :( ) => { //取消
410
- errors = [ ] ;
411
- if ( typeof parms . callback == "function" ) {
412
- parms . callback ( ) ;
413
- }
414
- }
390
+ return item ;
391
+ } ) . all ( ) ) . all ( ) ; //存放错误数据
392
+ }
393
+ } else {
394
+ importFail ( ) ;
395
+ return ;
396
+ }
397
+ if ( ! state . downloading || state . pauseing ) { //取消上传
398
+ return ;
399
+ }
400
+ data = datas . shift ( ) ; //第一组数据
401
+ if ( data && data . count ( ) ) {
402
+ importChunk ( { datas :data . all ( ) } , url , importCallback , importFail ) ;
403
+ } else {
404
+ if ( errors . length ) { //错误数据导出
405
+ commit ( 'set' , {
406
+ key :'modal' ,
407
+ modal :{
408
+ title :'提示' ,
409
+ type : 'warning' , //消息类型
410
+ content : i18n . t ( 'Import {success_number} data successfully, import {error_number} data failed! Did you download wrong data' ,
411
+ {
412
+ success_number :total - errors . length ,
413
+ error_number :errors . length
414
+ } ) , //'成功导入'+(total-errors.length)+'条数据,导入失败'+errors.length+'数据!是否下载错误数据?',
415
+ callback :( ) => {
416
+ let data = collect ( errors )
417
+ . prepend ( error_title . values ( ) . all ( ) )
418
+ . prepend ( error_title . keys ( ) . all ( ) ) . all ( ) ;
419
+ exportExcel ( data , options . sheet , i18n . t ( 'Wrong data' ) ) ; //错误数据
420
+ errors = [ ] ;
421
+ if ( typeof options . callback == "function" ) {
422
+ options . callback ( ) ;
423
+ }
424
+ } ,
425
+ cancel :( ) => { //取消
426
+ errors = [ ] ;
427
+ if ( typeof options . callback == "function" ) {
428
+ options . callback ( ) ;
415
429
}
416
- } , { root : true } ) ;
417
-
418
- } else { //全部导入成功
419
- let message = {
420
- 'showClose' : true , //显示关闭按钮
421
- 'title' : i18n . t ( 'All imported successfully' ) , //'全部导入成功!', //消息内容
422
- 'message' : '' , //消息内容
423
- 'type' : 'success' , //消息类型
424
- 'position' : 'top' ,
425
- 'iconClass' : 'fa-check' , //图标
426
- 'customClass' : '' , //自定义样式
427
- 'duration' : 3000 , //显示时间毫秒
428
- 'show' : true //是否自动弹出
429
- } ;
430
- dispatch ( 'pushMessage' , message , { root : true } ) ; //消息提醒
431
- if ( typeof parms . callback == "function" ) {
432
- parms . callback ( ) ;
433
430
}
434
431
}
435
- setTimeout ( ( ) => {
436
- commit ( {
437
- type : 'set' ,
438
- key :'download_progress' ,
439
- download_progress : 0
440
- } ) ;
441
- commit ( {
442
- type : 'set' ,
443
- key :'downloading' ,
444
- downloading : false
445
- } ) ;
446
- commit ( {
447
- type : 'set' ,
448
- key :'pauseing' ,
449
- pauseing : false
450
- } ) ;
451
- } , 1000 ) ;
452
- }
453
- } ;
432
+ } , { root : true } ) ;
454
433
434
+ }
435
+ else { //全部导入成功
436
+ let message = {
437
+ 'showClose' : true , //显示关闭按钮
438
+ 'title' : i18n . t ( 'All imported successfully' ) , //'全部导入成功!', //消息内容
439
+ 'message' : '' , //消息内容
440
+ 'type' : 'success' , //消息类型
441
+ 'position' : 'top' ,
442
+ 'iconClass' : 'fa-check' , //图标
443
+ 'customClass' : '' , //自定义样式
444
+ 'duration' : 3000 , //显示时间毫秒
445
+ 'show' : true //是否自动弹出
446
+ } ;
447
+ dispatch ( 'pushMessage' , message , { root : true } ) ; //消息提醒
448
+ if ( typeof options . callback == "function" ) {
449
+ options . callback ( ) ;
450
+ }
451
+ }
452
+ setTimeout ( ( ) => {
453
+ commit ( {
454
+ type : 'set' ,
455
+ key :'download_progress' ,
456
+ download_progress : 0
457
+ } ) ;
458
+ commit ( {
459
+ type : 'set' ,
460
+ key :'downloading' ,
461
+ downloading : false
462
+ } ) ;
463
+ commit ( {
464
+ type : 'set' ,
465
+ key :'pauseing' ,
466
+ pauseing : false
467
+ } ) ;
468
+ } , 1000 ) ;
455
469
}
456
- importChunk ( { datas :data . all ( ) } , url , importCallback , importFail ) ;
457
470
} ;
458
- }
459
471
460
- reader . readAsBinaryString ( parms . file ) ;
472
+ }
473
+ importChunk ( { datas :data . all ( ) } , url , importCallback , importFail ) ;
461
474
}
462
475
} ,
463
476
getters :{ }
0 commit comments