chore: init bj_power monorepo (dashboard/mes/wms/wms_client/workstation), clear subproject git metadata and align naming to folder names
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
import React, { useState } from 'react'
|
||||
import { NavLink } from 'react-router-dom'
|
||||
import { IconMoon, IconSun, IconUser } from '@douyinfe/semi-icons'
|
||||
import {
|
||||
Avatar,
|
||||
Button,
|
||||
Dropdown,
|
||||
Nav,
|
||||
Select,
|
||||
Space,
|
||||
Tooltip
|
||||
} from '@douyinfe/semi-ui'
|
||||
import { DropDownMenuItem } from '@douyinfe/semi-ui/lib/es/dropdown'
|
||||
import { useNavigate } from 'react-router'
|
||||
import { useLocale } from '@/locales'
|
||||
import useLocalStore from '@/stores/local'
|
||||
import useGlobalStore from '@/stores'
|
||||
import PasswordChangeModal from '@/components/change-password'
|
||||
import Logo from '@/assets/logo.png'
|
||||
import { useLoginApi } from '@/api/login'
|
||||
|
||||
export default () => {
|
||||
const navigate = useNavigate()
|
||||
const { formatMessage } = useLocale()
|
||||
|
||||
const { userInfo, clear, isDark, locale, setDark, changeLocale } =
|
||||
useLocalStore(state => state)
|
||||
const { connected } = useGlobalStore(state => state)
|
||||
const loginApi = useLoginApi()
|
||||
|
||||
const [isPasswordModalVisible, setIsPasswordModalVisible] = useState(false) // 添加状态管理
|
||||
|
||||
const switchMode = () => {
|
||||
setDark(!isDark)
|
||||
}
|
||||
|
||||
const switchLocale = (value: any) => {
|
||||
changeLocale(value)
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
// 业务影响:退出登录时通知后端删除 refresh token,防止 token 被复用
|
||||
loginApi.signOut({}).catch(() => {})
|
||||
clear()
|
||||
navigate('/login')
|
||||
}
|
||||
|
||||
const handlePasswordChange = () => {
|
||||
console.log('密码已更改')
|
||||
setIsPasswordModalVisible(false) // 关闭模态框
|
||||
}
|
||||
|
||||
const menu: DropDownMenuItem[] = [
|
||||
{
|
||||
node: 'title',
|
||||
name: userInfo?.name
|
||||
},
|
||||
{
|
||||
node: 'item',
|
||||
icon: null,
|
||||
name: formatMessage({ id: 'app.user.profile' }),
|
||||
type: 'primary',
|
||||
onClick: () => navigate('/profile')
|
||||
},
|
||||
{
|
||||
node: 'item',
|
||||
icon: null,
|
||||
name: formatMessage({ id: 'app.user.settings.change.password' }),
|
||||
type: 'primary',
|
||||
onClick: () => setIsPasswordModalVisible(true) // 显示模态框
|
||||
},
|
||||
{ node: 'divider' },
|
||||
{
|
||||
node: 'item',
|
||||
icon: null,
|
||||
name: formatMessage({ id: 'app.sign.out' }),
|
||||
type: 'danger',
|
||||
onClick: logout
|
||||
}
|
||||
]
|
||||
|
||||
return (
|
||||
<Nav mode="horizontal" style={{ paddingLeft: '10px' }}>
|
||||
<Nav.Header
|
||||
logo={<img src={Logo} alt={'首页'} />}
|
||||
text={
|
||||
<svg
|
||||
width="300"
|
||||
height="50"
|
||||
style={{ color: 'var(--semi-color-text-0)', fontSize: '20px' }}
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<filter id="filter">
|
||||
{/*<feGaussianBlur in="SourceGraphic" stdDeviation="0.5" />*/}
|
||||
<feOffset dx="5" dy="5" />
|
||||
</filter>
|
||||
<text
|
||||
filter="url(#filter)"
|
||||
x="10"
|
||||
y={'45%'}
|
||||
height={'100%'}
|
||||
dominantBaseline="middle"
|
||||
fill={
|
||||
connected
|
||||
? 'var(--semi-color-text-0)'
|
||||
: 'var(--semi-color-text-1)'
|
||||
}
|
||||
// stroke="green"
|
||||
fontSize="20">
|
||||
{import.meta.env.VITE_APP_TITLE}
|
||||
</text>
|
||||
</svg>
|
||||
}
|
||||
/>
|
||||
<Nav.Footer>
|
||||
<Space>
|
||||
<Tooltip
|
||||
position={'bottom'}
|
||||
content={formatMessage({
|
||||
id: isDark ? 'app.mode.light' : 'app.mode.dark'
|
||||
})}>
|
||||
<div>
|
||||
<Button
|
||||
theme="borderless"
|
||||
icon={
|
||||
isDark ? <IconSun size="large" /> : <IconMoon size="large" />
|
||||
}
|
||||
style={{
|
||||
color: 'var(--semi-color-text-2)'
|
||||
}}
|
||||
onClick={switchMode}
|
||||
/>
|
||||
</div>
|
||||
</Tooltip>
|
||||
<Select onChange={switchLocale} defaultValue={locale}>
|
||||
<Select.Option value="zh-CN">简体中文</Select.Option>
|
||||
<Select.Option value="en-US">English</Select.Option>
|
||||
</Select>
|
||||
{userInfo ? (
|
||||
<Dropdown trigger={'click'} position={'bottomRight'} menu={menu}>
|
||||
<span>
|
||||
<Avatar size="small" src={userInfo?.avatar}>
|
||||
<IconUser />
|
||||
</Avatar>
|
||||
</span>
|
||||
</Dropdown>
|
||||
) : (
|
||||
<NavLink to={'/login'}>
|
||||
<Button>登录</Button>
|
||||
</NavLink>
|
||||
)}
|
||||
</Space>
|
||||
</Nav.Footer>
|
||||
<PasswordChangeModal
|
||||
visible={isPasswordModalVisible}
|
||||
onCancel={() => setIsPasswordModalVisible(false)}
|
||||
onOk={handlePasswordChange}
|
||||
/>
|
||||
</Nav>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user