找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

微信小程序封装消息快速显示

作者:模板之家 2020-5-20 10:06 9591人关注

我记不住腾讯那些消息显示的方法,自己封装熟悉的名字 msg.js var x = {};x.success = function(title, cb){ var config = {}; config.title = title; config.icon = success; config.mask = true; config.duration ...

我记不住腾讯那些消息显示的方法,自己封装熟悉的名字

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"];
取消是内置的,如果点击了取消,不会执行success函数
索引从0开始
*/
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("错误", response.data.msg);
    }
    else{
        cb();
    }
};

module.exports = x;

 

路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)