From dd004276162a2bf9d042ff0aaa569dc30a95d827 Mon Sep 17 00:00:00 2001
From: binxie <137736985@qq.com>
Date: 星期一, 26 六月 2023 14:23:26 +0800
Subject: [PATCH] newbackup0626
---
force-app/main/default/aura/DealerPersonnelInformationImport/DealerPersonnelInformationImportHelper.js | 140 ++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 127 insertions(+), 13 deletions(-)
diff --git a/force-app/main/default/aura/DealerPersonnelInformationImport/DealerPersonnelInformationImportHelper.js b/force-app/main/default/aura/DealerPersonnelInformationImport/DealerPersonnelInformationImportHelper.js
index 685b5e8..ddd60f2 100644
--- a/force-app/main/default/aura/DealerPersonnelInformationImport/DealerPersonnelInformationImportHelper.js
+++ b/force-app/main/default/aura/DealerPersonnelInformationImport/DealerPersonnelInformationImportHelper.js
@@ -94,9 +94,49 @@
if (res != 'success') {
var ress = res.split('=');
console.log(ress);
+ let errorDatas = [];
+ let errorDataRow = [];
+ debugger
for (var i = 0; i < ress.length; i++) {
res1 += ress[i].substr(7) + '\n';
+ if (ress[i] != '') {
+ let errorData = {}
+ let index = errorDataRow.indexOf(ress[i].substr(7).substring(1, 2));
+ if (index == -1) {
+ errorData.errorRow = ress[i].substr(7).substring(1, 2);
+ errorDataRow.push(errorData.errorRow);
+ errorData.errorInfo = ress[i].substr(7).substring(6);
+ errorDatas.push(errorData);
+ } else {
+ errorDatas[index].errorInfo += '; ' + ress[i].substr(7).substring(6);
+ }
+ }
}
+ var fileContentData = component.get("v.fileContentData").split('\n');
+ let errorColumns = [
+ { label: '閿欒琛�', fieldName: 'errorRow', type: 'text', hideDefaultActions: true, initialWidth: 50 },
+ { label: '閿欒淇℃伅', fieldName: 'errorInfo', type: 'text', hideDefaultActions: true,initialWidth: 300,wrapText: true }
+ ];
+ for (var i = 0; i < fileContentData[0].split(',').length - 1; i++) {
+ errorColumns.push({
+ label: fileContentData[0].split(',')[i], fieldName: 'field' + i, type: 'text', hideDefaultActions: true,wrapText: true
+ });
+ }
+
+ for(var i = 0; i < errorDatas.length; i++){
+ let data = fileContentData[errorDatas[i].errorRow];
+ console.log('data = ' + JSON.stringify(data));
+ for(var j = 0; j < data.split(',').length; j++){
+ let label = 'field' + j;
+ errorDatas[i][label] = data.split(',')[j];
+ }
+ }
+ console.log('errorDatas = ' + JSON.stringify(errorDatas))
+
+ component.set('v.errorColumns', errorColumns);
+ component.set('v.errorData', errorDatas);
+ component.set("v.showErrorInfo", true);
+
console.log("==" + res1);
// this.error( "璇蜂慨鏀瑰悗閲嶆柊涓婁紶");
component.set('v.errorMessage', res1 + "璇蜂慨鏀瑰悗閲嶆柊涓婁紶");
@@ -117,8 +157,18 @@
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
- console.log("Error message: " +
- errors[0].message);
+ console.log("Error message: " + errors[0].message);
+ let errorDatas = [{
+ errorRow: '1',
+ errorInfo: errors[0].message
+ }];
+ let errorColumns = [
+ { label: '閿欒琛�', fieldName: 'errorRow', type: 'text', hideDefaultActions: true, initialWidth: 50 },
+ { label: '閿欒淇℃伅', fieldName: 'errorInfo', type: 'text', hideDefaultActions: true,initialWidth: 300,wrapText: true }
+ ];
+ component.set('v.errorData', errorDatas);
+ component.set('v.errorColumns', errorColumns);
+ component.set("v.showErrorInfo", true);
component.set('v.login', false);
}
} else {
@@ -145,36 +195,100 @@
window.setTimeout($A.getCallback(function () {
$A.util.addClass(component.find('errorDiv'), 'slds-hide');
}),
- 3000
+ 4000
);
},
- success : function(message) {
+ success: function (message) {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
- "title" : "鎴愬姛!",
- "message" : message,
- "duration" : "5000"
+ "title": "鎴愬姛!",
+ "message": message,
+ "duration": "5000"
});
toastEvent.fire();
},
-
- warning : function(message) {
+
+ warning: function (message) {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "璀﹀憡!",
"message": message,
- "duration" : "10000"
+ "duration": "10000"
});
toastEvent.fire();
},
-
- error : function(message) {
+
+ error: function (message) {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "閿欒!",
"message": message,
- "duration" : "sticky"
+ "duration": "sticky"
});
toastEvent.fire();
},
+ //zhj 瀵煎嚭閿欒淇℃伅 2023-05-16 start
+ exportErrorInfoHelper: function (component) {
+ var errorData = component.get('v.errorData');
+ var errorColumns = component.get('v.errorColumns');
+
+ var datas = [];
+ let errorColumnsArray = [];
+ for(var i in errorColumns){
+ errorColumnsArray.push(errorColumns[i].label);
+ }
+ datas.push(errorColumnsArray);
+ //datas.push(errorColumns);
+
+ for (var i in errorData) {
+ let data = [];
+ data.push(errorData[i].errorRow)
+ data.push(errorData[i].errorInfo)
+ for(var j = 0 ; j < Object.keys(errorData[i]).length - 2 ; j++){
+ data.push(errorData[i]['field' + j])
+ }
+ datas.push(data);
+ }
+
+ console.log('datas = ' + JSON.stringify(datas));
+ var csv = this.convertToCSV(component, datas);
+ console.log('csv = ' + JSON.stringify(csv))
+ this.downloadCSV(component, csv);
+ },
+
+ convertToCSV: function (component, data) {
+ console.log('enter convertToCSV')
+ console.log('data = ' + data);
+ var csv = '';
+ for (var i = 0; i < data.length; i++) {
+ var row = data[i];
+ console.log('row = ' + JSON.stringify(row));
+ for (var j = 0; j < row.length; j++) {
+ var val = '';
+ val = row[j] === null ? '' : row[j].toString();
+ console.log('val = ' + val);
+ if (val.indexOf(',') !== -1 || val.indexOf('"') !== -1 || val.indexOf('\n') !== -1) {
+ //val = '"' + val.replace(/"/g,'""') + '"';
+ }
+ if (j > 0) {
+ csv += ',';
+ }
+ csv += val;
+ }
+ csv += '\n';
+ }
+ return csv;
+ },
+
+ downloadCSV: function (component, csv) {
+ var link = document.createElement('a');
+ // 璁剧疆瀛楃闆嗗拰鏂囦欢澶�
+ let bom = "\uFEFF";
+ link.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(bom+csv);
+ link.download = 'data.csv';
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ },
+ //zhj 瀵煎嚭閿欒淇℃伅 2023-05-16 end
})
\ No newline at end of file
--
Gitblit v1.9.1