custom-popup-dialog.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <!-- 自定义弹框组件 -->
  3. <uni-popup ref="popupDialog" :is-mask-click="isMaskClick">
  4. <view class="dialog_wrap" :style="{ width: `${dialogWidth}rpx` }">
  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="showCloseBtn" 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. showCloseBtn: {//是否显示取消按钮
  54. type: Boolean,
  55. default: true
  56. }
  57. })
  58. const emit = defineEmits(['DialogConfirm']);
  59. const popupDialog = ref(null);
  60. //打开弹窗
  61. const OpenDialog = () => {
  62. popupDialog.value.open();
  63. }
  64. //关闭弹窗
  65. const CloseDialog = () => {
  66. popupDialog.value.close();
  67. }
  68. // 点击确定,只通知父组件,子组件不主动关闭!
  69. const handleConfirm = () => {
  70. emit('DialogConfirm')
  71. }
  72. defineExpose({
  73. OpenDialog,
  74. CloseDialog
  75. })
  76. </script>
  77. <style scoped lang="scss">
  78. .dialog_wrap {
  79. background: #fff;
  80. border-radius: 20rpx;
  81. overflow: hidden;
  82. }
  83. .dialog_title {
  84. height: 96rpx;
  85. padding: 0 40rpx;
  86. width: 100%;
  87. background-color: #F5F7FA;
  88. border-radius: 20rpx 20rpx 0 0;
  89. box-sizing: border-box;
  90. display: flex;
  91. justify-content: space-between;
  92. align-items: center;
  93. .dialog_title_lt {
  94. display: inline-flex;
  95. align-items: center;
  96. .title {
  97. margin-left: 16rpx;
  98. flex: 1;
  99. white-space: nowrap;
  100. overflow: hidden;
  101. text-overflow: ellipsis;
  102. color: #303133;
  103. font-weight: 500;
  104. font-size: 32rpx;
  105. }
  106. }
  107. }
  108. .dialog_content {
  109. min-height: 160rpx;
  110. height: auto;
  111. display: flex;
  112. // overflow: auto;
  113. width: 100%;
  114. box-sizing: border-box;
  115. padding: 40rpx;
  116. flex-wrap: wrap;
  117. }
  118. .dialog_footer {
  119. display: flex;
  120. border: 2rpx solid #EBEEF5;
  121. padding: 24rpx 40rpx;
  122. width: 100%;
  123. box-sizing: border-box;
  124. gap: 20rpx;
  125. .dialog-btn {
  126. flex: 1;
  127. display: inline-flex;
  128. align-items: center;
  129. justify-content: center;
  130. height: 80rpx;
  131. border-radius: 12rpx;
  132. font-size: 28rpx;
  133. font-weight: 500;
  134. }
  135. .cancel-btn {
  136. color: #606266;
  137. background-color: #f0f2f9;
  138. }
  139. .confirm-btn {
  140. color: #ffffff;
  141. background-color: #2e64fa;
  142. }
  143. }
  144. </style>