-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
477 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
docs/assets/index.aee4a039.css → docs/assets/index.e66c7085.css
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<script setup lang="ts"> | ||
import BScroll from '@better-scroll/core' | ||
import ScrollBar from '@better-scroll/scroll-bar' | ||
import ObserveDOM from '@better-scroll/observe-dom' | ||
import MouseWheel from '@better-scroll/mouse-wheel' | ||
import Pullup from '@better-scroll/pull-up' | ||
import type { BScrollConstructor } from '@better-scroll/core/dist/types/BScroll' | ||
import { onMounted, ref } from 'vue' | ||
const emits = defineEmits({ | ||
scroll: null, | ||
pullingUp: null, | ||
}) | ||
// 鼠标插件 | ||
BScroll.use(MouseWheel) | ||
BScroll.use(ObserveDOM) | ||
BScroll.use(ScrollBar) | ||
BScroll.use(Pullup) | ||
// 滚动 | ||
const scrollEl = ref(null) | ||
const bs = ref<BScrollConstructor>() | ||
const loading = ref(false) | ||
onMounted(() => { | ||
initBs() | ||
}) | ||
function initBs() { | ||
if (!scrollEl.value) | ||
return | ||
bs.value = new BScroll(scrollEl.value, { | ||
probeType: 3, | ||
click: true, | ||
pullUpLoad: true, | ||
observeDOM: true, // 开启 observe-dom 插件 | ||
mouseWheel: { | ||
speed: 20, | ||
invert: false, | ||
easeTime: 300, | ||
}, | ||
scrollY: true, | ||
scrollbar: true, | ||
}) | ||
bs.value.on('scroll', (data: any) => { | ||
emits('scroll', data) | ||
}) | ||
bs.value.on('pullingUp', () => { | ||
emits('pullingUp') | ||
loading.value = true | ||
}) | ||
} | ||
function finishPullUp() { | ||
if (bs.value) { | ||
bs.value.finishPullUp() | ||
bs.value.refresh() | ||
loading.value = false | ||
} | ||
} | ||
function scrollToElement(el: HTMLElement) { | ||
if (bs.value) | ||
bs.value.scrollToElement(el, 300, true, true) | ||
} | ||
defineExpose({ | ||
scrollToElement, | ||
finishPullUp, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div ref="scrollEl" class="scroll-wrapper"> | ||
<div> | ||
<slot /> | ||
|
||
<p class="loading-text"> | ||
{{ loading ? '加载中' : '触底后加载数据' }} | ||
</p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.scroll-wrapper { | ||
height: 100%; | ||
position: relative; | ||
overflow: hidden; | ||
/* background-color: #f9f9f9; */ | ||
} | ||
.loading-text { | ||
padding: 20px; | ||
text-align: center; | ||
background-color: #fff; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
<template> | ||
<div class="page-b-content"> | ||
<BScrollBox ref="bs" @pullingUp="pullingUp"> | ||
<Waterfall | ||
:list="list" | ||
:row-key="options.rowKey" | ||
:gutter="options.gutter" | ||
:has-around-gutter="options.hasAroundGutter" | ||
:width="options.width" | ||
:breakpoints="options.breakpoints" | ||
:img-selector="options.imgSelector" | ||
:background-color="options.backgroundColor" | ||
:lazyload="options.lazyload" | ||
:load-props="options.loadProps" | ||
> | ||
<template #default="{ item, url }"> | ||
<div class="bg-gray-900 rounded-lg shadow-md overflow-hidden transition-all duration-300 ease-linear hover:shadow-lg hover:shadow-gray-600 group"> | ||
<div class="overflow-hidden"> | ||
<LazyImg :url="url" class="cursor-pointer transition-all duration-300 ease-linear group-hover:scale-105" @load="imageLoad" @error="imageError" @success="imageSuccess" /> | ||
</div> | ||
<div class="px-4 pt-2 pb-4 border-t border-t-gray-800"> | ||
<h2 class="pb-4 text-gray-50 group-hover:text-yellow-300"> | ||
{{ item.name }} | ||
</h2> | ||
</div> | ||
</div> | ||
</template> | ||
</Waterfall> | ||
</BScrollBox> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted, reactive, ref } from 'vue' | ||
import type { ViewCard } from '../../lib/types/waterfall' | ||
import { LazyImg, Waterfall } from '../../lib/index' | ||
// import { LazyImg, Waterfall } from 'vue-waterfall-plugin-next' | ||
// import 'vue-waterfall-plugin-next/dist/style.css' | ||
import { getList } from '../api' | ||
import loading from '../assets/loading.png' | ||
import error from '../assets/error.png' | ||
import BScrollBox from './BScrollBox.vue' | ||
const useList = function() { | ||
const pages = ref([1, 2, 3, 4, 5]) | ||
const page = ref(1) | ||
const list = ref<ViewCard[]>([]) | ||
function handleChangePage(val: number) { | ||
page.value = val | ||
return handleLoadMore() | ||
} | ||
// 加载更多 | ||
function handleLoadMore() { | ||
return new Promise((resolve, reject) => { | ||
getList({ | ||
page: page.value, | ||
pageSize: 20, | ||
}).then((res) => { | ||
list.value.push(...res) | ||
resolve(true) | ||
}) | ||
}) | ||
} | ||
return { | ||
list, | ||
page, | ||
pages, | ||
handleLoadMore, | ||
handleChangePage, | ||
} | ||
} | ||
const options = reactive({ | ||
// 唯一key值 | ||
rowKey: 'id', | ||
// 卡片之间的间隙 | ||
gutter: 10, | ||
// 是否有周围的gutter | ||
hasAroundGutter: true, | ||
// 卡片在PC上的宽度 | ||
width: 320, | ||
// 自定义行显示个数,主要用于对移动端的适配 | ||
breakpoints: { | ||
1200: { | ||
// 当屏幕宽度小于等于1200 | ||
rowPerView: 4, | ||
}, | ||
800: { | ||
// 当屏幕宽度小于等于800 | ||
rowPerView: 3, | ||
}, | ||
500: { | ||
// 当屏幕宽度小于等于500 | ||
rowPerView: 2, | ||
}, | ||
}, | ||
// 动画效果 | ||
animationEffect: 'animate__fadeInUp', | ||
// 动画时间 | ||
animationDuration: 1000, | ||
// 动画延迟 | ||
animationDelay: 300, | ||
// 背景色 | ||
backgroundColor: '#2C2E3A', | ||
// imgSelector | ||
imgSelector: 'src.original', | ||
// 加载配置 | ||
loadProps: { | ||
loading, | ||
error, | ||
}, | ||
// 是否懒加载 | ||
lazyload: true, | ||
crossOrigin: true, | ||
}) | ||
const { | ||
list, | ||
page, | ||
pages, | ||
handleLoadMore, | ||
handleChangePage, | ||
} = useList() | ||
onMounted(() => { | ||
handleLoadMore() | ||
}) | ||
const bs = ref(null) | ||
async function pullingUp() { | ||
page.value += 1 | ||
await handleChangePage(page.value) | ||
if (bs.value) | ||
bs.value.finishPullUp() | ||
} | ||
function imageLoad(url: string) { | ||
// console.log(`${url}: 加载完成`) | ||
} | ||
function imageError(url: string) { | ||
console.error(`${url}: 加载失败`) | ||
} | ||
function imageSuccess(url: string) { | ||
// console.log(`${url}: 加载成功`) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.page-b-content { | ||
height: 100vh; | ||
background-color: #2C2E3A; | ||
} | ||
.page-menus { | ||
position: fixed; | ||
left: 20px; | ||
bottom: 20px; | ||
} | ||
.page-menus__item { | ||
width: 30px; | ||
height: 30px; | ||
border-radius: 50%; | ||
border: 2px solid #e7e7e7; | ||
background-color: #fff; | ||
margin-bottom: 14px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
cursor: pointer; | ||
font-size: 14px; | ||
color: #666; | ||
} | ||
.page-menus__item.active { | ||
background-color: #e75932; | ||
color: #fff; | ||
} | ||
/* .box1 { | ||
height: 500px; | ||
background-color: red; | ||
} | ||
.box2 { | ||
height: 500px; | ||
background-color: yellow; | ||
} | ||
.box3 { | ||
height: 500px; | ||
background-color: blue; | ||
} */ | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.