diff --git a/.vscode/settings.json b/.vscode/settings.json index 077404a..b33140a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,6 @@ { - + "workbench.editorAssociations": { + // "*.md": "vscode.markdown.preview.editor" // 预览打开 + "*.md": "default" // 默认打开 + } } \ No newline at end of file diff --git a/src/apps/ai-chat/chat-context/Dialog.tsx b/src/apps/ai-chat/chat-context/Dialog.tsx index 8987ed7..38ee05c 100644 --- a/src/apps/ai-chat/chat-context/Dialog.tsx +++ b/src/apps/ai-chat/chat-context/Dialog.tsx @@ -1,4 +1,4 @@ -import { DragModal, DragModalTitle, getComputedHeight } from '@/components/a/drag-modal/index.tsx'; +import { DragModal, DragModalTitle, getComputedHeight, useDragSize } from '@/components/a/drag-modal/index.tsx'; import { useChatStore } from '../store'; import { useShallow } from 'zustand/shallow'; import { Button } from '@/components/a/button.tsx'; @@ -68,6 +68,7 @@ export const ChatContextDialog = () => { setShowContext(false); }; const [role, setRole] = useState('user'); + const dragSize = useDragSize(); return ( { } - defaultSize={{ - width: 600, - height: 400, - }} - style={{ - left: computedHeight.width / 2 - 300, - top: computedHeight.height / 2 - 200, - }} + defaultSize={dragSize.defaultSize} + style={dragSize.style} /> ); }; diff --git a/src/apps/ai-chat/chat-copy/Dialog.tsx b/src/apps/ai-chat/chat-copy/Dialog.tsx index dced425..f9bd3e8 100644 --- a/src/apps/ai-chat/chat-copy/Dialog.tsx +++ b/src/apps/ai-chat/chat-copy/Dialog.tsx @@ -1,4 +1,4 @@ -import { DragModal, DragModalTitle, getComputedHeight } from '@/components/a/drag-modal/index.tsx'; +import { DragModal, DragModalTitle, getComputedHeight, useDragSize } from '@/components/a/drag-modal/index.tsx'; import { useChatStore } from '../store'; import { useShallow } from 'zustand/shallow'; import { ChatCopyList } from './List'; @@ -16,6 +16,7 @@ export const ChatCopyDialog = () => { if (!store.showCopy) { return null; } + const dragSize = useDragSize(); return ( { } - defaultSize={{ - width: 600, - height: 400, - }} - style={{ - left: computedHeight.width / 2 - 300, - top: computedHeight.height / 2 - 200, - }} + defaultSize={dragSize.defaultSize} + style={dragSize.style} /> ); }; diff --git a/src/apps/ai-chat/chat-history/Dialog.tsx b/src/apps/ai-chat/chat-history/Dialog.tsx index 7d88711..99832f1 100644 --- a/src/apps/ai-chat/chat-history/Dialog.tsx +++ b/src/apps/ai-chat/chat-history/Dialog.tsx @@ -1,16 +1,17 @@ -import { DragModal, DragModalTitle, getComputedHeight } from '@/components/a/drag-modal/index.tsx'; +import { DragModal, DragModalTitle, getComputedHeight, useDragSize } from '@/components/a/drag-modal/index.tsx'; import { useChatStore } from '../store'; import { useShallow } from 'zustand/shallow'; import { ChatHistoryList } from './List'; export const ChatHistoryDialog = ({ storeId }: { storeId: string }) => { const { showList, setShowList, setModelId, modelId } = useChatStore( - useShallow((state) => ({ showList: state.showList, setShowList: state.setShowList, setModelId: state.setModelId, modelId: state.modelId })), + useShallow((state) => ({ showList: state.showList, setShowList: state.setShowList, setModelId: state.setModelId, modelId: state.modelId })), ); const computedHeight = getComputedHeight(); if (!showList) { return null; } + const dragSize = useDragSize(); return ( { } - defaultSize={{ - width: 600, - height: 400, - }} - style={{ - left: computedHeight.width / 2 - 300, - top: computedHeight.height / 2 - 200, - }} + {...dragSize} /> ); }; diff --git a/src/apps/ai-chat/chat-model-setting/Dialog.tsx b/src/apps/ai-chat/chat-model-setting/Dialog.tsx index 46f346d..09023fb 100644 --- a/src/apps/ai-chat/chat-model-setting/Dialog.tsx +++ b/src/apps/ai-chat/chat-model-setting/Dialog.tsx @@ -1,4 +1,4 @@ -import { DragModal, DragModalTitle, getComputedHeight } from '@/components/a/drag-modal/index.tsx'; +import { DragModal, DragModalTitle, getComputedHeight, useDragSize } from '@/components/a/drag-modal/index.tsx'; import { useChatStore } from '../store'; import { useShallow } from 'zustand/shallow'; import { ChatSettingList } from './List'; @@ -16,6 +16,7 @@ export const ChatModelSettingDialog = () => { if (!showChatSetting) { return null; } + const dragSize = useDragSize(); return ( { } - defaultSize={{ - width: 600, - height: 400, - }} - style={{ - left: computedHeight.width / 2 - 300, - top: computedHeight.height / 2 - 200, - }} + {...dragSize} /> ); }; diff --git a/src/apps/ai-chat/chat-setting/Dialog.tsx b/src/apps/ai-chat/chat-setting/Dialog.tsx index 2add8c6..4e14e36 100644 --- a/src/apps/ai-chat/chat-setting/Dialog.tsx +++ b/src/apps/ai-chat/chat-setting/Dialog.tsx @@ -1,4 +1,4 @@ -import { DragModal, DragModalTitle, getComputedHeight } from '@/components/a/drag-modal/index.tsx'; +import { DragModal, DragModalTitle, getComputedHeight, useDragSize } from '@/components/a/drag-modal/index.tsx'; import { useChatStore } from '../store'; import { useShallow } from 'zustand/shallow'; import { ChatSettingList } from './List'; @@ -16,6 +16,7 @@ export const ChatSettingDialog = () => { if (!showSetting) { return null; } + const dragSize = useDragSize(); return ( { } - defaultSize={{ - width: 600, - height: 400, - }} - style={{ - left: computedHeight.width / 2 - 300, - top: computedHeight.height / 2 - 200, - }} + {...dragSize} /> ); }; diff --git a/src/apps/ai-chat/index.tsx b/src/apps/ai-chat/index.tsx index cbc7760..355ce8b 100644 --- a/src/apps/ai-chat/index.tsx +++ b/src/apps/ai-chat/index.tsx @@ -75,7 +75,7 @@ export const Chat = ({ storeId }: { storeId: string }) => { }, []); return ( -
+
{!id && (
diff --git a/src/apps/ai-chat/modules/ModelNav.tsx b/src/apps/ai-chat/modules/ModelNav.tsx index b4b0fc3..7c38152 100644 --- a/src/apps/ai-chat/modules/ModelNav.tsx +++ b/src/apps/ai-chat/modules/ModelNav.tsx @@ -41,7 +41,7 @@ export const ModelNav = () => { return (
提示词规划器
-
setShowChatSetting(true)}> + {/*
setShowChatSetting(true)}> {currentUserModel && ( { )} {!currentUserModel &&
Not Selected Model
} -
+
*/}
{/* { + return ( + + + + ); +}; + +export const AIEditor = () => { + return ( +
+
AI Editor
+
This is a placeholder for the AI Editor application.
+
+ ); +}; diff --git a/src/apps/ai-mark/index.tsx b/src/apps/ai-mark/index.tsx index 1d1b3fb..b3f75d0 100644 --- a/src/apps/ai-mark/index.tsx +++ b/src/apps/ai-mark/index.tsx @@ -5,14 +5,35 @@ import { Tooltip } from '@/components/a/tooltip'; export const queryMark = new QueryMark({ query: query, markType: 'md' }); import Fuse from 'fuse.js'; import { debounce } from 'lodash-es'; -import { SquareArrowOutUpRight } from 'lucide-react'; +import { Plus, SquareArrowOutUpRight } from 'lucide-react'; +import { Pencil, Trash2 } from 'lucide-react'; +import { Button } from '@/components/a/button'; +import { Confirm } from '@/components/a/confirm'; +import { toast } from 'react-toastify'; +import { ToastProvider } from '@/modules/toast/Provider'; +import { Modal } from '@/components/a/modal'; +import { useForm, Controller } from 'react-hook-form'; // 添加此行 export const App = () => { + return ( + + + + ); +}; +const AiMark = () => { const [list, setList] = useState([]); const [searchTerm, setSearchTerm] = useState(''); const [searchResults, setSearchResults] = useState([]); + const fuseRef = useRef>(null); + const [open, setOpen] = useState(false); + const [formData, setFormData] = useState(); + const onOpenEdit = (data: Mark) => { + setOpen(true); + setFormData(data); + }; // 实际执行搜索的函数 const performSearch = (term: string) => { if (!term.trim()) { @@ -47,6 +68,7 @@ export const App = () => { if (res.code === 200) { const list = res.data?.list || []; setList(list!); + const fuse = new Fuse(list, { keys: ['title', 'description', 'tags', 'summary'], }); @@ -65,13 +87,23 @@ export const App = () => { const link = item.link; window.open(link); }; - + const refresh = () => { + init(); + }; // 确定要显示的列表:有搜索内容时显示搜索结果,否则显示全部 const displayList = searchTerm.trim() ? searchResults : list; return ( -
-
+
+
+ { ))}
+
); }) )}
+ + setOpen(false)} + onSuccess={() => { + setOpen(false); + init(); + }} + /> + +
+ ); +}; + +export const MarkForm = (props?: { data?: Mark; onSuccess?: () => void; onCancel?: () => void }) => { + const { + register, + handleSubmit, + control, + formState: { errors }, + } = useForm({ + defaultValues: props?.data || { + title: '', + summary: '', + link: '', + tags: [], + }, + }); + + const onSubmit = async (data: Mark) => { + try { + const res = await queryMark.updateMark(data); + + if (res.code === 200) { + toast.success(data.id ? '更新成功' : '创建成功'); + props?.onSuccess?.(); + } else { + toast.error(res?.message || '操作失败'); + } + } catch (error) { + toast.error('操作失败'); + } + }; + + return ( +
+ {props?.data?.id && } + +
+ + + {errors.title &&

{errors.title.message}

} +
+ +
+ + + {errors.link &&

{errors.link.message}

} +
+ +
+ +