Demo.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <script setup>
  2. // 废弃
  3. import { ref, computed, getCurrentInstance, onMounted, nextTick } from 'vue'
  4. const props = defineProps({
  5. title: '',
  6. maxHeight: {
  7. default: 200
  8. }
  9. })
  10. const instance = getCurrentInstance()
  11. const demoContentRef = ref()
  12. const more = ref(true)
  13. const showMore = ref(false)
  14. const styles = computed(() => {
  15. return more.value ? {
  16. maxHeight: `${props.maxHeight}rpx`,
  17. overflow: 'hidden',
  18. } : {}
  19. })
  20. onMounted(getDemoContentRef)
  21. nextTick(getDemoContentRef)
  22. function callback(data) {
  23. const { height } = data
  24. showMore.value = height > uni.upx2px(props.maxHeight)
  25. more.value = height > uni.upx2px(props.maxHeight)
  26. }
  27. function getDemoContentRef() {
  28. let query = uni.createSelectorQuery().in(instance)
  29. query.select('.demoContent')
  30. .fields({ rect: true, size: true, scrollOffset: true }, callback)
  31. // .boundingClientRect(callback)
  32. .exec()
  33. }
  34. function toggleMore() {
  35. more.value = !more.value
  36. }
  37. </script>
  38. <template>
  39. <view>
  40. <view class="p-2 bg-slate-500 sticky t-0 flex item-center">
  41. <view class="flex-1 font-medium font-bold text-base text-slate-50">{{title}}</view>
  42. <view class="text-slate-200 text-center p-0-5 text-xs font-light" @tap="toggleMore" v-if="showMore">
  43. <text v-if="more">更多 ↓</text>
  44. <text v-else>收起 ↑ </text>
  45. </view>
  46. </view>
  47. <view class="p-2 bg-white" :style="styles" :class="{more: showMore && more}">
  48. <view class="demoContent">
  49. <slot></slot>
  50. </view>
  51. </view>
  52. </view>
  53. </template>
  54. <style lang="scss" scoped>
  55. .more {
  56. position: relative;
  57. &::after {
  58. content: '';
  59. position: absolute;
  60. bottom: 0;
  61. left: 0;
  62. height: 64rpx;
  63. width: 100%;
  64. border-radius: 4rpx 4rpx 0 0;
  65. background: linear-gradient(180deg, rgba(0,0,0,0), rgba(0,0,0,.5));
  66. // backdrop-filter: blur(4rpx) saturate(50%);
  67. // box-shadow: 0 -4rpx 8rpx rgba(0, 0, 0, .25);
  68. }
  69. }
  70. </style>