message.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /** iwb_admin-v1.1.0 MIT License By http://www.iwbnet.com e-mail:yueyy@iwbnet.com */
  2. ;/**
  3. * Name:message.js
  4. * Author:Van
  5. * E-mail:yueyy@iwbnet.com
  6. * Website:http://www.iwbnet.com
  7. * LICENSE:MIT
  8. */
  9. layui.define(['jquery', 'iwbConfig'], function (exports) {
  10. var $ = layui.jquery,
  11. iwbConfig = layui.iwbConfig,
  12. //modName = 'message',
  13. //doc = $(document),
  14. body = $('body'),
  15. msgSelect = 'iwb-message';
  16. var message = {
  17. v: '1.0.0',
  18. times: 1,
  19. _message: function () {
  20. var msg = $("." + msgSelect);
  21. if (msg.length > 0)
  22. return msg;
  23. body.append('<div class="'+msgSelect+'"></div>');
  24. return $("." + msgSelect);
  25. },
  26. show: function (options) {
  27. options = options || {};
  28. var that = this,
  29. id = that.times,
  30. skin = options.skin === undefined ? 'blue' : options.skin,
  31. msg = options.msg === undefined ? '请输入一些提示信息!' : options.msg,
  32. autoClose = options.autoClose === undefined ? true : options.autoClose,
  33. ms = that._message();
  34. var tpl = [
  35. '<div class="iwb-message-item layui-anim layui-anim-upbit" data-times="' + id + '">',
  36. '<div class="iwb-message-body iwb-skin-' + skin + '">',
  37. msg,
  38. '</div>',
  39. '<div class="iwb-close iwb-skin-' + skin + '"><i class="fa fa-times" aria-hidden="true"></i></div>',
  40. '</div>'
  41. ];
  42. ms.append(tpl.join(''));
  43. var times = ms.children('div[data-times=' + id + ']').find('i.fa-times');
  44. times.off('click').on('click', function () {
  45. var t = $(this).parents('div.iwb-message-item').removeClass('layui-anim-upbit').addClass('layui-anim-fadeout');
  46. setTimeout(function () {
  47. t.remove();
  48. }, 1000);
  49. });
  50. if (autoClose) { //是否自动关闭
  51. setTimeout(function () {
  52. times.click();
  53. }, 3000);
  54. }
  55. that.times++;
  56. }
  57. };
  58. layui.link(iwbConfig.resourcePath + 'plugins/layui/css/extend/message.css');
  59. exports('message', message);
  60. });