php+ajax实现带进度条的大数据排队导出思路以及源(3)

    //跟新进度条
            update_process(process_num);
            //alert(processed_count+'--'+processnum);

    //当执行结束
            if (processed_count >= processnum)
            {

      //压缩文件
                backup_compress();

return 'success';
            }
            if (data == '0'){

      //将ajax请求标记为执行完毕,执行下一个url请求
                ajaxmark=1;
                return false;
            }
            当一个表的数据未导出完成的时候,会循环调用自己去请求, php函数或判断是否到处完成,导出完成返回0  ,未完成返回1
            excel_export_ajax(index, num, processnum, tabletype);
        }
    });
}

/* 备份文件执行压缩 */
function backup_compress()
{
    win.$('#progress_info').text('正在生成压缩文件...');

$.ajax({
        url: "<?php echo WEB_URL;?>/index.php?q=onlinesea/compress/event/<?php echo $event;?>",
        success: function(msg){
            win.$('#process_bg').show().width('100%');
            win.$('#process_num').html('100');
            win.$('#progress_info').html('导出数据完成。&nbsp;&nbsp;<a href="' + msg + '">下载文件</a>');
        }
    });
}

/* 更新进度条 */
function update_process(process_num)
{
    win.$('#process_bg').show().width(process_num + '%');
    win.$('#process_num').html(process_num);
}

下面附上源码,咳咳相关php程序大家自己脑补下吧

复制代码 代码如下:


<script type="text/javascript" language="javascript">
var search_uri = "<?php echo $uri;?>";
var event = "<?php echo $event;?>";
var processed_count = 0;    // 已处理的数据条数
var index = 1;
var iii   = 0;
var ajaxmark = 1;
var win = $.dialog.parent;    // 顶层页面window对象
var count_arr = new Array(<?php echo count($this->tables);?>);
var type_arr = new Array();
function exportCsv()
{
    $('#loading').html('');
    tip();
    $.post("<?php echo WEB_URL;?>/index.php?q=onlinesea/getwherecount"+search_uri, function(json){
        var return_arr = eval('(' + json + ')');
        var num = return_arr['total'];
        var processnum = return_arr['processnum'];

if(num == 0){
            poptip.title('系统消息');
            poptip.content('查询结果为空,不能进行数据导出');
        }
        else
        {
            poptip.close();

            for (var i in return_arr['cntarr']){
                if (return_arr['cntarr'][i] != 0){
                    count_arr[i] = return_arr['cntarr'][i];
                }

            }
            var ii=0;
            for (var i in count_arr){
                  type_arr[ii]=i;
                  ii++;
            }
            exportCsvConfirm(num, processnum);
        }
    });
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wfwwgg.html