前端使用iframe配合后端做导出功能 iframe 导出 vue实现

<iframe style="display: none;" id="downloadIframeAgent"></iframe>  //写在body里,与<script></script>同级
<div slot="extra">
  <i-button type="info" style="width: 120px;height: 32px;margin-top: -3px;" @click="exportExcel" :loading="isLoading3">导出</i-button>
</div>
new Vue({
        el: '#app',
        data: function() {
            return{
                options: {
                    disabledDate:function(date) {
                        return date && date.valueOf() > Date.now();
                    }
                },
                formInline:{
                    date:['2020-09-07','2020-09-08'],
                    shopName:"",
                    organization:"",
                    staff:""
                },
                isLoading3:false,
            }
        },
mounted:function(){
            var _this = this;
            var downloadIframe = document.getElementById('downloadIframeAgent');
            if (downloadIframe.attachEvent) {
                downloadIframe.attachEvent("onload", function() {
                    //iframe加载完成后你需要进行的操作
                    var result = downloadIframe.contentWindow.document.body.innerHTML;
                    if(result != '') {
                        result = JSON.parse(result);
                        if(result.status != 200) {
                            _this.$Message.error(result.message);
                        }
                    }
                });
            } else {
                downloadIframe.onload = function() {
                    //iframe加载完成后你需要进行的操作
                    var result = downloadIframe.contentWindow.document.body.innerHTML;
                    if(result != '') {
                        result = JSON.parse(result);
                        if(result.status != 200) {
                            _this.$Message.error(result.message);
                        }
                    }
                };
            }
        },
// 导出
methods:{
	exportExcel:function(){
                var _this = this;
                var startTime='';
                var endTime='';
                var params = "";
                if(this.formInline.date.length>0){
                    startTime=_this.formInline.date[0];
                    endTime=_this.formInline.date[1];
                    if(startTime && endTime){
                        params += "startTime=" + startTime + "&endTime=" + endTime + "&";
                    }
                }
                if(_this.formInline.staff){
                    params += "salesmanInfo="+_this.formInline.staff+"&";
                }
                if(_this.formInline.shopName){
                    params += "companyName="+_this.formInline.shopName+"&";
                }
                if(_this.formInline.organization){
                    params += "diceAgentName="+_this.formInline.organization+"&";
                }
                if (params.length > 0) {
                    params = params.substring(0, params.length - 1);
                }

                var url = "/cooperatesys/lxactagent/hfLxListExcel?type=8&" + params;
                _this.isLoading3 = true;
                var iframe=$("#downloadIframeAgent");
                iframe.attr('src', url);
                var timer = setInterval(function () {
                    var iframeDoc = iframe.prop('contentWindow').document || iframe.prop('contentDocument');
                    if (iframeDoc.readyState == 'complete' || iframeDoc.readyState == 'interactive') {
                        _this.isLoading3 = false;
                        clearInterval(timer);
                        return;
                    }
                }, 4000);
            },
},
            

本文章为原创,转载请注明出处,谢谢!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值