Skip to content

Commit

Permalink
fix: 修复电影卡片可能因部分数据错误而不显示的Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ronggang committed Nov 8, 2023
1 parent 38946d4 commit 6786fa0
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 56 deletions.
110 changes: 79 additions & 31 deletions src/options/components/MovieInfoCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
<v-card color="blue-grey darken-2" class="white--text">
<!-- 标题 -->
<v-card-title class="pb-2">
<div :class="$vuetify.breakpoint.mdAndUp?'headline': 'title'">
<div :class="$vuetify.breakpoint.mdAndUp ? 'headline' : 'title'">
<span>{{ info.title }}</span>
<span
:class="['ml-1','grey--text',$vuetify.breakpoint.mdAndUp?'title':'caption']"
>({{ info.year || info.attrs.year[0] }})</span>
:class="[
'ml-1',
'grey--text',
$vuetify.breakpoint.mdAndUp ? 'title' : 'caption',
]"
>({{ info.year || info.attrs.year[0] }})</span
>
</div>
</v-card-title>
<v-img
Expand All @@ -17,7 +22,7 @@
:max-height="maxHeight"
position="left center"
>
<v-layout style="margin-left: 220px;" v-if="$vuetify.breakpoint.mdAndUp">
<v-layout style="margin-left: 220px" v-if="$vuetify.breakpoint.mdAndUp">
<!-- omit 格式 -->
<v-card-title class="pt-0" v-if="info.updateTime">
<v-flex xs12>
Expand Down Expand Up @@ -51,7 +56,10 @@
<v-flex xs12 class="my-2">
<v-divider light></v-divider>
</v-flex>
<div class="caption" v-html="`  ${info.summary.replace(/\n/g, '<br>')} @豆瓣`"></div>
<div
class="caption"
v-html="`  ${info.summary.replace(/\n/g, '<br>')} @豆瓣`"
></div>
</v-card-title>

<v-card-title class="pt-0" v-else-if="info.attrs">
Expand All @@ -61,7 +69,9 @@
</v-flex>
<v-flex xs12>
<span>{{ $t("movieInfoCard.director") }}</span>
<span class="caption">{{ formatArray(info.attrs.director) }}</span>
<span class="caption">{{
formatArray(info.attrs.director)
}}</span>
</v-flex>
<v-flex xs12>
<span>{{ $t("movieInfoCard.writer") }}</span>
Expand All @@ -73,15 +83,19 @@
</v-flex>
<v-flex xs12>
<span>{{ $t("movieInfoCard.type") }}</span>
<span class="caption">{{ formatArray(info.attrs.movie_type) }}</span>
<span class="caption">{{
formatArray(info.attrs.movie_type)
}}</span>
</v-flex>
<v-flex xs12>
<span>{{ $t("movieInfoCard.pubdate") }}</span>
<span class="caption">{{ formatArray(info.attrs.pubdate) }}</span>
</v-flex>
<v-flex xs12>
<span>{{ $t("movieInfoCard.duration") }}</span>
<span class="caption">{{ formatArray(info.attrs.movie_duration) }}</span>
<span class="caption">{{
formatArray(info.attrs.movie_duration)
}}</span>
</v-flex>
<v-flex xs12 class="my-2">
<v-divider light></v-divider>
Expand Down Expand Up @@ -120,19 +134,27 @@
<div class="caption" v-html="`${info.intro} @豆瓣`"></div>
</v-card-title>
</v-layout>
<v-layout v-else style="margin-left: 75px;">
<v-layout v-else style="margin-left: 75px">
<v-card-text class="pt-0">
<v-flex xs12>
<span class="caption">{{ info.original_title || info.alt_title }}</span>
<span class="caption">{{
info.original_title || info.alt_title
}}</span>
</v-flex>
<v-flex xs12>
<span class="caption">{{ formatArray(info.genres || info.attrs.movie_type) }}</span>
<span class="caption">{{
formatArray(info.genres || info.attrs.movie_type)
}}</span>
</v-flex>
<v-flex xs12>
<span class="caption">{{ formatArray(info.pubdate || info.attrs.pubdate) }}</span>
<span class="caption">{{
formatArray(info.pubdate || info.attrs.pubdate)
}}</span>
</v-flex>
<v-flex xs12>
<span class="caption">{{ formatArray(info.durations || info.attrs.movie_duration) }}</span>
<span class="caption">{{
formatArray(info.durations || info.attrs.movie_duration)
}}</span>
</v-flex>
</v-card-text>
</v-layout>
Expand All @@ -145,49 +167,56 @@
:href="info.link || info.url || info.mobile_link"
target="_blank"
rel="noopener noreferrer nofollow"
>豆瓣 {{ info.average || info.rating.value || info.rating.average }}</v-btn>
>豆瓣
{{ info.average || info.rating.value || info.rating.average }}</v-btn
>

<!-- IMDb评分 -->
<v-btn
color="amber"
:href="`https://www.imdb.com/title/${this.IMDbId}/`"
target="_blank"
rel="noopener noreferrer nofollow"
>IMDb {{ ratings.imdbRating }}</v-btn>
>IMDb {{ ratings.imdbRating }}</v-btn
>

<!-- 烂番茄新鲜度 -->
<v-btn
v-if="tomatoRating>0"
v-if="tomatoRating > 0"
color="red lighten-3"
:href="ratings.tomatoURL"
target="_blank"
rel="noopener noreferrer nofollow"
>
<v-avatar size="20" class="mr-1">
<img :src="rottenTomatoes.fresh" v-if="tomatoRating>=60" />
<img :src="rottenTomatoes.fresh" v-if="tomatoRating >= 60" />
<img :src="rottenTomatoes.rotten" v-else />
</v-avatar>
{{ tomatoRating }}%
</v-btn>

<!-- Metacritic评分 -->
<v-btn
v-if="metascore>0"
:color="metascore>60?'success':metascore>40?'warning':'error'"
v-if="metascore > 0"
:color="
metascore > 60 ? 'success' : metascore > 40 ? 'warning' : 'error'
"
:href="`https://www.metacritic.com/search/movie/${info.title}/results`"
target="_blank"
rel="noopener noreferrer nofollow"
style="min-width: unset;"
style="min-width: unset"
>
<v-avatar size="20" class="mr-2">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f2/Metacritic_M.png" />
<img
src="https://upload.wikimedia.org/wikipedia/commons/f/f2/Metacritic_M.png"
/>
</v-avatar>
{{ metascore }}
</v-btn>

<v-spacer></v-spacer>
<v-layout v-if="$vuetify.breakpoint.mdAndUp">
<v-flex xs6 v-if="rating>0">
<v-flex xs6 v-if="rating > 0">
<v-rating
v-model="rating"
background-color="white"
Expand All @@ -197,11 +226,16 @@
half-increments
size="30"
></v-rating>
<span
class="ma-2"
>{{ $t("movieInfoCard.ratings.douban", {average: info.average || info.rating.value || info.rating.average, numRaters: info.votes || info.rating.count || info.rating.numRaters}) }}</span>
<span class="ma-2">{{
$t("movieInfoCard.ratings.douban", {
average:
info.average || info.rating.value || info.rating.average,
numRaters:
info.votes || info.rating.count || info.rating.numRaters,
})
}}</span>
</v-flex>
<v-flex xs6 v-if="imdbRating>0">
<v-flex xs6 v-if="imdbRating > 0">
<v-rating
v-model="imdbRating"
background-color="white"
Expand All @@ -211,9 +245,12 @@
half-increments
size="30"
></v-rating>
<span
class="ma-2"
>{{ $t("movieInfoCard.ratings.imdb", {average: ratings.imdbRating, numRaters: ratings.imdbVotes.replace(/,/g, "")}) }}</span>
<span class="ma-2">{{
$t("movieInfoCard.ratings.imdb", {
average: ratings.imdbRating,
numRaters: ratings.imdbVotes.replace(/,/g, ""),
})
}}</span>
</v-flex>
</v-layout>
</v-card-actions>
Expand Down Expand Up @@ -292,11 +329,22 @@ export default Vue.extend({
.then(result => {
console.log(result);
this.visible = true;
let r = null;
if (Array.isArray(result)) {
this.info = result[0];
r = result[0];
} else {
this.info = result;
r = result;
}
if (!r.average && !r.rating) {
r.rating = {
average: "",
numRaters: 0,
value: ""
}
}
this.info = r;
})
.catch(error => {
console.log(error);
Expand Down
62 changes: 37 additions & 25 deletions src/options/components/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"
>
<v-container fluid grid-list-lg class="pa-3">
<div v-if="topSearches.length == 0"> {{ $t('common.loading') }} </div>
<v-layout v-else row wrap>
<div v-if="topSearches.length == 0">
{{ $t("common.loading") }}
</div>
<v-layout v-else row wrap>
<v-flex v-for="(item, index) in topSearches" :key="index" xs4>
<v-card
@click="searchHotItem(item)"
Expand All @@ -59,14 +61,17 @@

<!-- 评分,点击可前往豆瓣页面 -->
<a
v-if="item.doubanRating"
class="caption orange--text rating"
:href="item.link"
rel="noopener noreferrer nofollow"
target="_blank"
:title="$t('searchBox.toDouban')"
@click.stop
>{{ parseFloat(item.doubanRating).toFixed(1) }}</a
>{{
item.doubanRating
? parseFloat(item.doubanRating).toFixed(1)
: "--"
}}</a
>
</div>
<div
Expand Down Expand Up @@ -109,31 +114,31 @@
<v-card class="scroll-card">
<v-list dense>
<v-list-tile
@click="changeSearchSolution(null)"
:title="$t('searchBox.defaultTip')"
@click="changeSearchSolution(null)"
:title="$t('searchBox.defaultTip')"
>
<v-list-tile-title>{{
$t("searchBox.default")
}}</v-list-tile-title>
$t("searchBox.default")
}}</v-list-tile-title>
</v-list-tile>
<v-divider></v-divider>
<template
v-if="
$store.state.options.searchSolutions &&
$store.state.options.searchSolutions.length > 0
"
v-if="
$store.state.options.searchSolutions &&
$store.state.options.searchSolutions.length > 0
"
>
<v-list-tile
@click="changeSearchSolution(item)"
v-for="(item, index) in $store.state.options.searchSolutions"
:key="index"
@click="changeSearchSolution(item)"
v-for="(item, index) in $store.state.options.searchSolutions"
:key="index"
>
<v-list-tile-title>{{ item.name }}</v-list-tile-title>
</v-list-tile>
</template>
<v-btn flat small v-else to="/set-search-solution">{{
$t("searchBox.noSearchSolution")
}}</v-btn>
$t("searchBox.noSearchSolution")
}}</v-btn>

<v-divider></v-divider>
<v-list-tile @click="changeSearchSolution(allSite)">
Expand Down Expand Up @@ -181,7 +186,8 @@
<v-list-tile-avatar class="album" :size="75">
<img
:src="
item.image || item.img ||
item.image ||
item.img ||
(item.images
? item.images.small
: item.pic
Expand Down Expand Up @@ -220,17 +226,23 @@
<img src="https://img3.doubanio.com/favicon.ico" width="16" />
{{
parseFloat(
item.average ?item.average : item.rating? (item.rating.average || item.rating.value) : null
item.average
? item.average
: item.rating
? item.rating.average || item.rating.value
: null
).toFixed(1)
}}
</a>
<v-rating
:value="
item.average
? parseFloat(item.average) / 2
: item.rating? (item.rating.stars
? parseInt(item.rating.stars) / 10
: item.rating.star_count): 0
: item.rating
? item.rating.stars
? parseInt(item.rating.stars) / 10
: item.rating.star_count
: 0
"
background-color="grey lighten-2"
color="yellow accent-4"
Expand Down Expand Up @@ -268,7 +280,7 @@ import {
} from "@/interface/common";
import Extension from "@/service/extension";
import {eventBus} from "@/options/plugins/EventBus";
import { eventBus } from "@/options/plugins/EventBus";
import dayjs from "dayjs";
const extension = new Extension();
Expand Down Expand Up @@ -405,13 +417,13 @@ export default Vue.extend({
if (!key) {
return;
}
const targetRoute = {name: "search-torrent", params: {key,},}
const targetRoute = { name: "search-torrent", params: { key, }, }
// fix: NavigationDuplicated: Avoided redundant navigation to current location
if (this.$route.params.key === key && this.$route.name === targetRoute.name) {
console.log(`skip router.push same searchTorrent: key: ${key}`, this.$route)
// 这种情况下只能是用户手动触发的, 不能再次触发路由跳转, 使用 eventBus 触发搜索
console.log(`using eventBus.$emit searchTorrent: key: ${key}`)
eventBus.$emit("searchTorrent", {key})
eventBus.$emit("searchTorrent", { key })
return;
}
Expand Down

0 comments on commit 6786fa0

Please sign in to comment.