Upgrade feeds cards on custom navbar (fix #4305)

This commit is contained in:
the1812 2023-08-30 21:20:14 +08:00
parent 8e20ac5588
commit a49bfa2c09
6 changed files with 78 additions and 41 deletions

View File

@ -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)
},

View File

@ -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)
},

View File

@ -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)
},

View File

@ -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)),
)

View File

@ -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)

View File

@ -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)