Skip to content

Commit

Permalink
Add vue-waterfall-plugin-next to dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
hello8693 committed Oct 7, 2024
1 parent 9b53bf9 commit d6fee50
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"dependencies": {
"pinia": "^2.1.7",
"vue": "^3.4.29",
"vue-router": "^4.3.3"
"vue-router": "^4.3.3",
"vue-waterfall-plugin-next": "^2.6.0"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.8.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 38 additions & 20 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
@@ -1,51 +1,69 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import imageListData from '@/assets/imageList.json'
import { LazyImg, Waterfall } from 'vue-waterfall-plugin-next'
import 'vue-waterfall-plugin-next/dist/style.css'
const imageList = ref<string[]>([])
const imageList = ref<{ id: string; src: string; name: string }[]>([])
/**
* 获取随机ID
* @param {*} length
* @returns
*/
function randomID(length = 6) {
return Number(Math.random().toString().substr(3, length) + Date.now()).toString(36)
}
onMounted(() => {
imageList.value = imageListData
imageList.value = imageListData.map((imagePath: string) => ({
id: randomID(),
src: imagePath,
name: imagePath.split('/').pop() || ''
}))
})
const getFileName = (path: string) => {
return path.replace('./imgs/', '')
}
</script>

<template>
<div class="image-container">
<div v-for="image in imageList" :key="image" class="image-wrapper">
<img :src="image" alt="Image" />
<p class="image-filename">{{ getFileName(image) }}</p>
</div>
</div>
<h1>ClassIsland Hub</h1>
<Waterfall :list="imageList" :column-width="200" :gutter="16">
<template #default="{ item }">
<div class="image-wrapper">
<LazyImg :url="item" alt="Image" />
<p class="image-filename">{{ item.name }}</p>
</div>
</template>
</Waterfall>
</template>

<style scoped>
.image-container {
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
h1 {
text-align: center;
font-size: 24px;
margin-bottom: 20px;
color: #333;
}
.image-wrapper {
flex: 1 1 200px;
max-width: 200px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
overflow: hidden;
text-align: center;
}
img {
.image-wrapper img {
width: 100%;
height: auto;
display: block;
}
.image-filename {
margin-top: 5px;
font-size: 14px;
padding: 8px;
text-align: center;
font-size: 16px;
color: #333;
}
</style>

0 comments on commit d6fee50

Please sign in to comment.