From 3ce56643c9258779c7c97aeab4878c835fe9deb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=A7=82=E4=BC=9F?= Date: Thu, 13 Feb 2025 19:04:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A8=E5=B9=BF=E5=A4=A7=E4=BD=BF?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=B7=BB=E5=8A=A0=E5=88=A4=E6=96=AD=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Header/index.tsx | 13 +++++- src/components/Header/loggedInView.tsx | 8 +++- src/components/Header/profilePanel.tsx | 60 +++++++++++++++----------- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index a2391ac..bd642e8 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -90,6 +90,7 @@ const Header = () => { const [selectEl, setSelectEl] = useState(null); const [toolList, setToolList] = useState(TOOLKIT_LIST); const [user, setUser] = useState(null); + const [promotionInfo, setPromotionInfo] = useState(null); const [keyword, setKeyword] = useState(''); const open = Boolean(anchorEl); @@ -113,6 +114,16 @@ const Header = () => { } }); }); + + fetch('/api/v1/promotion_ambassador/info', { + credentials: 'include', + }).then((res) => { + res.json().then((data) => { + if (data.code === 0) { + setPromotionInfo(data.data); + } + }); + }); }, []); const handleSearch = (k: string) => { @@ -441,7 +452,7 @@ const Header = () => { > 工作台 - + ) : ( <> diff --git a/src/components/Header/loggedInView.tsx b/src/components/Header/loggedInView.tsx index 818c89a..f39edae 100644 --- a/src/components/Header/loggedInView.tsx +++ b/src/components/Header/loggedInView.tsx @@ -8,7 +8,7 @@ export interface LoggedInProps { verified: boolean; } -const LoggedInView = ({ user }: any) => { +const LoggedInView = ({ user, promotionInfo }: any) => { return ( { }, }} title={ - + } > diff --git a/src/components/Header/profilePanel.tsx b/src/components/Header/profilePanel.tsx index 0d76b39..adaec44 100644 --- a/src/components/Header/profilePanel.tsx +++ b/src/components/Header/profilePanel.tsx @@ -12,7 +12,7 @@ import { ListItemText, ListItemIcon, } from '@mui/material'; -import React, { useCallback } from 'react'; +import React, { useCallback, useState, useEffect } from 'react'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import { Badge, @@ -25,33 +25,18 @@ import { SpaceIcon, OrderIcon, PersonIcon, - PromotionIcon, LogoutIcon, + PromotionIcon, } from './components'; import alert from '@/components/Alert'; export interface ProfilePanelProps { userInfo: any | null; verified: boolean; + promotionInfo?: any; } const ProfilePanel: React.FC = (props) => { - const { userInfo, verified } = props; - const handleLogout = () => { - fetch('/api/v1/user/signout', { - credentials: 'include', - }).then(() => { - window.location.reload(); - }); - }; - - const toLink = (link: string) => () => { - window.open(link, '_target'); - }; - - const onCopy = useCallback(() => { - alert.success('用户ID已复制到剪贴板'); - }, []); - + const { userInfo, verified, promotionInfo } = props; const OPT_LIST = [ { name: '个人中心', @@ -63,17 +48,42 @@ const ProfilePanel: React.FC = (props) => { icon: , link: '/console/space/base', }, - { - name: '推广大使', - icon: , - link: '/console/personal/promotion', - }, + { name: '订单管理', icon: , link: '/console/space/order', }, ]; + const [optList, setOptList] = useState([...OPT_LIST]); + const handleLogout = () => { + fetch('/api/v1/user/signout', { + credentials: 'include', + }).then(() => { + window.location.reload(); + }); + }; + + const toLink = (link: string) => () => { + window.open(link, '_target'); + }; + + const onCopy = useCallback(() => { + alert.success('用户ID已复制到剪贴板'); + }, []); + + useEffect(() => { + if (promotionInfo?.referral_code) { + if (optList.findIndex((item) => item.name === '推广大使') === -1) { + optList.splice(2, 0, { + name: '推广大使', + icon: , + link: '/console/personal/promotion', + }); + setOptList([...optList]); + } + } + }, [promotionInfo]); return ( @@ -173,7 +183,7 @@ const ProfilePanel: React.FC = (props) => { bgcolor: 'background.paper', }} > - {OPT_LIST.map((item) => { + {optList.map((item) => { return (