mirror of
https://github.com/BewlyBewly/BewlyBewly.git
synced 2025-04-14 13:15:29 +00:00
* feat(video-card-avatar): add avatar component for multiple avatar display * refactor(video-card): add avatar component * refactor(views): modify video card calling method * feat(following): up joint submissions are combined into one video card display * feat(i18n): add cn translation * fix: dislike dialog ci type check * fix(video-card-avatar): add more display additions for undisplayed avatars * refactor(video-card): refactor author and authorList to handle single and multiple authors separately * fix(following): fix issue with duplicate authors in collaborative submissions * refactor(video-card): remove `authorList` prop * feat(video-card): redesign the multiple authors style * chore: update * chore: update --------- Co-authored-by: Hakadao <a578457889743@gmail.com>
211 lines
5.4 KiB
Vue
211 lines
5.4 KiB
Vue
<script setup lang="ts">
|
|
import type { Ref } from 'vue'
|
|
|
|
import { useBewlyApp } from '~/composables/useAppProvider'
|
|
import type { GridLayoutType } from '~/logic'
|
|
import type { FollowingLiveResult, List as FollowingLiveItem } from '~/models/live/getFollowingLiveList'
|
|
import api from '~/utils/api'
|
|
|
|
// https://github.com/starknt/BewlyBewly/blob/fad999c2e482095dc3840bb291af53d15ff44130/src/contentScripts/views/Home/components/ForYou.vue#L16
|
|
interface VideoElement {
|
|
uniqueId: string
|
|
item?: FollowingLiveItem
|
|
}
|
|
|
|
const props = defineProps<{
|
|
gridLayout: GridLayoutType
|
|
}>()
|
|
|
|
const emit = defineEmits<{
|
|
(e: 'beforeLoading'): void
|
|
(e: 'afterLoading'): void
|
|
}>()
|
|
|
|
const gridValue = computed((): string => {
|
|
if (props.gridLayout === 'adaptive')
|
|
return '~ 2xl:cols-5 xl:cols-4 lg:cols-3 md:cols-2 gap-5'
|
|
if (props.gridLayout === 'twoColumns')
|
|
return '~ cols-1 xl:cols-2 gap-4'
|
|
return '~ cols-1 gap-4'
|
|
})
|
|
|
|
const videoList = ref<VideoElement[]>([])
|
|
const isLoading = ref<boolean>(false)
|
|
const needToLoginFirst = ref<boolean>(false)
|
|
const containerRef = ref<HTMLElement>() as Ref<HTMLElement>
|
|
const page = ref<number>(1)
|
|
const noMoreContent = ref<boolean>(false)
|
|
const { handleReachBottom, handlePageRefresh, haveScrollbar } = useBewlyApp()
|
|
|
|
onMounted(async () => {
|
|
initData()
|
|
initPageAction()
|
|
})
|
|
|
|
onActivated(() => {
|
|
initPageAction()
|
|
})
|
|
|
|
function initPageAction() {
|
|
handleReachBottom.value = async () => {
|
|
if (isLoading.value)
|
|
return
|
|
if (noMoreContent.value)
|
|
return
|
|
|
|
getData()
|
|
}
|
|
handlePageRefresh.value = async () => {
|
|
if (isLoading.value)
|
|
return
|
|
|
|
initData()
|
|
}
|
|
}
|
|
|
|
async function initData() {
|
|
page.value = 1
|
|
videoList.value.length = 0
|
|
noMoreContent.value = false
|
|
|
|
await getData()
|
|
}
|
|
|
|
async function getData() {
|
|
emit('beforeLoading')
|
|
isLoading.value = true
|
|
|
|
try {
|
|
for (let i = 0; i < 3; i++)
|
|
await getFollowedUsersVideos()
|
|
}
|
|
finally {
|
|
isLoading.value = false
|
|
emit('afterLoading')
|
|
}
|
|
}
|
|
|
|
async function getFollowedUsersVideos() {
|
|
if (noMoreContent.value)
|
|
return
|
|
|
|
// if (list.value === '0') {
|
|
// noMoreContent.value = true
|
|
// return
|
|
// }
|
|
|
|
try {
|
|
let i = 0
|
|
// https://github.com/starknt/BewlyBewly/blob/fad999c2e482095dc3840bb291af53d15ff44130/src/contentScripts/views/Home/components/ForYou.vue#L208
|
|
const pendingVideos: VideoElement[] = Array.from({ length: 30 }, () => ({
|
|
uniqueId: `unique-id-${(videoList.value.length || 0) + i++})}`,
|
|
} satisfies VideoElement))
|
|
let lastVideoListLength = videoList.value.length
|
|
videoList.value.push(...pendingVideos)
|
|
|
|
const response: FollowingLiveResult = await api.live.getFollowingLiveList({
|
|
page: page.value,
|
|
page_size: 9,
|
|
})
|
|
|
|
if (response.code === -101) {
|
|
noMoreContent.value = true
|
|
needToLoginFirst.value = true
|
|
return
|
|
}
|
|
|
|
if (response.code === 0) {
|
|
if (response.data.list.length < 9)
|
|
noMoreContent.value = true
|
|
|
|
page.value++
|
|
|
|
const resData = [] as FollowingLiveItem[]
|
|
|
|
response.data.list.forEach((item: FollowingLiveItem) => {
|
|
resData.push(item)
|
|
})
|
|
|
|
// when videoList has length property, it means it is the first time to load
|
|
if (!videoList.value.length) {
|
|
videoList.value = resData.map(item => ({ uniqueId: `${item.roomid}`, item }))
|
|
}
|
|
else {
|
|
resData.forEach((item) => {
|
|
videoList.value[lastVideoListLength++] = {
|
|
uniqueId: `${item.roomid}`,
|
|
item,
|
|
}
|
|
})
|
|
}
|
|
|
|
if (!haveScrollbar() && !noMoreContent.value) {
|
|
getFollowedUsersVideos()
|
|
}
|
|
}
|
|
else if (response.code === -101) {
|
|
needToLoginFirst.value = true
|
|
}
|
|
}
|
|
finally {
|
|
videoList.value = videoList.value.filter(video => video.item)
|
|
}
|
|
}
|
|
|
|
function jumpToLoginPage() {
|
|
location.href = 'https://passport.bilibili.com/login'
|
|
}
|
|
|
|
defineExpose({ initData })
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<!-- By directly using predefined unocss grid properties, it is possible to dynamically set the grid attribute -->
|
|
<div hidden grid="~ 2xl:cols-5 xl:cols-4 lg:cols-3 md:cols-2 gap-5" />
|
|
<div hidden grid="~ cols-1 xl:cols-2 gap-4" />
|
|
<div hidden grid="~ cols-1 gap-4" />
|
|
|
|
<Empty v-if="needToLoginFirst" mt-6 :description="$t('common.please_log_in_first')">
|
|
<Button type="primary" @click="jumpToLoginPage()">
|
|
{{ $t('common.login') }}
|
|
</Button>
|
|
</Empty>
|
|
<div
|
|
v-else
|
|
ref="containerRef"
|
|
m="b-0 t-0" relative w-full h-full
|
|
:grid="gridValue"
|
|
>
|
|
<VideoCard
|
|
v-for="video in videoList"
|
|
:key="video.uniqueId"
|
|
:skeleton="!video.item"
|
|
:video="video.item ? {
|
|
// id: Number(video.item.modules.module_dynamic.major.archive?.aid),
|
|
title: `${video.item.title}`,
|
|
cover: `${video.item.room_cover}`,
|
|
author: {
|
|
name: video.item.uname,
|
|
authorFace: video.item.face,
|
|
mid: video.item.uid,
|
|
},
|
|
viewStr: video.item.text_small,
|
|
tag: video.item.area_name_v2,
|
|
roomid: video.item.roomid,
|
|
liveStatus: video.item.live_status,
|
|
} : undefined"
|
|
type="live"
|
|
:show-watcher-later="false"
|
|
:horizontal="gridLayout !== 'adaptive'"
|
|
/>
|
|
</div>
|
|
|
|
<!-- no more content -->
|
|
<Empty v-if="noMoreContent && !needToLoginFirst" class="pb-4" :description="$t('common.no_more_content')" />
|
|
</div>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
</style>
|