1. <script setup lang="ts">
    2. defineProps({
    3. show: {
    4. type: Boolean,
    5. default: false
    6. },
    7. title: {
    8. type: String,
    9. default: ''
    10. },
    11. message: {
    12. type: String,
    13. default: ''
    14. },
    15. close: {
    16. type: Function,
    17. default: function e(fn: Function) {
    18. fn()
    19. }
    20. }
    21. })
    22. const emit = defineEmits(['update:show'])
    23. const handleClick = () => {
    24. emit('update:show', false)
    25. }
    26. </script>
    27. <template>
    28. <div v-if="show" class="dialog-mask flex-center">
    29. <div class="dialog-box">
    30. <div class="dialog-header">{{title}}</div>
    31. <div class="dialog-content">{{message}}</div>
    32. <div class="dialog-footer">
    33. <button class="button" @click="close(handleClick)">确定</button>
    34. </div>
    35. </div>
    36. </div>
    37. </template>
    38. <style lang="scss">
    39. .flex-center {
    40. display: flex;
    41. justify-content: center;
    42. align-items: center;
    43. }
    44. .dialog-mask {
    45. position: fixed;
    46. left: 0;
    47. top: 0;
    48. width: 100%;
    49. height: 100%;
    50. background-color: rgba(0, 0, 0, 0.5);
    51. z-index: 1000;
    52. }
    53. .dialog-box {
    54. background-color: #fff;
    55. width: 300px;
    56. border-radius: 10px;
    57. overflow: hidden;
    58. .dialog-header {
    59. padding-top: 20px;
    60. font-weight: bold;
    61. text-align: center;
    62. }
    63. .dialog-content {
    64. padding: 5px 20px 20px 20px;
    65. font-size: 12px;
    66. text-align: center;
    67. white-space: pre-wrap;
    68. word-wrap: break-word;
    69. }
    70. .dialog-footer {
    71. display: flex;
    72. overflow: hidden;
    73. user-select: none;
    74. border-top: 1px solid #EBEDF0;
    75. .button {
    76. color: rgb(67, 103, 186);
    77. text-align: center;
    78. width: 100%;
    79. line-height: 40px;
    80. background-color: #fff;
    81. border: none;
    82. }
    83. .button:active {
    84. background-color: #f2f3f5;
    85. }
    86. }
    87. }
    88. </style>
    1. import { createApp } from 'vue'
    2. import Dialog from './index.vue'
    3. const createDialog = (title: String, message: String) => {
    4. const mountNode = document.createElement('div')
    5. const Instance = createApp(Dialog, {
    6. show: true,
    7. message,
    8. title,
    9. close: () => {
    10. Instance.unmount()
    11. document.body.removeChild(mountNode)
    12. },
    13. })
    14. Instance.mount(mountNode)
    15. document.body.appendChild(mountNode)
    16. }
    17. export default createDialog