common-dialog.vue 3.8 KB

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