common-dialog.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <u-popup v-model="showPopup" @close="closePopup" mode="center" border-radius="20">
  3. <view class="dialog-content">
  4. <!-- 标题 -->
  5. <view v-if="title" class="dialog-title">{{ title }}</view>
  6. <!-- 内容插槽 -->
  7. <view class="dialog-body">
  8. <slot></slot>
  9. </view>
  10. <!-- 按钮区域 -->
  11. <view class="dialog-footer" :class="{ 'single-btn': !showCancel }">
  12. <button v-if="showCancel" class="cancel-btn" @click="handleCancel">{{ cancelText }}</button>
  13. <button class="confirm-btn" @click="handleConfirm">{{ confirmText }}</button>
  14. </view>
  15. </view>
  16. </u-popup>
  17. </template>
  18. <script>
  19. export default {
  20. props: {
  21. // 弹窗标题
  22. title: {
  23. type: String,
  24. default: '温馨提示'
  25. },
  26. // 是否显示取消按钮
  27. showCancel: {
  28. type: Boolean,
  29. default: true
  30. },
  31. // 确认按钮文字
  32. confirmText: {
  33. type: String,
  34. default: '确定'
  35. },
  36. // 取消按钮文字
  37. cancelText: {
  38. type: String,
  39. default: '取消'
  40. }
  41. },
  42. data() {
  43. return {
  44. showPopup: false
  45. }
  46. },
  47. methods: {
  48. openPopup() {
  49. this.showPopup = true
  50. },
  51. closePopup() {
  52. this.showPopup = false
  53. },
  54. handleConfirm() {
  55. this.$emit('confirm')
  56. this.closePopup()
  57. },
  58. handleCancel() {
  59. this.$emit('cancel')
  60. this.closePopup()
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss">
  66. .dialog-content {
  67. width: 580rpx;
  68. background: #FFFFFF;
  69. border-radius: 20rpx;
  70. overflow: hidden;
  71. .dialog-title {
  72. font-size: 32rpx;
  73. color: #333333;
  74. text-align: center;
  75. padding: 30rpx;
  76. font-family: PingFang SC;
  77. font-weight: bold;
  78. }
  79. .dialog-body {
  80. padding: 0 40rpx;
  81. text-align: center;
  82. line-height: 48rpx;
  83. }
  84. .dialog-footer {
  85. display: flex;
  86. gap: 30rpx;
  87. padding: 30rpx;
  88. padding-bottom: 40rpx;
  89. button {
  90. flex: 1;
  91. height: 88rpx;
  92. line-height: 88rpx;
  93. font-size: 32rpx;
  94. border: none;
  95. margin: 0;
  96. &::after{
  97. border: none;
  98. }
  99. &.cancel-btn {
  100. background-color: #F5F5F5;
  101. color: #333333;
  102. }
  103. &.confirm-btn {
  104. background-color: #38C148;
  105. color: #FFFFFF;
  106. }
  107. }
  108. &.single-btn {
  109. display: flex;
  110. justify-content: center;
  111. .confirm-btn {
  112. flex: 1;
  113. max-width: 280rpx;
  114. }
  115. }
  116. }
  117. }
  118. </style>