customPopupDialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <!-- 自定义弹框组件 -->
  3. <uni-popup ref="popupDialog" :is-mask-click="isMaskClick">
  4. <view :class="['dialog_wrap',popupType]" :style="{ width: popupType=='center'?`${dialogWidth}rpx`:'100%' }">
  5. <view class="dialog_title" v-if="showTitle">
  6. <view class="dialog_title_lt">
  7. <text class="title">{{title}}</text>
  8. </view>
  9. <image v-if="showDialogClose" src="@/static/image/icon/close.png" style="width: 48rpx;height: 48rpx;"
  10. @click="CloseDialog"></image>
  11. </view>
  12. <view class="dialog_content">
  13. <slot></slot>
  14. </view>
  15. <!-- 自定义底部按钮区域 -->
  16. <view class="dialog_footer" v-if="showDialogFooter">
  17. <view v-if="showCancelBtn" class="dialog-btn cancel-btn" @click="CloseDialog">取消</view>
  18. <view class="dialog-btn confirm-btn" @click="handleConfirm">确定</view>
  19. </view>
  20. </view>
  21. </uni-popup>
  22. </template>
  23. <script setup>
  24. import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue';
  25. import {
  26. ref
  27. } from 'vue';
  28. const props = defineProps({
  29. showTitle: {//显示标题
  30. type: Boolean,
  31. default: true
  32. },
  33. title: {//标题
  34. type: String,
  35. default: '提示'
  36. },
  37. dialogWidth: {//弹框宽度
  38. type: String,
  39. default: '610'
  40. },
  41. isMaskClick:{//蒙版点击是否关闭弹窗
  42. type: Boolean,
  43. default: true
  44. },
  45. showDialogClose: {//关闭按钮
  46. type: Boolean,
  47. default: true
  48. },
  49. showDialogFooter:{//是否显示底部按钮
  50. type: Boolean,
  51. default: true
  52. },
  53. showCancelBtn: {//是否显示取消按钮
  54. type: Boolean,
  55. default: true
  56. }
  57. })
  58. const emit = defineEmits(['DialogConfirm']);
  59. const popupDialog = ref(null);
  60. const popupType = ref('center');//弹出方式 默认中间显示
  61. //打开弹窗
  62. const OpenDialog = (type='center') => {
  63. popupType.value = type;//弹出方式
  64. popupDialog.value.open(type);
  65. }
  66. //关闭弹窗
  67. const CloseDialog = () => {
  68. popupDialog.value.close();
  69. }
  70. // 点击确定,只通知父组件,子组件不主动关闭!
  71. const handleConfirm = () => {
  72. emit('DialogConfirm')
  73. }
  74. defineExpose({
  75. OpenDialog,
  76. CloseDialog
  77. })
  78. </script>
  79. <style scoped lang="scss">
  80. .dialog_wrap {
  81. background: #fff;
  82. border-radius: 20rpx;
  83. overflow: hidden;
  84. &.bottom{//从底部弹框
  85. border-radius: 40rpx 40rpx 0 0;
  86. .dialog_title{
  87. background-color: #FFFFFF;
  88. justify-content: center;
  89. .dialog_title_lt {
  90. .title {
  91. color: #000000;
  92. font-size: 36rpx;
  93. margin-left: 0;
  94. }
  95. }
  96. }
  97. .dialog_content{
  98. padding: 0;
  99. min-height: auto;
  100. }
  101. }
  102. }
  103. .dialog_title {
  104. height: 96rpx;
  105. padding: 0 40rpx;
  106. width: 100%;
  107. background-color: #F5F7FA;
  108. border-radius: 20rpx 20rpx 0 0;
  109. box-sizing: border-box;
  110. display: flex;
  111. justify-content: space-between;
  112. align-items: center;
  113. .dialog_title_lt {
  114. display: inline-flex;
  115. align-items: center;
  116. .title {
  117. margin-left: 16rpx;
  118. flex: 1;
  119. white-space: nowrap;
  120. overflow: hidden;
  121. text-overflow: ellipsis;
  122. color: #303133;
  123. font-weight: 500;
  124. font-size: 32rpx;
  125. }
  126. }
  127. }
  128. .dialog_content {
  129. min-height: 160rpx;
  130. height: auto;
  131. display: flex;
  132. // overflow: auto;
  133. width: 100%;
  134. box-sizing: border-box;
  135. padding: 40rpx;
  136. flex-wrap: wrap;
  137. }
  138. .dialog_footer {
  139. display: flex;
  140. border: 2rpx solid #EBEEF5;
  141. padding: 24rpx 40rpx;
  142. width: 100%;
  143. box-sizing: border-box;
  144. gap: 20rpx;
  145. .dialog-btn {
  146. flex: 1;
  147. display: inline-flex;
  148. align-items: center;
  149. justify-content: center;
  150. height: 80rpx;
  151. border-radius: 12rpx;
  152. font-size: 28rpx;
  153. font-weight: 500;
  154. }
  155. .cancel-btn {
  156. color: #606266;
  157. background-color: #f0f2f9;
  158. }
  159. .confirm-btn {
  160. color: #ffffff;
  161. background-color: #2e64fa;
  162. }
  163. }
  164. </style>