mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Upgrade feeds cards on custom navbar (fix #4305)
This commit is contained in:
parent
8e20ac5588
commit
a49bfa2c09
@ -23,14 +23,15 @@ export default Vue.extend({
|
||||
},
|
||||
mixins: [
|
||||
nextPageMixin(feedsCardTypes.bangumi, (card: any) => {
|
||||
const cardJson = JSON.parse(card.card)
|
||||
const pgc = lodash.get(card, 'modules.module_dynamic.major.pgc')
|
||||
const author = lodash.get(card, 'modules.module_author')
|
||||
return {
|
||||
id: card.desc.dynamic_id_str,
|
||||
title: cardJson.apiSeasonInfo.title,
|
||||
coverUrl: cardJson.apiSeasonInfo.cover,
|
||||
epCoverUrl: cardJson.cover,
|
||||
epTitle: cardJson.new_desc,
|
||||
url: cardJson.url,
|
||||
id: card.id_str,
|
||||
title: author.name,
|
||||
coverUrl: author.face,
|
||||
epCoverUrl: pgc.cover,
|
||||
epTitle: pgc.title.replace(new RegExp(`^${author.name}:`), ''),
|
||||
url: pgc.jump_url,
|
||||
get new() {
|
||||
return isNewID(this.id)
|
||||
},
|
||||
|
||||
@ -23,17 +23,18 @@ export default Vue.extend({
|
||||
},
|
||||
mixins: [
|
||||
nextPageMixin(feedsCardTypes.column, (card: any) => {
|
||||
const cardJson = JSON.parse(card.card)
|
||||
const article = lodash.get(card, 'modules.module_dynamic.major.article')
|
||||
const author = lodash.get(card, 'modules.module_author')
|
||||
return {
|
||||
id: card.desc.dynamic_id_str,
|
||||
cvID: cardJson.id,
|
||||
title: cardJson.title,
|
||||
upName: cardJson.author.name,
|
||||
upFaceUrl: cardJson.author.face,
|
||||
upID: cardJson.author.mid,
|
||||
description: cardJson.summary,
|
||||
covers: cardJson.image_urls,
|
||||
originalCovers: cardJson.origin_image_urls,
|
||||
id: card.id_str,
|
||||
cvID: article.id.toString(),
|
||||
title: article.title,
|
||||
upName: author.name,
|
||||
upFaceUrl: author.face,
|
||||
upID: author.mid,
|
||||
description: article.desc,
|
||||
covers: article.covers,
|
||||
originalCovers: article.covers,
|
||||
get new() {
|
||||
return isNewID(this.id)
|
||||
},
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { VideoCard } from '@/components/feeds/video-card'
|
||||
import { formatDuration, formatCount } from '@/core/utils/formatters'
|
||||
import { formatDuration, formatCount, parseDuration } from '@/core/utils/formatters'
|
||||
import { isNewID } from '@/components/feeds/notify'
|
||||
import { feedsCardTypes, groupVideoFeeds } from '@/components/feeds/api'
|
||||
import VideoCardComponent from '@/components/feeds/VideoCard.vue'
|
||||
@ -80,24 +80,25 @@ export default Vue.extend({
|
||||
},
|
||||
mixins: [
|
||||
nextPageMixin(feedsCardTypes.video, (card: any) => {
|
||||
const cardJson = JSON.parse(card.card)
|
||||
const archive = lodash.get(card, 'modules.module_dynamic.major.archive')
|
||||
const author = lodash.get(card, 'modules.module_author')
|
||||
return {
|
||||
id: card.desc.dynamic_id_str,
|
||||
aid: cardJson.aid,
|
||||
bvid: card.desc.bvid,
|
||||
videoUrl: `https://www.bilibili.com/${card.desc.bvid}`,
|
||||
coverUrl: cardJson.pic,
|
||||
title: cardJson.title,
|
||||
duration: cardJson.duration,
|
||||
durationText: formatDuration(cardJson.duration),
|
||||
description: cardJson.desc,
|
||||
pubTime: formatPubTime(cardJson.pubdate * 1000),
|
||||
pubTimeText: formatPubTimeText(cardJson.pubdate * 1000),
|
||||
upFaceUrl: card.desc.user_profile.info.face,
|
||||
upName: card.desc.user_profile.info.uname,
|
||||
upID: card.desc.user_profile.info.uid,
|
||||
id: card.id_str,
|
||||
aid: archive.aid,
|
||||
bvid: archive.bvid,
|
||||
videoUrl: `https://www.bilibili.com/${archive.bvid}`,
|
||||
coverUrl: archive.cover,
|
||||
title: archive.title,
|
||||
duration: parseDuration(archive.duration_text),
|
||||
durationText: formatDuration(parseDuration(archive.duration_text)),
|
||||
description: archive.desc,
|
||||
pubTime: formatPubTime(author.pub_ts * 1000),
|
||||
pubTimeText: formatPubTimeText(author.pub_ts * 1000),
|
||||
upFaceUrl: author.face,
|
||||
upName: author.name,
|
||||
upID: author.mid,
|
||||
watchlater: true,
|
||||
playCount: formatCount(cardJson.stat.view),
|
||||
playCount: formatCount(archive.stat.play),
|
||||
get new() {
|
||||
return isNewID(this.id)
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
applyContentFilter,
|
||||
isPreOrderedVideo,
|
||||
} from '@/components/feeds/api'
|
||||
import { descendingStringSort } from '@/core/utils/sort'
|
||||
import { descendingBigIntSort } from '@/core/utils/sort'
|
||||
import { logError } from '@/core/utils/log'
|
||||
import { setLatestID } from '@/components/feeds/notify'
|
||||
import { VLoading, VEmpty, ScrollTrigger } from '@/ui'
|
||||
@ -33,7 +33,7 @@ export const nextPageMixin = <MappedItem extends { id: string }, RawItem>(
|
||||
},
|
||||
computed: {
|
||||
sortedCards() {
|
||||
return ([...this.cards] as MappedItem[]).sort(descendingStringSort(it => it.id))
|
||||
return ([...this.cards] as MappedItem[]).sort(descendingBigIntSort(it => it.id))
|
||||
},
|
||||
},
|
||||
async created() {
|
||||
@ -56,12 +56,12 @@ export const nextPageMixin = <MappedItem extends { id: string }, RawItem>(
|
||||
this.hasMorePage = false
|
||||
throw new Error(json.message)
|
||||
}
|
||||
const jsonCards = lodash.get(json, 'data.cards', []).map(jsonMapper) as MappedItem[]
|
||||
const jsonCards = lodash.get(json, 'data.items', []).map(jsonMapper) as MappedItem[]
|
||||
|
||||
let concatCards = applyContentFilter(
|
||||
cards
|
||||
.concat(jsonCards)
|
||||
.sort(descendingStringSort(it => it.id))
|
||||
.sort(descendingBigIntSort(it => it.id))
|
||||
.filter(card => !isPreOrderedVideo(card)),
|
||||
)
|
||||
|
||||
|
||||
@ -19,9 +19,27 @@ export const formatFileSize = (bytes: number, fixed = 1) => {
|
||||
*/
|
||||
export const formatPercent = (percent: number, fixed = 1) =>
|
||||
`${Math.round(percent * 100 * 10 ** fixed) / 10 ** fixed}%`
|
||||
/** 格式化时长为`H:mm:ss.F`, 不足1小时则为`mm:ss.F`
|
||||
* @param time 时长
|
||||
* @param fixed 保留的小数位(毫秒), 默认不保留
|
||||
|
||||
/**
|
||||
* 将时长文本转换为秒数
|
||||
* @param durationText 时长文本
|
||||
*/
|
||||
export const parseDuration = (durationText: string) => {
|
||||
const parts = durationText.split(':')
|
||||
let result = 0
|
||||
parts.forEach((part, index) => {
|
||||
const isLastPart = index === parts.length - 1
|
||||
const partNumber = isLastPart ? parseFloat(part) : parseInt(part)
|
||||
if (Number.isNaN(partNumber)) {
|
||||
return
|
||||
}
|
||||
result += partNumber * 60 ** (parts.length - 1 - index)
|
||||
})
|
||||
return result
|
||||
}
|
||||
/** 格式化时长为 `H:mm:ss.F`, 不足1小时则为 `mm:ss.F`
|
||||
* @param time 时长 (秒)
|
||||
* @param fixed 保留的小数位 (毫秒), 默认不保留
|
||||
*/
|
||||
export const formatDuration = (time: number, fixed = 0) => {
|
||||
const second = (time % 60).toFixed(fixed)
|
||||
|
||||
@ -9,6 +9,17 @@ export const ascendingStringSort =
|
||||
<T>(itemProp: (obj: T) => string = selfSorter) =>
|
||||
(a: T, b: T) =>
|
||||
itemProp(a).localeCompare(itemProp(b))
|
||||
/** 字符串大数字升序排序 */
|
||||
export const ascendingBigIntSort =
|
||||
<T>(itemProp: (obj: T) => string = selfSorter) =>
|
||||
(a: T, b: T) => {
|
||||
const numberA = BigInt(itemProp(a))
|
||||
const numberB = BigInt(itemProp(b))
|
||||
if (numberA === numberB) {
|
||||
return 0
|
||||
}
|
||||
return numberA > numberB ? 1 : -1
|
||||
}
|
||||
/** 降序排序 */
|
||||
export const descendingSort =
|
||||
<T>(itemProp: (obj: T) => number = selfSorter) =>
|
||||
@ -19,3 +30,8 @@ export const descendingStringSort =
|
||||
<T>(itemProp: (obj: T) => string = selfSorter) =>
|
||||
(a: T, b: T) =>
|
||||
itemProp(b).localeCompare(itemProp(a))
|
||||
/** 字符串大数字降序排序 */
|
||||
export const descendingBigIntSort =
|
||||
<T>(itemProp: (obj: T) => string = selfSorter) =>
|
||||
(a: T, b: T) =>
|
||||
-ascendingBigIntSort(itemProp)(a, b)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user