custom-popup-dialog.vue 3.1 KB

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