chapterCatalog.vue 8.1 KB

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