| ({ | 
|     readFile: function (component, helper, file) { | 
|         if (!file) return; | 
|         if (!file.name.match(/\.(csv||CSV)$/)) { | 
|             return alert('only support csv files'); | 
|         } else { | 
|             reader = new FileReader(); | 
|             reader.onerror = function errorHandler(evt) { | 
|                 switch (evt.target.error.code) { | 
|                     case evt.target.error.NOT_FOUND_ERR: | 
|                         alert('File Not Found!'); | 
|                         break; | 
|                     case evt.target.error.NOT_READABLE_ERR: | 
|                         alert('File is not readable'); | 
|                         break; | 
|                     case evt.target.error.ABORT_ERR: | 
|                         break; // noop | 
|                     default: | 
|                         alert('An error occurred reading this file.'); | 
|                 }; | 
|             } | 
|             reader.onabort = function (e) { | 
|                 alert('File read cancelled'); | 
|             }; | 
|             reader.onloadstart = function (e) { | 
|                 var output = '<ui type=\"disc\"><li><strong>' + file.name + '</strong> (' + file.type + ')- ' + file.size + 'bytes, last modified: ' + file.lastModifiedDate.toLocaleDateString() + '</li></ui>'; | 
|                 component.set("v.filename", file.name); | 
|                 component.set("v.TargetFileName", output); | 
|             }; | 
|             reader.onload = function (e) { | 
|                 var data = e.target.result; | 
|                 // data.replace(/\n/,"") | 
|                 var allTextLines11 = data.split(/\r/); | 
|                 var s = allTextLines11.toString(); | 
|                 component.set("v.fileContentData", s); | 
|                 console.log("file dataqqq" + JSON.stringify(s)); | 
|                 var allTextLines = data.split(/\r\n|\n/); | 
|                 var dataRows = allTextLines.length - 1; | 
|                 var headers = allTextLines[0].split(','); | 
|                 var numOfRows = component.get("v.NumOfRecords"); | 
|                 if (dataRows > numOfRows + 1 || dataRows == 1 || dataRows == 0) { | 
|                     alert("File Rows between 1 to " + numOfRows + " ."); | 
|                     component.set("v.showMain", true); | 
|                 } | 
|                 else { | 
|                     var lines = []; | 
|                     var filecontentdata; | 
|                     var content = "<table class=\"table slds-table slds-table--bordered slds-table--cell-buffer\">"; | 
|                     content += "<thead><tr class=\"slds-text-title--caps\">"; | 
|                     content += '<th scope=\"col"\>' + '行号' + '</th>'; | 
|                     for (i = 0; i < headers.length; i++) { | 
|                         content += '<th scope=\"col"\>' + headers[i] + '</th>'; | 
|                     } | 
|                     content += "</tr></thead>"; | 
|                     for (var i = 1; i < allTextLines.length; i++) { | 
|                         filecontentdata = allTextLines[i].split(','); | 
|                         if (filecontentdata[0] != '') { | 
|                             content += "<tr>"; | 
|                             content += "<td>" + i + "</td>"; | 
|                             for (var j = 0; j < filecontentdata.length; j++) { | 
|                                 content += '<td>' + filecontentdata[j] + '</td>'; | 
|                             } | 
|                             content += "</tr>"; | 
|                         } | 
|                     } | 
|                     content += "</table>"; | 
|                     console.log(content); | 
|                     component.set("v.TableContent", content); | 
|                     component.set("v.showMain", false); | 
|                 } | 
|             } | 
|             reader.readAsText(file, 'gb2312'); | 
|   | 
|         } | 
|         var reader = new FileReader(); | 
|         reader.onloadend = function () { | 
|         }; | 
|         reader.readAsDataURL(file); | 
|     }, | 
|     saveRecords: function (component, event, helper) { | 
|         component.set('v.login', true); | 
|         var action = component.get("c.processData"); | 
|         var fieldsList = ['Name', 'Phone', 'AccountNumber']; //Please write your code dynamic fields | 
|         action.setParams({ | 
|             fileData: component.get("v.fileContentData"), | 
|             sobjectName: 'Account', //Any object | 
|             fields: fieldsList | 
|         }); | 
|         action.setCallback(this, function (response) { | 
|             var state = response.getState(); | 
|             if (state === "SUCCESS") { | 
|                 var res = response.getReturnValue(); | 
|                 var res1 = ''; | 
|                 if (res != 'success') { | 
|                     var ress = res.split('='); | 
|                     console.log(ress); | 
|                     for (var i = 0; i < ress.length; i++) { | 
|                         res1 += ress[i].substr(7) + '\n'; | 
|                     } | 
|                     console.log("==" + res1); | 
|                     // this.error( "请修改后重新上传"); | 
|                     component.set('v.errorMessage', res1 + "请修改后重新上传"); | 
|                     this.showErrorToast(component); | 
|                     component.set('v.login', false); | 
|                 } else { | 
|                     // this.success('导入成功'); | 
|                     component.set('v.successMessage', '导入成功'); | 
|                     this.showSuccessToast01(component); | 
|                     component.set("v.showMain", true); | 
|                     component.set('v.login', false); | 
|                 } | 
|             } | 
|             else if (state === "INCOMPLETE") { | 
|                 component.set('v.login', false); | 
|             } | 
|             else if (state === "ERROR") { | 
|                 var errors = response.getError(); | 
|                 if (errors) { | 
|                     if (errors[0] && errors[0].message) { | 
|                         console.log("Error message: " + | 
|                             errors[0].message); | 
|                         component.set('v.login', false); | 
|                     } | 
|                 } else { | 
|                     console.log("Unknown error"); | 
|                     component.set('v.login', false); | 
|                 } | 
|             } | 
|         }); | 
|         $A.enqueueAction(action); | 
|   | 
|     }, | 
|     //弹出 成功提示 | 
|     showSuccessToast01: function (component) { | 
|         $A.util.removeClass(component.find('successDiv01'), 'slds-hide'); | 
|         window.setTimeout($A.getCallback(function () { | 
|             $A.util.addClass(component.find('successDiv01'), 'slds-hide'); | 
|         }), | 
|             3000 | 
|         ); | 
|     }, | 
|     //弹出 错误提示 | 
|     showErrorToast: function (component) { | 
|         $A.util.removeClass(component.find('errorDiv'), 'slds-hide'); | 
|         window.setTimeout($A.getCallback(function () { | 
|             $A.util.addClass(component.find('errorDiv'), 'slds-hide'); | 
|         }), | 
|             4000 | 
|         ); | 
|     }, | 
|     success : function(message) { | 
|         var toastEvent = $A.get("e.force:showToast"); | 
|         toastEvent.setParams({ | 
|             "title" : "成功!", | 
|             "message" : message, | 
|             "duration" : "5000" | 
|         }); | 
|         toastEvent.fire(); | 
|     }, | 
|      | 
|     warning : function(message) { | 
|         var toastEvent = $A.get("e.force:showToast"); | 
|         toastEvent.setParams({ | 
|             "title": "警告!", | 
|             "message": message, | 
|             "duration" : "10000" | 
|         }); | 
|         toastEvent.fire(); | 
|     }, | 
|      | 
|     error : function(message) { | 
|         var toastEvent = $A.get("e.force:showToast"); | 
|         toastEvent.setParams({ | 
|             "title": "错误!", | 
|             "message": message, | 
|             "duration" : "sticky" | 
|         }); | 
|         toastEvent.fire(); | 
|     }, | 
| }) |