mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
优化变量名,修改组件name,优化api调用
This commit is contained in:
parent
435e1a88ad
commit
46710c8f42
@ -14,8 +14,9 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { CheckBox, SwitchBox } from '@/ui'
|
||||
import { bilibiliApi, getJsonWithCredentials } from '@/core/ajax'
|
||||
import { bilibiliApi, getJsonWithCredentials, getPages } from '@/core/ajax'
|
||||
import { FeedsCard, forEachFeedsCard } from '@/components/feeds/api'
|
||||
import { getUID } from '@/core/utils'
|
||||
|
||||
interface Group {
|
||||
name: string
|
||||
@ -80,35 +81,16 @@ export default Vue.extend({
|
||||
})),
|
||||
)
|
||||
|
||||
// fetch uid
|
||||
const uid = await getJsonWithCredentials('https://api.live.bilibili.com/User/getUserInfo').then(
|
||||
res => res.data.uid,
|
||||
)
|
||||
const uid = getUID()
|
||||
// fetch following
|
||||
const firstReq = await bilibiliApi(
|
||||
getJsonWithCredentials(
|
||||
`https://api.bilibili.com/x/relation/followings?vmid=${uid}&pn=1&ps=50`,
|
||||
),
|
||||
)
|
||||
const totalPages = Math.ceil(firstReq.total / 50)
|
||||
let allPages: Array<any> = []
|
||||
if (totalPages === 1) {
|
||||
allPages = [firstReq.list]
|
||||
}
|
||||
|
||||
const pagePromises = []
|
||||
for (let page = 2; page <= totalPages; page++) {
|
||||
pagePromises.push(
|
||||
bilibiliApi(
|
||||
getJsonWithCredentials(
|
||||
`https://api.bilibili.com/x/relation/followings?vmid=${uid}&pn=${page}&ps=50`,
|
||||
),
|
||||
).then(res => res.list),
|
||||
)
|
||||
}
|
||||
|
||||
const otherPagesData = await Promise.all(pagePromises)
|
||||
allPages = [firstReq.list, ...otherPagesData].flat()
|
||||
const allPages = await getPages({
|
||||
api: page =>
|
||||
getJsonWithCredentials(
|
||||
`https://api.bilibili.com/x/relation/followings?vmid=${uid}&pn=${page}&ps=50`,
|
||||
),
|
||||
getList: json => json.data.list,
|
||||
getTotal: json => json.data.total,
|
||||
})
|
||||
allPages.forEach(user => {
|
||||
this.followingMap.set(user.uname, user.tag)
|
||||
})
|
||||
@ -117,10 +99,13 @@ export default Vue.extend({
|
||||
updateCard(card: FeedsCard) {
|
||||
// 从username获得tag
|
||||
const userTagIds: number[] = this.followingMap.get(card.username)
|
||||
if (!userTagIds || !this.selectedGroupIds) {
|
||||
return
|
||||
}
|
||||
if (!userTagIds.some(item => this.selectedGroupIds.includes(item))) {
|
||||
card.element.classList.add('hide-feed')
|
||||
card.element.classList.add('group-filter-hide-feed')
|
||||
} else {
|
||||
card.element.classList.remove('hide-feed')
|
||||
card.element.classList.remove('group-filter-hide-feed')
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -128,7 +113,7 @@ export default Vue.extend({
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.hide-feed {
|
||||
.group-filter-hide-feed {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
|
||||
@ -16,13 +16,13 @@ const entry = async () => {
|
||||
if (leftPanel === null) {
|
||||
return
|
||||
}
|
||||
const FeedsFilterCard = await import('./FilterPanel.vue')
|
||||
const FilterPanel = await import('./FilterPanel.vue')
|
||||
const { mountVueComponent } = await import('@/core/utils')
|
||||
leftPanel.insertAdjacentElement('afterbegin', mountVueComponent(FeedsFilterCard).$el)
|
||||
leftPanel.insertAdjacentElement('afterbegin', mountVueComponent(FilterPanel).$el)
|
||||
}
|
||||
|
||||
export const component = defineComponentMetadata({
|
||||
name: 'groupFilter',
|
||||
name: 'feedsGroupFilter',
|
||||
entry,
|
||||
displayName: '动态分组过滤',
|
||||
author: { name: 'Rinne', link: 'https://github.com/OharaRinneY' },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user