1
0

message.vue 1.0 KB

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