成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出

本篇內(nèi)容介紹了“php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

創(chuàng)新互聯(lián)公司是一家專注于做網(wǎng)站、網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),南川網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:南川等地區(qū)。南川做網(wǎng)站價(jià)格咨詢:18980820575

廢話不多說,先上效果圖:

php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出

點(diǎn)擊導(dǎo)出,實(shí)現(xiàn)

php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出

點(diǎn)擊導(dǎo)出

php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出

統(tǒng)計(jì)完成之后

php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出

點(diǎn)擊確定

php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出

下面來談?wù)剬?shí)現(xiàn)的思路:

前面導(dǎo)出操作簡單,從第二個(gè)導(dǎo)出操作開始:

點(diǎn)擊"確定"調(diào)用exportCsv函數(shù)

復(fù)制代碼 代碼如下:


<a class="on" href="javascript:exportCsv();"><em>導(dǎo)出</em></a>

exportCvs函數(shù)如下
function exportCsv()
{

//清除等待的轉(zhuǎn)動圈
    $('#loading').html('');

 //彈出統(tǒng)計(jì)總數(shù)對話框,函數(shù)在后面給出定義
    tip();

//ajax請求總數(shù)
    $.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('系統(tǒng)消息');
            poptip.content('查詢結(jié)果為空,不能進(jìn)行數(shù)據(jù)導(dǎo)出');
        }
        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++;
            }

//當(dāng)數(shù)據(jù)不為空的時(shí)候彈出是否到處框
            exportCsvConfirm(num, processnum);
        }
    });
}

//彈出確認(rèn)下載  exportCsvConfirm函數(shù)

function exportCsvConfirm(num, processnum)
{
    var msg = '需要導(dǎo)出的數(shù)據(jù)有 <span >' + num + '</span> 行,可能會占用您較多時(shí)間來進(jìn)行導(dǎo)出。<br />您還需要繼續(xù)嗎?';

   // 提示是否繼續(xù)
    $.dialog.confirm(msg, function () {
        $('#loading').html('');
        processed_count = 0;
        index = 1;
        win.$('#process_bg').hide().width('0%').show();
        win.$('#process_num').html('0');

        $.dialog.through({
            title: '數(shù)據(jù)導(dǎo)出進(jìn)度',
            content: win.document.getElementById('processbar'),
            lock: true,
            opacity: '.1'
        },
        function(){
                window.location.reload();
        });
       //當(dāng)繼續(xù)的時(shí)候
        win.$('#progress_info').show().text('正在導(dǎo)出數(shù)據(jù),請耐心等待,請勿關(guān)閉窗口...');
      //開始執(zhí)行導(dǎo)出操作
        excel_export2(num, processnum);
    });
}

關(guān)鍵函數(shù)excel_export2隊(duì)列請求,首先會在前面定義全局變量

復(fù)制代碼 代碼如下:


var search_uri = "<?php echo $uri;?>";
var event = "<?php echo $event;?>";
var processed_count = 0;    // 已處理的數(shù)據(jù)條數(shù)
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();

我們要定義全局變量  index   和iii ,ajaxmark  ,index主要用于對一個(gè)表數(shù)據(jù)太多的時(shí)候進(jìn)行分批導(dǎo)出 ,iii用來控制隊(duì)列循環(huán),ajaxmark用來判斷前一個(gè)請求是否執(zhí)行成功了,成功的話在執(zhí)行下面的請求

復(fù)制代碼 代碼如下:


function excel_export2(num, processnum){
      //獲取tabletype
      tabletype=type_arr[iii];

     //獲取總數(shù)
      num = count_arr[tabletype];

    //判斷是否數(shù)組是否執(zhí)行完畢
      if(typeof(tabletype)=='undefined'&&typeof(num)=='undefined'){
            return false;
      }

     //判斷是否有上一個(gè)ajax請求是否完成
      if(ajaxmark==1){

            index = 1;
           //將ajax請求標(biāo)記為未執(zhí)行完成

ajaxmark=2;

          //執(zhí)行ajax請求,函數(shù)在后面給出
            retrun_var = excel_export_ajax(index, num, processnum, tabletype);
            //判斷函數(shù)返回
            if(typeof(retrun_var)=='undefined'){           

//將iii自增,執(zhí)行下一個(gè)數(shù)組數(shù)據(jù)
                  iii++;

//遞歸調(diào)用自己
                  excel_export2(num, processnum);
                  if(iii>100){
                        return false;
                  }

//當(dāng)ajax返回成功的時(shí)候,返回。
            }else if(retrun_var=='success'){
                  return false;
            }
            return false;
      }else{
            //setTimeout(excel_export2(num, processnum),3000);
            //setInterval(_excel_export2(num, processnum),3000);

//每隔3秒檢查是否ajax請求結(jié)束,這里settimeout 不能傳遞參數(shù),只能通過_excel_export2這種形式
            setTimeout(_excel_export2(num, processnum),3000);
      }
}

function _excel_export2(num, processnum){
       return function(){
             excel_export2(num, processnum);
       }
}

//excel_export_ajax函數(shù)  執(zhí)行導(dǎo)出
/* AJAX,遞歸調(diào)用 */
function excel_export_ajax(index, num, processnum, tabletype)
{
    $.ajax({
        url: "<?php echo WEB_URL;?>/index.php?q=onlinesea/exportcsv"+search_uri+"/index/"+index+ "/total/" + num + '/tabletype/' + tabletype,
        type: 'GET',
        success: function(data)
        {

//執(zhí)行次數(shù)自增
            ++processed_count;

//當(dāng)一個(gè)表數(shù)據(jù)太多,分批導(dǎo)出
            ++index;
            // 更新進(jìn)度條
  //判斷進(jìn)度
            var process_num = parseInt((processed_count / processnum) * 100);
  
            if (process_num >= 100)
            {
                process_num = 100;
            }

//跟新進(jìn)度條
            update_process(process_num);
            //alert(processed_count+'--'+processnum);

//當(dāng)執(zhí)行結(jié)束
            if (processed_count >= processnum)
            {

//壓縮文件
                backup_compress();

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

//將ajax請求標(biāo)記為執(zhí)行完畢,執(zhí)行下一個(gè)url請求
                ajaxmark=1;
                return false;
            }
            當(dāng)一個(gè)表的數(shù)據(jù)未導(dǎo)出完成的時(shí)候,會循環(huán)調(diào)用自己去請求, php函數(shù)或判斷是否到處完成,導(dǎo)出完成返回0  ,未完成返回1
            excel_export_ajax(index, num, processnum, tabletype);
        }
    });
}

/* 備份文件執(zhí)行壓縮 */
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('導(dǎo)出數(shù)據(jù)完成。&nbsp;&nbsp;<a href="' + msg + '" >下載文件</a>');
        }
    });
}

/* 更新進(jìn)度條 */
function update_process(process_num)
{
    win.$('#process_bg').show().width(process_num + '%');
    win.$('#process_num').html(process_num);
}

下面附上源碼,咳咳相關(guān)php程序大家自己腦補(bǔ)下吧

復(fù)制代碼 代碼如下:


<script type="text/javascript" language="javascript">
var search_uri = "<?php echo $uri;?>";
var event = "<?php echo $event;?>";
var processed_count = 0;    // 已處理的數(shù)據(jù)條數(shù)
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('系統(tǒng)消息');
            poptip.content('查詢結(jié)果為空,不能進(jìn)行數(shù)據(jù)導(dǎo)出');
        }
        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);
        }
    });
}

function exportCsvConfirm(num, processnum)
{
    var msg = '需要導(dǎo)出的數(shù)據(jù)有 <span >' + num + '</span> 行,可能會占用您較多時(shí)間來進(jìn)行導(dǎo)出。<br />您還需要繼續(xù)嗎?';
    $.dialog.confirm(msg, function () {
        $('#loading').html('');
        processed_count = 0;
        index = 1;
        win.$('#process_bg').hide().width('0%').show();
        win.$('#process_num').html('0');

        $.dialog.through({
            title: '數(shù)據(jù)導(dǎo)出進(jìn)度',
            content: win.document.getElementById('processbar'),
            lock: true,
            opacity: '.1'
        },
        function(){
                window.location.reload();
        });

        win.$('#progress_info').show().text('正在導(dǎo)出數(shù)據(jù),請耐心等待,請勿關(guān)閉窗口...');

        excel_export2(num, processnum);
    });
}

function excel_export2(num, processnum){

      tabletype=type_arr[iii];
      num = count_arr[tabletype];
      if(typeof(tabletype)=='undefined'&&typeof(num)=='undefined'){
            return false;
      }
      if(ajaxmark==1){

            index = 1;
            ajaxmark=2;
            retrun_var = excel_export_ajax(index, num, processnum, tabletype);

            if(typeof(retrun_var)=='undefined'){           
                  iii++;
                  excel_export2(num, processnum);
                  if(iii>100){
                        return false;
                  }
            }else if(retrun_var=='success'){
                  return false;
            }
            return false;
      }else{
            //setTimeout(excel_export2(num, processnum),3000);
            //setInterval(_excel_export2(num, processnum),3000);
            setTimeout(_excel_export2(num, processnum),3000);
      }
}
function _excel_export2(num, processnum){
       return function(){
             excel_export2(num, processnum);
       }
}
/* 執(zhí)行導(dǎo)出 */
function excel_export(num, processnum){
    var retrun_var = 'ss';
    for (var i in count_arr){
        num = count_arr[i];
        tabletype = i;
        index = 1;
        retrun_var = excel_export_ajax(index, num, processnum, tabletype);

        if(typeof(retrun_var)=='undefined'){
            //alert('xxxx');
            setTimeout(function(){exit;},5000);
        }
        if (retrun_var == 'success')
        {
            return false;
        }
    }

    return false;
}

/* AJAX,遞歸調(diào)用 */
function excel_export_ajax(index, num, processnum, tabletype)
{
    $.ajax({
        url: "<?php echo WEB_URL;?>/index.php?q=onlinesea/exportcsv"+search_uri+"/index/"+index+ "/total/" + num + '/tabletype/' + tabletype,
        type: 'GET',
        success: function(data)
        {
            ++processed_count;
            ++index;
            // 更新進(jìn)度條

            var process_num = parseInt((processed_count / processnum) * 100);

            if (process_num >= 100)
            {
                process_num = 100;
            }
            update_process(process_num);
            //alert(processed_count+'--'+processnum);
            if (processed_count >= processnum)
            {
                backup_compress();

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

            excel_export_ajax(index, num, processnum, tabletype);
        }
    });
}

/* 更新進(jìn)度條 */
function update_process(process_num)
{
    win.$('#process_bg').show().width(process_num + '%');
    win.$('#process_num').html(process_num);
}

/* 備份文件執(zhí)行壓縮 */
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('導(dǎo)出數(shù)據(jù)完成。&nbsp;&nbsp;<a href="' + msg + '" >下載文件</a>');
        }
    });
}
function tip()
{
    poptip = $.dialog.through({
        id: 'tip',
        title: '系統(tǒng)消息',
        content: '正在統(tǒng)計(jì)總數(shù),請勿關(guān)閉窗口&nbsp;&nbsp;<img src="http://images.cnblogs.com/loading_s.gif" />',
        width: 300,
        height: 100,
        icon: 'system',
        lock: true,
        opacity: .1
    },
    function(){
        window.location.reload();
    });

    poptip.show();
}

function packetDelete(url,msg)
{
    $.dialog.confirm(msg, function () {
        $.post(url, function(data){
          if(data == '1'){
              $.dialog('刪除成功', function(){window.location.reload();});
          }
          else if(data == '2'){
            $.dialog('刪除失敗', function(){window.location.reload();});
          }
          else if(data == '3'){
            $.dialog('文件不存在,或者已刪除', function(){window.location.reload();});
          }
      });
     });
}
</script>

“php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

文章題目:php+ajax怎么實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出
分享路徑:http://jinyejixie.com/article40/ghdoho.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、網(wǎng)站改版、微信小程序、域名注冊網(wǎng)站導(dǎo)航、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
新乐市| 新化县| 绍兴市| 方正县| 元谋县| 沁水县| 富蕴县| 潜山县| 浦东新区| 永城市| 临海市| 侯马市| 吴江市| 安达市| 连南| 文山县| 丹棱县| 荥阳市| 和田县| 慈利县| 嫩江县| 巴青县| 高碑店市| 金堂县| 文水县| 谷城县| 阜新| 庆元县| 景德镇市| 家居| 襄垣县| 磴口县| 大竹县| 榆中县| 裕民县| 五家渠市| 东丰县| 溧水县| 海阳市| 利川市| 宝清县|