Skip to content

Commit

Permalink
🎨 调整卡片封面加载逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Oct 11, 2024
1 parent 631fbfc commit d735d0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/components/main/t-annocard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:indeterminate="true"
v-else-if="props.modelValue.banner !== ''"
/>
<img src="/source/UI/defaultCover.webp" alt="cover" v-else />
<img src="/source/UI/defaultCover.webp" alt="cover" @click="createAnno" v-else />
<div class="anno-info">
<div class="anno-time">
<v-icon>mdi-clock-time-four-outline</v-icon>
Expand Down Expand Up @@ -112,8 +112,7 @@ async function shareAnno(): Promise<void> {
}
.anno-cover img {
min-width: 100%;
height: 100%;
width: 100%;
object-fit: cover;
object-position: center;
transition: all 0.3s linear;
Expand Down
30 changes: 16 additions & 14 deletions src/components/main/t-postcard.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<div v-if="card" :id="`post-card-${card.postId}`" class="tpc-card">
<div class="tpc-cover">
<img :src="card.cover" alt="cover" @click="createPost(card)" />
<img :src="localCover" alt="cover" @click="createPost(card)" v-if="localCover" />
<v-progress-circular color="primary" :indeterminate="true" v-else-if="card.cover !== ''" />
<img src="/source/UI/defaultCover.webp" alt="cover" @click="createPost(card)" v-else />
<div v-if="isAct" class="tpc-act">
<div class="tpc-status" :style="{ background: card.status?.colorCss }">
{{ card.status?.status }}
Expand Down Expand Up @@ -57,9 +59,9 @@
</div>
</template>
<script lang="ts" setup>
import { computed, onBeforeMount, ref } from "vue";
import { computed, onBeforeMount, onUnmounted, ref } from "vue";
import { generateShareImg } from "../../utils/TGShare.js";
import { generateShareImg, saveImgLocal } from "../../utils/TGShare.js";
import { createPost } from "../../utils/TGWindow.js";
import TpAvatar from "../post/tp-avatar.vue";
Expand All @@ -79,6 +81,7 @@ const props = withDefaults(defineProps<TPostCardProps>(), {
const emits = defineEmits<TPostCardEmits>();
const isAct = ref<boolean>(false);
const card = ref<TGApp.Plugins.Mys.News.RenderCard>();
const localCover = ref<string>();
const selectedList = computed({
get: () => props.selected,
set: (v) => {
Expand All @@ -87,8 +90,15 @@ const selectedList = computed({
},
});
onBeforeMount(() => {
onBeforeMount(async () => {
card.value = getPostCard(props.modelValue);
if (card.value && card.value.cover !== "") {
localCover.value = await saveImgLocal(card.value.cover);
}
});
onUnmounted(() => {
if (localCover.value) URL.revokeObjectURL(localCover.value);
});
/**
Expand Down Expand Up @@ -138,15 +148,7 @@ function getActivityStatus(status: number): TGApp.Plugins.Mys.News.RenderStatus
}
}
/**
* @description 获取封面图
* @since Beta v0.4.5
* @param {TGApp.Plugins.Mys.Post.FullData} item 咨讯列表项
* @returns {string} 封面图链接
*/
function getPostCover(item: TGApp.Plugins.Mys.Post.FullData): string {
// 默认封面图
const defaultCover = "/source/UI/defaultCover.webp";
let cover;
if (item.cover) {
cover = item.cover.url;
Expand All @@ -155,14 +157,14 @@ function getPostCover(item: TGApp.Plugins.Mys.Post.FullData): string {
} else if (item.post.images.length > 0) {
cover = item.post.images[0];
}
if (cover === undefined) return defaultCover;
if (cover === undefined) return "";
if (cover.endsWith(".gif")) return cover;
return `${cover}?x-oss-process=image/format,png`;
}
/**
* @description 获取公共属性
* @since Beta v0.4.5
* @since Beta v0.6.1
* @param {TGApp.Plugins.Mys.Post.FullData} item 咨讯列表项
* @returns {TGApp.Plugins.Mys.News.RenderCard} 渲染用咨讯列表项
*/
Expand Down

0 comments on commit d735d0d

Please sign in to comment.