2020-08-17 22:23:45 +08:00
|
|
|
<template>
|
2022-02-08 09:09:54 +08:00
|
|
|
<transition :name="ns.b('fade')">
|
2020-08-17 22:23:45 +08:00
|
|
|
<div
|
|
|
|
v-show="visible"
|
2022-01-19 15:04:01 +08:00
|
|
|
:class="[ns.b(), ns.m(type), ns.is('center', center), ns.is(effect)]"
|
2020-08-17 22:23:45 +08:00
|
|
|
role="alert"
|
|
|
|
>
|
2021-11-05 17:44:02 +08:00
|
|
|
<el-icon
|
|
|
|
v-if="showIcon && iconComponent"
|
2022-01-19 10:26:31 +08:00
|
|
|
:class="[ns.e('icon'), isBigIcon]"
|
2021-11-05 17:44:02 +08:00
|
|
|
>
|
2021-10-27 23:17:13 +08:00
|
|
|
<component :is="iconComponent" />
|
|
|
|
</el-icon>
|
2022-01-19 10:26:31 +08:00
|
|
|
<div :class="ns.e('content')">
|
2021-09-04 19:29:28 +08:00
|
|
|
<span
|
|
|
|
v-if="title || $slots.title"
|
2022-01-19 10:26:31 +08:00
|
|
|
:class="[ns.e('title'), isBoldTitle]"
|
2021-09-04 19:29:28 +08:00
|
|
|
>
|
2020-08-17 22:23:45 +08:00
|
|
|
<slot name="title">{{ title }}</slot>
|
|
|
|
</span>
|
2022-01-19 10:26:31 +08:00
|
|
|
<p v-if="$slots.default || description" :class="ns.e('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"
|
2022-02-11 23:37:50 +08:00
|
|
|
:class="[ns.e('close-btn'), ns.is('customed')]"
|
2021-10-27 23:17:13 +08:00
|
|
|
@click="close"
|
|
|
|
>
|
|
|
|
{{ closeText }}
|
|
|
|
</div>
|
2022-02-11 23:37:50 +08:00
|
|
|
<el-icon v-else :class="ns.e('close-btn')" @click="close">
|
2021-10-27 23:17:13 +08:00
|
|
|
<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'
|
2022-02-11 11:03:15 +08:00
|
|
|
import { TypeComponents, TypeComponentsMap } from '@element-plus/utils'
|
2022-01-19 10:26:31 +08:00
|
|
|
import { useNamespace } from '@element-plus/hooks'
|
2021-10-27 23:17:13 +08:00
|
|
|
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 }) {
|
2022-01-19 10:26:31 +08:00
|
|
|
const ns = useNamespace('alert')
|
|
|
|
|
2020-08-17 22:23:45 +08:00
|
|
|
// state
|
|
|
|
const visible = ref(true)
|
|
|
|
|
|
|
|
// computed
|
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(() =>
|
2022-01-19 15:04:01 +08:00
|
|
|
props.description || slots.default ? ns.is('big') : ''
|
2021-09-04 19:29:28 +08:00
|
|
|
)
|
|
|
|
const isBoldTitle = computed(() =>
|
2022-01-19 15:04:01 +08:00
|
|
|
props.description || slots.default ? ns.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 {
|
2022-01-19 10:26:31 +08:00
|
|
|
ns,
|
2020-08-17 22:23:45 +08:00
|
|
|
visible,
|
2021-10-27 23:17:13 +08:00
|
|
|
iconComponent,
|
2020-08-17 22:23:45 +08:00
|
|
|
isBigIcon,
|
|
|
|
isBoldTitle,
|
|
|
|
close,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|