/** * @author lishuwen * @time 2016-5-18:22:16 * @describe 一些常用的工具类 */ /** * 弹出一个提示信息 * @param content */ function showMessage(content) { layer.alert(content, { skin: 'layui-layer-molv', // 样式类名 closeBtn: 0, shade: 0.5, }); } /** * 关闭弹出框 */ function closeView(time = 0) { let index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引 if (time == 0) { setTimeout(() => { parent.layer.close(index); // 再执行关闭 }, 700) } else { parent.layer.close(index); // 再执行关闭 } } /** * 显示loading动画 */ function showLoding() { layer.msg('请稍等!', {icon: 16, shade: 0.3, time: false}); } /** * 隐藏loading动画 */ function cancelLoding() { let index = layer.msg('请稍等!', {icon: 16, shade: 0.2});//换了种风格 setTimeout(()=>{ layer.close(index); },300) } /** * 弹出一个成功吐司 * @param title */ function showToast(title) { layer.msg(title, {time: 1500, shade: 0.3, icon: 1}); } /** * 弹出一个错误吐司 * @param title */ function showToastError(title) { layer.msg(title, { time: 1500, icon: 2, shade: 0.3 }); } function sendAjax(url, param, callback) { showLoding(); $.ajax({ type: "post", url: url, data: param, dataType: "json", success: callback, error: function () { showMessage("服务异常") cancelLoding(); } }); }