feat(web): Unified frontend code style (#1923)

Co-authored-by: Fangyin Cheng <staneyffer@gmail.com>
Co-authored-by: 谨欣 <echo.cmy@antgroup.com>
Co-authored-by: 严志勇 <yanzhiyong@tiansuixiansheng.com>
Co-authored-by: yanzhiyong <932374019@qq.com>
This commit is contained in:
Dreammy23
2024-08-30 14:03:06 +08:00
committed by GitHub
parent f866580703
commit 471689ba20
247 changed files with 4960 additions and 4546 deletions

View File

@@ -1,38 +1,36 @@
import { UserInfoResponse } from '@/types/userinfo';
import { STORAGE_USERINFO_KEY } from '@/utils/constants/index';
import { LogoutOutlined } from '@ant-design/icons';
import { Avatar, Dropdown, Space } from 'antd';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Avatar } from 'antd';
import cls from 'classnames';
function UserBar({ onlyAvatar = false }) {
const { t } = useTranslation();
import { useEffect, useState } from 'react';
function UserBar({ onlyAvatar = false }) {
const [userInfo, setUserInfo] = useState<UserInfoResponse>();
useEffect(() => {
try {
const user = JSON.parse(localStorage.getItem(STORAGE_USERINFO_KEY) ?? '');
setUserInfo(user);
} catch (error) {
} catch {
return undefined;
}
}, []);
const logout = () => {
localStorage.removeItem(STORAGE_USERINFO_KEY);
window.location.href = `${process.env.LOGOUT_URL}&goto=${encodeURIComponent(window.location.href)}`;
};
// TODO: delete unused function
// const logout = () => {
// localStorage.removeItem(STORAGE_USERINFO_KEY);
// window.location.href = `${process.env.LOGOUT_URL}&goto=${encodeURIComponent(window.location.href)}`;
// };
return (
<div className="flex flex-1 items-center justify-center">
<div className='flex flex-1 items-center justify-center'>
<div
className={cls('flex items-center group w-full', {
'justify-center': onlyAvatar,
'justify-between': !onlyAvatar,
})}
>
<span className="flex gap-2 items-center">
<Avatar src={userInfo?.avatar_url} className="bg-gradient-to-tr from-[#31afff] to-[#1677ff] cursor-pointer">
<span className='flex gap-2 items-center'>
<Avatar src={userInfo?.avatar_url} className='bg-gradient-to-tr from-[#31afff] to-[#1677ff] cursor-pointer'>
{userInfo?.nick_name}
</Avatar>
<span