Click the button to perform the handler
1 Exportclick () {2 var3Profile = {4Content This. State.profile,5 type:MappingTypeForSevice.DomainMapping6 };7 if( This. Props.viewtype = =viewtype.edit)8Profile = This. Assembleprofiledto ();9 ElseTenProfile.content.id = This. props.mappingid! = "? This. Props.mappingid: This. ID; OneCommonfunction.exportclick (Profile, This. state.mappingname); A};
Commonfunction.exportclick definition
1Export Const Exportclick = (profile, mappingName) = = {2 mappingservice.downloadmapping (Profile) and then (3result = {4 if(!result)5 Throw("Error");6 Export_raw (mappingName, result)7 }8).Catch(E = {9 $$.error (' ERROR: ${e} ');Ten }); One};
Background return result is a string, XML is the content
Export_raw function definition (XML form)
1 var2Export_raw = (name = ", data) = = {3 Let4Elelink = document.createelement (' A ');5data =NewBlob ([data], {type: "Text/xml" });6EleLink.style.display = ' None ';7Elelink.download = name + '. Xml ';8 if(Window.navigator.msSaveOrOpenBlob) {9 varTenXML = name + '. Xml '; One Navigator.mssaveoropenblob (data, XML); A}Else { - // Let - //Dataurl = "data:;base64," + data; the //elelink.href = Dataurl; -Elelink.href =Url.createobjecturl (data); - Document.body.appendChild (elelink); - Elelink.click (); + Document.body.removeChild (elelink); - }; +};
Excel file returns
Haha, the meaning of the Word, Excel file is very special ~
Export_raw function definition (Excel form)
1Export_raw (name = "', data) {2 Let3Elelink = document.createelement (' A ');4EleLink.style.display = ' None ';5Elelink.download = name + '. xls ';6data = "Data:;base64," +data;7 if(Window.navigator.msSaveOrOpenBlob) {8 //If browser is IE9Let blob = This. Dataurltoblob (data);TenNavigator.mssaveoropenblob (BLOB, name + '. xls ')); One}Else { AElelink.href =data; - Document.body.appendChild (elelink); - Elelink.click (); the Document.body.removeChild (elelink); - }; -};
1Dataurltoblob = (dataurl) = = {2 var3arr = Dataurl.split (', '),4MIME = Arr[0].match (/:(. *?); [1],5BSTR = Atob (arr[1]), n =Bstr.length,6U8arr =NewUint8array (n);7 while(n--) {8U8arr[n] =bstr.charcodeat (n);9 }Ten return NewBlob ([U8arr], {type:mime}); One};
JS file Download