小程序模板網(wǎng)

微信小程序封裝消息快速顯示

發(fā)布時(shí)間:2020-05-20 10:05 所屬欄目:小程序開(kāi)發(fā)教程

我記不住騰訊那些消息顯示的方法,自己封裝熟悉的名字

msg.js

 

var x = {};

x.success = function(title, cb)
{
    var config = {};
    config.title = title;
    config.icon = "success";
    config.mask = true;
    config.duration = 3000;
    if(cb){
        config.success = function(){
            setTimeout(cb, config.duration);
        };
    }
    wx.showToast(config);
}

x.fail = function(title, cb)
{
    var config = {};
    config.title = title;
    config.image = "/images/error.png";
    config.mask = true;
    config.duration = 3000;
    if(cb){
        config.success = function(){
            setTimeout(cb, config.duration);
        };
    }
    wx.showToast(config);
}

x.loading = function(title, cb)
{
    var config = {};
    config.title = title;
    config.icon = "loading";
    config.mask = true;
    config.duration = 3000;
    if(cb){
        config.success = function(){
            setTimeout(cb, config.duration);
        };
    }
    wx.showToast(config);
}

x.none = function(title, cb)
{
    var config = {};
    config.title = title;
    config.icon = "none";
    config.mask = true;
    config.duration = 3000;
    if(cb){
        config.success = function(){
            setTimeout(cb, config.duration);
        };
    }
    wx.showToast(config);
}

x.sure = function(title, content, cb)
{
    var config = {};
    config.title = title;
    config.content = content;
    config.showCancel = false;
    config.success = function(res){
        if(res.confirm && cb){
            cb();
        }
    };
    wx.showModal(config);
};

x.sureCancel = function(title, content, cb1, cb2)
{
    var config = {};
    config.title = title;
    config.content = content;
    config.showCancel = true;
    config.success = function(res){
        if(res.confirm){
            if(cb1){
                cb1();
            }
        }
        else if(res.cancel){
            if(cb2){
                cb2();
            }
        }
    };
    wx.showModal(config);
};

x.showLoading = function(title, cb)
{
    var config = {};
    config.title = title;
    config.mask = true;
    if(cb){
        cb();
    }
    wx.showLoading(config);
};

x.hideLoading = function()
{
    wx.hideLoading();
};

/*
var title = ["A", "B"];
取消是內(nèi)置的,如果點(diǎn)擊了取消,不會(huì)執(zhí)行success函數(shù)
索引從0開(kāi)始
*/
x.list = function(title, cb)
{
    var config = {};
    config.itemList = title;
    config.success = function(res){
        cb(res.tapIndex);
    };
    wx.showActionSheet(config);
};

x.ifFailStop = function(response, cb)
{
    if(response.data.code > 0){
        x.sure("錯(cuò)誤", response.data.msg);
    }
    else{
        cb();
    }
};

module.exports = x;

 


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://22321a.com/wxmini/doc/course/25233.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢