IndexBar.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view>
  3. <scroll-view scroll-y class="indexes" :scroll-into-view="'indexes-'+ listCurID"
  4. :style="[{height:height}]" :scroll-with-animation="true"
  5. :enable-back-to-top="true" v-if="indexMap">
  6. <slot></slot>
  7. </scroll-view>
  8. <view class="indexBar" :style="[{height:height}]">
  9. <view class="indexBar-box" @touchstart="tStart" @touchend="tEnd" @touchmove.stop="tMove">
  10. <view class="indexBar-item" v-for="(item) in indexMap.keys()" :key="item" :id="item"
  11. @touchstart="getCur" @touchend="setCur"> {{ item }}
  12. </view>
  13. </view>
  14. </view>
  15. <!--选择显示-->
  16. <view v-show="!hidden" class="indexToast">
  17. {{ listCur }}
  18. </view>
  19. </view>
  20. </template>
  21. <script setup lang="ts">
  22. import {computed, getCurrentInstance, ref} from "vue";
  23. import {useGroupStore} from "@/store/groupStore";
  24. import type ChatSimple from "@/mode/ChatSimple";
  25. const groupStore = useGroupStore();
  26. const {proxy} = getCurrentInstance();
  27. const customBar = ref(proxy.customBar);
  28. const hidden = ref(true);
  29. const listCurID = ref('');
  30. const listCur = ref('');
  31. const height = computed(() => {
  32. return 'calc(100vh - ' + customBar.value + 'px ' + (props.bottom ? '- 50px' : '') + ')';
  33. })
  34. const props = defineProps(
  35. {
  36. //索引map
  37. indexMap: {
  38. type: Map,
  39. default: new Map<string, ChatSimple>()
  40. },
  41. //是否展示底部高度
  42. bottom: {
  43. type: Boolean,
  44. default: false
  45. },
  46. //是否展示底部高度
  47. bottomHeight: {
  48. type:Number,
  49. default: 0
  50. }
  51. }
  52. )
  53. //获取文字信息
  54. const getCur = (e: any) => {
  55. hidden.value = false;
  56. listCur.value = e.target.id;
  57. }
  58. const setCur = () => {
  59. hidden.value = true;
  60. }
  61. //滑动选择Item
  62. const tMove = (e: TouchEvent) => {
  63. let y = e.touches[0].clientY,
  64. offsettop = customBar.value;
  65. //判断选择区域,只有在选择区才会生效
  66. if (y > offsettop) {
  67. let num = (y - offsettop) / 20;
  68. listCur.value = props.indexMap.get(num)?.name
  69. }
  70. }
  71. //触发全部开始选择
  72. const tStart = () => {
  73. hidden.value = false
  74. }
  75. //触发结束选择
  76. const tEnd = () => {
  77. hidden.value = true;
  78. listCurID.value = listCur.value
  79. }
  80. const showGroup = (id: string) => {
  81. uni.navigateTo({
  82. url: '/pages/group/group?id=' + id
  83. })
  84. }
  85. </script>
  86. <style>
  87. .indexes {
  88. position: relative;
  89. }
  90. .indexBar {
  91. position: fixed;
  92. right: 0px;
  93. bottom: 0px;
  94. padding: 20upx 20upx 20upx 60upx;
  95. display: flex;
  96. align-items: center;
  97. }
  98. .indexBar .indexBar-box {
  99. width: 40upx;
  100. height: auto;
  101. background: #fff;
  102. display: flex;
  103. flex-direction: column;
  104. box-shadow: 0 0 20upx rgba(0, 0, 0, 0.1);
  105. border-radius: 10upx;
  106. }
  107. .indexBar-item {
  108. flex: 1;
  109. width: 40upx;
  110. height: 40upx;
  111. display: flex;
  112. align-items: center;
  113. justify-content: center;
  114. font-size: 24upx;
  115. color: #888;
  116. }
  117. .indexBar-item {
  118. width: 40upx;
  119. height: 40upx;
  120. z-index: 9;
  121. position: relative;
  122. }
  123. .indexBar-item::before {
  124. content: "";
  125. display: block;
  126. position: absolute;
  127. left: 0;
  128. height: 20upx;
  129. width: 4upx;
  130. background-color: #f37b1d;
  131. }
  132. .indexToast {
  133. position: fixed;
  134. top: 0;
  135. right: 80upx;
  136. bottom: 0;
  137. background: rgba(0, 0, 0, 0.5);
  138. width: 100upx;
  139. height: 100upx;
  140. border-radius: 10upx;
  141. margin: auto;
  142. color: #fff;
  143. line-height: 100upx;
  144. text-align: center;
  145. font-size: 48upx;
  146. }
  147. </style>