This commit is contained in:
2025-06-04 15:22:20 +08:00
parent 0b19ccb700
commit 56e3d08869
11 changed files with 177 additions and 15 deletions

View File

@@ -3,8 +3,8 @@ import { TextEditor } from '@kevisual/markdown-editor/tiptap/editor.ts';
import { Select } from '@/components/a/select.tsx';
import { useEffect, useRef, useState } from 'react';
import { getSuggestionItems } from '../ai-chat/editor/suggestion/item';
import { html2md } from '@kevisual/markdown-editor/tiptap/index.ts';
import { chatId } from '../ai-chat/utils/uuid';
// import { html2md } from '@kevisual/markdown-editor/tiptap/index.ts';
// import { chatId } from '../ai-chat/utils/uuid';
import '../ai-chat/index.css';
import { links } from './data/link.ts';
// const testImport = async () => {
@@ -44,6 +44,10 @@ export const App = (props: any) => {
return (
<div className='w-full h-full flex flex-col'>
<ShowLinks links={links} />
<div>
<i>登陆的demo账号: demo 密码为: 123456 </i>
</div>
</div>
);
};

81
src/apps/layout/index.tsx Normal file
View File

@@ -0,0 +1,81 @@
import { Layout, Header } from '@/components/b/layouts/main/layout';
import { basename } from '@/modules/basename';
import { queryLogin } from '@/modules/query';
import { useEffect, useState } from 'react';
type Props = {
children?: React.ReactNode;
};
export const AppLayout = (props: Props) => {
return (
<Layout
header={
<Header
title={
<div
className='px-2 cursor-pointer'
onClick={() => {
const url = new URL(window.location.href);
const pathname = url.pathname;
if (pathname === basename + '/') {
return;
}
// 如果当前路径不是根路径,则跳转到根路径
location.href = basename + '/';
}}>
AI Generative
</div>
}
className='bg-background border-b border-b-gray-200 text-foreground'
right={<UserInfo />}
/>
}>
{props.children}
</Layout>
);
};
type User = Awaited<ReturnType<typeof queryLogin.checkLocalUser>>;
export const UserInfo = () => {
const [user, setUser] = useState<User | null>(null);
useEffect(() => {
init();
}, []);
const init = async () => {
const userInfo = await queryLogin.checkLocalUser();
const token = await queryLogin.getToken();
if (userInfo) {
setUser(userInfo);
} else if (token) {
const userinfo = await queryLogin.getLoginUserByToken(token);
if (userinfo) {
setUser(userinfo);
}
}
};
return (
<div className='flex items-center gap-2'>
{!user && (
<div
onClick={() => {
const currentUrl = new URL(window.location.href);
const loginUrl = '/user/login/';
if (currentUrl.pathname !== loginUrl) {
const newUrl = new URL(loginUrl, window.location.origin);
newUrl.searchParams.set('redirect', currentUrl.pathname + currentUrl.search);
location.href = newUrl.toString();
}
}}>
login
</div>
)}
{user && (
<>
<img src={user?.avatar || '/root/center/panda.jpg'} alt='User Avatar' className='w-8 h-8 rounded-full' />
<span className='text-sm text-gray-700'>{user?.username}</span>
</>
)}
</div>
);
};

View File

@@ -237,7 +237,7 @@ export const EditMark = () => {
}
return <div className='w-full h-full'></div>;
};
export const LayoutMain = (props: { children?: React.ReactNode; expandChildren?: React.ReactNode; open?: boolean }) => {
export const LayoutMain = (props: { children?: React.ReactNode; expandChildren?: React.ReactNode; open?: boolean; hasTopTitle?: boolean }) => {
const getDocumentHeight = () => {
return document.documentElement.scrollHeight;
};
@@ -261,13 +261,16 @@ export const LayoutMain = (props: { children?: React.ReactNode; expandChildren?:
const isEdit = !!markData;
const hasExpandChildren = !!props.expandChildren;
const style = useMemo(() => {
const top = props.hasTopTitle ? 70 : 0; // Adjust top based on whether there's a title
if (!hasExpandChildren || openMenu) {
return {};
return {
top,
};
}
return {
top: getDocumentHeight() / 2 + 10,
top: getDocumentHeight() / 2 + 10 + top,
};
}, [getDocumentHeight, hasExpandChildren, openMenu]);
}, [getDocumentHeight, hasExpandChildren, openMenu, props.hasTopTitle]);
return (
<div className='w-full h-full flex'>
<div className={clsx('absolute top-4 z-10', openMenu ? 'left-4' : '-left-4')} style={style}>
@@ -313,12 +316,13 @@ export type AppProps = {
children?: React.ReactNode;
showSelect?: boolean;
openMenu?: boolean;
hasTopTitle?: boolean; // 是否有顶部标题
};
export const ProviderManagerName = 'mark-manager';
export const App = (props: AppProps) => {
return (
<ManagerProvider id={props.managerId}>
<LayoutMain expandChildren={props.children} open={props.openMenu}>
<LayoutMain expandChildren={props.children} open={props.openMenu} hasTopTitle={props.hasTopTitle}>
<Manager
markType={props.markType}
showSearch={props.showSearch}