主要代码
// base64转blob
function base64ToBlob(code) {
let parts = code.split(';base64,');
let contentType = parts[0].split(':')[1];
let raw = window.atob(parts[1]);
let rawLength = raw.length;
let uInt8Array = new Uint8Array(rawLength);
for(let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {type: contentType});
}
完整代码
<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.aurora-framework.org/application">
<a:view>
<script><![CDATA[
function query(){
$('query_cosoc_credit_data_result_ds').query();
}
function export_excel(){
$('query_cosoc_credit_data_result_ds_grid')._export();
}
function formatNumber(value){
if(value==0)
return '纸质';
else
return '电子';
}
// 征信授权书下载
function downLoadTorenderercredit_auth_power(value, record, name){
if (value){
if (value.length > 20){
return '<a href="javascript:downLoadTo(\'征信授权书\',\'' + value + '\')">征信授权书下载</a>';
}
}
}
// 面签照下载
function downLoadTorendererinterview(value, record, name){
if (value){
if (value.length > 20){
return '<a href="javascript:downLoadTo(\'面签照\',\'' + value + '\')">面签照下载</a>';
}
}
}
function downLoadTo(name,value) {
if(!!value) {
let imgData = value;
var fileName = name+'.jpg';
if (value.indexOf("data:application/pdf") != -1){
fileName = name+'.pdf';
}
this.downloadFile(fileName, imgData);
}
}
// 下载
function downloadFile(fileName, content) {
let aLink = document.createElement('a');
let blob = base64ToBlob(content); // new Blob([content]);
let evt = document.createEvent('HTMLEvents');
evt.initEvent('click', true, true);// initEvent 不加后两个参数在FF下会报错 事件类型,是否冒泡,是否阻止浏览器的默认行为
aLink.download = fileName;
aLink.href = URL.createObjectURL(blob);
aLink.dispatchEvent(new MouseEvent('click', {bubbles: true, cancelable: true, view: window}));// 兼容火狐
}
// base64转blob
function base64ToBlob(code) {
let parts = code.split(';base64,');
let contentType = parts[0].split(':')[1];
let raw = window.atob(parts[1]);
let rawLength = raw.length;
let uInt8Array = new Uint8Array(rawLength);
for(let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new Blob([uInt8Array], {type: contentType});
}
]]></script>
<a:dataSets>
<a:dataSet id="query_ds">
<a:fields>
<a:field name="custname"/>
<a:field name="business_no"/>
<a:field name="loan_stat_des" displayField="code" options="loan_stat_ds" returnField="loan_stat" valueField="value"/>
<a:field name="loan_stat"/>
</a:fields>
</a:dataSet>
<a:dataSet id="query_cosoc_credit_data_result_ds" autoQuery="true" model="crdt.CRDTZYH.query_cosoc_credit_data" pageSize="15" queryDataSet="query_ds" selectable="true" selectionModel="single"><![CDATA[
]]></a:dataSet>
</a:dataSets>
<a:screenBody>
<a:screenTopToolbar>
<a:screenTitle/>
<a:gridButton click="query" text="HLS.QUERY"/>
<a:gridButton click="export_excel" text="导出"/>
</a:screenTopToolbar>
<a:form column="4" labelWidth="100" marginWidth="30" title="查询条件">
<a:textField name="name" bindTarget="query_ds" prompt="姓名"/>
<a:textField name="id_card" bindTarget="query_ds" prompt="身份证号"/>
</a:form>
<a:grid id="query_cosoc_credit_data_result_ds_grid" bindTarget="query_cosoc_credit_data_result_ds" marginHeight="180" marginWidth="30" navBar="true">
<a:toolBar>
<a:button text="下载征信授权书" />
<a:button text="下载面签照" />
</a:toolBar>
<a:columns>
<a:column name="name" prompt="姓名"/>
<a:column name="id_card_no" prompt="身份证号"/>
<a:column name="bank_card_no" prompt="银行卡号"/>
<a:column name="sign_type" prompt="签约类型" renderer="formatNumber" />
<a:column name="query_id" prompt="查询id"/>
<a:column name="creation_date" prompt="查询时间" renderer="Aurora.formatDate"/>
<a:column name="credit_auth_power" prompt="征信授权书" renderer="downLoadTorenderercredit_auth_power" />
<a:column name="interview" prompt="面签照" renderer="downLoadTorendererinterview" />
</a:columns>
</a:grid>
</a:screenBody>
</a:view>
</a:screen>