mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
完成运行功能
This commit is contained in:
@@ -25,7 +25,6 @@ export default function Chat(props: {id: number, revalidator: () => void}) {
|
||||
}
|
||||
|
||||
request={async (messages) => {
|
||||
// // const proChat = useProChat()
|
||||
const response = await getResponse(messages, id, proChatRef.current, revalidator)
|
||||
return response// 支持流式和非流式
|
||||
}}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import CodeMirror from '@uiw/react-codemirror';
|
||||
import { python } from '@codemirror/lang-python';
|
||||
import { Drawer, FloatButton } from 'antd';
|
||||
import { useState } from 'react';
|
||||
import { QuestionCircleOutlined } from '@ant-design/icons';
|
||||
import Chat from '@renderer/components/Chat';
|
||||
import "./codeEditor.scss"
|
||||
@@ -9,13 +8,12 @@ interface CodeEditorProps {
|
||||
id: number;
|
||||
defaultValue: string;
|
||||
revalidator: () => void;
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
|
||||
}
|
||||
|
||||
export default function CodeEditor(props: CodeEditorProps) {
|
||||
const { id, defaultValue, revalidator} = props;
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const { id, defaultValue, revalidator, open, setOpen} = props;
|
||||
return (
|
||||
<div>
|
||||
<FloatButton icon={<QuestionCircleOutlined />} type="primary" onClick={() => {
|
||||
@@ -36,10 +34,7 @@ export default function CodeEditor(props: CodeEditorProps) {
|
||||
</Drawer>
|
||||
|
||||
<CodeMirror
|
||||
// theme="dark"
|
||||
// height="100%"
|
||||
maxHeight='550px'
|
||||
// width='587px'
|
||||
className='code-mirror'
|
||||
value={defaultValue}
|
||||
onChange={async (value) => {
|
||||
@@ -54,8 +49,6 @@ export default function CodeEditor(props: CodeEditorProps) {
|
||||
}}
|
||||
extensions={[python()]}
|
||||
/>
|
||||
|
||||
{/* </Spin> */}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,34 +1,62 @@
|
||||
import { Form, useLoaderData, useRevalidator, useSubmit } from "react-router-dom"
|
||||
import "./content.scss"
|
||||
import CodeEditor from "@renderer/components/CodeEditor"
|
||||
import { Button } from "antd"
|
||||
import { localServerBaseUrl } from "@renderer/config"
|
||||
import { useState } from "react"
|
||||
import { useStore } from "@renderer/store/useStore"
|
||||
|
||||
export const Content = () => {
|
||||
const {content, categories} = useLoaderData() as {
|
||||
const { content, categories } = useLoaderData() as {
|
||||
content: ContentType
|
||||
categories: CategoryType[]
|
||||
}
|
||||
const revalidator = useRevalidator();
|
||||
const submit = useSubmit()
|
||||
const [open, setOpen] = useState(false);
|
||||
const setChatMessages = useStore(state => state.setChatMessage)
|
||||
const chatMessages = useStore(state => state.chatMessages)
|
||||
return (
|
||||
<Form method="PUT">
|
||||
<main className="content-page" key={content.id}>
|
||||
<input name="id" type="text" defaultValue={content.id} hidden></input>
|
||||
<input autoFocus defaultValue={content.title} name="title" onChange={(e) => {
|
||||
submit(e.target.form)
|
||||
}}/>
|
||||
<select name="category_id" value={content.category_id} onChange={(e)=>
|
||||
submit(e.target.form)
|
||||
}>
|
||||
<option value="0">未分类</option>
|
||||
{categories.map((category) => (
|
||||
<option key={category.id} value={category.id}>{category.name}</option>
|
||||
))}
|
||||
</select>
|
||||
{/* <textarea defaultValue={content.content} name="content" onChange={(e) => {
|
||||
submit(e.target.form)
|
||||
setCode(e.target.value)
|
||||
}}/> */}
|
||||
<CodeEditor id={content.id} defaultValue={content.content} revalidator={()=>revalidator.revalidate()} />
|
||||
</main>
|
||||
</Form>
|
||||
<Form method="PUT">
|
||||
<main className="content-page" key={content.id}>
|
||||
<input name="id" type="text" defaultValue={content.id} hidden></input>
|
||||
<input autoFocus defaultValue={content.title} name="title" onChange={(e) => {
|
||||
submit(e.target.form)
|
||||
}} />
|
||||
<div className="flex justify-between">
|
||||
<select name="category_id" value={content.category_id} onChange={(e) =>
|
||||
submit(e.target.form)
|
||||
}>
|
||||
<option value="0">未分类</option>
|
||||
{categories.map((category) => (
|
||||
<option key={category.id} value={category.id}>{category.name}</option>
|
||||
))}
|
||||
</select>
|
||||
<Button onClick={async () => {
|
||||
revalidator.revalidate()
|
||||
const res = await fetch(localServerBaseUrl + "/execute", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
code: content.content
|
||||
})
|
||||
});
|
||||
const data = await res.json();
|
||||
setOpen(true)
|
||||
setChatMessages([...chatMessages,
|
||||
{ role: "assistant", content: "代码运行结果如下:" + JSON.stringify(data), createAt: new Date().getTime(), updateAt: new Date().getTime(), id: new Date().getTime().toString() }])
|
||||
}}>运行</Button>
|
||||
</div>
|
||||
<CodeEditor
|
||||
open={open}
|
||||
setOpen={setOpen}
|
||||
id={content.id}
|
||||
defaultValue={content.content}
|
||||
revalidator={() => revalidator.revalidate()}
|
||||
/>
|
||||
</main>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user