Skip to content

Commit

Permalink
chore: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
lhlyu committed Jul 29, 2024
1 parent fe0f743 commit bfa2720
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@lhlyu/vue-virtual-waterfall",
"description": "vue3 virtual waterfall component",
"version": "1.0.6-beta.1",
"version": "1.0.6-beta.2",
"author": "lhlyu",
"repository": {
"type": "git",
Expand Down
1 change: 0 additions & 1 deletion src/example/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class="card"
:data-id="item.id"
>

<div
class="body"
v-if="!onlyImage"
Expand Down
38 changes: 2 additions & 36 deletions src/example/useWaterfall.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import { reactive, render, h, onMounted } from 'vue'
import Card from './Card.vue'

// 下面第一个代理地址官方不让用,第二个消耗自己的流量扛不住
// 实在不行自己搭个:https://mirai.mamoe.net/topic/1322/rs-pixiv-%E6%98%93%E4%BA%8E%E6%90%AD%E5%BB%BA%E7%9A%84pixiv%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1
// const proxy_base_url = "https://proxy.pixivel.moe/" // 不让用
// const proxy_base_url = 'https://pixiv.tatakai.top/'
// const proxy_base_url = "https://px.s.rainchan.win/"
const proxy_base_url = "https://i.pixiv.re/"

const handlerUrl = (url: string): string => {
url = url.replace('_p0.', '_p0_master1200.')
url = url.replace('.png', '.jpg')
return proxy_base_url + 'c/540x540_70/img-master/' + url
}

const handlerAvatar = (url: string): string => {
url = url.replace('.', '_50.')
return proxy_base_url + url
}

// 计算真实高度,这里只计算除了图片的高度
function getRealHeight(item: ItemOption, realWidth: number) {
const dom = document.createElement('div')
Expand Down Expand Up @@ -94,31 +76,15 @@ const useWaterfall = () => {
return
}
data.page += 1
const response = await fetch(`https://mock.tatakai.top/images/${data.page}/${data.size}`)
const response = await fetch(`https://mock.tatakai.top/images?page=${data.page}&size=${data.size}&mode=simple`)
const result = await response.json()
if (!result.list.length) {
data.end = true
return
}
data.total = result.total
data.max = result.max

const list: ItemOption[] = []

for (let i = 0; i < result.list.length; i++) {
list.push({
id: result.list[i].id,
title: result.list[i].title,
url: handlerUrl(result.list[i].url),
width: result.list[i].width,
height: result.list[i].height,
avatar: handlerAvatar(result.list[i].author.avatar),
user: result.list[i].author.name,
views: result.list[i].statistic.views
})
}

data.list = [...data.list, ...list]
data.list = [...data.list, ...result.list]
}

// 检查是否加载更多
Expand Down

0 comments on commit bfa2720

Please sign in to comment.