index.vue 2.1 KB

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