123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <template>
- <div class="m-alert" :class="typeClass" v-show="visible">
- <i class="iconfont m-alert__icon" :class="[ iconClass, isBigIcon ]" v-if="showIcon"></i>
- <div class="m-alert__content">
- <span class="m-alert__title" :class="isBoldTitle">
- <slot name="title">{{ title }}</slot>
- </span>
- <p class="m-alert__description" v-if="$slots.default && !description"><slot></slot></p>
- <p class="m-alert__description" v-if="description && !$slots.default">{{ description }}</p>
- <i class="iconfont m-alert__closebtn" :class="closeIconClass" @click="close" v-show="closable">
- {{closeText}}
- </i>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: "mAlert"
- };
- </script>
- <script setup>
- import { computed, ref } from 'vue-demi';
- const TYPE_CLASSES_MAP = {
- 'success': 'icon-success-filling',
- 'warning': 'icon-warning-filling',
- 'error': 'icon-delete-filling'
- };
- const emit = defineEmits(['close'])
- const props = defineProps({
- title: {
- type: String,
- default: ''
- },
- type: {
- type: String,
- default: 'info'
- },
- effect: {
- type: String,
- default: 'light',
- validator: function(value) {
- return ['light', 'dark'].indexOf(value) !== -1;
- }
- },
- closable: {
- type: Boolean,
- default: true
- },
- closeText: {
- type: String,
- default: ''
- },
- showIcon: Boolean,
- center: Boolean,
- description: {
- type: String,
- default: ''
- },
- })
- const visible = ref(true)
- const typeClass = computed(() => {
- return {
- [`m-alert--${props.type}`]: props.type,
- [`is-${props.effect}`]:props.effect,
- 'is-center': props.center
- }
- })
- const closeIconClass = computed(() => {
- return {
- 'icon-close': props.closeText === '',
- 'is-customed': props.closeText !== ''
- }
- })
- const iconClass = computed(() => {
- return TYPE_CLASSES_MAP[props.type] || 'icon-prompt-filling';
- })
- const isBigIcon = computed(() => {
- })
- const isBoldTitle = computed(() => {
- return props.description ? 'is-bold' : '';
- })
- const close = () => {
- visible.value = false
- emit('close')
- }
- </script>
- <style lang="scss" scoped>
- @import '../../styles/components/alert.scss';
- </style>
|