message.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <teleport to="body">
  3. <transition name="fade">
  4. <div class="ui-message" :style="{ zIndex: zIndex, marginTop: `${index.value * 60}px` }" :class="type" v-if="show">
  5. <ui-icon :type="icons[type]" class="icon" />
  6. <p>{{ msg }}</p>
  7. </div>
  8. </transition>
  9. </teleport>
  10. </template>
  11. <script setup>
  12. import uiIcon from '../icon'
  13. import getZindex from '../../utils/zindex'
  14. import { defineProps, onMounted, ref, nextTick } from 'vue'
  15. const props = defineProps({
  16. msg: {
  17. type: String,
  18. },
  19. type: {
  20. type: String,
  21. },
  22. time: {
  23. type: Number,
  24. },
  25. destroy: {
  26. type: Function,
  27. },
  28. index: {},
  29. })
  30. const zIndex = getZindex()
  31. const icons = {
  32. success: 'state_s',
  33. warning: 'state_e',
  34. error: 'state_f',
  35. }
  36. const show = ref(false)
  37. if (props.time) {
  38. setTimeout(() => {
  39. show.value = false
  40. setTimeout(props.destroy, 500)
  41. }, props.time)
  42. }
  43. onMounted(() => nextTick(() => (show.value = true)))
  44. </script>
  45. <script>
  46. export default { name: 'UiMessage' }
  47. </script>