146 lines
3.0 KiB
JavaScript
146 lines
3.0 KiB
JavaScript
export default {
|
|
// 消息提示
|
|
msg(content) {
|
|
uni.showToast({
|
|
title: content,
|
|
icon: 'none'
|
|
})
|
|
},
|
|
// 错误消息
|
|
msgError(content) {
|
|
uni.showToast({
|
|
title: content,
|
|
icon: 'error',
|
|
mask: true,
|
|
duration: 2000,
|
|
})
|
|
},
|
|
|
|
msgFail(content) {
|
|
uni.showToast({
|
|
title: content,
|
|
icon: 'fail',
|
|
})
|
|
},
|
|
|
|
// 成功消息
|
|
msgSuccess(content, complete) {
|
|
uni.showToast({
|
|
title: content,
|
|
icon: 'success'
|
|
})
|
|
},
|
|
// 隐藏消息
|
|
hideMsg(content) {
|
|
uni.hideToast()
|
|
},
|
|
// 弹出提示
|
|
// alert(content) {
|
|
// uni.showModal({
|
|
// title: '提示',
|
|
// content: content,
|
|
// showCancel: false
|
|
// })
|
|
// },
|
|
alert(...args) {
|
|
let config = {
|
|
title: '提示',
|
|
content: '',
|
|
showCancel: false
|
|
};
|
|
|
|
// 如果第一个参数是对象,说明是完整配置
|
|
if (typeof args[0] === 'object') {
|
|
config = args[0];
|
|
}
|
|
// alert(content)
|
|
else if (args.length === 1 && typeof args[0] === 'string') {
|
|
config.content = args[0];
|
|
}
|
|
// alert(title, content)
|
|
else if (args.length === 2 && typeof args[0] === 'string' && typeof args[1] === 'string') {
|
|
config.title = args[0];
|
|
config.content = args[1];
|
|
}
|
|
// alert(title, content, success)
|
|
else if (args.length === 3 && typeof args[0] === 'string' && typeof args[1] === 'string' && typeof args[2] ===
|
|
'function') {
|
|
config.title = args[0];
|
|
config.content = args[1];
|
|
config.success = args[2];
|
|
}
|
|
// alert(content, success?, fail?, complete?)
|
|
else {
|
|
config.content = args[0];
|
|
const [success, fail, complete] = args.slice(1);
|
|
if (typeof success === 'function') config.success = success;
|
|
if (typeof fail === 'function') config.fail = fail;
|
|
if (typeof complete === 'function') config.complete = complete;
|
|
}
|
|
|
|
uni.showModal(config);
|
|
},
|
|
/*
|
|
* 使用方法
|
|
* this.$modal.scanCode((res) => {
|
|
let result = res.result;
|
|
})
|
|
*/
|
|
scanCode(...args) {
|
|
let config = {
|
|
onlyFromCamera: true,
|
|
scanType: ['barCode', 'qrCode']
|
|
}
|
|
|
|
if (args.length === 1 && typeof args[0] === 'object') {
|
|
config = args;
|
|
} else {
|
|
const [success, fail, complete] = args;
|
|
if (typeof success === 'function') config.success = success;
|
|
if (typeof fail === 'function') config.fail = fail;
|
|
if (typeof complete === 'function') config.complete = complete;
|
|
}
|
|
|
|
uni.scanCode(config);
|
|
},
|
|
// 确认窗体
|
|
confirm(content) {
|
|
return new Promise((resolve, reject) => {
|
|
uni.showModal({
|
|
title: '系统提示',
|
|
content: content,
|
|
cancelText: '取消',
|
|
confirmText: '确定',
|
|
success: function(res) {
|
|
if (res.confirm) {
|
|
resolve(res.confirm)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// 提示信息
|
|
showToast(option) {
|
|
if (typeof option === "object") {
|
|
uni.showToast(option)
|
|
} else {
|
|
uni.showToast({
|
|
title: option,
|
|
icon: "none",
|
|
duration: 2500
|
|
})
|
|
}
|
|
},
|
|
// 打开遮罩层
|
|
loading(content) {
|
|
uni.showLoading({
|
|
title: content,
|
|
// icon: 'none',
|
|
mask: true
|
|
})
|
|
},
|
|
// 关闭遮罩层
|
|
closeLoading() {
|
|
uni.hideLoading()
|
|
}
|
|
} |