Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
perf: Optimize the menu in the upper right corner
gaoSird2ff2862ee1a
diff --git a/@types/resources.d.ts b/@types/resources.d.tsindex 30ec8531..3a58c5ee 100644--- a/@types/resources.d.ts+++ b/@types/resources.d.ts@@ -288,7 +288,9 @@ interface Resources {"profile": "个人中心","logout": "退出登录","unknownUser": "未知用户",+ "docs": "帮助文档","login": "登录",+ "support": "支持","notifications": "消息通知","noNotifications": "暂无消息","markAllAsRead": "全部标记为已读",diff --git a/src/app/i18n/locales/en/common.json b/src/app/i18n/locales/en/common.jsonindex 7b79d883..b05ff8a9 100644--- a/src/app/i18n/locales/en/common.json+++ b/src/app/i18n/locales/en/common.json@@ -2,7 +2,9 @@"profile": "Profile","logout": "Logout","unknownUser": "Unknown User",+ "docs": "Docs","login": "Login",+ "support": "Support","notifications": "Notifications","noNotifications": "No notifications","markAllAsRead": "Mark all as read",diff --git a/src/app/i18n/locales/zh-CN/common.json b/src/app/i18n/locales/zh-CN/common.jsonindex 50ef4367..e65e7f65 100644--- a/src/app/i18n/locales/zh-CN/common.json+++ b/src/app/i18n/locales/zh-CN/common.json@@ -2,7 +2,9 @@"profile": "个人中心","logout": "退出登录","unknownUser": "未知用户",+ "docs": "帮助文档","login": "登录",+ "support": "支持","notifications": "消息通知","noNotifications": "暂无消息","markAllAsRead": "全部标记为已读",diff --git a/src/app/layout/LyaoutHeader.tsx b/src/app/layout/LyaoutHeader.tsxindex a6e400ff..8d6ab8b6 100644--- a/src/app/layout/LyaoutHeader.tsx+++ b/src/app/layout/LyaoutHeader.tsx@@ -1,16 +1,24 @@"use client";-import { ForwardedRef, forwardRef, memo, useRef, useState } from "react";+import {+ ForwardedRef,+ forwardRef,+ memo,+ useMemo,+ useRef,+ useState,+} from "react";import styles from "./styles/lyaoutHeader.module.scss";import { useUserStore } from "@/store/user";import Link from "next/link";import Image from "next/image";import LayoutNav from "@/app/layout/layoutNav";import { NoSSR } from "@kwooshung/react-no-ssr";-import { Button, Dropdown, MenuProps, Badge } from "antd";+import { Button, Badge, Popover } from "antd";import {+ ArrowLeftOutlined,BellOutlined,- CaretDownOutlined,+ BookOutlined,CrownOutlined,} from "@ant-design/icons";import { useRouter } from "next/navigation";@@ -22,6 +30,14 @@ import SignInCalendar from "@/components/SignInCalendar";import VipContentModal from "@/components/modals/VipContentModal";import PointsDetailModal from "@/components/modals/PointsDetailModal";import LanguageSwitcher from "@/components/common/LanguageSwitcher";+import {+ UserOutlined,+ FileTextOutlined,+ WalletOutlined,+ GithubOutlined,+ LogoutOutlined,+ QuestionCircleOutlined,+} from "@ant-design/icons";import logo from "@/assets/images/logo.png";@@ -33,96 +49,130 @@ function UserInfo() {const userInfo = useUserStore((state) => state.userInfo)!;const router = useRouter();const { t } = useTransClient("common");- const { t: tVip } = useTransClient("vip");- const lng = useGetClientLng();- const items: MenuProps["items"] = [- {- key: "1",- label: (- <div- onClick={() => {- router.push(`/${lng}/profile`);- }}- >- {t("profile")}- </div>- ),- },- {- key: "2",- label: (- <div- onClick={() => {- router.push(`/${lng}/income`);- }}- >- {t("header.income" as any)}- </div>- ),- },- {- key: "3",- label: (- <div- onClick={() => {- router.push(`/${lng}/wallet`);- }}- >- {t("header.wallet" as any)}- </div>- ),- },- // {- // key: "4",- // label: (- // <div- // onClick={() => {- // router.push(`/${lng}/notification`);- // }}- // >- // {t("header.messages")}- // </div>- // ),- // },+ const menuItems = useMemo(() => {+ return [+ {+ href: `/profile`,+ label: t("profile"),+ icon: <UserOutlined />,+ border: true,+ },+ {+ href: `/income`,+ label: t("header.income"),+ icon: <FileTextOutlined />,+ },+ {+ href: `/wallet`,+ label: t("header.wallet"),+ icon: <WalletOutlined />,+ border: true,+ },+ {+ href: `https://docs.aitoearn.ai/`,+ label: t("docs"),+ icon: <BookOutlined />,+ },+ {+ label: t("support"),+ icon: <QuestionCircleOutlined />,+ href: "https://github.com/yikart/AiToEarn/issues",+ },+ {+ label: "Github",+ icon: <GithubOutlined />,+ href: `https://github.com/yikart/AiToEarn`,+ subtitle: (+ <img src="https://img.shields.io/github/stars/yikart/AiToEarn.svg" />+ ),+ },+ {+ onClick: () => {+ useUserStore.getState().logout();+ router.push(`/`);+ },+ label: t("logout"),+ icon: <LogoutOutlined />,+ },+ ];+ }, [router, t]);- {- key: "7",- label: (- <div- onClick={() => {- useUserStore.getState().logout();- router.push(`/${lng}/`);- }}- >- {t("logout")}- </div>- ),- },- ];+ const avatar = (+ <Image+ className={styles["layoutHeader-userinfo-avatar"]}+ src={userInfo?.avatar || logo}+ alt={t("profile")}+ width={35}+ height={35}+ style={{+ borderRadius: "50%",+ backgroundColor: "#e9d5ff",+ padding: "3px",+ }}+ />+ );return (<div className={styles["layoutHeader-userinfo__wrapper"]}>- <Dropdown menu={{ items }} arrow placement="bottom">+ <Popover+ placement="bottomLeft"+ arrow={false}+ styles={{ body: { padding: "0" } }}+ content={+ <div className={styles.layoutHeaderMenu}>+ <div className="layoutHeaderMenu-head">+ <div className="layoutHeaderMenu-head-info">+ <span className="layoutHeaderMenu-head-info-name">+ {userInfo.name}+ </span>+ <span className="layoutHeaderMenu-head-info-mail">+ {userInfo.mail}+ </span>+ </div>+ <div className="layoutHeaderMenu-head-avatar">{avatar}</div>+ </div>+ <div className="layoutHeaderMenu-content">+ {menuItems.map((v) => {+ return (+ <a+ className={`layoutHeaderMenu-item ${v.border ? "layoutHeaderMenu-item--border" : ""}`}+ href={v.href}+ key={v.label}+ title={v.label}+ target={v.href?.includes("https://") ? "_blank" : "_self"}+ onClick={() => v.onClick}+ >+ <p className="layoutHeaderMenu-item-label">+ {v.icon}+ {v.label}+ </p>+ <div className="layoutHeaderMenu-item-subtitle">+ {v.subtitle+ ? v.subtitle+ : v.href && (+ <ArrowLeftOutlined+ style={{+ transform: "rotate(140deg)",+ fontSize: "12px",+ }}+ />+ )}+ </div>+ </a>+ );+ })}+ </div>+ </div>+ }+ ><div className={styles["layoutHeader-userinfo"]}>- <Image- className={styles["layoutHeader-userinfo-avatar"]}- src={userInfo?.avatar || logo}- alt={t("profile")}- width={35}- height={35}- style={{- borderRadius: "50%",- backgroundColor: "#e9d5ff",- padding: "3px",- }}- />+ {avatar}<div className={styles["layoutHeader-userinfo-name"]}>{userInfo?.name || t("unknownUser")}</div>- <CaretDownOutlined /></div>- </Dropdown>+ </Popover></div>);}diff --git a/src/app/layout/styles/lyaoutHeader.module.scss b/src/app/layout/styles/lyaoutHeader.module.scssindex 0469a5f0..b08eb49e 100644--- a/src/app/layout/styles/lyaoutHeader.module.scss+++ b/src/app/layout/styles/lyaoutHeader.module.scss@@ -167,6 +167,84 @@}}+.layoutHeaderMenu {+ width: 225px;+ flex-direction: column;+ min-width: 0;+ display: flex;+ :global {+ .layoutHeaderMenu-head {+ display: flex;+ justify-content: space-between;+ align-items: center;+ min-width: 0;+ padding: 15px 15px 5px;+ width: 100%;+ &-info {+ display: flex;+ flex-direction: column;+ width: 100%;+ margin-right: 10px;+ min-width: 0;+ overflow: hidden;+ text-overflow: ellipsis;+ &-name, &-mail {+ @include omitText(1);+ }+ &-name {}+ &-mail {+ font-size: var(--fs-xs);+ color: var(--grayColor8);+ }+ }+ }+ .layoutHeaderMenu-content {+ padding: 4px;+ }+ .layoutHeaderMenu-item {+ color: var(--text-color);+ position: relative;+ display: flex;+ justify-content: space-between;+ align-items: center;+ cursor: pointer;+ border-radius: 0.25rem;+ padding: 7px 11px;+ font-size: var(--fs-sm);+ user-select: none;+ outline: none;+ &:hover {+ background: rgba(200, 206, 218, 0.2);+ }+ &-subtitle {+ display: flex;+ align-items: center;+ }+ &-label {+ .anticon {+ margin-right: 8px;+ }+ }+ &--border {+ position: relative;+ &:after {+ content: "";+ display: block;+ position: absolute;+ width: 100%;+ height: 1px;+ background: var(--grayColor2);+ left: 0;+ bottom: -4px;+ }+ }+ }+ .layoutHeaderMenu-item--border + .layoutHeaderMenu-item {+ margin-top: 8px;+ }+ }+}+.ant-popover-title {font-size: 16px !important;}diff --git a/src/app/styles/mixin.scss b/src/app/styles/mixin.scssindex e7b9d1f5..1668ff36 100644--- a/src/app/styles/mixin.scss+++ b/src/app/styles/mixin.scss@@ -49,6 +49,7 @@-webkit-box-orient: vertical;-webkit-line-clamp: $line;overflow: hidden;+ text-overflow: ellipsis;}@mixin triangle-indicator($size: 12px, $color: #fff, $active-color: var(--colorPrimary5), $border-width: 1px) {