lime-floating-panel.uvue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="demo-block">
  3. <text class="demo-block__title-text ultra">浮动面板</text>
  4. <text class="demo-block__desc-text">浮动在页面底部的面板,可以上下拖动来浏览内容,常用于提供额外的功能或信息。</text>
  5. <view class="demo-block__body">
  6. <view class="demo-block">
  7. <view class="demo-block__body">
  8. <view class="tabs">
  9. <text class="tab" :class="{active: active == 0}" @click="tabChange(0)">基础用法</text>
  10. <text class="tab" :class="{active: active == 1}" @click="tabChange(1)">自定义锚点</text>
  11. <text class="tab" :class="{active: active == 2}" @click="tabChange(2)">仅头部拖拽</text>
  12. </view>
  13. <button type="primary" v-if="active == 1" style="margin-top: 20rpx;" @click="to">自定义锚点: 跳到3</button>
  14. <l-floating-panel v-if="active == 0">
  15. <scroll-view scroll-y direction="vertical" style="flex: 1" @scrolltolower="scrolltolower">
  16. <view v-for="(_, index) in list" class="cell" :key="index">内容:{{index}}</view>
  17. <view class="loading" v-if="loading">
  18. <text style="color: #999;">loading</text>
  19. </view>
  20. </scroll-view>
  21. </l-floating-panel>
  22. <l-floating-panel v-if="active == 1" v-model:height="height" :anchors="anchors" :defaultAnchor="1" ref="floatingPanelRef">
  23. <view style="align-items: center; padding: 15px">
  24. <text>面板显示高度 {{ height.toFixed(0) }} px</text>
  25. </view>
  26. </l-floating-panel>
  27. <l-floating-panel v-if="active == 2" :content-draggable="false" @height-change="heightChange">
  28. <view style="align-items: center; padding: 15px">
  29. <text>面板显示高度 {{ height.toFixed(0) }} px</text>
  30. </view>
  31. </l-floating-panel>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script setup>
  38. const floatingPanelRef = ref<LFloatingPanelComponentPublicInstance|null>(null)
  39. const active = ref(0)
  40. const loading = ref(false)
  41. const height = ref(0)
  42. const anchors = ref([50,400,700])
  43. const list = ref<number[]>([])
  44. const to = () => {
  45. if(floatingPanelRef.value == null) return
  46. floatingPanelRef.value!.toAnchor(2)
  47. }
  48. const heightChange = (res: UTSJSONObject) => {
  49. console.log('heightChange', res)
  50. height.value = (res['height'] ?? 0) as number
  51. }
  52. const tabChange = (index: number) => {
  53. active.value = index
  54. }
  55. const getData = () => {
  56. loading.value = true
  57. setTimeout(() => {
  58. for (var i = 0; i < 20; i++) {
  59. list.value.push(i)
  60. }
  61. loading.value = false
  62. },500)
  63. }
  64. const scrolltolower = () => {
  65. getData()
  66. }
  67. scrolltolower()
  68. </script>
  69. <style lang="scss">
  70. .tabs {
  71. display: flex;
  72. flex-direction: row;
  73. padding: 15px 60rpx;
  74. justify-content: space-between;
  75. background-color: white;
  76. // background-color: #ffb400;
  77. }
  78. .tab{
  79. margin-right:10px;
  80. color: rgba(0, 0, 0, 0.6);
  81. }
  82. .text {
  83. margin: 30px 0;
  84. color: rgba(0, 0, 0, 0.6);
  85. }
  86. .active {
  87. font-weight: bold;
  88. color: rgba(0, 0, 0, 1);
  89. }
  90. .cell {
  91. padding: 30rpx;
  92. }
  93. .loading {
  94. padding: 30rpx;
  95. align-items: center;
  96. }
  97. .panel {
  98. box-shadow: 0 -10rpx 20rpx rgba(0, 0, 0, 0.03);
  99. // background-color: aqua;
  100. }
  101. .demo-block {
  102. margin: 32px 20px 0;
  103. overflow: visible;
  104. &__title {
  105. margin: 0;
  106. margin-top: 8px;
  107. &-text {
  108. color: rgba(0, 0, 0, 0.6);
  109. font-weight: 400;
  110. font-size: 14px;
  111. line-height: 16px;
  112. &.large {
  113. color: rgba(0, 0, 0, 0.9);
  114. font-size: 18px;
  115. font-weight: 700;
  116. line-height: 26px;
  117. }
  118. &.ultra {
  119. color: rgba(0, 0, 0, 0.9);
  120. font-size: 24px;
  121. font-weight: 700;
  122. line-height: 32px;
  123. }
  124. }
  125. }
  126. &__desc-text {
  127. color: rgba(0, 0, 0, 0.6);
  128. margin: 8px 16px 0 0;
  129. font-size: 14px;
  130. line-height: 22px;
  131. }
  132. &__body {
  133. margin: 16px 0;
  134. overflow: visible;
  135. .demo-block {
  136. // margin-top: 0px;
  137. margin: 0;
  138. }
  139. }
  140. }
  141. </style>