lime-floating-panel.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <demo-block title="浮动面板" type="ultra">
  3. <view class="tabs">
  4. <text class="tab" :class="{active: active == 0}" @click="tabChange(0)">基础用法</text>
  5. <text class="tab" :class="{active: active == 1}" @click="tabChange(1)">自定义锚点</text>
  6. <text class="tab" :class="{active: active == 2}" @click="tabChange(2)">仅头部拖拽</text>
  7. </view>
  8. <view v-if="active == 1" style="padding: 20rpx" @click="to">自定义锚点: 跳到3</view>
  9. <view class="content">
  10. <view @click="onClick">content</view>
  11. <view @click="onClick">content</view>
  12. <view @click="onClick">content</view>
  13. <view @click="onClick">content</view>
  14. <view @click="onClick">content</view>
  15. <view @click="onClick">content</view>
  16. <view @click="onClick">content</view>
  17. <view @click="onClick">content</view>
  18. <view @click="onClick">content</view>
  19. <view @click="onClick">content</view>
  20. <view @click="onClick">content</view>
  21. <view @click="onClick">content</view>
  22. <view @click="onClick">content</view>
  23. <view @click="onClick">content</view>
  24. </view>
  25. <view v-if="active == 0">
  26. <l-floating-panel>
  27. <scroll-view scroll-y style="height: 100%;" @scrolltolower="scrolltolower">
  28. <view v-for="(item, index) in list" class="cell" :key="index">内容:{{index}}</view>
  29. <view style="text-align: center; padding: 15px;" v-if="loading">
  30. <text style="color: #999;">loading</text>
  31. </view>
  32. </scroll-view>
  33. </l-floating-panel>
  34. </view>
  35. <view v-if="active == 1">
  36. <!-- #ifdef VUE3 -->
  37. <l-floating-panel v-model:height="height" :anchors="anchors" :defaultAnchor="1" ref="floatingPanelRef">
  38. <view style="text-align: center; padding: 15px">
  39. <text>面板显示高度 {{ height.toFixed(0) }} px</text>
  40. </view>
  41. </l-floating-panel>
  42. <!-- #endif -->
  43. <!-- #ifndef VUE3 -->
  44. <l-floating-panel :height.sync="height" :anchors="anchors" :defaultAnchor="1">
  45. <view style="text-align: center; padding: 15px">
  46. <text>面板显示高度 {{ height.toFixed(0) }} px</text>
  47. </view>
  48. </l-floating-panel>
  49. <!-- #endif -->
  50. </view>
  51. <view v-if="active == 2">
  52. <l-floating-panel :content-draggable="false" @height-change="heightChange">
  53. <view style="text-align: center; padding: 15px">
  54. <text style="display: block;">内容不可拖拽</text>
  55. <text style="color: #999;">当前高度 {{height3}}</text>
  56. </view>
  57. </l-floating-panel>
  58. </view>
  59. </demo-block>
  60. </template>
  61. <script>
  62. export default {
  63. data() {
  64. const {windowHeight} = uni.getSystemInfoSync()
  65. return {
  66. height: 0,
  67. height3: 0,
  68. active: 0,
  69. loading: false,
  70. list: [],
  71. anchors: [
  72. 30,
  73. Math.round(0.4 * windowHeight),
  74. Math.round(0.7 * windowHeight),
  75. ],
  76. }
  77. },
  78. methods: {
  79. scrolltolower() {
  80. this.getData()
  81. },
  82. heightChange({height}) {
  83. this.height3 = height
  84. },
  85. onClick() {
  86. uni.showToast({
  87. icon: "none",
  88. title: "点击了内容"
  89. })
  90. },
  91. to() {
  92. this.$refs.floatingPanelRef.toAnchor(2)
  93. },
  94. getData() {
  95. this.loading = true
  96. setTimeout(() => {
  97. this.list.push(...new Array(10).fill(0))
  98. this.loading = false
  99. },500)
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. .tabs {
  106. display: flex;
  107. flex-direction: row;
  108. padding: 15px 60rpx;
  109. justify-content: space-between;
  110. background-color: white;
  111. }
  112. .tab{margin-right:10px}
  113. .tab:last-child {
  114. margin-right:0px
  115. }
  116. .text {
  117. display: block;
  118. margin: 30px 0;
  119. color: rgba(0, 0, 0, 0.6);
  120. }
  121. .active {
  122. color: blue;
  123. }
  124. .cell {
  125. height: 120rpx;
  126. padding: 30rpx;
  127. box-sizing: border-box;
  128. border-bottom: 1rpx solid #eee;
  129. &:first-child{
  130. border-top: 1rpx solid #eee;
  131. }
  132. }
  133. </style>