common-dialog.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <u-popup v-model="showPopup" @close="closePopup" mode="center" border-radius="20" :width="width">
  3. <view class="dialog-content" :style="customStyle">
  4. <image v-if="bgImage" :src="bgImage" class="dialog-bg-image" mode="scaleToFill"></image>
  5. <!-- 标题 -->
  6. <view v-if="title && showTitle" class="dialog-title">{{ title }}</view>
  7. <!-- 内容插槽 -->
  8. <view class="dialog-body">
  9. <slot></slot>
  10. </view>
  11. <!-- 按钮区域 -->
  12. <view class="dialog-footer" :class="{ 'single-btn': !showCancel }" v-if="showFooter" width="90%">
  13. <button v-if="showCancel" class="cancel-btn" @click="handleCancel">{{ cancelText }}</button>
  14. <button class="confirm-btn" @click="handleConfirm">{{ confirmText }}</button>
  15. </view>
  16. </view>
  17. </u-popup>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. // 弹窗宽度
  23. width: {
  24. type: String,
  25. default: '580rpx'
  26. },
  27. showTitle: {
  28. type: Boolean,
  29. default: true
  30. },
  31. // 弹窗标题
  32. title: {
  33. type: String,
  34. default: '温馨提示'
  35. },
  36. // 是否显示取消按钮
  37. showCancel: {
  38. type: Boolean,
  39. default: true
  40. },
  41. // 确认按钮文字
  42. confirmText: {
  43. type: String,
  44. default: '确定'
  45. },
  46. // 取消按钮文字
  47. cancelText: {
  48. type: String,
  49. default: '取消'
  50. },
  51. // 是否显示底部按钮
  52. showFooter: {
  53. type: Boolean,
  54. default: true
  55. },
  56. // 自定义弹窗样式
  57. customStyle: {
  58. type: Object,
  59. default: () => ({})
  60. },
  61. // 背景图片
  62. bgImage: {
  63. type: String,
  64. default: ''
  65. }
  66. },
  67. data() {
  68. return {
  69. showPopup: false
  70. }
  71. },
  72. methods: {
  73. openPopup() {
  74. this.showPopup = true
  75. },
  76. closePopup() {
  77. this.showPopup = false
  78. },
  79. handleConfirm() {
  80. this.$emit('confirm')
  81. this.closePopup()
  82. },
  83. handleCancel() {
  84. this.$emit('cancel')
  85. this.closePopup()
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss">
  91. .dialog-content {
  92. background: #FFFFFF;
  93. border-radius: 20rpx;
  94. overflow: hidden;
  95. position: relative;
  96. .dialog-bg-image {
  97. position: absolute;
  98. top: 0;
  99. left: 0;
  100. width: 100%;
  101. height: 100%;
  102. z-index: 0;
  103. }
  104. .dialog-title {
  105. font-size: 32rpx;
  106. color: #333333;
  107. text-align: center;
  108. padding: 30rpx;
  109. font-family: PingFang SC;
  110. font-weight: bold;
  111. position: relative;
  112. z-index: 1;
  113. }
  114. .dialog-body {
  115. padding: 0 40rpx;
  116. text-align: center;
  117. line-height: 48rpx;
  118. position: relative;
  119. z-index: 1;
  120. }
  121. .dialog-footer {
  122. display: flex;
  123. gap: 30rpx;
  124. padding: 30rpx;
  125. padding-bottom: 40rpx;
  126. position: relative;
  127. z-index: 1;
  128. button {
  129. flex: 1;
  130. height: 88rpx;
  131. line-height: 88rpx;
  132. font-size: 32rpx;
  133. border: none;
  134. margin: 0;
  135. &::after {
  136. border: none;
  137. }
  138. &.cancel-btn {
  139. background-color: #F5F5F5;
  140. color: #333333;
  141. }
  142. &.confirm-btn {
  143. background-color: #38C148;
  144. color: #FFFFFF;
  145. }
  146. }
  147. &.single-btn {
  148. display: flex;
  149. justify-content: center;
  150. .confirm-btn {
  151. flex: 1;
  152. max-width: 280rpx;
  153. }
  154. }
  155. }
  156. }
  157. </style>