chapterCatalog.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <uni-popup @maskClick="emits('Close')" :animation="false" mask-background-color="rgba(0,0,0,0)" ref="catalog" background-color="#fff" @change="onChange">
  3. <view style="'position': fixed;display: flex;
  4. 'justify-content': space-around;
  5. 'align-items': center;margin-left: auto;padding-left: 10%;padding-right: 10%;margin-top: 5%;" :style="{'backgroundColor':db_color}">
  6. <image :src="book_data.book_cover" style="width: 100rpx;height: 150rpx;"></image>
  7. <view style="margin-left: 100rpx;">
  8. <view style="font-size: 1.5ex;" :style="{'color':font_color}" >{{book_data.book_name}}</view>
  9. <view style="font-size: 1.5ex; margin-top: 50rpx;" :style="{'color':font_color}" >{{book_data.author_name}}</view>
  10. </view>
  11. </view>
  12. <view style="display: flex;
  13. align-items: center;margin-top: 5%;">
  14. <view :style="{'color':font_color,'fontSize':'1.5ex','paddingLeft':'10%','width':'65%'}">{{tools.book_status_title(book_data)}}</view>
  15. <view @click="onClickSort" :style="{'color':font_color,'fontSize':'1.5ex'}">
  16. <image src="../../static/logo.png" style="width: 25rpx;height: 25rpx;;"></image>
  17. <text :style="{'color':font_color,'width':'80%'}">{{ sortName }} </text>
  18. </view>
  19. </view>
  20. <view style="border-bottom: #eee solid 1px;display: flex;
  21. align-items: center;margin-top: 5%;">
  22. </view>
  23. <view
  24. :style="{'backgroundColor':db_color,'paddingLeft':'10%','paddingRight':'10%','marginTop':'5%'}"
  25. @touchend.stop>
  26. <view>
  27. <!-- <movable-area>
  28. <movable-view class="action-bar-box" direction="vertical" @change="change" :y="y" :animation="false">
  29. <view style="border-bottom: #000 solid 2px;width: 100%;"></view>
  30. <view style="border-bottom: #000 solid 2px;width: 100%;"></view>
  31. </movable-view>
  32. </movable-area> -->
  33. <scroll-view
  34. scroll-y="true"
  35. :style="{
  36. height: scrollHeight + 'px',
  37. position: 'relative',
  38. zIndex: 1
  39. }"
  40. @scroll="handleScroll"
  41. :scroll-top="scrollTop"
  42. :show-scrollbar="false"
  43. >
  44. <!-- <view
  45. class="scroll-bar"
  46. :style="{
  47. height: localHeight + 'px'
  48. }"
  49. ></view> -->
  50. <view
  51. class="list"
  52. :style="{
  53. transform: `translateY(${offset}px)`
  54. }"
  55. >
  56. <view v-for="(item, index) in visibleData" :key="item.id">
  57. <!-- <slot :item="item" :active="active"></slot> -->
  58. <view :style="{'widows':'100%'}" class="directory-listItem" @click="clickChar(item)">
  59. <text class="ellipsis" :style="{'color':font_color,'width':'80%'}">{{ item.name }} </text>
  60. <image src="../../static/logo.png" style="width: 25rpx;height: 25rpx;;"></image>
  61. </view>
  62. </view>
  63. </view>
  64. </scroll-view>
  65. </view>
  66. </view>
  67. </uni-popup>
  68. </template>
  69. <script setup lang="ts">
  70. import { ref,onMounted,computed, nextTick} from 'vue';
  71. import { ReadSetting } from '../../stores/readSetting';
  72. import { tools } from '../../framework/tools';
  73. import { book_item_data } from '../../data/data';
  74. import { UserStatus } from '../../stores/userStatusManager';
  75. // const {items,remain,size,active,scrollHeight} = defineProps(['items','remain','size','active','scrollHeight'])
  76. const {items,remain,size,scrollHeight} =defineProps({
  77. items: {
  78. type: Array,
  79. required: true,
  80. default: []
  81. },
  82. remain: {
  83. type: Number,
  84. required: true,
  85. default: 0
  86. },
  87. size: {
  88. type: Number,
  89. required: true,
  90. default: 0
  91. },
  92. // active: {
  93. // type: Number,
  94. // required: true,
  95. // default: 0
  96. // },
  97. scrollHeight: {
  98. type: Number,
  99. required: true,
  100. default: 0
  101. },
  102. });
  103. const emits = defineEmits(['clickChar','Close'])
  104. let start = ref(0)
  105. let end = ref(0)
  106. let offset = ref(0)
  107. let scrollTop = ref(0)
  108. let y = ref(0)
  109. let sortStatus = 1;
  110. let sortName = ref('倒序')
  111. let mode = ref(ReadSetting().getReadSetting().readMode)
  112. let sortItems = ref(items)
  113. const catalog = ref(null)
  114. onMounted(()=>{
  115. const type = 'bottom'
  116. // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
  117. catalog.value.open(type)
  118. })
  119. let preCount = computed(()=>{
  120. return Math.min(start.value, remain);
  121. })
  122. let nextCount = computed(()=>{
  123. return Math.min(sortItems.value.length - end.value, remain);
  124. })
  125. let visibleData = computed(()=>{
  126. const t_start = start.value - preCount.value;
  127. const t_end = end.value + nextCount.value;
  128. return sortItems.value.slice(t_start, t_end);
  129. })
  130. let localHeight = computed(()=>{
  131. return sortItems.value.length * size;
  132. })
  133. function clickChar(item){
  134. emits('clickChar',item)
  135. }
  136. function change(e){
  137. if (e.detail.source !== 'touch') {
  138. return;
  139. }
  140. let y = e.detail.y;
  141. let scroll = (y / (scrollHeight - 40)) * (localHeight.value - scrollHeight);
  142. scroll = scroll < 0 ? 0 : scroll;
  143. scrollTop.value = scroll;
  144. }
  145. function handleScroll(ev){
  146. const scrollTop = ev.detail.scrollTop;
  147. y.value = (scrollTop / (localHeight.value - scrollHeight)) * (scrollHeight - 40);
  148. // 开始位置
  149. const t_start = Math.floor(scrollTop / size);
  150. start.value = start.value < 0 ? 0 : t_start;
  151. // 结束位置
  152. end.value = t_start +remain;
  153. // 计算偏移
  154. const t_offset = scrollTop - (scrollTop % size) - preCount.value * size;
  155. offset.value = t_offset < 0 ? 0 : t_offset;
  156. }
  157. //
  158. function onChange(e){
  159. if(e.show==false){
  160. emits('Close')
  161. }
  162. }
  163. let font_color = ref(tools.getFontColorByMode(ReadSetting().data.readMode))
  164. let db_color = ref(tools.getDbColorByMode(ReadSetting().data.readMode))
  165. let book_data:book_item_data = UserStatus().getUserSelectBook()
  166. function onClickSort(){
  167. if(sortStatus==1){
  168. sortStatus = 2;
  169. sortName.value = "正序"
  170. }else{
  171. sortStatus = 1;
  172. sortName.value = "倒序"
  173. }
  174. sortItems.value = []
  175. start.value = 0
  176. end.value = 0
  177. offset.value = 0
  178. scrollTop.value = 0
  179. y.value = 0
  180. sortItems.value = items
  181. nextTick(()=>{
  182. if(sortStatus==1){
  183. sortItems.value = sortItems.value.sort((a:any,b:any)=>{
  184. return a.id - b.id
  185. })
  186. }else{
  187. sortItems.value = sortItems.value.sort((a:any,b:any)=>{
  188. return b.id - a.id
  189. })
  190. }
  191. })
  192. }
  193. </script>
  194. <style scoped>
  195. .list {
  196. position: absolute;
  197. top: 0;
  198. left: 0;
  199. width: 100%;
  200. }
  201. .action-bar-box {
  202. padding: 3px;
  203. display: flex;
  204. flex-flow: column;
  205. justify-content: space-around;
  206. align-items: center;
  207. position: absolute;
  208. right: 0;
  209. background-color: transparent;
  210. border-radius: 10rpx;
  211. box-shadow: 0 0 5px #000;
  212. width: 20px;
  213. height: 40px;
  214. z-index: 2;
  215. }
  216. .directory-listItem {
  217. display: flex;
  218. align-items: center;
  219. padding-left: 10px;
  220. height: 40px;
  221. font-size: 14px;
  222. /* border-bottom: #eee solid 1px; */
  223. }
  224. .active {
  225. color: red;
  226. }
  227. /* .directory {
  228. position: fixed;
  229. display: flex;
  230. flex-flow: column;
  231. width: 100%;
  232. height: 30%;
  233. } */
  234. .scroll-view {
  235. scrollbar-width: none; /* 对于微信小程序等平台,可以使用scrollbar-width设置为none */
  236. }
  237. .scroll-view {
  238. over-scroll: false;
  239. }
  240. .scroll-view::-webkit-scrollbar {
  241. display: none; /* 隐藏滚动条 */
  242. }
  243. .ellipsis {
  244. white-space: nowrap; /* 防止文本换行 */
  245. overflow: hidden; /* 隐藏超出容器的文本 */
  246. text-overflow: ellipsis; /* 当文本溢出时显示省略号 */
  247. width: 100%; /* 或其他你需要的宽度 */
  248. }
  249. </style>