mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-05-14 04:07:37 +08:00
✨ 加载指定用户帖子
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
<div class="tpc-title" :title="card.title" @click="shareCard">{{ card.title }}</div>
|
||||
</div>
|
||||
<div class="tpc-mid" v-if="card.user !== null">
|
||||
<TpAvatar :data="card.user" position="left" />
|
||||
<TpAvatar :data="card.user" position="left" @click="onUserClick()" />
|
||||
</div>
|
||||
<div class="tpc-bottom" v-if="card.data !== null">
|
||||
<div class="tpc-tags">
|
||||
@@ -80,8 +80,15 @@ import { useRoute, useRouter } from "vue-router";
|
||||
import { generateShareImg } from "@/utils/TGShare.js";
|
||||
import { createPost } from "@/utils/TGWindow.js";
|
||||
|
||||
type TPostCardProps = { modelValue: TGApp.BBS.Post.FullData; selectMode?: boolean };
|
||||
type TPostCardEmits = (e: "onSelected", v: string) => void;
|
||||
type TPostCardProps = {
|
||||
modelValue: TGApp.BBS.Post.FullData;
|
||||
selectMode?: boolean;
|
||||
userClick?: boolean;
|
||||
};
|
||||
type TPostCardEmits = {
|
||||
(e: "onSelected", v: string): void;
|
||||
(e: "onUserClick", v: TGApp.BBS.Post.User): void;
|
||||
};
|
||||
type TPostStatus = RenderStatus & { stat: ActStat };
|
||||
type RenderForum = { name: string; icon: string; id: number };
|
||||
type RenderStatus = { stat: number; label: string; color: string };
|
||||
@@ -226,6 +233,11 @@ async function toForum(forum: RenderForum): Promise<void> {
|
||||
const gid = props.modelValue.post.game_id;
|
||||
await emit("active_deep_link", `router?path=/posts/forum/${gid}/${forum.id}`);
|
||||
}
|
||||
|
||||
function onUserClick(): void {
|
||||
if (!card.value || card.value.user === null) return;
|
||||
emits("onUserClick", card.value.user);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
.tpc-card {
|
||||
@@ -280,6 +292,7 @@ async function toForum(forum: RenderForum): Promise<void> {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
padding: 0 10px;
|
||||
cursor: v-bind("props.userClick ? 'pointer' : 'default'");
|
||||
}
|
||||
|
||||
.tpc-bottom {
|
||||
|
||||
@@ -89,17 +89,20 @@ const levelColor = computed<string>(() => {
|
||||
|
||||
.tpa-img {
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
box-sizing: border-box;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.tpa-icon {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
left: 5px;
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
</span>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { emit } from "@tauri-apps/api/event";
|
||||
import { toRaw } from "vue";
|
||||
|
||||
export type TpMention = { insert: { mention: { uid: string; nickname: string } } };
|
||||
@@ -14,11 +15,9 @@ const props = defineProps<TpMentionProps>();
|
||||
|
||||
console.log("tpMention", props.data.insert.mention.uid, toRaw(props.data).insert.mention);
|
||||
|
||||
// todo 个人主页
|
||||
function toLink(): void {
|
||||
async function toLink(): Promise<void> {
|
||||
const uid = props.data.insert.mention.uid;
|
||||
const link = `https://www.miyoushe.com/ys/accountCenter/postList?id=${uid}`;
|
||||
window.open(link);
|
||||
await emit("userMention", uid);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
307
src/components/viewPost/vp-overlay-user.vue
Normal file
307
src/components/viewPost/vp-overlay-user.vue
Normal file
@@ -0,0 +1,307 @@
|
||||
<template>
|
||||
<TOverlay v-model="visible">
|
||||
<div class="vp-ou-box">
|
||||
<div class="vp-ou-user" v-if="userInfo">
|
||||
<div class="vp-ouu-info">
|
||||
<div class="left">
|
||||
<div class="avatar">
|
||||
<TMiImg :src="userInfo.avatar_url" alt="avatar" :ori="true" />
|
||||
</div>
|
||||
<div class="pendant" v-if="userInfo.pendant !== ''">
|
||||
<TMiImg :src="userInfo.pendant" alt="pendant" :ori="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="right">
|
||||
<div class="title">
|
||||
<div class="nickname">{{ userInfo.nickname }}</div>
|
||||
<div class="level">Lv.{{ userInfo.level_exp.level }}</div>
|
||||
</div>
|
||||
<div class="desc" :title="userInfo.introduce">{{ userInfo.introduce }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="vp-ou-mid">
|
||||
<v-btn :loading="load" size="small" class="vp-ou-btn" @click="loadPosts()" rounded>
|
||||
加载更多({{ results.length }})
|
||||
</v-btn>
|
||||
<div class="vp-ouu-extra" v-if="userInfo">
|
||||
<span>ID:{{ userInfo.uid }}</span>
|
||||
<span>IP:{{ userInfo.ip_region }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="vp-ou-divider" />
|
||||
<div class="vp-ou-list">
|
||||
<TPostCard
|
||||
class="vp-ou-item"
|
||||
:model-value="item"
|
||||
v-for="item in results"
|
||||
:key="item.post.post_id"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</TOverlay>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import TMiImg from "@comp/app/t-mi-img.vue";
|
||||
import TOverlay from "@comp/app/t-overlay.vue";
|
||||
import TPostCard from "@comp/app/t-postcard.vue";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { computed, ref, shallowRef, watch } from "vue";
|
||||
|
||||
import bbsReq from "@/web/request/bbsReq.js";
|
||||
import postReq from "@/web/request/postReq.js";
|
||||
|
||||
type ToPostUserProps = { gid: number; uid: string; postId?: string };
|
||||
|
||||
const props = defineProps<ToPostUserProps>();
|
||||
const visible = defineModel<boolean>();
|
||||
const offset = ref<string>();
|
||||
const isLast = ref<boolean>(false);
|
||||
const load = ref<boolean>(false);
|
||||
const userInfo = shallowRef<TGApp.BBS.User.Info>();
|
||||
const results = shallowRef<Array<TGApp.BBS.Post.FullData>>([]);
|
||||
const levelColor = computed<string>(() => {
|
||||
if (!userInfo.value) return "var(--tgc-od-white)";
|
||||
const level = userInfo.value.level_exp.level;
|
||||
if (level < 5) return "var(--tgc-od-green)";
|
||||
if (level < 9) return "var(--tgc-od-blue)";
|
||||
if (level < 13) return "var(--tgc-od-purple)";
|
||||
if (level > 12) return "var(--tgc-od-orange)";
|
||||
return "var(--tgc-od-white)";
|
||||
});
|
||||
|
||||
watch(
|
||||
() => visible.value,
|
||||
async () => {
|
||||
if (visible.value && results.value.length === 0) await loadPosts();
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.uid,
|
||||
async () => {
|
||||
if (visible.value) {
|
||||
offset.value = "";
|
||||
isLast.value = false;
|
||||
results.value = [];
|
||||
await loadUser();
|
||||
await loadPosts();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
async function loadUser(): Promise<void> {
|
||||
const resp = await bbsReq.otherUserInfo(props.gid, props.uid);
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.warn(`[${resp.retcode}] ${resp.message}`);
|
||||
return;
|
||||
}
|
||||
userInfo.value = resp;
|
||||
console.log(userInfo.value);
|
||||
}
|
||||
|
||||
async function loadPosts(): Promise<void> {
|
||||
if (load.value) return;
|
||||
load.value = true;
|
||||
if (isLast.value) {
|
||||
showSnackbar.warn("没有更多了");
|
||||
load.value = false;
|
||||
return;
|
||||
}
|
||||
const resp = await postReq.user.post(props.uid, props.gid, offset.value);
|
||||
if ("retcode" in resp) {
|
||||
showSnackbar.warn(`[${resp.retcode}] ${resp.message}`);
|
||||
load.value = false;
|
||||
visible.value = false;
|
||||
return;
|
||||
}
|
||||
offset.value = resp.next_offset;
|
||||
isLast.value = resp.is_last;
|
||||
results.value = results.value.concat(resp.list);
|
||||
load.value = false;
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.vp-ou-box {
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 400px;
|
||||
height: 500px;
|
||||
box-sizing: border-box;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: flex-start;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
background-color: var(--box-bg-1);
|
||||
row-gap: 8px;
|
||||
}
|
||||
|
||||
.vp-ou-user {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
justify-content: center;
|
||||
row-gap: 4px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.vp-ouu-info {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
max-width: 100%;
|
||||
|
||||
.left {
|
||||
position: relative;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
box-sizing: border-box;
|
||||
padding: 5px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
.avatar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
background: var(--common-shadow-1);
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
object-fit: contain;
|
||||
}
|
||||
}
|
||||
|
||||
.pendant {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
display: flex;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 50%;
|
||||
object-fit: contain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.right {
|
||||
position: relative;
|
||||
display: flex;
|
||||
max-width: calc(100% - 50px);
|
||||
height: 50px;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
color: var(--box-text-4);
|
||||
|
||||
.title {
|
||||
position: relative;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
column-gap: 4px;
|
||||
font-family: var(--font-title);
|
||||
font-size: 16px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
.title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.level {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 2px;
|
||||
border-radius: 2px;
|
||||
background: v-bind(levelColor);
|
||||
color: var(--tgc-white-1);
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.desc {
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: 26px;
|
||||
border-top: 2px solid var(--common-shadow-2);
|
||||
font-size: 14px;
|
||||
opacity: 0.7;
|
||||
text-align: left;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.vp-ou-mid {
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.vp-ou-btn {
|
||||
width: fit-content;
|
||||
background: var(--tgc-btn-1);
|
||||
color: var(--btn-text);
|
||||
}
|
||||
|
||||
.vp-ouu-extra {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
column-gap: 8px;
|
||||
font-size: 12px;
|
||||
color: var(--box-text-4);
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.vp-ou-divider {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
background-color: var(--common-shadow-2);
|
||||
}
|
||||
|
||||
.vp-ou-list {
|
||||
position: relative;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
flex-direction: column;
|
||||
padding-right: 8px;
|
||||
padding-bottom: 8px;
|
||||
overflow-y: auto;
|
||||
row-gap: 10px;
|
||||
}
|
||||
|
||||
.vp-ou-item {
|
||||
height: fit-content;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -7,7 +7,7 @@
|
||||
>
|
||||
<TMiImg :ori="true" :src="props.modelValue.user.reply_bubble.url" alt="bubble" />
|
||||
</div>
|
||||
<div class="tpr-user">
|
||||
<div class="tpr-user" @click="handleUser()">
|
||||
<div class="tpru-left">
|
||||
<div class="avatar">
|
||||
<TMiImg :ori="true" :src="props.modelValue.user.avatar_url" alt="avatar" />
|
||||
@@ -104,7 +104,7 @@ import TMiImg from "@comp/app/t-mi-img.vue";
|
||||
import showDialog from "@comp/func/dialog.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import { event, path } from "@tauri-apps/api";
|
||||
import type { Event, UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { emit, Event, UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { save } from "@tauri-apps/plugin-dialog";
|
||||
import { writeTextFile } from "@tauri-apps/plugin-fs";
|
||||
import { computed, onMounted, onUnmounted, ref, shallowRef, toRaw, watch } from "vue";
|
||||
@@ -226,6 +226,11 @@ async function exportData(): Promise<void> {
|
||||
await writeTextFile(savePath, data);
|
||||
showSnackbar.success("导出成功");
|
||||
}
|
||||
|
||||
async function handleUser(): Promise<void> {
|
||||
const uid = props.modelValue.user.uid;
|
||||
await emit("userMention", uid);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
.tpr-reply-box {
|
||||
@@ -264,6 +269,7 @@ async function exportData(): Promise<void> {
|
||||
height: 40px;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
cursor: pointer;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
|
||||
@@ -351,7 +351,7 @@ async function freshUser(uid?: string): Promise<void> {
|
||||
}
|
||||
const uidReal = uid || briefInfo.value.uid;
|
||||
await showLoading.start(`[${uidReal}]获取用户收藏`);
|
||||
let res = await postReq.userFavourite(cookie.value, uidReal);
|
||||
let res = await postReq.user.collect(cookie.value, uidReal);
|
||||
while (true) {
|
||||
if ("retcode" in res) {
|
||||
await showLoading.end();
|
||||
@@ -363,7 +363,7 @@ async function freshUser(uid?: string): Promise<void> {
|
||||
await mergePosts(posts, uid || briefInfo.value.uid);
|
||||
if (res.is_last) break;
|
||||
await showLoading.update(`[offset]${res.next_offset} [is_last]${res.is_last}`);
|
||||
res = await postReq.userFavourite(cookie.value, uid || briefInfo.value.uid, res.next_offset);
|
||||
res = await postReq.user.collect(cookie.value, uid || briefInfo.value.uid, res.next_offset);
|
||||
}
|
||||
await showLoading.end();
|
||||
showSnackbar.success("获取用户收藏成功,即将刷新页面");
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
</v-app-bar>
|
||||
<div class="posts-grid">
|
||||
<div v-for="post in posts" :key="post.post.post_id">
|
||||
<TPostCard :model-value="post" v-if="post" />
|
||||
<TPostCard :model-value="post" :user-click="true" @onUserClick="handleUserClick" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="posts-load-more">
|
||||
@@ -122,6 +122,7 @@
|
||||
</v-btn>
|
||||
</div>
|
||||
<VpOverlaySearch :gid="curGid.toString()" v-model="showSearch" :keyword="search" />
|
||||
<VpOverlayUser v-model="showUser" :gid="curGid" :uid="curUid" />
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import TGameNav from "@comp/app/t-gameNav.vue";
|
||||
@@ -130,6 +131,7 @@ import TPostCard from "@comp/app/t-postcard.vue";
|
||||
import showLoading from "@comp/func/loading.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import VpOverlaySearch from "@comp/viewPost/vp-overlay-search.vue";
|
||||
import VpOverlayUser from "@comp/viewPost/vp-overlay-user.vue";
|
||||
import { computed, onMounted, ref, shallowRef, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
@@ -152,10 +154,14 @@ const route = useRoute();
|
||||
const router = useRouter();
|
||||
const curGid = ref<number>(2);
|
||||
const curSortType = ref<number>(1);
|
||||
const search = ref<string>("");
|
||||
const showSearch = ref<boolean>(false);
|
||||
const firstLoad = ref<boolean>(false);
|
||||
const isReq = ref<boolean>(false);
|
||||
|
||||
const search = ref<string>("");
|
||||
const showSearch = ref<boolean>(false);
|
||||
const curUid = ref<string>("");
|
||||
const showUser = ref<boolean>(false);
|
||||
|
||||
const selectedForum = shallowRef<SortSelect>();
|
||||
const sortGameList = shallowRef<Array<SortSelectGame>>([]);
|
||||
const postRaw = shallowRef<PostRaw>({ isLast: false, lastId: "", total: 0 });
|
||||
@@ -274,6 +280,8 @@ async function freshPostData(): Promise<void> {
|
||||
query: { gid: curGid.value, forum: selectedForum.value.value },
|
||||
});
|
||||
isReq.value = true;
|
||||
if (showSearch.value) showSearch.value = false;
|
||||
if (showUser.value) showUser.value = false;
|
||||
const gameLabel = curGame.value?.text ?? "";
|
||||
await showLoading.start(`正在刷新${gameLabel}帖子`);
|
||||
const forumLabel = getForum(selectedForum.value.value).text;
|
||||
@@ -328,8 +336,16 @@ function searchPost(): void {
|
||||
return;
|
||||
}
|
||||
const numCheck = Number(search.value);
|
||||
if (isNaN(numCheck)) showSearch.value = true;
|
||||
else createPost(search.value);
|
||||
if (isNaN(numCheck)) {
|
||||
if (showUser.value) showUser.value = false;
|
||||
showSearch.value = true;
|
||||
} else createPost(search.value);
|
||||
}
|
||||
|
||||
function handleUserClick(user: TGApp.BBS.Post.User): void {
|
||||
if (showSearch.value) showSearch.value = false;
|
||||
curUid.value = user.uid;
|
||||
showUser.value = true;
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
</v-app-bar>
|
||||
<div class="post-topic-grid">
|
||||
<div v-for="post in posts" :key="post.post.post_id">
|
||||
<TPostCard :model-value="post" v-if="post" />
|
||||
<TPostCard :model-value="post" :user-click="true" @onUserClick="handleUserClick" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="load-more">
|
||||
@@ -84,6 +84,7 @@
|
||||
</v-btn>
|
||||
</div>
|
||||
<VpOverlaySearch :gid="curGid.toString()" v-model="showSearch" :keyword="search" />
|
||||
<VpOverlayUser v-model="showUser" :gid="curGid" :uid="curUid" />
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import TGameNav from "@comp/app/t-gameNav.vue";
|
||||
@@ -92,6 +93,7 @@ import TPostCard from "@comp/app/t-postcard.vue";
|
||||
import showLoading from "@comp/func/loading.js";
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
import VpOverlaySearch from "@comp/viewPost/vp-overlay-search.vue";
|
||||
import VpOverlayUser from "@comp/viewPost/vp-overlay-user.vue";
|
||||
import { computed, onMounted, ref, shallowRef, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
@@ -106,11 +108,16 @@ type GameList = TGApp.BBS.Topic.GameInfo & { icon?: string };
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const showSearch = ref<boolean>(false);
|
||||
|
||||
const curGid = ref<number>(0);
|
||||
const curSortType = ref<0 | 1 | 2>(0);
|
||||
const search = ref<string>("");
|
||||
const curTopic = ref<string>("");
|
||||
|
||||
const search = ref<string>("");
|
||||
const showSearch = ref<boolean>(false);
|
||||
const curUid = ref<string>("");
|
||||
const showUser = ref<boolean>(false);
|
||||
|
||||
const isReq = ref<boolean>(false);
|
||||
const allGames = shallowRef<Array<TGApp.BBS.Game.Item>>([]);
|
||||
const postRaw = shallowRef<PostMiniData>({ isLast: false, lastId: "", total: 0 });
|
||||
@@ -202,6 +209,8 @@ async function firstLoad(): Promise<void> {
|
||||
async function freshPostData(): Promise<void> {
|
||||
if (isReq.value) return;
|
||||
isReq.value = true;
|
||||
if (showSearch.value) showSearch.value = false;
|
||||
if (showUser.value) showUser.value = false;
|
||||
if (postRaw.value.isLast) {
|
||||
showSnackbar.warn("已经到底了");
|
||||
return;
|
||||
@@ -240,8 +249,10 @@ function searchPost(): void {
|
||||
return;
|
||||
}
|
||||
const numCheck = Number(search.value);
|
||||
if (isNaN(numCheck)) showSearch.value = true;
|
||||
else createPost(search.value);
|
||||
if (isNaN(numCheck)) {
|
||||
if (showUser.value) showUser.value = false;
|
||||
showSearch.value = true;
|
||||
} else createPost(search.value);
|
||||
}
|
||||
|
||||
function getGameList(gameList: Array<TGApp.BBS.Topic.GameInfo> | undefined): Array<GameList> {
|
||||
@@ -251,6 +262,12 @@ function getGameList(gameList: Array<TGApp.BBS.Topic.GameInfo> | undefined): Arr
|
||||
return { ...item, icon: game?.app_icon };
|
||||
});
|
||||
}
|
||||
|
||||
function handleUserClick(user: TGApp.BBS.Post.User): void {
|
||||
if (showSearch.value) showSearch.value = false;
|
||||
curUid.value = user.uid;
|
||||
showUser.value = true;
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
.post-topic-top {
|
||||
|
||||
21
src/types/BBS/Post.d.ts
vendored
21
src/types/BBS/Post.d.ts
vendored
@@ -74,6 +74,27 @@ declare namespace TGApp.BBS.Post {
|
||||
*/
|
||||
type NewsRes = { list: Array<FullData>; last_id: string; is_last: boolean };
|
||||
|
||||
/**
|
||||
* @description 用户发布帖子返回
|
||||
* @since Beta v0.7.2
|
||||
* @interface UserPostResp
|
||||
* @extends TGApp.BBS.Response.BaseWithData
|
||||
* @property {UserPostRes} data 返回数据
|
||||
* @return UserPostResp
|
||||
*/
|
||||
type UserPostResp = TGApp.BBS.Response.BaseWithData<UserPostRes>;
|
||||
|
||||
/**
|
||||
* @description 用户发布帖子数据
|
||||
* @since Beta v0.7.2
|
||||
* @interface UserPostRes
|
||||
* @property {Array<FullData>} list 帖子列表
|
||||
* @property {boolean} is_last 是否最后一页
|
||||
* @property {string} next_offset 下一页偏移量
|
||||
* @return UserPostRes
|
||||
*/
|
||||
type UserPostRes = { list: Array<FullData>; is_last: boolean; next_offset: string };
|
||||
|
||||
/**
|
||||
* @description 帖子数据
|
||||
* @since Beta v0.7.2
|
||||
|
||||
@@ -41,7 +41,13 @@
|
||||
<span>{{ postData?.stat?.forward_num }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<TpAvatar :data="postData.user" position="right" v-if="postData.user" />
|
||||
<TpAvatar
|
||||
:data="postData.user"
|
||||
position="right"
|
||||
style="cursor: pointer"
|
||||
v-if="postData.user"
|
||||
@click="handleUser(postData.user)"
|
||||
/>
|
||||
</div>
|
||||
<div class="tp-post-title" @click="toPost()">
|
||||
<span class="mpt-official" v-if="postData.post.post_status.is_official">官</span>
|
||||
@@ -96,6 +102,7 @@
|
||||
:gid="postData.post.game_id"
|
||||
v-if="postData?.collection && postData"
|
||||
/>
|
||||
<VpOverlayUser v-if="postData" :gid="postData.post.game_id" :uid="curUid" v-model="showUser" />
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import TMiImg from "@comp/app/t-mi-img.vue";
|
||||
@@ -109,8 +116,9 @@ import TpParser from "@comp/viewPost/tp-parser.vue";
|
||||
import VpBtnCollect from "@comp/viewPost/vp-btn-collect.vue";
|
||||
import VpBtnReply from "@comp/viewPost/vp-btn-reply.vue";
|
||||
import VpOverlayCollection from "@comp/viewPost/vp-overlay-collection.vue";
|
||||
import VpOverlayUser from "@comp/viewPost/vp-overlay-user.vue";
|
||||
import { app, webviewWindow } from "@tauri-apps/api";
|
||||
import { emit, listen, UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { emit, type Event, listen, UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onBeforeMount, onMounted, onUnmounted, ref, shallowRef } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
@@ -131,12 +139,15 @@ const postId = Number(useRoute().params.post_id);
|
||||
const showCollection = ref<boolean>(false);
|
||||
const isLike = ref<boolean>(false);
|
||||
const shareTime = ref<number>(Math.floor(Date.now() / 1000));
|
||||
const curUid = ref<string>("");
|
||||
const showUser = ref<boolean>(false);
|
||||
const renderPost = shallowRef<Array<TGApp.BBS.SctPost.Base>>([]);
|
||||
const postData = shallowRef<TGApp.BBS.Post.FullData>();
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
let shareTimer: NodeJS.Timeout | null = null;
|
||||
let incognitoListener: UnlistenFn | null = null;
|
||||
let userListener: UnlistenFn | null = null;
|
||||
|
||||
function getGameIcon(gameId: number): string {
|
||||
const find = TGBbs.channels.find((item) => item.gid === gameId);
|
||||
@@ -146,6 +157,11 @@ function getGameIcon(gameId: number): string {
|
||||
|
||||
onBeforeMount(async () => {
|
||||
incognitoListener = await listen<void>("switchIncognito", () => window.location.reload());
|
||||
userListener = await listen<string>("userMention", (e: Event<string>) => {
|
||||
if (e.payload !== curUid.value) curUid.value = e.payload;
|
||||
if (showCollection.value) showCollection.value = false;
|
||||
showUser.value = true;
|
||||
});
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -188,6 +204,21 @@ onMounted(async () => {
|
||||
await showLoading.end();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
if (shareTimer !== null) {
|
||||
clearInterval(shareTimer);
|
||||
shareTimer = null;
|
||||
}
|
||||
if (incognitoListener !== null) {
|
||||
incognitoListener();
|
||||
incognitoListener = null;
|
||||
}
|
||||
if (userListener !== null) {
|
||||
userListener();
|
||||
userListener = null;
|
||||
}
|
||||
});
|
||||
|
||||
async function openJson(): Promise<void> {
|
||||
// @ts-expect-error import.meta
|
||||
if (import.meta.env.MODE === "production") return;
|
||||
@@ -199,6 +230,7 @@ function getShareTimer(): void {
|
||||
}
|
||||
|
||||
function showOverlayC() {
|
||||
if (showUser.value) showUser.value = false;
|
||||
showCollection.value = true;
|
||||
}
|
||||
|
||||
@@ -315,16 +347,11 @@ async function toForum(forum: TGApp.BBS.Post.Forum): Promise<void> {
|
||||
await emit("active_deep_link", `router?path=/posts/forum/${forum.game_id}/${forum.id}`);
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (shareTimer !== null) {
|
||||
clearInterval(shareTimer);
|
||||
shareTimer = null;
|
||||
}
|
||||
if (incognitoListener !== null) {
|
||||
incognitoListener();
|
||||
incognitoListener = null;
|
||||
}
|
||||
});
|
||||
function handleUser(user: TGApp.BBS.Post.User): void {
|
||||
curUid.value = user.uid;
|
||||
if (showCollection.value) showCollection.value = false;
|
||||
showUser.value = true;
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
.tp-post-body {
|
||||
|
||||
@@ -48,13 +48,13 @@ async function getUserFullInfo(
|
||||
|
||||
/**
|
||||
* @description 根据gid和id获取用户信息
|
||||
* @since Beta v0.7.1
|
||||
* @param {number} gid - gid
|
||||
* @since Beta v0.7.2
|
||||
* @param {string} gid - gid
|
||||
* @param {string} userId - 用户 id
|
||||
* @returns {Promise<TGApp.BBS.Response.Base | TGApp.BBS.User.Info>}
|
||||
*/
|
||||
async function getOtherUserInfo(
|
||||
gid: number,
|
||||
gid: string,
|
||||
userId: string,
|
||||
): Promise<TGApp.BBS.Response.Base | TGApp.BBS.User.Info> {
|
||||
const params = { gids: gid.toString(), uid: userId };
|
||||
|
||||
@@ -171,6 +171,29 @@ async function getTopicPostList(
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取用户发布帖子
|
||||
* @since Beta v0.7.2
|
||||
* @param {string} uid 用户 ID
|
||||
* @param {number} gid 社区 ID
|
||||
* @param {string} offset 偏移量
|
||||
* @returns {Promise<TGApp.BBS.Post.UserPostRes|TGApp.BBS.Response.Base>}
|
||||
*/
|
||||
async function getUserPost(
|
||||
uid: string,
|
||||
gid: number,
|
||||
offset?: string,
|
||||
): Promise<TGApp.BBS.Post.UserPostRes | TGApp.BBS.Response.Base> {
|
||||
const params = offset ? { uid, gids: gid, offset, size: 20 } : { uid, gids: gid, size: 20 };
|
||||
const resp = await TGHttp<TGApp.BBS.Post.UserPostResp>(`${bapBu}userPost`, {
|
||||
method: "GET",
|
||||
headers: { referer: Referer },
|
||||
query: params,
|
||||
});
|
||||
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 搜索帖子
|
||||
* @since Beta v0.7.1
|
||||
@@ -222,7 +245,7 @@ const postReq = {
|
||||
topic: getTopicPostList,
|
||||
reply: { main: getPostReplies, sub: getSubReplies },
|
||||
search: searchPosts,
|
||||
userFavourite: userFavouritePost,
|
||||
user: { post: getUserPost, collect: userFavouritePost },
|
||||
};
|
||||
|
||||
export default postReq;
|
||||
|
||||
Reference in New Issue
Block a user