Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

关于单击a标签的实现数据导出功能

我要实现的功能是:单击按钮,导出数据生成excel表。后端给我地址,我只要把数据发过去,他就能返回地址给我,从而实现下载功能。我之前的做法是打开页面的时候就自动生成url,考虑到服务器的压力,这种做法被否决了。我现在单击按钮,只能把url添加到a标签的href上,双击才能下载。这与需求单击实现下载不符,如何单击实现下载啦?

HTML:
p.s:下面结构中的文本是被a标签包裹,有类名download;
<div class='manageReportForms_btn'>导出当前数据</div>

JS:

$scope.exportData=function (start,end) {

    channel.push("waiter_xlsx", {"startTime":start,"endTime":end});
    channel.on("waiter_xlsx",function (payload) {
        var data=payload.data
        $(".download").attr("href",data.url);
    })
}
$scope.exportVal=function (val) {
    channel.push("waiter_xlsx",{"interval":val});
    channel.on("waiter_xlsx",function (payload) {
        var data=payload.data
        $(".download").attr("href",data.url);
    })
}
$('.manageReportForms_btn').click(function () {
    var iptVal=$(this).siblings().children('.manageReportForms_context').find('span').text();
    var interval;
    if(iptVal == '昨天'){
        interval=-2;
    }else if(iptVal == '过去7天'){
        interval=-8;
    }else if(iptVal == '过去30天'){
        interval=-31;
    }else{
        var start=iptVal.split('——')[0];
        var end=iptVal.split('——')[1];
    }
    $scope.exportVal(interval);
    $scope.exportData(start,end);
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

$scope.exportVal=function (val) {

channel.push("waiter_xlsx",{"interval":val});
channel.on("waiter_xlsx",function (payload) {
    var data=payload.data
    Window.location.href=data.url;
    return false;
})

}

这样试试


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...