diff --git a/src/admin-page/user-manage/edit/List.tsx b/src/admin-page/user-manage/edit/List.tsx
index b295fba..9654749 100644
--- a/src/admin-page/user-manage/edit/List.tsx
+++ b/src/admin-page/user-manage/edit/List.tsx
@@ -3,7 +3,6 @@ import { Fragment, useEffect, useMemo, useState } from 'react';
import { useUserStore } from '../store';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
-import { useNavigate } from 'react-router';
import { EditOutlined, SettingOutlined, LinkOutlined, SaveOutlined, DeleteOutlined, LeftOutlined, PlusOutlined } from '@ant-design/icons';
import clsx from 'clsx';
import { isObjectNull } from '@/utils/is-null';
@@ -80,7 +79,6 @@ const FormModal = () => {
);
};
export const List = () => {
- const navicate = useNavigate();
const userStore = useUserStore(
useShallow((state) => {
return {
diff --git a/src/assets/panda.png b/src/assets/panda.png
new file mode 100644
index 0000000..c1e67f6
Binary files /dev/null and b/src/assets/panda.png differ
diff --git a/src/index.css b/src/index.css
index 766953e..f23714c 100644
--- a/src/index.css
+++ b/src/index.css
@@ -40,4 +40,7 @@ body {
&::-webkit-scrollbar-corner {
display: block; /* 修复交汇时出现的白块 */
}
+}
+.kv-container.active {
+ background: #ebe9e987 !important;
}
\ No newline at end of file
diff --git a/src/modules/index.ts b/src/modules/index.ts
index 1416ff0..9146ec5 100644
--- a/src/modules/index.ts
+++ b/src/modules/index.ts
@@ -1,2 +1,4 @@
export * from './query';
export * from './deck-to-flow/deck';
+
+export * from './navicate';
\ No newline at end of file
diff --git a/src/modules/layout/LayoutUser.tsx b/src/modules/layout/LayoutUser.tsx
index 25efc34..350bfbe 100644
--- a/src/modules/layout/LayoutUser.tsx
+++ b/src/modules/layout/LayoutUser.tsx
@@ -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: ,
- 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');
}
diff --git a/src/modules/layout/Menu.tsx b/src/modules/layout/Menu.tsx
index ff1240a..4fafaeb 100644
--- a/src/modules/layout/Menu.tsx
+++ b/src/modules/layout/Menu.tsx
@@ -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 (
{
)}
-
menuStore.setOpenUser(true)}>
+
menuStore.setOpenUser(true)}>
+ {menuStore.me?.avatar ? (
+

+ ) : (
+

+ )}
+
menuStore.setOpenUser(true)}>
{menuStore.me?.username}
diff --git a/src/modules/layout/store/index.ts b/src/modules/layout/store/index.ts
index 43a5443..fc82606 100644
--- a/src/modules/layout/store/index.ts
+++ b/src/modules/layout/store/index.ts
@@ -10,6 +10,7 @@ type Me = {
description?: string;
type?: 'user' | 'org';
orgs?: string[];
+ avatar?: string;
};
export type LayoutStore = {
open: boolean;
diff --git a/src/modules/navicate.ts b/src/modules/navicate.ts
new file mode 100644
index 0000000..b7f4dfa
--- /dev/null
+++ b/src/modules/navicate.ts
@@ -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;
+};
diff --git a/src/modules/query.ts b/src/modules/query.ts
index 38f14da..01b90f2 100644
--- a/src/modules/query.ts
+++ b/src/modules/query.ts
@@ -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;
diff --git a/src/pages/ai-agent/edit/List.tsx b/src/pages/ai-agent/edit/List.tsx
index 6da90e3..b27d271 100644
--- a/src/pages/ai-agent/edit/List.tsx
+++ b/src/pages/ai-agent/edit/List.tsx
@@ -4,7 +4,6 @@ import { useEffect } from 'react';
import { CardBlank } from '@/components/card/CardBlank';
import { Button, Form, Input, message, Modal, Tooltip } from 'antd';
import copy from 'copy-to-clipboard';
-import { useNavigate } from 'react-router';
import { EditOutlined, SettingOutlined, LinkOutlined, SaveOutlined, DeleteOutlined, LeftOutlined, CaretRightOutlined } from '@ant-design/icons';
import clsx from 'clsx';
import { isObjectNull } from '@/utils/is-null';
diff --git a/src/pages/ai-chat/AiModule.tsx b/src/pages/ai-chat/AiModule.tsx
index 5d27f9c..4934790 100644
--- a/src/pages/ai-chat/AiModule.tsx
+++ b/src/pages/ai-chat/AiModule.tsx
@@ -5,11 +5,11 @@ import { Button, Dropdown, Form, Input, message, Modal, Tooltip } from 'antd';
import { useEffect, useLayoutEffect, useMemo, useState } from 'react';
import { TextArea } from '../container/components/TextArea';
import clsx from 'clsx';
-import { query } from '@/modules';
+import { query, useNewNavigate } from '@/modules';
import { nanoid } from 'nanoid';
import { ChatMessage } from './module/ChatMessage';
import { isObjectNull } from '@/utils/is-null';
-import { useLocation, useNavigate } from 'react-router';
+import { useLocation } from 'react-router';
const testId = '60aca66b-4be9-4266-9568-6001032c7e13';
const NormalMessage = ({ onSend }: { onSend: any }) => {
const [message, setMessage] = useState('');
@@ -173,7 +173,7 @@ export const useListenQuery = () => {
export const AiMoudle = () => {
const [form] = Form.useForm();
- const navigate = useNavigate();
+ const navigate = useNewNavigate();
const aiStore = useAiStore(
useShallow((state) => {
return {
diff --git a/src/pages/app/edit/AppVersionList.tsx b/src/pages/app/edit/AppVersionList.tsx
index 5250c52..fd2718f 100644
--- a/src/pages/app/edit/AppVersionList.tsx
+++ b/src/pages/app/edit/AppVersionList.tsx
@@ -5,9 +5,9 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { Button, Form, Input, Modal, Tooltip } from 'antd';
import { CloudUploadOutlined, DeleteOutlined, EditOutlined, FileOutlined, LeftOutlined, PlusOutlined } from '@ant-design/icons';
import { isObjectNull } from '@/utils/is-null';
-import { useNavigate } from 'react-router';
import { FileUpload } from '../modules/FileUpload';
import clsx from 'clsx';
+import { useNewNavigate } from '@/modules';
const FormModal = () => {
const [form] = Form.useForm();
const containerStore = useAppVersionStore(
@@ -98,7 +98,7 @@ export const AppVersionList = () => {
};
}),
);
- const navigate = useNavigate();
+ const navigate = useNewNavigate();
const [isUpload, setIsUpload] = useState(false);
useEffect(() => {
// fetch app version list
diff --git a/src/pages/app/edit/List.tsx b/src/pages/app/edit/List.tsx
index c0f726c..6bf2f02 100644
--- a/src/pages/app/edit/List.tsx
+++ b/src/pages/app/edit/List.tsx
@@ -4,8 +4,8 @@ import { useEffect } from 'react';
import { Button, Form, Input, message, Modal, Select, Tooltip } from 'antd';
import { CodeOutlined, DashboardOutlined, DeleteOutlined, EditOutlined, LinkOutlined, PlusOutlined, UnorderedListOutlined } from '@ant-design/icons';
import { isObjectNull } from '@/utils/is-null';
-import { useNavigate } from 'react-router';
import { FileUpload } from '../modules/FileUpload';
+import { useNewNavigate } from '@/modules';
const FormModal = () => {
const [form] = Form.useForm();
const containerStore = useUserAppStore(
@@ -104,7 +104,7 @@ export const List = () => {
};
}),
);
- const navicate = useNavigate();
+ const navicate = useNewNavigate();
useEffect(() => {
userAppStore.getList();
}, []);
diff --git a/src/pages/code-editor/edit/Edit.tsx b/src/pages/code-editor/edit/Edit.tsx
index 2c33e88..eaaa56c 100644
--- a/src/pages/code-editor/edit/Edit.tsx
+++ b/src/pages/code-editor/edit/Edit.tsx
@@ -1,18 +1,19 @@
import { createEditorInstance, editor } from '@kevisual/codemirror/dist/editor.json';
import { useEffect, useRef, useLayoutEffect, useState, useCallback } from 'react';
-import { useLocation, useNavigate } from 'react-router';
+import { useLocation } from 'react-router';
import { useCodeEditorStore, ParseData } from '../store';
import { Button, message, Tooltip } from 'antd';
import { LeftOutlined, MessageOutlined, SaveOutlined } from '@ant-design/icons';
import { useAiStore } from '@/pages/ai-chat';
import { useShallow } from 'zustand/react/shallow';
+import { useNewNavigate } from '@/modules';
export const App = () => {
const ref = useRef
(null);
const editorRef = useRef(null);
const location = useLocation();
const store = useCodeEditorStore();
const [mounted, setMounted] = useState(false);
- const navigator = useNavigate();
+ const navigator = useNewNavigate();
const aiStore = useAiStore(
useShallow((state) => {
return {
diff --git a/src/pages/code-editor/hooks/use-to-code-editor.ts b/src/pages/code-editor/hooks/use-to-code-editor.ts
index 060c53e..4e25cea 100644
--- a/src/pages/code-editor/hooks/use-to-code-editor.ts
+++ b/src/pages/code-editor/hooks/use-to-code-editor.ts
@@ -1,7 +1,7 @@
-import { useNavigate } from 'react-router';
+import { useNewNavigate } from '@/modules';
import { ParseData } from '../store';
export const useToCodeEditor = () => {
- const navigate = useNavigate();
+ const navigate = useNewNavigate();
const toPage = (pathKey: ParseData['updatePath'], data: ParseData['data']) => {
navigate('/code-editor', {
state: {
diff --git a/src/pages/container/edit/List.tsx b/src/pages/container/edit/List.tsx
index e387ee1..1909ab7 100644
--- a/src/pages/container/edit/List.tsx
+++ b/src/pages/container/edit/List.tsx
@@ -5,7 +5,7 @@ import { useContainerStore } from '../store';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
import copy from 'copy-to-clipboard';
-import { useNavigate } from 'react-router';
+import { useNewNavigate } from '@/modules';
import {
EditOutlined,
SettingOutlined,
@@ -98,7 +98,7 @@ const FormModal = () => {
);
};
export const ContainerList = () => {
- const navicate = useNavigate();
+ const navicate = useNewNavigate();
const containerStore = useContainerStore(
useShallow((state) => {
return {
diff --git a/src/pages/map/index.tsx b/src/pages/map/index.tsx
index 7f0a7a0..8f36839 100644
--- a/src/pages/map/index.tsx
+++ b/src/pages/map/index.tsx
@@ -1,5 +1,5 @@
import clsx from 'clsx';
-import { useNavigate } from 'react-router-dom';
+import { useNewNavigate } from '@/modules';
const serverList = ['container', 'panel', 'publish', 'code-editor', 'map', 'ai-chat'];
const serverPath = [
{
@@ -44,7 +44,7 @@ const serverPath = [
},
];
const ServerPath = () => {
- const navigate = useNavigate();
+ const navigate = useNewNavigate();
return (
Site Map
diff --git a/src/pages/org/edit/List.tsx b/src/pages/org/edit/List.tsx
index 7e6446f..1bae437 100644
--- a/src/pages/org/edit/List.tsx
+++ b/src/pages/org/edit/List.tsx
@@ -3,7 +3,7 @@ import { Fragment, useEffect, useMemo, useState } from 'react';
import { useOrgStore } from '../store';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
-import { useNavigate } from 'react-router';
+import { useNewNavigate } from '@/modules';
import {
EditOutlined,
SettingOutlined,
@@ -91,7 +91,7 @@ const FormModal = () => {
);
};
export const List = () => {
- const navicate = useNavigate();
+ const navicate = useNewNavigate();
const userStore = useOrgStore(
useShallow((state) => {
return {
diff --git a/src/pages/org/edit/UserList.tsx b/src/pages/org/edit/UserList.tsx
index 2864468..3e44659 100644
--- a/src/pages/org/edit/UserList.tsx
+++ b/src/pages/org/edit/UserList.tsx
@@ -5,7 +5,7 @@ import { useEffect } from 'react';
import { Button, Input, message, Modal, Select, Tooltip } from 'antd';
import { DeleteOutlined, EditOutlined, LeftOutlined, PlusOutlined } from '@ant-design/icons';
import { Form } from 'antd';
-import { useNavigate } from 'react-router';
+import { useNewNavigate } from '@/modules';
import { isObjectNull } from '@/utils/is-null';
const FormModal = () => {
@@ -90,7 +90,7 @@ const FormModal = () => {
export const UserList = () => {
const param = useParams();
- const navicate = useNavigate();
+ const navicate = useNewNavigate();
const orgStore = useOrgStore(
useShallow((state) => {
return {
diff --git a/src/pages/panel/deck/deck-store.ts b/src/pages/panel/deck/deck-store.ts
index 7101cb8..6c39942 100644
--- a/src/pages/panel/deck/deck-store.ts
+++ b/src/pages/panel/deck/deck-store.ts
@@ -10,6 +10,8 @@ type DeckPageStore = {
loading: boolean;
setLoading: (loading: boolean) => void;
pageData: any[];
+ cids: string[];
+ setCids: () => void;
setPageData: (data: any[]) => void;
getPageData: () => any[];
selected: any;
@@ -57,4 +59,12 @@ export const useDeckPageStore = create
((set, get) => ({
getCode: () => {
return get().code;
},
+ cids: [],
+ setCids: () => {
+ const pageData = get().pageData;
+ const cids = pageData.map((item) => item.codeId).filter((item) => item);
+ // cids 去重复
+ const newCids = Array.from(new Set(cids));
+ set({ cids: newCids });
+ },
}));
diff --git a/src/pages/panel/deck/index.tsx b/src/pages/panel/deck/index.tsx
index 3773c20..0ae0796 100644
--- a/src/pages/panel/deck/index.tsx
+++ b/src/pages/panel/deck/index.tsx
@@ -22,12 +22,14 @@ export const clearBlank = (newStyle: any) => {
return change;
};
export const useListener = (id?: string, opts?: any) => {
- const { refresh } = opts || {};
+ const { refresh, cids = [] } = opts || {};
const connected = useStore((state) => state.connected);
// 监听服务器的消息
useEffect(() => {
if (!id) return;
if (!connected) return;
+ if (cids.length === 0) return;
+ console.log('cids', cids);
ws.send(
JSON.stringify({
type: 'subscribe',
@@ -35,7 +37,7 @@ export const useListener = (id?: string, opts?: any) => {
type: 'pageEdit',
data: {
pid: id,
- cids: ['170c0b55-8c13-4d6e-bf35-3f935d979a0d'],
+ cids: cids,
},
},
}),
@@ -46,7 +48,7 @@ export const useListener = (id?: string, opts?: any) => {
if (!connected) return;
ws.removeEventListener('message', listener);
};
- }, [id, connected]);
+ }, [id, connected, cids]);
const listener = (event) => {
const parseIfJson = (data: string) => {
try {
@@ -66,17 +68,6 @@ export const useListener = (id?: string, opts?: any) => {
}
};
};
-const getParent = (data: { children?: string[]; [key: string]: any }[], id: string, list: string[]) => {
- for (let item of data) {
- if (item.children?.includes(id)) {
- // 找到了当前的父亲节点
- list.unshift(item.id);
- getParent(data, item.id, list);
- return;
- }
- }
- return;
-};
export const Deck = () => {
const params = useParams<{ id: string }>();
@@ -86,6 +77,7 @@ export const Deck = () => {
const deckPageStore = useDeckPageStore();
const { code, setCode } = deckPageStore;
const { selected, setSelected } = deckPageStore;
+ const { cids } = deckPageStore;
const aiStore = useAiStore(
useShallow((state) => {
return {
@@ -129,6 +121,7 @@ export const Deck = () => {
const result = getContainerData({ page, containerList });
console.log('result', result);
deckPageStore.setPageData(result);
+ deckPageStore.setCids();
init(result);
}
};
@@ -149,12 +142,12 @@ export const Deck = () => {
});
// container.reRender();
containerList.forEach((item) => {
- container.hotReload(item.id);
+ container.renderId(item.id);
});
// @ts-ignore
window.c = container;
};
- useListener(id, { refresh });
+ useListener(id, { refresh, cids });
const onContainer = (e) => {
const { data } = e;
const types = ['position', 'resize'];
diff --git a/src/pages/panel/edit/List.tsx b/src/pages/panel/edit/List.tsx
index beb80a0..792eea7 100644
--- a/src/pages/panel/edit/List.tsx
+++ b/src/pages/panel/edit/List.tsx
@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
import copy from 'copy-to-clipboard';
-import { useNavigate } from 'react-router';
+import { useNewNavigate } from '@/modules';
import { useToCodeEditor } from '@/pages/code-editor';
import { CardBlank } from '@/components/card/CardBlank';
import {
@@ -103,7 +103,7 @@ const FormModal = () => {
);
};
export const List = () => {
- const navicate = useNavigate();
+ const navicate = useNewNavigate();
const toCodeEditor = useToCodeEditor();
const editStore = useEditStore(
useShallow((state) => {
diff --git a/src/pages/prompt/edit/List.tsx b/src/pages/prompt/edit/List.tsx
index c5b7e64..43f4c79 100644
--- a/src/pages/prompt/edit/List.tsx
+++ b/src/pages/prompt/edit/List.tsx
@@ -4,7 +4,7 @@ import { usePromptStore } from '../store/prompt';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
import copy from 'copy-to-clipboard';
-import { useNavigate } from 'react-router';
+import { useNewNavigate } from '@/modules';
import { EditOutlined, SettingOutlined, LinkOutlined, SaveOutlined, DeleteOutlined, LeftOutlined, CaretRightOutlined, PlusOutlined } from '@ant-design/icons';
import clsx from 'clsx';
import { TextArea } from '@/pages/container/components/TextArea';
@@ -104,7 +104,7 @@ const FormModal = () => {
);
};
export const List = () => {
- const navicate = useNavigate();
+ const navicate = useNewNavigate();
const aiStore = useAiStore(
useShallow((state) => {
return {
diff --git a/src/pages/publish/edit/List.tsx b/src/pages/publish/edit/List.tsx
index 9f3c45a..a1d5973 100644
--- a/src/pages/publish/edit/List.tsx
+++ b/src/pages/publish/edit/List.tsx
@@ -4,7 +4,7 @@ import { usePublishStore } from '../store';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
import copy from 'copy-to-clipboard';
-import { useNavigate } from 'react-router';
+import { useNewNavigate } from '@/modules';
const FormModal = () => {
const [form] = Form.useForm();
const containerStore = usePublishStore(
@@ -70,7 +70,7 @@ const FormModal = () => {
);
};
export const List = () => {
- const navicate = useNavigate();
+ const navicate = useNewNavigate();
const containerStore = usePublishStore(
useShallow((state) => {
return {
diff --git a/src/pages/user/edit/List.tsx b/src/pages/user/edit/List.tsx
index b295fba..8f97a78 100644
--- a/src/pages/user/edit/List.tsx
+++ b/src/pages/user/edit/List.tsx
@@ -3,7 +3,7 @@ import { Fragment, useEffect, useMemo, useState } from 'react';
import { useUserStore } from '../store';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
-import { useNavigate } from 'react-router';
+import { useNewNavigate } from '@/modules';
import { EditOutlined, SettingOutlined, LinkOutlined, SaveOutlined, DeleteOutlined, LeftOutlined, PlusOutlined } from '@ant-design/icons';
import clsx from 'clsx';
import { isObjectNull } from '@/utils/is-null';
@@ -80,7 +80,7 @@ const FormModal = () => {
);
};
export const List = () => {
- const navicate = useNavigate();
+ const navicate = useNewNavigate();
const userStore = useUserStore(
useShallow((state) => {
return {
diff --git a/src/pages/user/edit/Profile.tsx b/src/pages/user/edit/Profile.tsx
new file mode 100644
index 0000000..22120ba
--- /dev/null
+++ b/src/pages/user/edit/Profile.tsx
@@ -0,0 +1,92 @@
+import { Form, Input } from 'antd';
+import { useUserStore } from '../store';
+import { useEffect } from 'react';
+import { useShallow } from 'zustand/react/shallow';
+import { isObjectNull } from '@/utils/is-null';
+import { useLayoutStore } from '@/modules/layout/store';
+import { AvatarUpload } from '../module/AvatarUpload';
+import { UploadOutlined } from '@ant-design/icons';
+import PandaPNG from '@/assets/panda.png';
+export const Profile = () => {
+ const [form] = Form.useForm();
+ const userStore = useUserStore(
+ useShallow((state) => {
+ return {
+ showEdit: state.showEdit,
+ setShowEdit: state.setShowEdit,
+ formData: state.formData,
+ updateData: state.updateData,
+ setFormData: state.setFormData,
+ };
+ }),
+ );
+
+ const layoutStore = useLayoutStore(
+ useShallow((state) => {
+ return {
+ me: state.me,
+ };
+ }),
+ );
+ const avatar = layoutStore.me?.avatar;
+ useEffect(() => {
+ const fromData = layoutStore.me;
+ if (isObjectNull(fromData)) {
+ form.setFieldsValue({});
+ } else {
+ form.setFieldsValue(fromData);
+ }
+ console.log('fromData', fromData);
+ }, [layoutStore.me]);
+ return (
+
+
+
Profile
+
Edit your profile
+
+
+
+ {avatar &&

}
+ {!avatar &&

}
+
+
+
+
+
+
+
+
+ {
+ console.log('upload');
+ }}
+ />
+ }
+ />
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
diff --git a/src/pages/user/index.tsx b/src/pages/user/index.tsx
index 5d09c8e..e1e1214 100644
--- a/src/pages/user/index.tsx
+++ b/src/pages/user/index.tsx
@@ -2,12 +2,14 @@ import { Navigate, Route, Routes } from 'react-router-dom';
import { List } from './edit/List';
import { Main } from './layouts';
import { Login } from './login/Login';
+import { Profile } from './edit/Profile';
export const App = () => {
return (
}>
}>
} />
+ } />
} />
diff --git a/src/pages/user/module/AvatarUpload.tsx b/src/pages/user/module/AvatarUpload.tsx
new file mode 100644
index 0000000..285bf59
--- /dev/null
+++ b/src/pages/user/module/AvatarUpload.tsx
@@ -0,0 +1,68 @@
+import { useState } from 'react';
+import { LoadingOutlined, PlusOutlined } from '@ant-design/icons';
+import { Flex, message, Upload } from 'antd';
+import type { GetProp, UploadProps } from 'antd';
+
+type FileType = Parameters>[0];
+
+const getBase64 = (img: FileType, callback: (url: string) => void) => {
+ const reader = new FileReader();
+ reader.addEventListener('load', () => callback(reader.result as string));
+ reader.readAsDataURL(img);
+};
+
+const beforeUpload = (file: FileType) => {
+ const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
+ if (!isJpgOrPng) {
+ message.error('You can only upload JPG/PNG file!');
+ }
+ const isLt2M = file.size / 1024 / 1024 < 2;
+ if (!isLt2M) {
+ message.error('Image must smaller than 2MB!');
+ }
+ return isJpgOrPng && isLt2M;
+};
+
+export const AvatarUpload = () => {
+ const [loading, setLoading] = useState(false);
+ const [imageUrl, setImageUrl] = useState();
+
+ const handleChange: UploadProps['onChange'] = (info) => {
+ if (info.file.status === 'uploading') {
+ setLoading(true);
+ return;
+ }
+ if (info.file.status === 'done') {
+ // Get this url from response in real world.
+ getBase64(info.file.originFileObj as FileType, (url) => {
+ setLoading(false);
+ setImageUrl(url);
+ });
+ }
+ };
+
+ const uploadButton = (
+
+ );
+ const onAciton = async (file) => {
+ console.log('file', file);
+ return '';
+ };
+ return (
+
+
+ {imageUrl ?
: uploadButton}
+
+
+ );
+};