Browse Source

feat(components): add default avatar icon and optimize project card display

1. 新增DefaultAvatar默认用户头像图标组件
2. 扩展CanvasTemplateItem类型添加userInfo字段
3. 改造项目卡片头像渲染逻辑,无头像时使用默认图标
4. 注释调VIP标签代码,优化副标题空值处理
5. 调整mapTemplateToShow函数获取头像和文本的逻辑
6. 修复代码缩进格式问题
feature/group
huangmin 1 month ago
parent
commit
5636f1b488
  1. 37
      src/components/HomeProjectsContent.tsx
  2. 6
      src/components/icons/index.tsx

37
src/components/HomeProjectsContent.tsx

@ -15,6 +15,7 @@ import {
import {
ArrowIcon,
CloseIcon,
DefaultAvatar,
LeftOutlinedIcon,
SearchIcon,
StartCreation,
@ -74,6 +75,12 @@ type CanvasTemplateItem = {
desp: string;
deleted: boolean;
categoryName: string;
userInfo: {
avatar: string;
code: string;
id: number;
name: string;
}
};
type ListResponse<T> = {
@ -198,20 +205,28 @@ function ShowCard({ id, title, subtitle, image, avatar, vip, data, onOpen }: Sho
</div>
<div className="mt-3">
<div className="flex items-center gap-[5px]">
<span className="grid h-5 w-5 place-items-center rounded-full bg-[#d6ceef] text-[11px]">
{avatar}
</span>
{avatar ?
<img
src={avatar || '/empty_project.png'}
alt=""
className="grid h-5 w-5 place-items-center rounded-full bg-[#d6ceef] text-[11px]">
</img>
:
<div className="grid h-5 w-5 place-items-center rounded-full bg-[#d6ceef] text-[11px]">
<DefaultAvatar></DefaultAvatar>
</div>
}
<h3 className="truncate text-[16px] font-medium leading-tight text-[#333]">
{title}
</h3>
{vip ? (
{/* {vip ? (
<span className="rounded-full bg-[linear-gradient(90deg,#d6ceef_45%,#f0f0f0_100%)] px-2.5 py-0.5 text-[12px] font-medium leading-none text-[#5c3bc7]">
VIP
</span>
) : null}
) : null} */}
</div>
<p className="mt-2 truncate text-[13px] leading-tight text-[#666]">
{subtitle}
{subtitle || '-'}
</p>
</div>
</article>
@ -499,8 +514,8 @@ function useProjectSectionState(pageSize: number, t: Translate, initialPage = 1)
try {
const data = await listCanvasWorkflows({ page: nextPage, pageSize });
const nextProjects = data.list
.filter((item) => !item.deleted)
.map((item) => mapWorkflowToProject(item));
.filter((item) => !item.deleted)
.map((item) => mapWorkflowToProject(item));
setProjects((currentProjects) =>
options?.append ? [...currentProjects, ...nextProjects] : nextProjects
);
@ -1266,10 +1281,10 @@ function AllProjectsSection({ onBackClick }: { onBackClick: () => void }) {
function mapTemplateToShow(item: CanvasTemplateItem, t: Translate): ShowData {
return {
id: item.id,
title: item.name || t("home.templateFallback"),
subtitle: item.desp || item.categoryName || t("home.templateSubtitleFallback"),
title: item.name || '',
subtitle: item.desp || '',
image: item.coverUrl || '',
avatar: item.categoryName?.slice(0, 1) || item.name?.slice(0, 1) || t("home.templateAvatarFallback"),
avatar: item?.userInfo?.avatar || '',
vip: item.type === 1,
data: item.properties || '',
};

6
src/components/icons/index.tsx

@ -181,3 +181,9 @@ export const LeftOutlinedIcon = () => (
<path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 000 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path>
</svg>
);
export const DefaultAvatar = () => {
return (
<svg viewBox="64 64 896 896" focusable="false" data-icon="user" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M858.5 763.6a374 374 0 00-80.6-119.5 375.63 375.63 0 00-119.5-80.6c-.4-.2-.8-.3-1.2-.5C719.5 518 760 444.7 760 362c0-137-111-248-248-248S264 225 264 362c0 82.7 40.5 156 102.8 201.1-.4.2-.8.3-1.2.5-44.8 18.9-85 46-119.5 80.6a375.63 375.63 0 00-80.6 119.5A371.7 371.7 0 00136 901.8a8 8 0 008 8.2h60c4.4 0 7.9-3.5 8-7.8 2-77.2 33-149.5 87.8-204.3 56.7-56.7 132-87.9 212.2-87.9s155.5 31.2 212.2 87.9C779 752.7 810 825 812 902.2c.1 4.4 3.6 7.8 8 7.8h60a8 8 0 008-8.2c-1-47.8-10.9-94.3-29.5-138.2zM512 534c-45.9 0-89.1-17.9-121.6-50.4S340 407.9 340 362c0-45.9 17.9-89.1 50.4-121.6S466.1 190 512 190s89.1 17.9 121.6 50.4S684 316.1 684 362c0 45.9-17.9 89.1-50.4 121.6S557.9 534 512 534z"></path></svg>
)
}
Loading…
Cancel
Save