💄 调整收藏页UI,优化刷新逻辑

This commit is contained in:
目棃
2024-11-19 10:04:20 +08:00
parent c6f45f0a35
commit 7932de8654
2 changed files with 118 additions and 134 deletions

View File

@@ -60,8 +60,7 @@
<v-checkbox-btn <v-checkbox-btn
v-if="props.selectMode" v-if="props.selectMode"
class="tpc-select" class="tpc-select"
v-model="selectedList" @click="emits('onSelected', props.modelValue.post.post_id)"
:value="props.modelValue.post.post_id"
data-html2canvas-ignore data-html2canvas-ignore
/> />
<div class="tpc-info-id" v-else>{{ props.modelValue.post.post_id }}</div> <div class="tpc-info-id" v-else>{{ props.modelValue.post.post_id }}</div>
@@ -78,11 +77,10 @@ import TpAvatar from "../post/tp-avatar.vue";
interface TPostCardProps { interface TPostCardProps {
modelValue: TGApp.Plugins.Mys.Post.FullData; modelValue: TGApp.Plugins.Mys.Post.FullData;
selectMode?: boolean; selectMode?: boolean;
selected?: string[];
} }
interface TPostCardEmits { interface TPostCardEmits {
(e: "onSelected", value: string[]): void; (e: "onSelected", value: string): void;
} }
const props = withDefaults(defineProps<TPostCardProps>(), { const props = withDefaults(defineProps<TPostCardProps>(), {
@@ -92,13 +90,7 @@ const emits = defineEmits<TPostCardEmits>();
const isAct = ref<boolean>(false); const isAct = ref<boolean>(false);
const card = ref<TGApp.Plugins.Mys.News.RenderCard>(); const card = ref<TGApp.Plugins.Mys.News.RenderCard>();
const localCover = ref<string>(); const localCover = ref<string>();
const selectedList = computed({
get: () => props.selected,
set: (v) => {
if (v === undefined) return;
emits("onSelected", v);
},
});
const cardBg = computed<string>(() => { const cardBg = computed<string>(() => {
if (card.value && card.value.status) return card.value.status.colorCss; if (card.value && card.value.status) return card.value.status.colorCss;
return "none"; return "none";
@@ -384,9 +376,10 @@ async function toForum(forum: TGApp.Plugins.Mys.News.RenderForum): Promise<void>
justify-content: center; justify-content: center;
-webkit-backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
backdrop-filter: blur(20px); backdrop-filter: blur(20px);
background: var(--tgc-yellow-2); background: var(--box-bg-2);
border-bottom-right-radius: 4px; border-bottom-right-radius: 4px;
box-shadow: 0 0 10px var(--tgc-dark-1); box-shadow: 0 0 10px var(--tgc-dark-1);
color: var(--box-text-5);
} }
.tpc-forum img { .tpc-forum img {

View File

@@ -1,6 +1,10 @@
<template> <template>
<div class="pc-container"> <v-app-bar>
<div class="pc-top"> <div class="pc-top">
<div class="pc-title">
<img src="/source/UI/posts.png" alt="posts" />
<span>收藏</span>
</div>
<v-select <v-select
v-model="curSelect" v-model="curSelect"
class="pc-select" class="pc-select"
@@ -13,6 +17,12 @@
<v-list-item v-bind="props" :title="item.raw.title" :subtitle="item.raw.desc" /> <v-list-item v-bind="props" :title="item.raw.title" :subtitle="item.raw.desc" />
</template> </template>
</v-select> </v-select>
</div>
<template #append>
<v-pagination class="pc-page" v-model="page" :total-visible="view" :length="length" />
</template>
<template #extension>
<div class="pc-btns">
<v-btn <v-btn
size="small" size="small"
class="pc-btn" class="pc-btn"
@@ -73,20 +83,15 @@
@click="deleteOper(true)" @click="deleteOper(true)"
:title="selectedMode ? '删除帖子' : '删除合集'" :title="selectedMode ? '删除帖子' : '删除合集'"
/> />
<v-pagination class="pc-page" v-model="page" :total-visible="view" :length="length" />
</div> </div>
</template>
</v-app-bar>
<div class="pc-posts"> <div class="pc-posts">
<div v-for="item in getPageItems()" :key="item.post.post_id"> <div v-for="item in curPosts" :key="item.post.post_id">
<TPostCard <TPostCard @onSelected="handleSelected" :model-value="item" :select-mode="selectedMode" />
@onSelected="handleSelected" </div>
:model-value="item"
:selected="selectedPost"
:select-mode="selectedMode"
/>
</div> </div>
<ToCollectPost @submit="load" :post="selectedPost" v-model="showOverlay" /> <ToCollectPost @submit="load" :post="selectedPost" v-model="showOverlay" />
</div>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { event } from "@tauri-apps/api"; import { event } from "@tauri-apps/api";
@@ -115,6 +120,11 @@ const view = computed(() => {
if (length.value === 1) return 0; if (length.value === 1) return 0;
return length.value > 5 ? 5 : length.value; return length.value > 5 ? 5 : length.value;
}); });
const curPosts = computed<TGApp.Plugins.Mys.Post.FullData[]>(() => {
return selected.value
.slice((page.value - 1) * 12, page.value * 12)
.map((i) => JSON.parse(i.content));
});
const selectedMode = ref<boolean>(false); const selectedMode = ref<boolean>(false);
const selectedPost = ref<Array<string>>([]); const selectedPost = ref<Array<string>>([]);
@@ -134,8 +144,12 @@ onUnmounted(() => {
} }
}); });
function handleSelected(v: string[]) { function handleSelected(v: string) {
selectedPost.value = v; if (selectedPost.value.includes(v)) {
selectedPost.value = selectedPost.value.filter((i) => i !== v);
} else {
selectedPost.value.push(v);
}
} }
function sortPost(value: boolean) { function sortPost(value: boolean) {
@@ -326,25 +340,6 @@ async function freshPost(select: string | null): Promise<void> {
showSnackbar.success(`切换合集 ${select},共 ${selected.value.length} 条帖子`); showSnackbar.success(`切换合集 ${select},共 ${selected.value.length} 条帖子`);
} }
// 获取当前页的帖子
function getPageItems(): TGApp.Plugins.Mys.Post.FullData[] {
const posts = selected.value.slice((page.value - 1) * 12, page.value * 12);
const card: TGApp.Plugins.Mys.Post.FullData[] = [];
for (const post of posts) {
try {
card.push(JSON.parse(post.content));
} catch (e) {
TGLogger.Error("[PostCollect] getPageItems");
if (typeof e === "string") {
TGLogger.Error(e);
} else if (e instanceof Error) {
TGLogger.Error(e.message);
}
}
}
return card;
}
watch( watch(
() => curSelect.value, () => curSelect.value,
async () => await freshPost(curSelect.value), async () => await freshPost(curSelect.value),
@@ -413,59 +408,55 @@ async function mergePosts(
} }
</script> </script>
<style lang="css" scoped> <style lang="css" scoped>
.pc-container { .pc-top {
position: relative;
display: flex; display: flex;
height: 100%; align-items: flex-end;
flex-direction: column; justify-content: space-between;
align-items: center; padding: 0 10px;
row-gap: 10px; gap: 10px;
} }
.pc-top { .pc-title {
position: relative;
display: flex; display: flex;
width: 100%;
height: 60px;
align-items: center; align-items: center;
justify-content: flex-start; justify-content: center;
column-gap: 10px; gap: 10px;
img {
width: 32px;
height: 32px;
}
span {
color: var(--common-text-title);
font-family: var(--font-title);
font-size: 20px;
}
} }
.pc-select { .pc-select {
max-width: 400px; max-width: 400px;
max-height: 100%; height: 50px;
} }
.pc-page { .pc-btns {
margin-left: auto; display: flex;
} align-items: center;
justify-content: center;
/* stylelint-disable-next-line selector-class-pattern */ padding: 0 10px;
.pc-page > .v-pagination__list { gap: 10px;
justify-content: flex-end;
}
/* stylelint-disable-next-line selector-class-pattern */
.v-btn--disabled.pc-btn {
background: var(--tgc-dark-1);
color: var(--tgc-white-1);
} }
.pc-btn { .pc-btn {
height: 40px; height: 40px;
border: 1px solid var(--common-shadow-4);
background: var(--btn-bg-1); background: var(--btn-bg-1);
color: var(--btn-text-1); color: var(--btn-text-1);
font-family: var(--font-title); font-family: var(--font-title);
} }
.dark .pc-btn {
border: 1px solid var(--common-shadow-2);
}
.pc-posts { .pc-posts {
display: grid; display: grid;
font-family: var(--font-title);
grid-gap: 10px; grid-gap: 10px;
grid-template-columns: repeat(4, minmax(320px, 1fr)); grid-template-columns: repeat(4, minmax(320px, 1fr));
} }