AiMessage.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!-- ai全局提示 message -->
  2. <template>
  3. <div
  4. v-if="visible"
  5. class="ai-message"
  6. :class="{
  7. success: option.type === 'success',
  8. warning: option.type === 'warning',
  9. error: option.type === 'error'
  10. }"
  11. >
  12. {{ option.text }}
  13. </div>
  14. </template>
  15. <script setup lang="ts">
  16. import { watch, computed } from 'vue'
  17. const props = defineProps({
  18. /*
  19. 配置
  20. text: 提示文字
  21. type: 提示状态 success warning error
  22. */
  23. messageOption: {
  24. type: Object,
  25. default: () => {}
  26. },
  27. visible: {
  28. type: Boolean,
  29. default: false
  30. }
  31. })
  32. const option = computed(() => {
  33. return {
  34. text: '',
  35. type: '', // success warning error
  36. ...props.messageOption
  37. }
  38. })
  39. const emit = defineEmits(['update:visible'])
  40. watch(
  41. () => props.visible,
  42. (value) => {
  43. if (value) {
  44. setTimeout(() => {
  45. emit('update:visible', false)
  46. }, 1500)
  47. }
  48. }
  49. )
  50. </script>
  51. <style lang="less" scoped>
  52. @import '../styles/variables.less';
  53. .ai-message {
  54. position: absolute;
  55. left: 50%;
  56. top: 50%;
  57. transform: translate(-50%, -50%);
  58. background: #fff;
  59. padding: 8px 16px;
  60. border-radius: 8px;
  61. box-shadow: 2px 2px 10px 2px rgba(0, 0, 0, 0.1);
  62. max-width: 300px;
  63. border: 1px solid transparent;
  64. &.success {
  65. // border-color: $--color-success;
  66. color: @color-success;
  67. // box-shadow: 2px 2px 10px 2px rgba($--color-success, 0.1);
  68. }
  69. &.warning {
  70. // border-color: $--color-warning;
  71. color: @color-warning;
  72. // box-shadow: 2px 2px 10px 2px rgba($--color-warning, 0.1);
  73. }
  74. &.error {
  75. // border-color: $--color-danger;
  76. color: @color-danger;
  77. // box-shadow: 2px 2px 10px 2px rgba($--color-danger, 0.1);
  78. }
  79. }
  80. </style>