Skip to content

Commit 5ce296b

Browse files
1.1.2
1 parent 657a2b0 commit 5ce296b

File tree

11 files changed

+119
-39
lines changed

11 files changed

+119
-39
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
- 如果图片过大,硬盘性能不好,可能会造成加载浏览卡顿,这时候,建议使用固态硬盘,或者调小每一页展示的图片数量!!
3838

3939
## 使用示例
40-
41-
### 其一
42-
**[TG preview link](https://t.me/edge_wasteland/6464)**
40+
- **[YouTube](https://www.youtube.com/watch?v=MHicKz_QJ1w)**
41+
- **[Telegram](https://t.me/edge_wasteland/6526)**
42+
- **[哔哩哔哩](https://www.bilibili.com/video/BV1tm411Q7Js/)**
4343
<!-- **[GIF preview link](https://postimg.cc/ctZfPV1q)** -->
4444

4545
### For NSFW Use

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "waterfall-picture-viewer",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "A simple picture viewer",
55
"productName": "W Viewer",
66
"author": "边缘坐标 <[email protected]>",

src-electron/traverseFolder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ export function imageRetrieval (thepath, pFormats) {
118118
imageLinks = [];
119119
picLinks = [];
120120
traverseFolderObjects(thepath);
121+
console.log('Finish traverseFolderObjects!');
121122
return picLinks;
122-
// traverseFolder(thepath);
123-
// return imageLinks;
124123
}
125124
// // 开始遍历
126125
// traverseFolder(rootPath);

src/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ async function initData() {
1919
let tmpdata: any
2020
if (tmpdata = await window.storeAPI.get('itemNum')) setStore.perPageNum = tmpdata
2121
if (tmpdata = await window.storeAPI.get('WBreakpoint')) setStore.waterfallBreakpoint = tmpdata
22-
console.log(await window.storeAPI.get('WBreakpoint'), setStore.waterfallBreakpoint)
22+
if (tmpdata = await window.storeAPI.get('cycleUpdate')) setStore.cycleUpdate = tmpdata
23+
// console.log(await window.storeAPI.get('WBreakpoint'), setStore.waterfallBreakpoint)
2324
console.log('APP setData inited!')
2425
}
2526

src/components/SetComponent.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<template v-slot:after>
2727
<q-tab-panels v-model="tab" animated swipeable vertical transition-prev="jump-up" transition-next="jump-up">
2828
<q-tab-panel name="mails">
29+
<!-- ANCHOR 基础设置 -->
2930
<div class="text-h4 q-mb-md">基础设置</div>
3031
<q-input v-model="simpleSetData.perPageNum" :label="'每页展示图片数目 当前:' + setStore.perPageNum + '/页'">
3132
<template v-slot:after>
@@ -43,6 +44,15 @@
4344
</q-tooltip></q-btn>
4445
</template>
4546
</q-input>
47+
<q-toggle :label="`自动重排开启状态${setStore.cycleUpdate}`" v-model="setStore.cycleUpdate" />
48+
<q-icon round dense flat color="primary" name="mdi-help"><q-tooltip class="bg-purple text-body2"
49+
:offset="[10, 10]">
50+
自动重排:如果您经常遇到瀑布流排版不正确导致需要手动点击以重新排版的情况,可以开启此选项。
51+
</q-tooltip></q-icon>
52+
<q-btn class="float-right" round dense flat icon="mdi-content-save"
53+
@click="saveData('cycleUpdate')"><q-tooltip class="bg-purple text-body2" :offset="[10, 10]">
54+
保存设置
55+
</q-tooltip></q-btn>
4656
<!-- <div>是否开启图片查看器画廊:<q-toggle disable v-model="simpleSetData.vNavbar" /></div> -->
4757
<div>
4858
<br />
@@ -184,7 +194,9 @@ function saveData(id) {
184194
setStore.waterfallBreakpoint = WBV2WB(WBValue.value)
185195
window.storeAPI.set('WBreakpoint', JSON.parse(JSON.stringify(setStore.waterfallBreakpoint)))
186196
break
187-
197+
case 'cycleUpdate':
198+
window.storeAPI.set('cycleUpdate', setStore.cycleUpdate)
199+
break
188200
}
189201
}
190202

src/components/WaterFall.vue

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@
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-
5344
import { NInputNumber } from 'naive-ui'
5445
import { onMounted, onUnmounted, reactive, ref, computed, watch } from 'vue'
5546
import { 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) // 啥玩意《
7364
const 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
// 加载更多
118109
function 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 查看器初始化
128120
import PhotoSwipeLightbox from 'photoswipe/lightbox';
129121
import 'photoswipe/style.css';
130122
let 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
// 首次加载
160193
onMounted(() => {
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

src/pages/AboutPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<img src="~assets/20240128.png" class="max-w-sm rounded-lg shadow-2xl" />
1212
<div>
1313
<h1 class="text-5xl font-bold">About Program</h1>
14-
<p class="text-subtitle2 text-xl">简约瀑布流查看器哦~<br /><b>Version:1.1.1</b></p>
14+
<p class="text-subtitle2 text-xl">简约瀑布流查看器哦~<br /><b>Version:1.1.2</b></p>
1515
<button @click="openLink('https://github.com/Edge-coordinates/Waterfall_picture_viewer')"
1616
class="btn btn-primary">给个Star吧~</button>
1717
</div>

src/pages/IndexPage.vue

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<template>
22
<q-page style="margin-top: 20px;">
3-
<!-- <div class="row items-center justify-evenly">
4-
<router-link to="/test" class="btn">Go to Test</router-link>
5-
<button class="btn" @click="querydb">Button</button>
6-
<button class="btn" @click="picInfoInit">Button</button>
7-
</div> -->
83
<div v-if="ifImgPreOK" class="h-full">
94
<water-fall :imgs="imgs"></water-fall>
105
<!-- <water-fall /> -->
@@ -113,22 +108,23 @@ async function picInfoInit(fpath) {
113108
ifImgPreOK.value = true
114109
}
115110
111+
import { normalizePath } from './normalize-path'
112+
113+
function getFolderPath(fpath, fullfpath) {
114+
fpath = normalizePath(fpath)
115+
fullfpath = normalizePath(fullfpath)
116+
let root = '/' + fpath.split('/')[1] + '/'
117+
return fullfpath.replace(fpath, root)
118+
}
119+
116120
// eslint-disable-next-line @typescript-eslint/no-explicit-any
117121
function onUpload(e: any) {
122+
console.log('onUpload!');
123+
// ! 修改计算逻辑,不用正则了,采用原始字符串匹配?
118124
let fpath = e.file.fullPath // 相对路径
119125
const fullfpath = e.file.file.path // 绝对路径
120-
let rt = new RegExp(String.raw`\\${fpath.split('/')[1]}\\`)
121-
const match = rt.exec(fullfpath);
122-
const matchedText = match![0];
123-
const beforeMatch = fullfpath.substring(0, match!.index);
124-
fpath = beforeMatch + matchedText
125-
console.log(e)
126-
console.log(rt, fpath, fullfpath);
127-
console.log(match, matchedText, beforeMatch)
128-
// fpath = fullfpath.split(rt)[0] + rt + '\\'
129-
// console.log(fpath);
130-
131-
// console.log(rt, fpath, fullfpath)
126+
fpath = getFolderPath(fpath, fullfpath)
127+
console.log(fpath);
132128
133129
picInfoInit(fpath)
134130
}

src/pages/normalize-path.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*!
2+
* normalize-path <https://github.com/jonschlinkert/normalize-path>
3+
*
4+
* Copyright (c) 2014-2018, Jon Schlinkert.
5+
* Released under the MIT License.
6+
*/
7+
8+
export function normalizePath (path, stripTrailing: boolean = true) {
9+
if (typeof path !== 'string') {
10+
throw new TypeError('expected path to be a string');
11+
}
12+
13+
if (path === '\\' || path === '/') return '/';
14+
15+
const len = path.length;
16+
if (len <= 1) return path;
17+
18+
// ensure that win32 namespaces has two leading slashes, so that the path is
19+
// handled properly by the win32 version of path.parse() after being normalized
20+
// https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
21+
let prefix = '';
22+
if (len > 4 && path[3] === '\\') {
23+
const ch = path[2];
24+
if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
25+
path = path.slice(2);
26+
prefix = '//';
27+
}
28+
}
29+
30+
const segs = path.split(/[/\\]+/);
31+
if (stripTrailing !== false && segs[segs.length - 1] === '') {
32+
segs.pop();
33+
}
34+
return prefix + segs.join('/');
35+
}

src/stores/viewerSet-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const useSettingStore = defineStore('setting', {
44
state: () => ({
55
isOpen: false,
66
perPageNum: 20,
7+
cycleUpdate: false,
78
imageFormat: [
89
'.webp',
910
'.jxl',

0 commit comments

Comments
 (0)