Toast.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports["default"] = void 0;
  5. var _utils = require("../utils");
  6. var _popup = require("../mixins/popup");
  7. var _icon = _interopRequireDefault(require("../icon"));
  8. var _loading = _interopRequireDefault(require("../loading"));
  9. var _use = (0, _utils.use)('toast'),
  10. sfc = _use[0],
  11. bem = _use[1];
  12. var STYLE = ['success', 'fail', 'loading'];
  13. var _default = sfc({
  14. mixins: [_popup.PopupMixin],
  15. props: {
  16. className: null,
  17. forbidClick: Boolean,
  18. message: [String, Number],
  19. type: {
  20. type: String,
  21. "default": 'text'
  22. },
  23. loadingType: {
  24. type: String,
  25. "default": 'circular'
  26. },
  27. position: {
  28. type: String,
  29. "default": 'middle'
  30. },
  31. lockScroll: {
  32. type: Boolean,
  33. "default": false
  34. }
  35. },
  36. data: function data() {
  37. return {
  38. clickable: false
  39. };
  40. },
  41. mounted: function mounted() {
  42. this.toggleClickale();
  43. },
  44. destroyed: function destroyed() {
  45. this.toggleClickale();
  46. },
  47. watch: {
  48. value: function value() {
  49. this.toggleClickale();
  50. },
  51. forbidClick: function forbidClick() {
  52. this.toggleClickale();
  53. }
  54. },
  55. methods: {
  56. toggleClickale: function toggleClickale() {
  57. var clickable = this.value && this.forbidClick;
  58. if (this.clickable !== clickable) {
  59. this.clickable = clickable;
  60. var action = clickable ? 'add' : 'remove';
  61. document.body.classList[action]('van-toast--unclickable');
  62. }
  63. }
  64. },
  65. render: function render(h) {
  66. var _this = this;
  67. var type = this.type,
  68. message = this.message;
  69. var style = STYLE.indexOf(type) !== -1 ? 'default' : type;
  70. var Content = function Content() {
  71. switch (style) {
  72. case 'text':
  73. return h("div", [message]);
  74. case 'html':
  75. return h("div", {
  76. "domProps": {
  77. "innerHTML": message
  78. }
  79. });
  80. default:
  81. return [type === 'loading' ? h(_loading["default"], {
  82. "attrs": {
  83. "color": "white",
  84. "type": _this.loadingType
  85. }
  86. }) : h(_icon["default"], {
  87. "class": bem('icon'),
  88. "attrs": {
  89. "name": type
  90. }
  91. }), (0, _utils.isDef)(message) && h("div", {
  92. "class": bem('text')
  93. }, [message])];
  94. }
  95. };
  96. return h("transition", {
  97. "attrs": {
  98. "name": "van-fade"
  99. }
  100. }, [h("div", {
  101. "directives": [{
  102. name: "show",
  103. value: this.value
  104. }],
  105. "class": [bem([style, this.position]), this.className]
  106. }, [Content()])]);
  107. }
  108. });
  109. exports["default"] = _default;