feat: 暂存添加ai chat and prompt generate
This commit is contained in:
38
src/pages/ai-chat/AiModule.tsx
Normal file
38
src/pages/ai-chat/AiModule.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useShallow } from 'zustand/react/shallow';
|
||||
import { useAiStore } from './store/ai-store';
|
||||
import { CloseOutlined } from '@ant-design/icons';
|
||||
import { Button } from 'antd';
|
||||
|
||||
export const AiMoudle = () => {
|
||||
const aiStore = useAiStore(
|
||||
useShallow((state) => {
|
||||
return {
|
||||
open: state.open,
|
||||
setOpen: state.setOpen,
|
||||
runAi: state.runAi,
|
||||
};
|
||||
}),
|
||||
);
|
||||
if (!aiStore.open) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<div className='w-96 flex-shrink-0 bg-gray-100 border-l-2 shadow-lg flex flex-col'>
|
||||
<div className='flex gap-4 bg-slate-400 p-2'>
|
||||
<Button className='position ml-4 !bg-slate-400 !border-black' onClick={() => aiStore.setOpen(false)} icon={<CloseOutlined />}></Button>
|
||||
<h1 className='ml-10'>Ai Moudle</h1>
|
||||
</div>
|
||||
<div className='flex-grow p-2'>
|
||||
<div> chat message</div>
|
||||
<div>
|
||||
<Button
|
||||
onClick={() => {
|
||||
aiStore.runAi();
|
||||
}}>
|
||||
Send
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
7
src/pages/ai-chat/index.tsx
Normal file
7
src/pages/ai-chat/index.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
import { AiMoudle } from './AiModule';
|
||||
import { useAiStore } from './store/ai-store';
|
||||
export { AiMoudle, useAiStore };
|
||||
|
||||
export const App = () => {
|
||||
return <div>AI Chat</div>;
|
||||
};
|
||||
58
src/pages/ai-chat/store/ai-store.ts
Normal file
58
src/pages/ai-chat/store/ai-store.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { query } from '@/modules';
|
||||
import { message } from 'antd';
|
||||
import { create } from 'zustand';
|
||||
|
||||
export type AiStore = {
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
type?: string;
|
||||
key: string;
|
||||
setKey: (key: string) => void;
|
||||
setType?: (type: string) => void;
|
||||
sendMsg: (msg: string) => void;
|
||||
formData: any;
|
||||
setFormData: (data: any) => void;
|
||||
runAi: () => any;
|
||||
title: string;
|
||||
setTitle: (title: string) => void;
|
||||
};
|
||||
|
||||
export const useAiStore = create<AiStore>((set, get) => {
|
||||
return {
|
||||
open: false,
|
||||
setOpen: (open) => set({ open }),
|
||||
key: '',
|
||||
setKey: (key) => set({ key }),
|
||||
sendMsg: (msg) => {
|
||||
console.log(msg);
|
||||
},
|
||||
formData: {},
|
||||
setFormData: (data) => set({ formData: data }),
|
||||
runAi: async () => {
|
||||
const { formData } = get();
|
||||
const res = await query.post({
|
||||
path: 'ai',
|
||||
key: 'run',
|
||||
data: {
|
||||
key: formData.key,
|
||||
inputs: [
|
||||
{
|
||||
key: 'title',
|
||||
value: '根据描述生成代码',
|
||||
},
|
||||
{
|
||||
key: 'description',
|
||||
value: '我想获取一个card, 包含标题和内容,标题是evision,内容是这是一个测试',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
if (res.code === 200) {
|
||||
console.log(res.data);
|
||||
message.success('Success');
|
||||
}
|
||||
},
|
||||
title: '',
|
||||
setTitle: (title) => set({ title }),
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user