fix: bug
This commit is contained in:
@@ -35,7 +35,7 @@ async def generate_quote_excel(
|
||||
}
|
||||
"""
|
||||
|
||||
async def _work() -> str:
|
||||
def _work() -> str:
|
||||
template = Path(template_path)
|
||||
output = Path(output_path)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -122,7 +122,7 @@ async def generate_contract_word(
|
||||
}
|
||||
"""
|
||||
|
||||
async def _work() -> str:
|
||||
def _work() -> str:
|
||||
template = Path(template_path)
|
||||
output = Path(output_path)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -148,7 +148,7 @@ async def generate_quote_pdf_from_data(
|
||||
that can be sent to customers.
|
||||
"""
|
||||
|
||||
async def _work() -> str:
|
||||
def _work() -> str:
|
||||
output = Path(output_pdf_path)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -195,4 +195,3 @@ async def generate_quote_pdf_from_data(
|
||||
return str(output)
|
||||
|
||||
return await asyncio.to_thread(_work)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Globe,
|
||||
FileStack,
|
||||
Settings2,
|
||||
ChevronDown,
|
||||
} from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
@@ -21,6 +22,7 @@ export function AppSidebar() {
|
||||
const pathname = usePathname();
|
||||
const [cloudDocs, setCloudDocs] = useState<CloudDocLinkRead[]>([]);
|
||||
const [portalLinks, setPortalLinks] = useState<PortalLinkRead[]>([]);
|
||||
const [projectArchiveOpen, setProjectArchiveOpen] = useState(false);
|
||||
|
||||
const loadCloudDocs = useCallback(async () => {
|
||||
try {
|
||||
@@ -90,6 +92,24 @@ export function AppSidebar() {
|
||||
))}
|
||||
</nav>
|
||||
<Separator />
|
||||
{/* 项目档案放在云文档之前,支持收纳折叠 */}
|
||||
<div className="px-2 pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setProjectArchiveOpen((v) => !v)}
|
||||
className="w-full flex items-center justify-between text-xs text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<span>项目档案</span>
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
"h-3 w-3 transition-transform",
|
||||
projectArchiveOpen ? "rotate-180" : "rotate-0"
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
{projectArchiveOpen && <HistoricalReferences />}
|
||||
<Separator />
|
||||
<div className="flex-1 min-h-0 overflow-y-auto flex flex-col">
|
||||
<div className="p-2 shrink-0">
|
||||
<div className="flex items-center justify-between px-2 mb-2">
|
||||
@@ -156,7 +176,6 @@ export function AppSidebar() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{pathname === "/workspace" && <HistoricalReferences />}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ import { cn } from "@/lib/utils";
|
||||
import {
|
||||
listProjects,
|
||||
projectsApi,
|
||||
customersApi,
|
||||
type ProjectRead,
|
||||
type CustomerRead,
|
||||
} from "@/lib/api/client";
|
||||
import { Copy, Search, FileText, Eye, Pencil, Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
@@ -47,6 +49,11 @@ export function HistoricalReferences() {
|
||||
const [editRaw, setEditRaw] = useState("");
|
||||
const [editMd, setEditMd] = useState("");
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [editCustomer, setEditCustomer] = useState<CustomerRead | null>(null);
|
||||
const [customerName, setCustomerName] = useState("");
|
||||
const [customerContact, setCustomerContact] = useState("");
|
||||
const [customerTags, setCustomerTags] = useState("");
|
||||
const [savingCustomer, setSavingCustomer] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
@@ -85,9 +92,20 @@ export function HistoricalReferences() {
|
||||
(p.ai_solution_md || "").toLowerCase().includes(q)
|
||||
);
|
||||
}
|
||||
return list.slice(0, 20);
|
||||
return list.slice(0, 50);
|
||||
}, [projects, search]);
|
||||
|
||||
const groupedByCustomer = useMemo(() => {
|
||||
const map = new Map<string, ProjectRead[]>();
|
||||
filtered.forEach((p) => {
|
||||
const name = p.customer?.name || "未关联客户";
|
||||
const key = name;
|
||||
if (!map.has(key)) map.set(key, []);
|
||||
map.get(key)!.push(p);
|
||||
});
|
||||
return Array.from(map.entries()).sort(([a], [b]) => a.localeCompare(b, "zh-CN"));
|
||||
}, [filtered]);
|
||||
|
||||
const copySnippet = (text: string, label: string) => {
|
||||
if (!text) return;
|
||||
navigator.clipboard.writeText(text);
|
||||
@@ -119,12 +137,40 @@ export function HistoricalReferences() {
|
||||
}
|
||||
};
|
||||
|
||||
const openEditCustomer = (p: ProjectRead | null) => {
|
||||
if (!p?.customer) return;
|
||||
setEditCustomer(p.customer);
|
||||
setCustomerName(p.customer.name);
|
||||
setCustomerContact(p.customer.contact_info || "");
|
||||
setCustomerTags(p.customer.tags || "");
|
||||
};
|
||||
|
||||
const handleSaveCustomer = async () => {
|
||||
if (!editCustomer) return;
|
||||
setSavingCustomer(true);
|
||||
try {
|
||||
const updated = await customersApi.update(editCustomer.id, {
|
||||
name: customerName.trim() || editCustomer.name,
|
||||
contact_info: customerContact.trim() || null,
|
||||
tags: customerTags.trim() || null,
|
||||
});
|
||||
toast.success("客户信息已保存");
|
||||
// 更新本地 projects 中的 customer 信息
|
||||
setProjects((prev) =>
|
||||
prev.map((p) =>
|
||||
p.customer_id === updated.id ? { ...p, customer: updated } : p
|
||||
)
|
||||
);
|
||||
setEditCustomer(null);
|
||||
} catch (e) {
|
||||
toast.error("保存客户失败");
|
||||
} finally {
|
||||
setSavingCustomer(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="border-t p-2">
|
||||
<p className="text-xs font-medium text-muted-foreground px-2 mb-2 flex items-center gap-1">
|
||||
<FileText className="h-3.5 w-3.5" />
|
||||
历史参考
|
||||
</p>
|
||||
<div className="p-2">
|
||||
<div className="space-y-2 mb-2">
|
||||
<div className="flex gap-1 items-center">
|
||||
<Select
|
||||
@@ -156,70 +202,77 @@ export function HistoricalReferences() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="max-h-48 overflow-y-auto space-y-1">
|
||||
<div className="max-h-64 overflow-y-auto space-y-2 pr-1">
|
||||
{loading ? (
|
||||
<p className="text-xs text-muted-foreground px-2">加载中...</p>
|
||||
) : filtered.length === 0 ? (
|
||||
<p className="text-xs text-muted-foreground px-2">暂无项目</p>
|
||||
) : (
|
||||
filtered.map((p) => (
|
||||
<div
|
||||
key={p.id}
|
||||
className={cn(
|
||||
"rounded border bg-background/50 p-2 text-xs space-y-1"
|
||||
)}
|
||||
>
|
||||
<p className="font-medium text-foreground line-clamp-1 flex items-center justify-between gap-1">
|
||||
<span>项目 #{p.id}</span>
|
||||
{p.customer?.tags && (
|
||||
<span className="text-muted-foreground font-normal truncate max-w-[60%]">
|
||||
{parseTags(p.customer.tags).slice(0, 2).join(", ")}
|
||||
</span>
|
||||
)}
|
||||
groupedByCustomer.map(([customerName, items]) => (
|
||||
<div key={customerName} className="space-y-1">
|
||||
<p className="px-2 text-[11px] font-medium text-muted-foreground">
|
||||
{customerName}
|
||||
</p>
|
||||
<p className="text-muted-foreground line-clamp-2">
|
||||
{p.raw_requirement.slice(0, 80)}…
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-1 pt-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-xs"
|
||||
onClick={() => openPreview(p)}
|
||||
title="预览"
|
||||
{items.map((p) => (
|
||||
<div
|
||||
key={p.id}
|
||||
className={cn(
|
||||
"rounded border bg-background/50 p-2 text-xs space-y-1 ml-1"
|
||||
)}
|
||||
>
|
||||
<Eye className="h-3 w-3 mr-0.5" />
|
||||
预览
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-xs"
|
||||
onClick={() => openEdit(p)}
|
||||
title="编辑"
|
||||
>
|
||||
<Pencil className="h-3 w-3 mr-0.5" />
|
||||
编辑
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-xs"
|
||||
onClick={() => copySnippet(p.raw_requirement, "原始需求")}
|
||||
>
|
||||
<Copy className="h-3 w-3 mr-0.5" />
|
||||
需求
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-xs"
|
||||
onClick={() => copySnippet(p.ai_solution_md || "", "方案")}
|
||||
>
|
||||
<Copy className="h-3 w-3 mr-0.5" />
|
||||
方案
|
||||
</Button>
|
||||
</div>
|
||||
<p className="font-medium text-foreground line-clamp-1 flex items-center justify-between gap-1">
|
||||
<span>项目 #{p.id}</span>
|
||||
{p.customer?.tags && (
|
||||
<span className="text-muted-foreground font-normal truncate max-w-[60%]">
|
||||
{parseTags(p.customer.tags).slice(0, 2).join(", ")}
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
<p className="text-muted-foreground line-clamp-2">
|
||||
{p.raw_requirement.slice(0, 80)}…
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-1 pt-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-xs"
|
||||
onClick={() => openPreview(p)}
|
||||
title="预览"
|
||||
>
|
||||
<Eye className="h-3 w-3 mr-0.5" />
|
||||
预览
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-xs"
|
||||
onClick={() => openEdit(p)}
|
||||
title="编辑"
|
||||
>
|
||||
<Pencil className="h-3 w-3 mr-0.5" />
|
||||
编辑
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-xs"
|
||||
onClick={() => copySnippet(p.raw_requirement, "原始需求")}
|
||||
>
|
||||
<Copy className="h-3 w-3 mr-0.5" />
|
||||
需求
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-xs"
|
||||
onClick={() => copySnippet(p.ai_solution_md || "", "方案")}
|
||||
>
|
||||
<Copy className="h-3 w-3 mr-0.5" />
|
||||
方案
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
@@ -232,8 +285,16 @@ export function HistoricalReferences() {
|
||||
<DialogTitle>
|
||||
项目 #{previewProject?.id}
|
||||
{previewProject?.customer?.name && (
|
||||
<span className="text-sm font-normal text-muted-foreground ml-2">
|
||||
<span className="text-sm font-normal text-muted-foreground ml-2 flex items-center gap-2">
|
||||
{previewProject.customer.name}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-6 px-1.5 text-[11px]"
|
||||
onClick={() => openEditCustomer(previewProject)}
|
||||
>
|
||||
编辑客户
|
||||
</Button>
|
||||
</span>
|
||||
)}
|
||||
</DialogTitle>
|
||||
@@ -298,6 +359,55 @@ export function HistoricalReferences() {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* 客户二次编辑弹窗 */}
|
||||
<Dialog open={!!editCustomer} onOpenChange={() => !savingCustomer && setEditCustomer(null)}>
|
||||
<DialogContent className="sm:max-w-sm">
|
||||
<DialogHeader>
|
||||
<DialogTitle>编辑客户</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-4 py-2">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="hist-customer-name">客户名称</Label>
|
||||
<Input
|
||||
id="hist-customer-name"
|
||||
value={customerName}
|
||||
onChange={(e) => setCustomerName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="hist-customer-contact">联系方式</Label>
|
||||
<Input
|
||||
id="hist-customer-contact"
|
||||
value={customerContact}
|
||||
onChange={(e) => setCustomerContact(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="hist-customer-tags">标签(逗号分隔)</Label>
|
||||
<Input
|
||||
id="hist-customer-tags"
|
||||
value={customerTags}
|
||||
onChange={(e) => setCustomerTags(e.target.value)}
|
||||
placeholder="如:重点客户, 已签约"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setEditCustomer(null)}
|
||||
disabled={savingCustomer}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleSaveCustomer} disabled={savingCustomer}>
|
||||
{savingCustomer && <Loader2 className="h-4 w-4 animate-spin mr-2" />}
|
||||
保存
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user