message.vue 1.1 KB

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