diff --git a/src/components/ChatAi/index.jsx b/src/components/ChatAi/index.jsx
index 8c78897..13422cb 100644
--- a/src/components/ChatAi/index.jsx
+++ b/src/components/ChatAi/index.jsx
@@ -2,18 +2,24 @@ import { Button, Drawer, Input, Space, message } from 'antd';
import { useChat } from "ai/react";
import { CodeHighlight } from "@mantine/code-highlight";
import { DownloadOutlined } from '@ant-design/icons';
-import { useEffect, useRef } from 'react';
+import { useRef, useEffect } from 'react';
+import { useSessionStorage } from 'react-use';
export default function ChatAIDrawer({ open, onClose, onExport }) {
const STORAGE_KEY = 'chat_history';
+ const [storedMessages, setStoredMessages] = useSessionStorage(STORAGE_KEY, '[]');
+
const { messages, input, handleSubmit, handleInputChange, isLoading, setMessages } = useChat({
api: "https://test-ai-quirkyai.vercel.app/api/chat",
- initialMessages: JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]'),
+ initialMessages: JSON.parse(storedMessages),
});
+
const messagesEndRef = useRef(null);
+
+ // 当 messages 改变时,自动更新 session storage
useEffect(() => {
- localStorage.setItem(STORAGE_KEY, JSON.stringify(messages));
- }, [messages]);
+ setStoredMessages(JSON.stringify(messages));
+ }, [messages, setStoredMessages]);
// 新消息时自动滚动到底部
useEffect(() => {
@@ -40,7 +46,7 @@ export default function ChatAIDrawer({ open, onClose, onExport }) {
size="small"
onClick={() => {
setMessages([]);
- localStorage.removeItem(STORAGE_KEY);
+ setStoredMessages('[]');
message.success('历史记录已清空');
}}
>
diff --git a/src/pages/company/quotation/detail/index.jsx b/src/pages/company/quotation/detail/index.jsx
index 0f1586b..256c229 100644
--- a/src/pages/company/quotation/detail/index.jsx
+++ b/src/pages/company/quotation/detail/index.jsx
@@ -121,7 +121,7 @@ const QuotationForm = () => {
// 修改初始值,确保每个项目都有唯一ID
const initialValues = {
- currency: "CNY",
+ currency: "TWD",
sections: [
{
key: uuidv4(),
@@ -129,10 +129,10 @@ const QuotationForm = () => {
items: [
{
key: uuidv4(),
- productName: "",
+ name: "",
quantity: 1,
price: 0,
- note: "",
+ description: "",
unit: "",
},
],
@@ -150,10 +150,10 @@ const QuotationForm = () => {
const handleAddItem = (add, sectionIndex) => {
add({
key: uuidv4(),
- productName: "",
+ name: "",
quantity: 1,
price: 0,
- note: "",
+ description: "",
});
};
@@ -173,16 +173,16 @@ const QuotationForm = () => {
quataName: data.attributes.quataName,
customers: data.attributes.customers.map((customer) => customer.id) || [],
description: data.attributes.description,
- currency: data.attributes.currency || "CNY",
+ currency: data.attributes.currency || "TWD",
sections: data.attributes.sections.map((section) => ({
key: uuidv4(),
sectionName: section.sectionName,
items: section.items.map((item) => ({
key: uuidv4(),
- productName: item.name,
+ name: item.name,
quantity: Number(item.quantity) || 0,
price: Number(item.price) || 0,
- note: item.description || "",
+ description: item.description || "",
unit: item.unit || "",
})),
})),
@@ -192,7 +192,7 @@ const QuotationForm = () => {
form.setFieldsValue(formData);
setFormValues(formData);
- setCurrentCurrency(data.attributes.currency || "CNY");
+ setCurrentCurrency(data.attributes.currency || "TWD");
setTaxRate(data.attributes.taxRate || 0);
setDiscount(data.attributes.discount || 0);
@@ -225,57 +225,6 @@ const QuotationForm = () => {
}
};
- // 使用选中的模版
- const handleUseTemplate = (template) => {
- const sections = form.getFieldValue("sections") || [];
- const newSection = {
- key: uuidv4(),
- sectionName: template.attributes.name,
- items: (template.attributes.items || []).map((item) => ({
- key: uuidv4(),
- productName: item.name || "",
- note: item.description || "",
- price: item.price || 0,
- quantity: item.quantity || 1,
- unit: item.unit || "",
- })),
- };
-
- const newSections = [...sections, newSection];
- form.setFieldValue("sections", newSections);
-
- // 更新 formValues 以触发重新计算
- const currentFormValues = form.getFieldsValue();
- setFormValues({
- ...currentFormValues,
- sections: newSections,
- });
-
- setTemplateModalVisible(false);
- message.success("套用模版成功");
- };
-
- // 创建自定义小节
- const handleCreateCustom = () => {
- const sections = form.getFieldValue("sections") || [];
- const newSection = {
- key: uuidv4(),
- sectionName: `服务类型 ${sections.length + 1}`,
- items: [
- {
- key: uuidv4(),
- productName: "",
- note: "",
- price: 0,
- quantity: 1,
- unit: "",
- },
- ],
- };
-
- form.setFieldValue("sections", [...sections, newSection]);
- setTemplateModalVisible(false);
- };
@@ -295,22 +244,22 @@ const QuotationForm = () => {
const quotationData = {
quataName: template.attributes.templateName,
description: template.attributes.description,
- currency: template.attributes.currency || "CNY",
+ currency: template.attributes.currency || "TWD",
category: template.attributes.category,
sections: template.attributes.sections.map((section) => ({
key: uuidv4(),
sectionName: section.sectionName,
items: section.items.map((item) => ({
key: uuidv4(),
- productName: item.name,
+ name: item.name,
quantity: item.quantity,
price: item.price,
- note: item.description,
+ description: item.description,
unit: item.unit,
})),
})),
};
- setCurrentCurrency(template.attributes.currency || "CNY");
+ setCurrentCurrency(template.attributes.currency || "TWD");
form.setFieldsValue(quotationData);
setFormValues(quotationData);
}
@@ -350,11 +299,11 @@ const QuotationForm = () => {
sections: values.sections.map((section) => ({
sectionName: section.sectionName,
items: section.items.map((item) => ({
- name: item.productName,
+ name: item.name,
unit: item.unit,
price: item.price,
quantity: item.quantity,
- description: item.note,
+ description: item.description,
})),
})),
beforeTaxAmount,
@@ -520,7 +469,7 @@ const QuotationForm = () => {
>
@@ -544,7 +493,7 @@ const QuotationForm = () => {