custom-modal.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view v-if="visible" class="modal-overlay" @click.stop="handleOverlayClick">
  3. <view class="modal-container" @click.stop>
  4. <view class="modal-title">{{ title }}</view>
  5. <view class="modal-content">{{ content }}</view>
  6. <view class="modal-footer">
  7. <view v-if="showCancel" class="modal-btn cancel-btn" @click="handleCancel">
  8. {{ cancelText }}
  9. </view>
  10. <view class="modal-btn confirm-btn" @click="handleConfirm">
  11. {{ confirmText }}
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'CustomModal',
  20. props: {
  21. visible: {
  22. type: Boolean,
  23. default: false
  24. },
  25. title: {
  26. type: String,
  27. default: '提示'
  28. },
  29. content: {
  30. type: String,
  31. default: ''
  32. },
  33. showCancel: {
  34. type: Boolean,
  35. default: false
  36. },
  37. cancelText: {
  38. type: String,
  39. default: '取消'
  40. },
  41. confirmText: {
  42. type: String,
  43. default: '确定'
  44. }
  45. },
  46. methods: {
  47. handleConfirm() {
  48. this.$emit('confirm')
  49. },
  50. handleCancel() {
  51. this.$emit('cancel')
  52. },
  53. handleOverlayClick() {
  54. // 点击遮罩层不做任何操作,防止误触
  55. }
  56. }
  57. }
  58. </script>
  59. <style scoped>
  60. .modal-overlay {
  61. position: fixed;
  62. top: 0;
  63. left: 0;
  64. right: 0;
  65. bottom: 0;
  66. background-color: rgba(0, 0, 0, 0.6);
  67. display: flex;
  68. align-items: center;
  69. justify-content: center;
  70. z-index: 9999;
  71. }
  72. .modal-container {
  73. width: 600rpx;
  74. background-color: #fff;
  75. border-radius: 16rpx;
  76. overflow: hidden;
  77. }
  78. .modal-title {
  79. padding: 40rpx 40rpx 20rpx;
  80. font-size: 36rpx;
  81. font-weight: 600;
  82. color: #333;
  83. text-align: center;
  84. }
  85. .modal-content {
  86. padding: 20rpx 40rpx 40rpx;
  87. font-size: 32rpx;
  88. color: #666;
  89. text-align: center;
  90. line-height: 1.6;
  91. }
  92. .modal-footer {
  93. display: flex;
  94. border-top: 1rpx solid #e5e5e5;
  95. }
  96. .modal-btn {
  97. flex: 1;
  98. padding: 30rpx;
  99. font-size: 34rpx;
  100. text-align: center;
  101. color: #333;
  102. }
  103. .cancel-btn {
  104. border-right: 1rpx solid #e5e5e5;
  105. color: #666;
  106. }
  107. .confirm-btn {
  108. color: #576b95;
  109. font-weight: 500;
  110. }
  111. </style>