customDialog.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <uni-popup ref="popupRef" type="center" :mask-click="false">
  3. <view class="custom_dialog">
  4. <!-- 标题 -->
  5. <view class="dialog_header" v-if="title">
  6. <text class="dialog_title">{{ title }}</text>
  7. <!-- <view class="close_icon" @click="close">✕</view> -->
  8. </view>
  9. <!-- 内容区域 -->
  10. <view class="dialog_body">
  11. <slot></slot>
  12. </view>
  13. </view>
  14. </uni-popup>
  15. </template>
  16. <script setup>
  17. import { ref } from 'vue';
  18. import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue';
  19. const props = defineProps({
  20. title: {
  21. type: String,
  22. default: '提示'
  23. }
  24. });
  25. const emit = defineEmits(['confirm', 'close']);
  26. const popupRef = ref(null);
  27. const open = () => {
  28. popupRef.value?.open();
  29. };
  30. const close = () => {
  31. popupRef.value?.close();
  32. emit('close');
  33. };
  34. const handleConfirm = () => {
  35. // 发射事件,父组件处理逻辑
  36. // 父组件如果验证失败,不调用 close() 即可保持弹窗打开
  37. emit('confirm', { close });
  38. };
  39. defineExpose({
  40. open,
  41. close
  42. });
  43. </script>
  44. <style lang="scss" scoped>
  45. .custom_dialog {
  46. width: 330px;
  47. background-color: #fff;
  48. border-radius: 20rpx;
  49. overflow: hidden;
  50. display: flex;
  51. flex-direction: column;
  52. }
  53. .dialog_header {
  54. position: relative;
  55. height: 60rpx;
  56. display: flex;
  57. align-items: center;
  58. justify-content: center;
  59. border-bottom: 1rpx solid #eee;
  60. .dialog_title {
  61. font-size: 22rpx;
  62. // font-weight: bold;
  63. color: #333;
  64. }
  65. .close_icon {
  66. position: absolute;
  67. right: 30rpx;
  68. top: 10rpx;
  69. font-size: 40rpx;
  70. color: #999;
  71. padding: 10rpx;
  72. }
  73. }
  74. .dialog_body {
  75. padding: 20rpx;
  76. min-height: 200rpx;
  77. height: auto;
  78. overflow:hidden;
  79. }
  80. .dialog_footer {
  81. display: flex;
  82. border-top: 1rpx solid #eee;
  83. .btn {
  84. flex: 1;
  85. height: 100rpx;
  86. line-height: 100rpx;
  87. font-size: 32rpx;
  88. margin: 0;
  89. border-radius: 0;
  90. background-color: #fff;
  91. &::after {
  92. border: none;
  93. }
  94. }
  95. .cancel_btn {
  96. color: #666;
  97. border-right: 1rpx solid #eee;
  98. }
  99. .confirm_btn {
  100. color: #2E64FA;
  101. font-weight: bold;
  102. }
  103. }
  104. </style>