4141<!-- eslint-disable @typescript-eslint/no-explicit-any -->
4242<!-- eslint-disable @typescript-eslint/no-unused-vars -->
4343<script setup lang="ts">
44-
45- function getFolder(filePath : string , regexPattern : RegExp ): string {
46- var directory = filePath .substring (
47- 0 ,
48- filePath .lastIndexOf (' \\ ' ),
49- );
50- return directory .replace (regexPattern , ' ' )
51- }
52-
5344import { NInputNumber } from ' naive-ui'
5445import { onMounted , onUnmounted , reactive , ref , computed , watch } from ' vue'
5546import { LazyImg , Waterfall } from ' vue-waterfall-plugin-next'
@@ -69,7 +60,7 @@ const props = defineProps({
6960 }
7061})
7162
72- let oImgs = ref (props .imgs )
63+ let oImgs = ref (props .imgs ) // 啥玩意《
7364const inputPageValue = ref (1 )
7465// import { LazyImg, Waterfall } from 'vue-waterfall-plugin-next'
7566// import 'vue-waterfall-plugin-next/dist/style.css'
@@ -116,6 +107,7 @@ function scrollToTop() {
116107
117108// 加载更多
118109function handleLoadMore() {
110+ console .log (' handleLoadMore!' );
119111 getList ({
120112 page: page .value ,
121113 pageSize: setStore .perPageNum ,
@@ -124,12 +116,13 @@ function handleLoadMore() {
124116 })
125117}
126118
127-
119+ // ANCHOR 查看器初始化
128120import PhotoSwipeLightbox from ' photoswipe/lightbox' ;
129121import ' photoswipe/style.css' ;
130122let lightbox: any , thisPic: string
123+ let isLightboxOpen = ref (false )
131124
132- function handleViewerKeyDown(event ) {// 检查是否按下了特定的键,例如 Ctrl + S
125+ function handleViewerKeyDown(event ) {// * 查看器内部 检查是否按下了特定的键,例如 Ctrl + S
133126 if (event .key === ' Delete' ) {
134127 event .preventDefault (); // 阻止默认行为(例如保存网页)
135128 console .log (' pressed Delete.' );
@@ -155,10 +148,51 @@ function handleViewerKeyDown(event) {// 检查是否按下了特定的键,例
155148 // 可以添加其他条件检查
156149}
157150
151+ let theCycleUpdateInterval
152+ function turnOnCycleUpdate() {
153+ console .log (' Turn on cycleUpdate' );
154+ theCycleUpdateInterval = window .setInterval (handleLoadMore , 500 );
155+ }
156+
157+ function tEventListening() { // * 一些乱七八糟的事件的监听
158+ if (setStore .cycleUpdate ) {
159+ turnOnCycleUpdate ()
160+ }
161+ document .addEventListener (' keydown' , function (event : any ) {
162+ const key = event .key
163+ if (isLightboxOpen .value == false ) {
164+ if (key == ' ArrowRight' ) {
165+ if (page .value < pageNum .value ) {
166+ page .value = page .value + 1
167+ handleLoadMore ()
168+ }
169+ }
170+ if (key == ' ArrowLeft' ) {
171+ if (page .value > 1 ) {
172+ page .value = page .value - 1
173+ handleLoadMore ()
174+ }
175+ }
176+ }
177+ });
178+ setStore .$subscribe ((mutation : any , state ) => {
179+ // console.log(mutation, state)
180+ // 监听 章节正则表达式变化,之后重绘书籍
181+ if (mutation .events .key == ' cycleUpdate' ) {
182+ // console.log(state.cycleUpdate)
183+ if (state .cycleUpdate )
184+ turnOnCycleUpdate ()
185+ else
186+ window .clearInterval (theCycleUpdateInterval );
187+ }
188+ })
189+
190+ }
158191
159192// 首次加载
160193onMounted (() => {
161194 handleLoadMore ()
195+ tEventListening ()
162196 if (! lightbox ) {
163197 lightbox = new PhotoSwipeLightbox ({
164198 gallery: ' #pic-wrapper' ,
@@ -208,11 +242,13 @@ onMounted(() => {
208242 lightbox .on (' openingAnimationStart' , () => {
209243 // 开始监听 查看器内 快捷键
210244 document .addEventListener (' keydown' , handleViewerKeyDown );
245+ isLightboxOpen .value = true
211246 console .log (' openingAnimationStart' );
212247 });
213248
214249 lightbox .on (' closingAnimationStart' , () => {
215250 document .removeEventListener (' keydown' , handleViewerKeyDown );
251+ isLightboxOpen .value = false
216252 console .log (' closingAnimationStart' );
217253 });
218254
0 commit comments