/*
 * @Author: 莫靓仔
 * @description: 文件描述
 * @Date: 2021-09-14 17:49:54
 * @LastEditors: 莫靓仔
 * @LastEditTime: 2021-09-14 19:03:37
 */
// 防抖
function debounce(fn, delay) {
    var time = delay || 1000
    var timer
    return function () {
        var th = this
        var args = arguments
        if (timer) {
            clearTimeout(timer)
        }
        timer = setTimeout(function () {
            timer = null
            fn.apply(th, args)
        }, time)
    }
}

// 节流
function throttle(fn, interval) {
    var last
    var timer
    var time = interval || 2000
    return function () {
        var th = this
        var args = arguments
        var now = +new Date()
        if (last && now - last < time) {
            clearTimeout(timer)
            timer = setTimeout(function () {
                last = now
                fn.apply(th, args)
            }, time)
        } else {
            last = now
            fn.apply(th, args)
        }
    }
}

// 弹窗
var appTips = {
    successMsg: function (message, style) {
        var css = {
            skin: 'layui-msg-success-style',
            offset: '20px'
        }
        css = $.extend(css, style)
        layer.msg(message, css)
    },
    warningMsg: function (message, style) {
        var css = {
            skin: 'layui-msg-warning-style',
            offset: '20px'
        }
        css = $.extend(css, style)
        layer.msg(message, css)
    },
    tipsMsg: function (message, style) {
        var css = {
            skin: 'layui-msg-tips-style',
            offset: '20px'
        }
        css = $.extend(css, style)
        layer.msg(message, css)
    },
    errorMsg: function (message, style) {
        var css = {
            skin: 'layui-msg-error-style',
            offset: '20px'
        }
        css = $.extend(css, style)
        layer.msg(message, css)
    },
    alert: function () {
        layer.alert()
    }
}
