read.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <readPage ref="readPages" @touchstart="onStartClickView"
  3. @touchend="onEndClickView" @touchmove="hideSetting" v-for="(book_read_data_item,index) in book_text_list_view" :key="book_read_data_item.book_chapter_id"
  4. :text_content="book_read_data_item.book_content" :book_title="book_read_data_item.book_title">
  5. </readPage>
  6. <settingMenu ref="Menu" v-if="menuShow" @clickCatalog="onClickCatalog"
  7. @clickPreChapter="onClickPreChapter" @clickNextChapter="onClickNextChapter"
  8. @clickMode="onClickMode" @clickOpenSetting="onClickOpenSetting"
  9. @Close="closeMenu" @changeFontSize="onChangeFontSize" @changeBgColor="onChangeBgColor">
  10. </settingMenu>
  11. <chapterCatalog v-if="showChapterList" :items="directoryList" :size="40" :remain="16"
  12. :scrollHeight="windowHeight*0.6" @clickChar="goToChapter" @Close="showChapterList=false">
  13. </chapterCatalog>
  14. </template>
  15. <script setup lang="ts">
  16. import { ref } from 'vue';
  17. import { book_data, book_item_data, book_read_data, chapter_item_data } from '../../data/data';
  18. import { tools } from '../../framework/tools';
  19. import { UserStatus } from '../../stores/userStatusManager';
  20. import { log } from '../../framework/log';
  21. import readPage from '../../components/read/readPage.vue'
  22. import settingMenu from '../../components/read/settingMenu.vue'
  23. import chapterCatalog from '../../components/read/chapterCatalog.vue'
  24. import {onPullDownRefresh,onReachBottom} from '@dcloudio/uni-app'
  25. import { ReadSetting } from '../../stores/readSetting';
  26. import { config } from '../../config/config';
  27. const {windowHeight} = uni.getSystemInfoSync()
  28. const readPages = ref(null)
  29. const Menu = ref(null)
  30. let book_data:book_item_data = UserStatus().getUserSlectBook()
  31. let directoryList:chapter_item_data[] = []
  32. let cur_read_chapter_index =ref(0)
  33. let start_read_chapter_id = book_data.start_read_chapter_id
  34. //设置属性
  35. let read_setting_data = ReadSetting().getReadSetting()
  36. let fontSize = config.read_config.fontSizeList[read_setting_data.fontSizeIndex]
  37. let bgColor = config.read_config.colorList[read_setting_data.colorBgIndex]
  38. //设置属性end
  39. if(book_data!=null&&start_read_chapter_id!=-1){
  40. initView()
  41. }
  42. let book_text_list_view = ref<Array<book_read_data>>([])
  43. let book_text_list_cache = ref<Map<number,book_read_data>>(new Map<number,book_read_data>())
  44. function initView(){
  45. tools.getChapterList(book_data.chapter_path,(chapter_ls)=>{
  46. directoryList = chapter_ls
  47. cur_read_chapter_index.value = tools.getCurChapterIndex(start_read_chapter_id,directoryList)
  48. draw()
  49. })
  50. }
  51. function draw(dir_is_down:boolean=true){
  52. let loading_view = (d:book_read_data)=>{
  53. if(d!=null){
  54. if(dir_is_down){
  55. book_text_list_view.value.push(d)
  56. }else{
  57. book_text_list_view.value.unshift(d)
  58. }
  59. }
  60. }
  61. if(cur_read_chapter_index.value<=directoryList.length&&cur_read_chapter_index.value>=0){
  62. let data = tools.getCurChapterData(cur_read_chapter_index.value,directoryList)
  63. if(data!=null){
  64. let cache_data = book_text_list_cache.value.get(data.id)
  65. if(cache_data!=null){
  66. loading_view(cache_data)
  67. }else{
  68. tools.getCurChapterTxt(book_data.base_path,data.id,fontSize*2,(text:string)=>{
  69. cache_data = new book_read_data()
  70. cache_data.book_content = text
  71. cache_data.book_chapter_id = data.id
  72. cache_data.book_title = tools.autoParagraphTitle(data.name,fontSize*4)
  73. book_text_list_cache.value.set(data.id,cache_data)
  74. loading_view(cache_data)
  75. })
  76. }
  77. }
  78. }else{
  79. log.Error("暂无可读取内容!")
  80. }
  81. }
  82. function down_dir_load(){
  83. cur_read_chapter_index.value+=1;
  84. draw()
  85. }
  86. function up_dir_load(){
  87. cur_read_chapter_index.value-=1;
  88. draw(false)
  89. }
  90. onPullDownRefresh( async () => {
  91. showTopLoadingStatus()
  92. uni.stopPullDownRefresh();
  93. })
  94. onReachBottom(async ()=>{
  95. showBottomLoadingStatus()
  96. })
  97. function showBottomLoadingStatus(){
  98. readPages.value.find((child,index)=>{
  99. if( index == (book_text_list_view.value.length-1) ){
  100. child.showBottomLoading()
  101. down_dir_load()
  102. }
  103. })
  104. }
  105. function showTopLoadingStatus(){
  106. readPages.value.find((child,index)=>{
  107. if( index == 0 ){
  108. child.showTopLoading()
  109. up_dir_load()
  110. }
  111. })
  112. }
  113. //设置相关
  114. let menuShow = ref(false)
  115. let startTouchY = ref(-1)
  116. let endTouchY = ref(-1)
  117. function onClickCatalog(){
  118. closeMenu()
  119. showChapterList.value = true
  120. }
  121. function hideChapterList(){
  122. showChapterList.value = false
  123. }
  124. function onClickMode(){
  125. console.log("点了模式")
  126. }
  127. function onClickOpenSetting(){
  128. console.log("点了设置")
  129. showSetting()
  130. }
  131. function onClickPreChapter(){
  132. goToChapter(tools.getPreChapterData(cur_read_chapter_index.value,directoryList))
  133. hideSetting()
  134. }
  135. function onClickNextChapter(){
  136. goToChapter(tools.getNextChapterData(cur_read_chapter_index.value,directoryList))
  137. hideSetting()
  138. }
  139. function onStartClickView(e){
  140. startTouchY.value = e.changedTouches[0].pageY
  141. }
  142. function onEndClickView(e){
  143. endTouchY.value = e.changedTouches[0].pageY
  144. if(Math.abs(endTouchY.value-startTouchY.value)<=5){
  145. startTouchY.value = -1
  146. showMenuView()
  147. }
  148. }
  149. function showMenuView(){
  150. menuShow.value = true
  151. }
  152. function hideAllTop(){
  153. }
  154. function showSetting(){
  155. Menu.value.showSettingFont()
  156. }
  157. function hideSetting(){
  158. startTouchY.value = -1
  159. menuShow.value = false
  160. hideChapterList()
  161. }
  162. function closeMenu(){
  163. hideSetting()
  164. }
  165. function onChangeFontSize(index:number){
  166. let new_index = -1;
  167. if(index>0){
  168. new_index = ReadSetting().getReadSetting().fontSizeIndex + 1
  169. if(new_index>=config.read_config.fontSizeList.length){
  170. }else{
  171. ReadSetting().changeFontSize(new_index)
  172. }
  173. }else{
  174. new_index = ReadSetting().getReadSetting().fontSizeIndex - 1
  175. if(new_index<0){
  176. }else{
  177. ReadSetting().changeFontSize(new_index)
  178. }
  179. }
  180. }
  181. function onChangeBgColor(index:number){
  182. }
  183. //设置end
  184. //章节列表 start
  185. let showChapterList = ref(false)
  186. function goToChapter(chapter_list_item_data:chapter_item_data){
  187. // console.log("想看",chapter_list_item_data)
  188. cur_read_chapter_index.value = tools.getCurChapterIndex(chapter_list_item_data.id,directoryList)
  189. book_text_list_view.value = []
  190. draw()
  191. hideChapterList()
  192. }
  193. // function getCurChapterId(){
  194. // return tools.getCurChapterData(cur_read_chapter_index.value,directoryList).id
  195. // }
  196. </script>
  197. <style scoped>
  198. </style>