common-dialog.vue 3.1 KB

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