暂存,修改navigate和添加图片

This commit is contained in:
2024-10-12 12:38:19 +08:00
parent 929aaebf20
commit 3eaa94eb46
29 changed files with 244 additions and 58 deletions

View File

@@ -1,2 +1,4 @@
export * from './query';
export * from './deck-to-flow/deck';
export * from './navicate';

View File

@@ -16,14 +16,14 @@ import {
SwitcherOutlined,
UserOutlined,
} from '@ant-design/icons';
import { useNavigate } from 'react-router';
import { useMemo } from 'react';
import { query } from '../query';
import { useNewNavigate } from '../navicate';
const meun = [
{
title: 'Your profile',
icon: <HomeOutlined />,
link: '/map',
link: '/user/profile',
},
{
title: 'Your orgs',
@@ -45,7 +45,7 @@ export const LayoutUser = () => {
switchOrg: state.switchOrg,
})),
);
const navigate = useNavigate();
const navigate = useNewNavigate();
const items = useMemo(() => {
const orgs = store.me?.orgs || [];
return orgs.map((item) => {
@@ -91,6 +91,7 @@ export const LayoutUser = () => {
onClick={() => {
if (item.link) {
navigate(item.link);
setOpen(false);
} else {
message.info('Coming soon');
}

View File

@@ -15,7 +15,7 @@ import {
SmileOutlined,
SwitcherOutlined,
} from '@ant-design/icons';
import { useNavigate } from 'react-router';
import { useNewNavigate } from '../navicate';
const meun = [
{
title: 'Home',
@@ -69,7 +69,7 @@ const meun = [
];
export const LayoutMenu = () => {
const { open, setOpen } = useLayoutStore(useShallow((state) => ({ open: state.open, setOpen: state.setOpen })));
const navigate = useNavigate();
const navigate = useNewNavigate();
return (
<div className={clsx('w-full h-full absolute z-20', !open && 'hidden')}>
<div

View File

@@ -7,6 +7,7 @@ import { useLayoutStore } from './store';
import { useShallow } from 'zustand/react/shallow';
import { useEffect } from 'react';
import { LayoutUser } from './LayoutUser';
import PandaPNG from '@/assets/panda.png';
type LayoutMainProps = {
title?: React.ReactNode;
@@ -52,7 +53,13 @@ export const LayoutMain = (props: LayoutMainProps) => {
</Tooltip>
</div>
)}
<div className='w-8 h-8 rounded-full bg-blue-200 avatar cursor-pointer' onClick={() => menuStore.setOpenUser(true)}></div>
<div className='w-8 h-8 rounded-full avatar cursor-pointer' onClick={() => menuStore.setOpenUser(true)}>
{menuStore.me?.avatar ? (
<img className='w-8 h-8 rounded-full' src={menuStore.me?.avatar} alt='avatar' />
) : (
<img className='w-8 h-8 rounded-full' src={PandaPNG} alt='avatar' />
)}
</div>
<div className='cursor-pointer' onClick={() => menuStore.setOpenUser(true)}>
{menuStore.me?.username}
</div>

View File

@@ -10,6 +10,7 @@ type Me = {
description?: string;
type?: 'user' | 'org';
orgs?: string[];
avatar?: string;
};
export type LayoutStore = {
open: boolean;

12
src/modules/navicate.ts Normal file
View File

@@ -0,0 +1,12 @@
import { NavigateFunction, To, useNavigate } from 'react-router-dom';
/**
* 如果有basepath刚好给path加上basepath
* @returns NavigateFunction
*/
export const useNewNavigate = (): NavigateFunction => {
const navigate = useNavigate();
const fn = (path: To, data?: any) => {
navigate(path, data);
};
return fn as NavigateFunction;
};

View File

@@ -1,5 +1,4 @@
import { Query, QueryClient } from '@kevisual/query';
import { QueryWs } from '@kevisual/query/ws';
import { QueryClient } from '@kevisual/query';
import { modal } from './redirect-to-login';
import { create } from 'zustand';
import { message } from 'antd';
@@ -25,10 +24,8 @@ query.afterResponse = async (res) => {
return res;
};
export const request = query.post;
export const queryWs = new QueryWs({
url: '/api/router',
});
export const ws = queryWs.ws;
export const ws = query.qws.ws;
type Store = {
connected: boolean;
setConnected: (connected: boolean) => void;