优化图片加载(同步更新)合并reset.css

This commit is contained in:
chuzhongzai 2024-01-03 14:37:34 +08:00
parent df24dcb3e2
commit b02e96a021
2 changed files with 33 additions and 13 deletions

View File

@ -1,10 +1,15 @@
<script setup> <script setup>
import {computed, ref} from "vue"; import {computed, ref, watch} from "vue";
import store from "../store/index.js"; import store from "../store/index.js";
let onlineReadingScrollbar = ref() let onlineReadingScrollbar = ref()
let links = ref() let links = ref()
let index = ref(0) let index = ref(0) //
let temp_index = ref(0) // let page = ref(0) // +1=
let imagesForLoading = ref([])
let loadIndex = ref(0)
let isReading = ref(false)
let max = ref(0) let max = ref(0)
let current_page = 0 let current_page = 0
let lengthPerPage = computed(() => { let lengthPerPage = computed(() => {
@ -13,9 +18,11 @@ let lengthPerPage = computed(() => {
let readingGallery = computed(() => { let readingGallery = computed(() => {
return store.state.readingGallery return store.state.readingGallery
}) })
let isShowUp = computed(() => { watch((store.state), (value) => {
alterPage() if(value.isReading && !isReading.value) {
return store.state.isReading alterPage()
isReading.value = true
}
}) })
// //
@ -28,19 +35,31 @@ function alterPage(){
max.value = 0 max.value = 0
} }
index.value = 0 index.value = 0
temp_index.value = 1 page.value = 1
loadIndex.value = 0
imagesForLoading.value.splice(0)
loadImage()
} }
// //
function jump(targetIndex){ function jump(targetIndex){
links.value = readingGallery.value.images.slice(targetIndex * lengthPerPage.value, (targetIndex + 1) * lengthPerPage.value) links.value = readingGallery.value.images.slice(targetIndex * lengthPerPage.value, (targetIndex + 1) * lengthPerPage.value)
index.value = targetIndex index.value = targetIndex
temp_index.value = targetIndex + 1 page.value = targetIndex + 1
imagesForLoading.value.splice(0)
loadIndex.value = 0
loadImage()
onlineReadingScrollbar.value.setScrollTop(0) onlineReadingScrollbar.value.setScrollTop(0)
} }
function loadImage(){
if(loadIndex.value < links.value.length)
imagesForLoading.value.push(links.value[loadIndex.value++])
}
function closeDialog(){ function closeDialog(){
onlineReadingScrollbar.value.setScrollTop(0) onlineReadingScrollbar.value.setScrollTop(0)
isReading.value = false
store.commit("_closeReader") store.commit("_closeReader")
} }
@ -76,7 +95,7 @@ function set_current_page(page){
</script> </script>
<template> <template>
<el-dialog v-model="isShowUp" width="90%" style="margin-top: 0; margin-bottom: 0; padding: 0" @close="closeDialog"> <el-dialog v-model="isReading" width="90%" style="margin-top: 0; margin-bottom: 0; padding: 0" @close="closeDialog">
<template #header style="padding-bottom: 0"> <template #header style="padding-bottom: 0">
在线预览: {{readingGallery.name}}<br> 在线预览: {{readingGallery.name}}<br>
页数{{readingGallery.pages}}<br> 页数{{readingGallery.pages}}<br>
@ -86,9 +105,9 @@ function set_current_page(page){
</div> </div>
</template> </template>
<el-scrollbar height="75vh" ref="onlineReadingScrollbar"> <el-scrollbar height="75vh" ref="onlineReadingScrollbar">
<div v-for="(link, i) in links" style="display: inline-block; text-align: center; min-height: 300px"> <div v-for="(link, i) in imagesForLoading" style="display: inline-block; text-align: center; min-height: 300px">
<el-image :src="link" :style="{'width': '66vw', 'background-color': 'gary'}" <el-image :src="link" :style="{'width': '66vw', 'background-color': 'gary'}"
:preview-src-list="links" :initial-index="i" @switch="switch_page" @show="set_current_page(i)" loading="lazy"/><br> :preview-src-list="links" :initial-index="i" @switch="switch_page" @show="set_current_page(i)" loading="lazy" @load="loadImage"/><br>
{{lengthPerPage * index + i + 1}} {{lengthPerPage * index + i + 1}}
</div> </div>
</el-scrollbar> </el-scrollbar>
@ -106,10 +125,10 @@ function set_current_page(page){
<span v-if="max >= 9"> <span v-if="max >= 9">
<el-button @click="jump(index - 1)" :disabled="index === 0">上一页</el-button> <el-button @click="jump(index - 1)" :disabled="index === 0">上一页</el-button>
1 &lt; 1 &lt;
<el-input-number v-model="temp_index" :min="1" :max="max"/> <el-input-number v-model="page" :min="1" :max="max"/>
&lt; {{max}} &lt; {{max}}
<el-button @click="jump(index + 1)" :disabled="index === max - 1">下一页</el-button> <el-button @click="jump(index + 1)" :disabled="index === max - 1">下一页</el-button>
<el-button @click="jump(temp_index - 1)" size="large">跳转</el-button> <el-button @click="jump(page - 1)" size="large">跳转</el-button>
</span> </span>
</el-dialog> </el-dialog>
</template> </template>

View File

@ -2,6 +2,7 @@ import { createApp } from 'vue'
import App from './App.vue' import App from './App.vue'
import 'element-plus/dist/index.css' import 'element-plus/dist/index.css'
import element from "element-plus" import element from "element-plus"
import "./reset.css"
import 'element-plus/theme-chalk/dark/css-vars.css' import 'element-plus/theme-chalk/dark/css-vars.css'
createApp(App).use(element).mount('#app') createApp(App).use(element).mount('#app')