uview-ui-pr
Version:
uView UI,是uni-app生态优秀的UI框架,全面的组件和便捷的工具会让您信手拈来,如鱼得水
138 lines (131 loc) • 2.71 kB
JavaScript
/**
* 提示与加载工具类
*/
const tips = {
isLoading: false,
isConfirm: false,
/**
* 成功弹框
* @param {String} title 文案
* @param {Number} duration 显示时长
*/
success(title, duration = 1500, mask = true) {
uni.showToast({
title: title,
icon: "success",
mask: mask,
duration: duration,
});
if (duration > 0) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, duration);
});
}
},
/**
* 失败弹框
* @param {String} title 文案
* @param {Number} duration 显示时长
*/
error(title, duration = 1500, mask = true) {
uni.showToast({
title: title,
icon: "error",
mask: mask,
duration: duration,
});
if (duration > 0) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, duration);
});
}
},
/**
* 确认窗口
* @param {Object/String} params 参数
* 参数为 String 时,为显示的文案内容
*/
confirm(params) {
if (this.isConfirm) {
return false;
}
this.isConfirm = true;
if (typeof params === "string") {
params = {
content: params,
};
}
return new Promise((resolve, reject) => {
uni.showModal({
title: String(params.title || "提示"),
content: params.content,
showCancel: params.showCancel || false,
cancelText: params.cancelText || "取消",
confirmText: params.confirmText || "确定",
// #ifdef H5 || MP-WEIXIN || MP-BAIDU
cancelColor: params.cancelColor || "#000000",
confirmColor: params.confirmColor || "#576B95",
// #endif
success: (res) => {
this.isConfirm = false;
if (res.confirm) {
resolve(true);
} else if (res.cancel) {
resolve(false);
}
},
fail: (res) => {
this.isConfirm = false;
resolve(false);
},
});
});
},
/**
* 普通 无图标
* @param {String} title 文案
*/
toast(title, duration = 1500, mask = true) {
uni.showToast({
title: title,
icon: "none",
mask: mask,
duration,
});
if (duration > 0) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, duration);
});
}
},
/**
* 弹出加载提示
* @param {String} title 文案
*/
loading(title = "加载中...", mask = true) {
if (this.isLoading) {
return;
}
this.isLoading = true;
uni.showLoading({
title: title,
mask: mask,
});
},
/**
* 加载完毕
*/
loaded() {
if (this.isLoading) {
this.isLoading = false;
uni.hideLoading();
}
},
};
export default tips;