index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <uni-popup background-color="#fff" ref="popupRef" type="bottom">
  3. <view class="h-88vh">
  4. <view class="hc-popup-nav-bar">
  5. <text class="cancel" @click="cancelClick">取消</text>
  6. <text class="title" v-if="popupTitle">{{popupTitle}}</text>
  7. <text class="sure" @click="confirmClick">确定</text>
  8. </view>
  9. <view class="hc-popup-content" :style="`background: ${bg}`">
  10. <scroll-view class="h-full" :scroll-x="scrollX" :scroll-y="scrollY" v-if="isScroll">
  11. <slot/>
  12. </scroll-view>
  13. <template v-else>
  14. <slot/>
  15. </template>
  16. </view>
  17. </view>
  18. </uni-popup>
  19. </template>
  20. <script setup>
  21. import { ref, watch } from "vue";
  22. //参数
  23. const props = defineProps({
  24. scroll: {
  25. type: Boolean,
  26. default: true,
  27. },
  28. scrollX: {
  29. type: Boolean,
  30. default: true,
  31. },
  32. scrollY: {
  33. type: Boolean,
  34. default: true,
  35. },
  36. title: {
  37. type: String,
  38. default: '',
  39. },
  40. bg: {
  41. type: String,
  42. default: 'white',
  43. },
  44. })
  45. const popupRef = ref(null)
  46. const isScroll = ref(props.scroll)
  47. const popupTitle = ref(props.title)
  48. //监听
  49. watch(() => [
  50. props.title
  51. ], ([title]) => {
  52. popupTitle.value = title
  53. })
  54. const emit = defineEmits(['cancel', 'confirm'])
  55. //取消
  56. const cancelClick = () => {
  57. emit('cancel')
  58. popupRef.value?.close()
  59. }
  60. //确认
  61. const confirmClick = () => {
  62. emit('confirm')
  63. }
  64. //设置标题
  65. const setTitle = (val) => {
  66. popupTitle.value = val
  67. }
  68. //导出
  69. defineExpose({
  70. open: () => {
  71. popupRef.value?.open()
  72. },
  73. close: () => {
  74. popupRef.value?.close()
  75. },
  76. setTitle
  77. })
  78. </script>
  79. <style lang="scss" scoped>
  80. .hc-popup-nav-bar {
  81. position: relative;
  82. padding: 0 28rpx;
  83. border-bottom: 1px solid #eee;
  84. display: flex;
  85. justify-content: space-between;
  86. align-items: center;
  87. height: 90rpx;
  88. }
  89. .hc-popup-content {
  90. position: relative;
  91. height: calc(100% - 90rpx);
  92. }
  93. </style>