2020-08-17 22:23:45 +08:00
|
|
|
<template>
|
|
|
|
<transition name="el-alert-fade">
|
|
|
|
<div
|
|
|
|
v-show="visible"
|
|
|
|
class="el-alert"
|
|
|
|
:class="[typeClass, center ? 'is-center' : '', 'is-' + effect]"
|
|
|
|
role="alert"
|
|
|
|
>
|
2021-10-27 23:17:13 +08:00
|
|
|
<el-icon v-if="showIcon" class="el-alert__icon" :class="isBigIcon">
|
|
|
|
<component :is="iconComponent" />
|
|
|
|
</el-icon>
|
2020-08-17 22:23:45 +08:00
|
|
|
<div class="el-alert__content">
|
2021-09-04 19:29:28 +08:00
|
|
|
<span
|
|
|
|
v-if="title || $slots.title"
|
|
|
|
class="el-alert__title"
|
|
|
|
:class="[isBoldTitle]"
|
|
|
|
>
|
2020-08-17 22:23:45 +08:00
|
|
|
<slot name="title">{{ title }}</slot>
|
|
|
|
</span>
|
2021-09-12 22:02:45 +08:00
|
|
|
<p v-if="$slots.default || description" class="el-alert__description">
|
2020-08-17 22:23:45 +08:00
|
|
|
<slot>
|
|
|
|
{{ description }}
|
|
|
|
</slot>
|
|
|
|
</p>
|
2021-10-27 23:17:13 +08:00
|
|
|
<template v-if="closable">
|
|
|
|
<div
|
|
|
|
v-if="closeText"
|
|
|
|
class="el-alert__closebtn is-customed"
|
|
|
|
@click="close"
|
|
|
|
>
|
|
|
|
{{ closeText }}
|
|
|
|
</div>
|
|
|
|
<el-icon v-else class="el-alert__closebtn" @click="close">
|
|
|
|
<close />
|
|
|
|
</el-icon>
|
|
|
|
</template>
|
2020-08-17 22:23:45 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</template>
|
2021-09-04 19:29:28 +08:00
|
|
|
<script lang="ts">
|
2021-08-24 13:36:48 +08:00
|
|
|
import { defineComponent, computed, ref } from 'vue'
|
2021-10-27 23:17:13 +08:00
|
|
|
import { ElIcon } from '@element-plus/components/icon'
|
|
|
|
import { TypeComponents, TypeComponentsMap } from '@element-plus/utils/icon'
|
|
|
|
import { alertProps, alertEmits } from './alert'
|
2020-08-17 22:23:45 +08:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'ElAlert',
|
2021-09-13 10:48:10 +08:00
|
|
|
|
2021-10-27 23:17:13 +08:00
|
|
|
components: {
|
|
|
|
ElIcon,
|
|
|
|
...TypeComponents,
|
|
|
|
},
|
|
|
|
|
2021-09-13 10:48:10 +08:00
|
|
|
props: alertProps,
|
|
|
|
emits: alertEmits,
|
|
|
|
|
|
|
|
setup(props, { emit, slots }) {
|
2020-08-17 22:23:45 +08:00
|
|
|
// state
|
|
|
|
const visible = ref(true)
|
|
|
|
|
|
|
|
// computed
|
2021-09-04 19:29:28 +08:00
|
|
|
const typeClass = computed(() => `el-alert--${props.type}`)
|
2021-10-27 23:17:13 +08:00
|
|
|
const iconComponent = computed(
|
|
|
|
() => TypeComponentsMap[props.type] || TypeComponentsMap['info']
|
2021-09-04 19:29:28 +08:00
|
|
|
)
|
|
|
|
const isBigIcon = computed(() =>
|
2021-09-13 10:48:10 +08:00
|
|
|
props.description || slots.default ? 'is-big' : ''
|
2021-09-04 19:29:28 +08:00
|
|
|
)
|
|
|
|
const isBoldTitle = computed(() =>
|
2021-09-13 10:48:10 +08:00
|
|
|
props.description || slots.default ? 'is-bold' : ''
|
2021-09-04 19:29:28 +08:00
|
|
|
)
|
2020-08-17 22:23:45 +08:00
|
|
|
|
|
|
|
// methods
|
2021-09-13 10:48:10 +08:00
|
|
|
const close = (evt: MouseEvent) => {
|
2020-08-17 22:23:45 +08:00
|
|
|
visible.value = false
|
2021-09-13 10:48:10 +08:00
|
|
|
emit('close', evt)
|
2020-08-17 22:23:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
visible,
|
|
|
|
typeClass,
|
2021-10-27 23:17:13 +08:00
|
|
|
iconComponent,
|
2020-08-17 22:23:45 +08:00
|
|
|
isBigIcon,
|
|
|
|
isBoldTitle,
|
|
|
|
close,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|