4ef60d8af273b54c49836ae552cc3ca3bde44265978be64a27a84a12e36dc4ee7049eacb5bdd6b5416739287c06f5fa53ad7c06a02f349f600c8b9b145bf8a 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <transition name="el-alert-fade">
  3. <div
  4. class="el-alert"
  5. :class="[typeClass, center ? 'is-center' : '', 'is-' + effect]"
  6. v-show="visible"
  7. role="alert"
  8. >
  9. <i class="el-alert__icon" :class="[ iconClass, isBigIcon ]" v-if="showIcon"></i>
  10. <div class="el-alert__content">
  11. <span class="el-alert__title" :class="[ isBoldTitle ]" v-if="title || $slots.title">
  12. <slot name="title">{{ title }}</slot>
  13. </span>
  14. <p class="el-alert__description" v-if="$slots.default && !description"><slot></slot></p>
  15. <p class="el-alert__description" v-if="description && !$slots.default">{{ description }}</p>
  16. <i class="el-alert__closebtn" :class="{ 'is-customed': closeText !== '', 'el-icon-close': closeText === '' }" v-show="closable" @click="close()">{{closeText}}</i>
  17. </div>
  18. </div>
  19. </transition>
  20. </template>
  21. <script type="text/babel">
  22. const TYPE_CLASSES_MAP = {
  23. 'success': 'el-icon-success',
  24. 'warning': 'el-icon-warning',
  25. 'error': 'el-icon-error'
  26. };
  27. export default {
  28. name: 'ElAlert',
  29. props: {
  30. title: {
  31. type: String,
  32. default: ''
  33. },
  34. description: {
  35. type: String,
  36. default: ''
  37. },
  38. type: {
  39. type: String,
  40. default: 'info'
  41. },
  42. closable: {
  43. type: Boolean,
  44. default: true
  45. },
  46. closeText: {
  47. type: String,
  48. default: ''
  49. },
  50. showIcon: Boolean,
  51. center: Boolean,
  52. effect: {
  53. type: String,
  54. default: 'light',
  55. validator: function(value) {
  56. return ['light', 'dark'].indexOf(value) !== -1;
  57. }
  58. }
  59. },
  60. data() {
  61. return {
  62. visible: true
  63. };
  64. },
  65. methods: {
  66. close() {
  67. this.visible = false;
  68. this.$emit('close');
  69. }
  70. },
  71. computed: {
  72. typeClass() {
  73. return `el-alert--${ this.type }`;
  74. },
  75. iconClass() {
  76. return TYPE_CLASSES_MAP[this.type] || 'el-icon-info';
  77. },
  78. isBigIcon() {
  79. return this.description || this.$slots.default ? 'is-big' : '';
  80. },
  81. isBoldTitle() {
  82. return this.description || this.$slots.default ? 'is-bold' : '';
  83. }
  84. }
  85. };
  86. </script>