♻️ 帖子的用户数据单独出来作为组件

This commit is contained in:
BTMuli
2024-01-12 19:04:50 +08:00
parent cfe3570d12
commit 0ce60d04ae
8 changed files with 126 additions and 319 deletions

View File

@@ -1,7 +1,7 @@
/**
* @file plugins/Mys/types/Forum.d.ts
* @description Mys 插件论坛类型定义文件
* @since Beta v0.3.7
* @since Beta v0.4.0
*/
/**
@@ -46,17 +46,13 @@ declare namespace TGApp.Plugins.Mys.Forum {
/**
* @description 用于渲染的咨讯卡片
* @since Beta v0.3.7
* @since Beta v0.4.0
* @interface RenderCard
* @property {string} title 标题
* @property {string} cover 封面图片 URL
* @property {string} postId 帖子 ID
* @property {string} subtitle 副标题
* @property user 发帖用户
* @property {string} user.nickname 用户昵称
* @property {string} user.pendant 用户头像挂件
* @property {string} user.icon 用户头像
* @property {string} user.label 用户标签
* @property {TGApp.Plugins.Mys.User.Post} user 发帖用户
* @property forum 版块
* @property {string} forum.name 版块名称
* @property {string} forum.icon 版块图标
@@ -74,12 +70,7 @@ declare namespace TGApp.Plugins.Mys.Forum {
cover: string;
postId: string;
subtitle: string;
user: {
nickname: string;
pendant: string;
icon: string;
label: string;
};
user: TGApp.Plugins.Mys.User.Post;
forum: {
name: string;
icon: string;

View File

@@ -1,7 +1,7 @@
/**
* @file plugins/Mys/types/news.d.ts
* @description Mys 插件咨讯类型定义文件
* @since Beta v0.3.7
* @since Beta v0.4.0
*/
/**
@@ -122,17 +122,13 @@ declare namespace TGApp.Plugins.Mys.News {
/**
* @description 用于渲染的咨讯卡片
* @since Alpha v0.2.1
* @since Beta v0.4.0
* @interface RenderCard
* @property {string} title 标题
* @property {string} cover 封面图片 URL
* @property {number} postId 帖子 ID
* @property {string} subtitle 副标题
* @property user 发帖用户
* @property {string} user.nickname 用户昵称
* @property {string} user.pendant 用户头像挂件
* @property {string} user.icon 用户头像
* @property {string} user.label 用户标签
* @property {TGApp.Plugins.Mys.User.Post} user 发帖用户
* @property forum 版块
* @property {string} forum.name 版块名称
* @property {string} forum.icon 版块图标
@@ -150,12 +146,7 @@ declare namespace TGApp.Plugins.Mys.News {
cover: string;
postId: number;
subtitle: string;
user: {
nickname: string;
pendant: string;
icon: string;
label: string;
};
user: TGApp.Plugins.Mys.User.Post;
forum: {
name: string;
icon: string;

View File

@@ -78,7 +78,7 @@ export function getPostCover(item: TGApp.Plugins.Mys.News.Item): string {
/**
* @description 获取公共属性
* @since Alpha v0.2.1
* @since Beta v0.4.0
* @param {TGApp.Plugins.Mys.News.Item} item 咨讯列表项
* @returns {TGApp.Plugins.Mys.News.RenderCard} 渲染用咨讯列表项
*/
@@ -88,12 +88,7 @@ function getCommonCard(item: TGApp.Plugins.Mys.News.Item): TGApp.Plugins.Mys.New
cover: getPostCover(item),
postId: Number(item.post.post_id),
subtitle: item.post.post_id,
user: {
nickname: item.user.nickname,
pendant: item.user.pendant,
icon: item.user.avatar_url,
label: item.user.certification.label,
},
user: item.user,
forum: {
name: item.forum.name,
icon: item.forum.icon,

View File

@@ -13,18 +13,12 @@ import { getPostCover } from "./getNewsCard";
* @returns {TGApp.Plugins.Mys.Forum.RenderCard} 渲染用帖子
*/
function getPostCard(post: TGApp.Plugins.Mys.News.Item): TGApp.Plugins.Mys.Forum.RenderCard {
const userLabel = getUserLabel(post);
return {
title: post.post.subject,
cover: getPostCover(post),
postId: post.post.post_id,
subtitle: post.post.post_id,
user: {
nickname: post.user.nickname,
pendant: post.user.pendant,
icon: post.user.avatar_url,
label: userLabel,
},
user: post.user,
forum: {
name: post.forum.name,
icon: post.forum.icon,
@@ -39,19 +33,6 @@ function getPostCard(post: TGApp.Plugins.Mys.News.Item): TGApp.Plugins.Mys.Forum
};
}
/**
* @description 获取用户描述
* @since Beta v0.3.7
* @param {TGApp.Plugins.Mys.News.Item} post 帖子
* @returns {string} 描述
*/
function getUserLabel(post: TGApp.Plugins.Mys.News.Item): string {
if (post.user.certification.label !== "") {
return post.user.certification.label;
}
return post.user.introduce;
}
/**
* @description 获取渲染用帖子数据
* @since Beta v0.3.7