zoukankan      html  css  js  c++  java
  • export-data.js

    var timeBtnClick = (function() {
        function _todayClick() {
            $('.select-time .today').on('click', function() {
                $('#export-date-start-time').val(countDate.getDate(0));
                $('#export-date-end-time').val(countDate.getDate(-1));
            });
        }
    
        function _yesterdayClick() {
            $('.select-time .yesterday').on('click', function(){
                $('#export-date-start-time').val(countDate.getDate(1));
                $('#export-date-end-time').val(countDate.getDate(0));
            });
        }
    
        function _sevenClick() {
            $('.select-time .recent-seven-days').on('click', function(){
                $('#export-date-start-time').val(countDate.getDate(7));
                $('#export-date-end-time').val(countDate.getDate(0));
            });
        }
    
        function _thirtyClick() {
            $('.select-time .recent-thirty-days').on('click', function(){
                $('#export-date-start-time').val(countDate.getDate(30));
                $('#export-date-end-time').val(countDate.getDate(0));
            });
        }
    
        return {
            init: function() {
                _todayClick();
                _yesterdayClick();
                _sevenClick();
                _thirtyClick();
            }
        };
    })();
    
    var countDate = (function() {
        function getDate(days) {
            var now = new Date(),
                newDate = new Date(now.getTime() - 86400000 * days),
                yyyy = newDate.getFullYear(),
                mm = (newDate.getMonth() + 1) < 9 ? '0' + (newDate.getMonth() + 1) : newDate.getMonth() + 1,
                dd = newDate.getDate() < 9 ? '0' + newDate.getDate() : newDate.getDate();
            return (yyyy + '-' + mm + '-' + dd + ' 00:00');
        }
        return {
            getDate: getDate
        };
    })();
    
    var inputInit = (function() {
        function _initPlaceholder() {
            $('.export-date-time').placeholder();
        }
        function _initTimepicker() {
            $('.export-date-time').datetimepicker({
                dateFormat : "yy-mm-dd",
                timeFormat : "HH:mm"
            }).placeholder();
        }
        return {
            init: function() {
                _initPlaceholder();
                _initTimepicker();
            }
        };
    })();
    
    var exportBtnClick = (function() {
        function _initExportBtnClick() {
            $('.export-data-container').on('click', ".export-data-btn:not('.disabled-btn')", function(){
                $this = $(this);
                $('.error-msg').hide();
                $this.find('.loading-icon').hide();
                var startTime = $('#export-date-start-time').val(),
                    endTime = $('#export-date-end-time').val(),
                    dataType = $this.data('type'),
                    timeErrorMsg = $('.time-error-msg');
                if (startTime > endTime) {
                    timeErrorMsg.html(reminder_message.please_choose_correct_time);
                    timeErrorMsg.show();
                    return;
                } else {
                    timeErrorMsg.hide();
                }
    
                if (!startTime || !endTime) {
                    timeErrorMsg.html(reminder_message.please_choose_time);
                    timeErrorMsg.show();
                    return;
                } else {
                    timeErrorMsg.hide();
                }
                $('.export-data-btn').addClass('disabled-btn');
                $this.find('.loading-icon').css('display', 'inline-block');
                ifContinue = true;
                check_export($this, dataType, startTime, endTime, ifContinue);
            });
        }
        function check_export($this, dataType, startTime, endTime, ifContinue) {
            var taskId = $this.data('task-id') ? $this.data('task-id') : '',
                xlsFileLink = $('#xls-file-link'),
                loadingIcon = $this.find('.loading-icon'),
                exportDataBtn = $('.export-data-btn');
            if (ifContinue) {
                $.ajax({
                    type: 'GET',
                    url: '/export-data?startTime=' + startTime + '&endTime=' + endTime + '&dataType=' + dataType + '&taskId=' + taskId,
                    dataType: 'JSON',
                    success: function(data){
                        if (data.error_msg) {
                            if_continue = false;
                            $this.data('task-id', '');
                            $('.time-error-msg').show();
                            loadingIcon.hide();
                            exportDataBtn.removeClass('disabled-btn');
                        }
    
                        if (data.xls_name) {
                            ifContinue = false;
                            xlsFileLink.attr('href', '/media/' + data.xls_name);
                            xlsFileLink[0].click();
                            xlsFileLink.removeAttr('href');
                            $this.data('task-id', '');
                            loadingIcon.hide();
                            exportDataBtn.removeClass('disabled-btn');
                        } else if (data.task_id) {
                            $this.data('task-id', data.task_id);
                        }
    
                    },
                    error: function(e){
                        if_continue = false;
                        $this.data('task-id', '');
                        $this.next('.error-msg').show();
                        loadingIcon.hide();
                        exportDataBtn.removeClass('disabled-btn');
                    }
                });
                t = setTimeout(function(){
                    console.log("Looping to query.");
                    check_export($this, dataType, startTime, endTime, ifContinue);
                }, 1000);
            }
    
    
        }
        return {
            init: _initExportBtnClick
        };
    })();
    
    $(document).ready(function(){
        timeBtnClick.init();
        inputInit.init();
        exportBtnClick.init();
    });
  • 相关阅读:
    GitBook基本使用
    Window 远程桌面漏洞风险,各个厂家的扫描修复方案(CVE-2019-0708)
    应急响应实战笔记(续)
    不同系统下,复制文件时新文件的日期区别
    Window应急响应(六):NesMiner挖矿病毒
    利用python输出000至999中间的数
    揭秘骗局:这是一张会变的图片
    如何查看github排行热度
    zabbix使用自动发现功能批量监控服务器端口的可用性
    使用python脚本批量设置nginx站点的rewrite规则
  • 原文地址:https://www.cnblogs.com/Brittany-yan/p/5287351.html
Copyright © 2011-2022 走看看