loading.js 2.3 KB
export function showloading(txt) {
    $("#luckysheet-cell-loading").find("span").text(txt).end().show();
};

export function hideloading() {
    $("#luckysheet-cell-loading").hide();
};




// 消息弹框 ***********************************************************
const showAlert = (message, style, time)  =>{
    style = (style === undefined) ? 'alert-success-custom' : style;
    time = (time === undefined) ? 5000 : time;
    var iconName = 'fa-check';
    if(style === 'alert-warning-custom'){
        iconName = 'fa-warning';
    } else if(style === 'alert-danger-custom'){
        iconName = 'fa-times';
    }
    var id = (new Date()).getTime();
    var icon = `<i style="font-size:14px;margin-right: 3px;" class="fa ${iconName} ${style}" aria-hidden="true"></i>`
    $(`<div id="${id}"></div>`)
        .appendTo('body')
        .addClass('alert-custom ' + style)
        .html(icon + message)
        .show()
        .delay(time)
        .fadeOut();
    // 隐藏后删除
    setTimeout(function (){
        $('#'+id).remove();
    },5500)
};

export function showSuccess(message, style, time) {
    showAlert(message,'alert-success-custom');
};

export function showDanger(message, style, time) {
    showAlert(message,'alert-danger-custom');
};

export function showWarning(message, style, time) {
    showAlert(message,'alert-warning-custom');
};

var func = null;
var arr = [];
/**
 * 延迟加载函数
 * @param message
 * @param style
 * @param time
 */
export function delayMessage(data) {
    let message = data.handelMsg;

    if(!message){
        return;
    }

    var id = 'toast' + (new Date()).getTime();
    var html = `<div id="${id}"   class="toast align-items-center border-0 m-2" role="alert" aria-live="assertive" aria-atomic="true">
      <div class="d-flex">
        <div class="toast-body">
          ${message}
        </div>
        <button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
      </div>
    </div>`;
    if($('#delayMessageLive').length == 0){
        $(`<div id="delayMessageLive" class="position-absolute top-0 end-0 p-3" style="z-index: 100000"></div>`).appendTo('body');
    }
    $(html).appendTo('#delayMessageLive');

    var toastLiveExample = document.getElementById(id)
    var toast = new bootstrap.Toast(toastLiveExample)
    toast.show()
};