custom-popup-dialog.vue 2.8 KB

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