mui顯示等待框

這裏使用的是5+自帶的等待框:

 

plus.nativeUI.showWaiting();  //等待框開啓

 

plus.nativeUI.closeWaiting(); //等待框關閉

 

參考:https://blog.csdn.net/weixin_44285250/article/details/87918882

不過有的時候會出現這樣的問題,當我用ajax請求數據的時候,數據請求過快,導致我剛開始等待就直接關閉了,從用戶的角度就是看不到加載的等待框。所以這邊加了個延時操作setTimeout:

setTimeout(function() {
                        plus.nativeUI.closeWaiting(); //等待框關閉
                        if (res.success) {
                            if (res.count <= 0) {

                            } else {
                                var flag = "";
                                var src = "";
                                var computerName = "";
                                var machineType = "";
                                var userDepartment = "";
                                var userName = "";
                                var userCode = "";
                                var productCode = "";
                                var location = "";
                                var type = "";
                                var count = res.data.length;
                                for (var i = 0; i < count; i++) {
                                    var dom = document.createElement("li");
                                    dom.className = "mui-table-view-cell mui-input-row";
                                    if (res.data[i].flag == "0") {
                                        flag = "待完善";
                                        src = "../../images/dairuku.png";
                                    }
                                    if (res.data[i].computerName == null) {
                                        computerName = "";
                                    } else {
                                        computerName = res.data[i].computerName;
                                    }

                                    if (res.data[i].machineType == null) {
                                        machineType = "";
                                    } else {
                                        machineType = res.data[i].machineType;
                                    }

                                    if (res.data[i].userDepartment == null) {
                                        userDepartment = "";
                                    } else {
                                        userDepartment = res.data[i].userDepartment;
                                    }

                                    if (res.data[i].userName == null) {
                                        userName = "";
                                    } else {
                                        userName = res.data[i].userName;
                                    }

                                    if (res.data[i].userCode == null) {
                                        userCode = "";
                                    } else {
                                        userCode = res.data[i].userCode;
                                    }

                                    if (res.data[i].productCode == null) {
                                        productCode = "";
                                    } else {
                                        productCode = res.data[i].productCode;
                                    }

                                    if (res.data[i].flag == null) {
                                        flag = "";
                                    } else {
                                        flag = res.data[i].flag;
                                    }
                                    if (res.data[i].location == null) {
                                        location = "";
                                    } else {
                                        location = res.data[i].location;
                                    }
                                    if (res.data[i].type == null) {
                                        type = "";
                                    } else {
                                        type = res.data[i].type;
                                    }
                                    dom.innerHTML = '<a href="javascript:;" title="ZiChanLingYong_Detail.html" id="' + res.data[i].id + '">' +
                                        '<img class="mui-media-object mui-pull-right" src="' + src + '">' +
                                        '<div class="mui-media-body">' +
                                        '申請人:' + res.data[i].applier +
                                        '<p class="mui-ellipsis">計算機名:' + computerName + '&nbsp;&nbsp;&nbsp;&nbsp;出廠編碼:' + productCode + '</p>' +
                                        '<span computerName="' + computerName + '" machineType="' + machineType + '" userDepartment="' +
                                        userDepartment + '" userName="' + userName + '" userCode = "' + userCode + '" productCode="' +
                                        productCode +
                                        '" flag = "' + flag + '" location = "' + location + '" type = "' + type + '"></span>'
                                    '</div>' +
                                    '</a>';
                                    document.getElementById("aa").appendChild(dom);
                                }
                            }
                        } else {
                            mui.toast(res.msg);
                        }
                    }, 500);

當請求返回成功的時候,加了500ms的timeout,那麼不管怎麼樣,都能成功顯示加載框。

另外,還可以在方法中添加參數:plus.nativeUI.showWaiting(“等待中...”);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章