common.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @author lishuwen
  3. * @time 2016-5-18:22:16
  4. * @describe 一些常用的工具类
  5. */
  6. /**
  7. * 弹出一个提示信息
  8. * @param content
  9. */
  10. function showMessage(content) {
  11. layer.alert(content, {
  12. skin: 'layui-layer-molv', // 样式类名
  13. closeBtn: 0,
  14. shade: 0.5,
  15. });
  16. }
  17. /**
  18. * 关闭弹出框
  19. */
  20. function closeView(time = 0) {
  21. let index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
  22. if (time == 0) {
  23. setTimeout(() => {
  24. parent.layer.close(index); // 再执行关闭
  25. }, 700)
  26. } else {
  27. parent.layer.close(index); // 再执行关闭
  28. }
  29. }
  30. /**
  31. * 显示loading动画
  32. */
  33. function showLoding() {
  34. layer.msg('请稍等!', {icon: 16, shade: 0.3, time: false});
  35. }
  36. /**
  37. * 隐藏loading动画
  38. */
  39. function cancelLoding() {
  40. let index = layer.msg('请稍等!', {icon: 16, shade: 0.2});//换了种风格
  41. setTimeout(()=>{
  42. layer.close(index);
  43. },300)
  44. }
  45. /**
  46. * 弹出一个成功吐司
  47. * @param title
  48. */
  49. function showToast(title) {
  50. layer.msg(title, {time: 1500, shade: 0.3, icon: 1});
  51. }
  52. /**
  53. * 弹出一个错误吐司
  54. * @param title
  55. */
  56. function showToastError(title) {
  57. layer.msg(title, {
  58. time: 1500,
  59. icon: 2,
  60. shade: 0.3
  61. });
  62. }
  63. function sendAjax(url, param, callback) {
  64. showLoding();
  65. $.ajax({
  66. type: "post",
  67. url: url,
  68. data: param,
  69. dataType: "json",
  70. success: callback,
  71. error: function () {
  72. showMessage("服务异常")
  73. cancelLoding();
  74. }
  75. });
  76. }