+
{showSidebarTrigger && (
<>
>
)}
-
+
{breadcrumbs?.map((item, index) => (
@@ -52,6 +58,20 @@ export function AppHeader({
))}
+
+
+
+
+
+
+
+ AI Provider Settings
+
+
+
+
)
diff --git a/lib/db/codegen/mutaitons.ts b/lib/db/codegen/mutaitons.ts
index f2998175..8acf642f 100644
--- a/lib/db/codegen/mutaitons.ts
+++ b/lib/db/codegen/mutaitons.ts
@@ -6,12 +6,22 @@ export async function createCodegen(codegen: Codegen | Codegen[]) {
}
export async function upsertCodegen(codegen: Codegen) {
- const result = await CodegenModel.findOneAndUpdate(
- { title: codegen.title },
- codegen,
- { upsert: true, new: true },
- )
- return result
+ if (codegen._id) {
+ const result = await CodegenModel.findByIdAndUpdate(
+ codegen._id,
+ codegen,
+ { new: true },
+ )
+ return result
+ } else {
+ const result = await CodegenModel.
+ findOneAndUpdate(
+ { title: codegen.title },
+ codegen,
+ { upsert: true, new: true },
+ )
+ return result
+ }
}
export async function upsertCodegens(codegens: Codegen[]) {
diff --git a/lib/db/codegen/types.ts b/lib/db/codegen/types.ts
index 40f96d61..53dc1390 100644
--- a/lib/db/codegen/types.ts
+++ b/lib/db/codegen/types.ts
@@ -20,6 +20,7 @@ export interface CodegenRule {
}
export interface Codegen {
+ _id?: string // MongoDB 文档ID,编辑时必需
title: string
description: string
fullStack: "React" | "Vue"
From 072df690da0bb96d38459ae232111b52174675f6 Mon Sep 17 00:00:00 2001
From: cavinHuang <943866180@qq.com>
Date: Tue, 20 May 2025 12:05:42 +0800
Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=A7=81?=
=?UTF-8?q?=E6=9C=89=E7=BB=84=E4=BB=B6=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E7=BB=84=E4=BB=B6=E5=BA=93=E7=AE=A1?=
=?UTF-8?q?=E7=90=86=E3=80=81=E6=96=87=E6=A1=A3=E7=BC=96=E8=BE=91=E5=8F=8A?=
=?UTF-8?q?JSON=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA=EF=BC=9B=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E8=A7=84=E5=88=99=E9=85=8D=E7=BD=AE=E7=95=8C=E9=9D=A2?=
=?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?=
=?UTF-8?q?=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../components/PrivateComponentsConfig.tsx | 954 ++++++++++++++++++
app/main/settings/components/RulesConfig.tsx | 16 +-
app/main/settings/components/types.ts | 9 +-
lib/db/codegen/mutaitons.ts | 3 +-
4 files changed, 970 insertions(+), 12 deletions(-)
create mode 100644 app/main/settings/components/PrivateComponentsConfig.tsx
diff --git a/app/main/settings/components/PrivateComponentsConfig.tsx b/app/main/settings/components/PrivateComponentsConfig.tsx
new file mode 100644
index 00000000..d9be6ef7
--- /dev/null
+++ b/app/main/settings/components/PrivateComponentsConfig.tsx
@@ -0,0 +1,954 @@
+import React, { useState, useRef, useEffect } from "react"
+import { Button } from "@/components/ui/button"
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
+import { Input } from "@/components/ui/input"
+import { Textarea } from "@/components/ui/textarea"
+import { PlusCircle, Trash2, AlertCircle, X, FileText, Code, Eye, Copy, CheckCircle2 } from "lucide-react"
+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
+import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "@/components/ui/dialog"
+import { Rule } from "./types"
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
+import { Badge } from "@/components/ui/badge"
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
+import { Label } from "@/components/ui/label"
+import { ScrollArea } from "@/components/ui/scroll-area"
+import { Separator } from "@/components/ui/separator"
+
+// 定义组件库接口
+interface ComponentLibrary {
+ name: string;
+ components: {
+ name: string;
+ docs?: {
+ description: string;
+ api: string;
+ }
+ }[];
+}
+
+interface PrivateComponentsConfigProps {
+ rule: Rule
+ index: number
+ updateRule: (index: number, field: string, value: any) => void
+}
+
+export default function PrivateComponentsConfig({ rule, index, updateRule }: PrivateComponentsConfigProps) {
+ // 组件库列表状态
+ const [libraries, setLibraries] = useState
(() => {
+ if (!rule.docs) return ["@private-basic-components"];
+ return Object.keys(rule.docs).length > 0 ? Object.keys(rule.docs) : ["@private-basic-components"];
+ });
+
+ // 当前选中的组件库
+ const [selectedLibrary, setSelectedLibrary] = useState(libraries[0] || "@private-basic-components");
+
+ // 组件添加相关状态
+ const [componentInput, setComponentInput] = useState("")
+ const [error, setError] = useState(null)
+
+ // 新组件库添加状态
+ const [showAddLibrary, setShowAddLibrary] = useState(false)
+ const [newLibraryName, setNewLibraryName] = useState("")
+ const [libraryError, setLibraryError] = useState(null)
+
+ // 文档编辑相关状态
+ const [showDocsEditor, setShowDocsEditor] = useState<{componentName: string, libraryName: string} | null>(null)
+ const [componentDocs, setComponentDocs] = useState<{description: string, api: string}>({
+ description: '',
+ api: ''
+ })
+
+ // 文档预览状态
+ const [previewDocs, setPreviewDocs] = useState<{isOpen: boolean, componentName: string, libraryName: string, docs: {description: string, api: string}} | null>(null)
+
+ // 其他状态
+ const [copiedDocName, setCopiedDocName] = useState(null)
+ const [showImportJson, setShowImportJson] = useState(false)
+ const [jsonInput, setJsonInput] = useState("")
+ const [jsonError, setJsonError] = useState(null)
+ const [importedComponents, setImportedComponents] = useState<{name: string, library: string}[]>([])
+
+ // 创建一个ref对象的Map,用于存储每个组件的引用
+ const componentRefs = useRef
) : rule.type === "private-components" ? (
-