新增预览分页,可以设置每页有多少张图片;将预览抽取为单独一个组件;(同步更新)

This commit is contained in:
chuzhongzai 2023-06-29 14:18:04 +08:00
parent 1549696042
commit 07eb3567b4
4 changed files with 126 additions and 40 deletions

View File

@ -32,7 +32,7 @@
<hr> <hr>
<el-button @click="isAlterAuthCode = true">修改授权码</el-button> <el-button @click="isAlterAuthCode = true">修改授权码</el-button>
<el-button @click="deleteAuthCode">删除本地授权码</el-button> <el-button @click="deleteAuthCode">删除本地授权码</el-button>
<el-button @click="isConfigDarkMode = true">夜间模式配置</el-button> <el-button @click="isConfig = true">配置</el-button>
<span style="display: inline">夜间模式</span> <span style="display: inline">夜间模式</span>
<el-switch @click="toggleStyle" v-model="isDark">夜间模式</el-switch> <el-switch @click="toggleStyle" v-model="isDark">夜间模式</el-switch>
<hr> <hr>
@ -133,17 +133,25 @@
</div> </div>
</el-dialog> </el-dialog>
<el-dialog title="配置夜间模式" v-model="isConfigDarkMode"> <el-dialog title="配置" v-model="isConfig">
<span style="display: inline-block">夜间模式跟随系统</span> <div>
<el-switch v-model="darkConfig.followSystem"></el-switch><br> 夜间模式<hr>
<span style="display: inline-block">自定义起始时间(精确到分)</span> <span style="display: inline-block">夜间模式跟随系统</span>
<el-switch v-model="darkConfig.customTime"></el-switch><br> <el-switch v-model="darkConfig.followSystem"></el-switch><br>
<el-form :disabled="!darkConfig.customTime"> <span style="display: inline-block">自定义起始时间(精确到分)</span>
<el-time-picker v-model="darkConfig.startTime" /> ~ <el-switch v-model="darkConfig.customTime"></el-switch><br>
<el-time-picker v-model="darkConfig.endTime"/> <el-form :disabled="!darkConfig.customTime">
</el-form> <el-time-picker v-model="darkConfig.startTime" /> ~
<el-time-picker v-model="darkConfig.endTime"/>
</el-form>
</div>
<div>
在线预览<hr>
<span style="display: inline-block">在线预览分页页数:</span>
<input v-model="lengthPerPage">
</div>
<template #footer> <template #footer>
<el-button type="primary" @click="saveDarkConfig">保存</el-button> <el-button type="primary" @click="saveConfig">保存</el-button>
</template> </template>
</el-dialog> </el-dialog>
@ -197,12 +205,13 @@ let tempAuthCode = ref("")
let isQuerying = ref(false) let isQuerying = ref(false)
let isViewingTag = ref(false) let isViewingTag = ref(false)
let isConfigDarkMode = ref(false) let isConfig = ref(false)
let isDark = ref(false) let isDark = ref(false)
let keyword = ref("") let keyword = ref("")
let galleries = ref([]) let galleries = ref([])
let queryPage = ref({}) let queryPage = ref({})
let darkConfig = ref({}) let darkConfig = ref({})
let lengthPerPage = ref(0)
// //
let type = ref("link") let type = ref("link")
@ -401,12 +410,12 @@ function resetLocalQuery(){
store.commit("_searchLocalByKeyword", "") store.commit("_searchLocalByKeyword", "")
param.value = "" param.value = ""
} }
function queryGalleries(link){ function queryGalleries(link) {
let tempParam let tempParam
if(link !== null) { if (link !== null) {
let url = new URL(link) let url = new URL(link)
tempParam = url.search.replace("?f_search=", "") tempParam = url.search.replace("?f_search=", "")
}else{ } else {
tempParam = keyword.value tempParam = keyword.value
} }
tempParam = tempParam.replace(" ", "+") tempParam = tempParam.replace(" ", "+")
@ -426,7 +435,7 @@ function queryGalleries(link){
tempGalleries.forEach((gallery) => { tempGalleries.forEach((gallery) => {
galleries.value.push(gallery) galleries.value.push(gallery)
}) })
}else { } else {
ElMessage({message: res.data.data, type: "error"}) ElMessage({message: res.data.data, type: "error"})
} }
}) })
@ -484,6 +493,9 @@ function toggleStyle(){
onMounted(() => { onMounted(() => {
const auth = localStorage.getItem("auth") const auth = localStorage.getItem("auth")
adjustForStyle() adjustForStyle()
store.state.lengthPerPage = localStorage.getItem("lengthPerPage")
store.state.lengthPerPage = store.state.lengthPerPage === null ? 30: Number(store.state.lengthPerPage)
lengthPerPage.value = store.state.lengthPerPage
if(auth !== null){ if(auth !== null){
store.dispatch("validate", auth) store.dispatch("validate", auth)
@ -566,7 +578,7 @@ function light(){
document.querySelector(".DashBoard").style.setProperty("background-color", "ghostwhite") document.querySelector(".DashBoard").style.setProperty("background-color", "ghostwhite")
document.querySelector(".app").style.setProperty("background-color", "#c6e2ff") document.querySelector(".app").style.setProperty("background-color", "#c6e2ff")
} }
function saveDarkConfig(){ function saveConfig(){
if(darkConfig.value.customTime) { if(darkConfig.value.customTime) {
if(darkConfig.value.startTime === undefined || darkConfig.value.endTime === undefined){ if(darkConfig.value.startTime === undefined || darkConfig.value.endTime === undefined){
ElMessage("请正确选择起始时间") ElMessage("请正确选择起始时间")
@ -574,8 +586,10 @@ function saveDarkConfig(){
} }
} }
store.state.lengthPerPage = Number(lengthPerPage.value)
localStorage.setItem("lengthPerPage", lengthPerPage.value)
localStorage.setItem("darkConfig", JSON.stringify(darkConfig.value)) localStorage.setItem("darkConfig", JSON.stringify(darkConfig.value))
isConfigDarkMode.value = false isConfig.value = false
adjustForStyle() adjustForStyle()
} }
</script> </script>

View File

@ -0,0 +1,78 @@
<script setup>
import {computed, ref, watch} from "vue";
import store from "../store/index.js";
let props = defineProps(['currentLinks', 'isOnlineReading'])
let isShowUp = ref()
let onlineReadingScrollbar = ref()
let links = ref()
let index = ref(0)
let temp_index = ref(0) //
let max = ref(0)
let lengthPerPage = computed(() => {
return store.state.lengthPerPage
})
watch(props, (props)=>{
isShowUp.value = props.isOnlineReading
alterPage()
})
//
function alterPage(){
console.log(lengthPerPage.value, props.currentLinks.length)
if(props.currentLinks.length > lengthPerPage.value){
links.value = props.currentLinks.slice(0, lengthPerPage.value)
max.value = Math.ceil(props.currentLinks.length / lengthPerPage.value)
}else{
links.value = props.currentLinks
}
index.value = 0
temp_index.value = 1
}
//
function jump(targetIndex){
links.value = props.currentLinks.slice(targetIndex * lengthPerPage.value, (targetIndex + 1) * lengthPerPage.value)
index.value = targetIndex
temp_index.value = targetIndex + 1
}
function closeDialog(){
onlineReadingScrollbar.value.setScrollTop(0)
}
</script>
<template>
<el-dialog title="在线预览" v-model="isShowUp" width="90%" style="margin-top: 0; margin-bottom: 0; padding: 0" @close="closeDialog">
<div style="font-size: 20px; text-align: center; " v-if="max > 0">
{{index + 1}} - {{(index) * lengthPerPage + 1}} ~ {{(index + 1) * lengthPerPage + 1 > currentLinks.length? currentLinks.length: (index + 1) * lengthPerPage + 1}}
</div>
<el-scrollbar height="75vh" ref="onlineReadingScrollbar">
<el-image v-for="(link, i) in links" :src="link" :style="{'width': store.state.imageWidth, 'padding-right': store.state.imagePadding, 'background-color': 'ghostwhite'}"
:preview-src-list="currentLinks" :initial-index="index * lengthPerPage + i" loading="lazy"/>
</el-scrollbar>
<!-- 十页以下-->
<span v-if="max > 1 && max < 9">
<el-button @click="jump(index - 1)" :disabled="index === 0">上一页</el-button>
<el-button v-for="i in max" @click="jump(i - 1)">
{{i}}
</el-button>
<el-button @click="jump(index + 1)" :disabled="index === max - 1">下一页</el-button>
</span>
<!-- 十页及以上-->
<span v-if="max >= 9">
<el-button @click="jump(index - 1)" :disabled="index === 0">上一页</el-button>
1 &lt;
<el-input-number v-model="temp_index" :min="1" :max="max"/>
&lt; {{max}}
<el-button @click="jump(index + 1)" :disabled="index === max - 1">下一页</el-button><br>
<el-button @click="jump(temp_index - 1)" >跳转</el-button>
</span>
</el-dialog>
</template>
<style scoped>
</style>

View File

@ -111,12 +111,7 @@
</el-form> </el-form>
</el-dialog> </el-dialog>
<el-dialog v-model="isOnlineReading" title="在线预览" @close="closeOnlineReading" width="90%" style="margin-top: 0; margin-bottom: 0; padding: 0"> <OnlineReader :currentLinks="currentLinks" :isOnlineReading="isOnlineReading"/>
<el-scrollbar height="84vh" ref="onlineReadingScrollbar">
<el-image v-for="(link, index) in currentLinks" :src="link" :style="{'width': imageWidth, 'padding-right': imagePadding, 'background-color': 'ghostwhite'}"
:preview-src-list="currentLinks" :initial-index="index" loading="lazy"/>
</el-scrollbar>
</el-dialog>
<span v-show="!loadComplete" class="side">请输入授权码后再查看</span> <span v-show="!loadComplete" class="side">请输入授权码后再查看</span>
</div> </div>
@ -127,6 +122,7 @@ import store from "../store";
import {computed, ref} from "vue"; import {computed, ref} from "vue";
import axios from "axios"; import axios from "axios";
import {ElMessage} from "element-plus"; import {ElMessage} from "element-plus";
import OnlineReader from "./OnlineReader.vue";
// //
let inputNode = ref(null) let inputNode = ref(null)
@ -316,10 +312,6 @@ function deleteGallery(gid){
function onlineGalleryReader(gid){ function onlineGalleryReader(gid){
store.dispatch("queryOnlineLinks", gid) store.dispatch("queryOnlineLinks", gid)
} }
function closeOnlineReading(){
store.state.isOnlineReading = false
onlineReadingScrollbar.value.setScrollTop(0)
}
function shareGallery(data){ function shareGallery(data){
const {gid, shortName} = data const {gid, shortName} = data
let link let link

View File

@ -118,18 +118,19 @@ const actions = {
context.dispatch("updateGalleryTasks", "all").then(() => confirmCurrentTask(context.state)) context.dispatch("updateGalleryTasks", "all").then(() => confirmCurrentTask(context.state))
//获取图片合适长度 //获取图片合适长度
let screenWidth = window.screen.width * 0.9 - 40 // let screenWidth = window.screen.width * 0.9 - 40
let width // let width
let i // let i
for(i=3; i>0; i--) // for(i=3; i>0; i--)
if(screenWidth / i <= 350 || screenWidth / i >= 100){ // if(screenWidth / i <= 350 || screenWidth / i >= 100){
width = screenWidth / i // width = screenWidth / i
break // break
} // }
//
width = width - (width % 10) // width = width - (width % 10)
state.imageWidth = width + 'px' //写死图片合适宽度
state.imagePadding = ((screenWidth - i * width) / i) + 'px' state.imageWidth = 550 + 'px'
state.imagePadding = 10 + 'px'
} }
else else
context.commit("_unAuthed") context.commit("_unAuthed")
@ -615,6 +616,7 @@ const state = {
currentLinks: [], //当前本子链接 currentLinks: [], //当前本子链接
imageWidth: "", //图片宽度 imageWidth: "", //图片宽度
imagePadding: "", //图片padding imagePadding: "", //图片padding
lengthPerPage: 0, //在线预览每页图片数量
page: 1, //当前页数 page: 1, //当前页数
length: 10, //每页能有多少个链接 length: 10, //每页能有多少个链接