This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import axios from 'axios';
|
|
||||||
import { Spin, Alert } from 'antd';
|
import { Spin, Alert } from 'antd';
|
||||||
|
|
||||||
interface LogisticsDetail {
|
interface LogisticsDetail {
|
||||||
@@ -28,13 +27,20 @@ const LogisticsQuery: React.FC<LogisticsQueryProps> = ({ id }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`/api/tools/logistics/detail/${id}`);
|
const response = await fetch(`/api/tools/logistics/detail/${id}`);
|
||||||
if (response.data && response.data.length > 0) {
|
|
||||||
setData(response.data[0]);
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
if (data && data.length > 0) {
|
||||||
|
setData(data[0]);
|
||||||
} else {
|
} else {
|
||||||
setError('No data found');
|
setError('No data found');
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err: unknown) {
|
||||||
|
console.error('Error fetching logistics data:', err);
|
||||||
setError('Error fetching data');
|
setError('Error fetching data');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
// src/pages/api/tools/parseAddress.ts
|
// src/pages/api/tools/parseAddress.ts
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
interface ExtractedInfoItem {
|
interface ExtractedInfoItem {
|
||||||
text: string;
|
text: string;
|
||||||
@@ -73,13 +72,18 @@ export default async function handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 第一步:提取姓名和电话
|
// 第一步:提取姓名和电话
|
||||||
const extractInfoResponse = await axios.post<ExtractInfoResponse>(
|
const extractInfoResponse = await fetch(extractInfoUrl, {
|
||||||
extractInfoUrl,
|
method: 'POST',
|
||||||
{ text },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
{ headers: { 'Content-Type': 'application/json' } }
|
body: JSON.stringify({ text })
|
||||||
);
|
});
|
||||||
|
|
||||||
const extractedInfo = extractInfoResponse.data.extracted_info[0];
|
if (!extractInfoResponse.ok) {
|
||||||
|
throw new Error(`Extract info API failed: ${extractInfoResponse.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const extractInfoData: ExtractInfoResponse = await extractInfoResponse.json();
|
||||||
|
const extractedInfo = extractInfoData.extracted_info[0];
|
||||||
|
|
||||||
let name: string | null = null;
|
let name: string | null = null;
|
||||||
let phone: string | null = null;
|
let phone: string | null = null;
|
||||||
@@ -104,16 +108,22 @@ export default async function handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 第二步:解析地址
|
// 第二步:解析地址
|
||||||
const parseLocationResponse = await axios.post<ParseLocationResponse>(
|
const parseLocationResponse = await fetch(parseLocationUrl, {
|
||||||
parseLocationUrl,
|
method: 'POST',
|
||||||
{ text: addressText },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
{ headers: { 'Content-Type': 'application/json' } }
|
body: JSON.stringify({ text: addressText })
|
||||||
);
|
});
|
||||||
|
|
||||||
|
if (!parseLocationResponse.ok) {
|
||||||
|
throw new Error(`Parse location API failed: ${parseLocationResponse.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const parseLocationData: ParseLocationResponse = await parseLocationResponse.json();
|
||||||
|
|
||||||
const combinedResponse: CombinedResponse = {
|
const combinedResponse: CombinedResponse = {
|
||||||
name,
|
name,
|
||||||
phone,
|
phone,
|
||||||
address: parseLocationResponse.data,
|
address: parseLocationData,
|
||||||
};
|
};
|
||||||
|
|
||||||
res.status(200).json(combinedResponse);
|
res.status(200).json(combinedResponse);
|
||||||
@@ -122,9 +132,9 @@ export default async function handler(
|
|||||||
// 根据错误类型返回不同的错误信息
|
// 根据错误类型返回不同的错误信息
|
||||||
if (error.message === '服务配置错误:API地址未设置') {
|
if (error.message === '服务配置错误:API地址未设置') {
|
||||||
res.status(500).json({ error: '服务配置错误,请联系管理员' });
|
res.status(500).json({ error: '服务配置错误,请联系管理员' });
|
||||||
} else if (axios.isAxiosError(error)) {
|
} else if (error instanceof TypeError && error.message.includes('fetch')) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
error: `外部服务请求失败: ${error.response?.status || '未知错误'}`
|
error: `外部服务请求失败: 网络连接错误`
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.status(500).json({ error: '服务器内部错误' });
|
res.status(500).json({ error: '服务器内部错误' });
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import axios from 'axios';
|
|
||||||
import connectDB from '@/utils/connectDB';
|
import connectDB from '@/utils/connectDB';
|
||||||
|
|
||||||
//const extractInfoAPI = 'http://192.168.1.8:8006/extract_info/';
|
//const extractInfoAPI = 'http://192.168.1.8:8006/extract_info/';
|
||||||
@@ -17,8 +16,20 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const { text } = req.body;
|
const { text } = req.body;
|
||||||
|
|
||||||
// 1. 使用 extract_info API 提取信息
|
// 1. 使用 extract_info API 提取信息
|
||||||
const extractResponse = await axios.post(extractInfoAPI, { text });
|
const extractResponse = await fetch(extractInfoAPI, {
|
||||||
const extractedInfo = extractResponse.data.extracted_info[0];
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ text })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!extractResponse.ok) {
|
||||||
|
throw new Error(`Extract info API failed: ${extractResponse.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const extractData = await extractResponse.json();
|
||||||
|
const extractedInfo = extractData.extracted_info[0];
|
||||||
|
|
||||||
// 提取信息失败时抛出异常
|
// 提取信息失败时抛出异常
|
||||||
if (!extractedInfo) {
|
if (!extractedInfo) {
|
||||||
@@ -32,8 +43,19 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const fullAddress = `${city}${county}${detailAddress}`;
|
const fullAddress = `${city}${county}${detailAddress}`;
|
||||||
|
|
||||||
// 3. 使用 parse_location API 解析完整地址
|
// 3. 使用 parse_location API 解析完整地址
|
||||||
const parseResponse = await axios.post(parseLocationAPI, { text: fullAddress });
|
const parseResponse = await fetch(parseLocationAPI, {
|
||||||
const parsedLocation = parseResponse.data;
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ text: fullAddress })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!parseResponse.ok) {
|
||||||
|
throw new Error(`Parse location API failed: ${parseResponse.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedLocation = await parseResponse.json();
|
||||||
|
|
||||||
// 4. 返回组合后的结果
|
// 4. 返回组合后的结果
|
||||||
const result = {
|
const result = {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Modal, Form, Input, Select, message, DatePicker } from 'antd';
|
import { Modal, Form, Input, Select, DatePicker, App } from 'antd';
|
||||||
import { ISalesRecord } from '@/models/types';
|
import { ISalesRecord } from '@/models/types';
|
||||||
import axios from 'axios';
|
|
||||||
import { useUserInfo } from '@/store/userStore';
|
import { useUserInfo } from '@/store/userStore';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
|
const { useApp } = App;
|
||||||
|
|
||||||
interface SalesRecordModalProps {
|
interface SalesRecordModalProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
@@ -19,6 +20,7 @@ const SalesRecordModal: React.FC<SalesRecordModalProps> = ({ visible, onCancel,
|
|||||||
const [accounts, setAccounts] = useState<any[]>([]);
|
const [accounts, setAccounts] = useState<any[]>([]);
|
||||||
const [users, setUsers] = useState<any[]>([]);
|
const [users, setUsers] = useState<any[]>([]);
|
||||||
const userInfo = useUserInfo(); // 获取当前用户信息
|
const userInfo = useUserInfo(); // 获取当前用户信息
|
||||||
|
const { message } = useApp(); // 使用 useApp hook 获取 message 实例
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (userInfo.团队?._id) {
|
if (userInfo.团队?._id) {
|
||||||
@@ -49,36 +51,56 @@ const SalesRecordModal: React.FC<SalesRecordModalProps> = ({ visible, onCancel,
|
|||||||
|
|
||||||
const fetchCustomers = async (teamId: string) => {
|
const fetchCustomers = async (teamId: string) => {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get(`/api/backstage/customers?teamId=${teamId}`);
|
const response = await fetch(`/api/backstage/customers?teamId=${teamId}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
setCustomers(data.customers);
|
setCustomers(data.customers);
|
||||||
} catch (error) {
|
} catch (error: unknown) {
|
||||||
|
console.error('加载客户数据失败:', error);
|
||||||
message.error('加载客户数据失败');
|
message.error('加载客户数据失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchProducts = async (teamId: string) => {
|
const fetchProducts = async (teamId: string) => {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get(`/api/backstage/products?teamId=${teamId}`);
|
const response = await fetch(`/api/backstage/products?teamId=${teamId}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
setProducts(data.products);
|
setProducts(data.products);
|
||||||
} catch (error) {
|
} catch (error: unknown) {
|
||||||
|
console.error('加载产品数据失败:', error);
|
||||||
message.error('加载产品数据失败');
|
message.error('加载产品数据失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchAccounts = async (teamId: string) => {
|
const fetchAccounts = async (teamId: string) => {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get(`/api/backstage/accounts?teamId=${teamId}`);
|
const response = await fetch(`/api/backstage/accounts?teamId=${teamId}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
setAccounts(data.accounts);
|
setAccounts(data.accounts);
|
||||||
} catch (error) {
|
} catch (error: unknown) {
|
||||||
|
console.error('加载账户数据失败:', error);
|
||||||
message.error('加载账户数据失败');
|
message.error('加载账户数据失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchUsers = async (teamId: string) => {
|
const fetchUsers = async (teamId: string) => {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get(`/api/backstage/users?teamId=${teamId}`);
|
const response = await fetch(`/api/backstage/users?teamId=${teamId}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
setUsers(data.users);
|
setUsers(data.users);
|
||||||
} catch (error) {
|
} catch (error: unknown) {
|
||||||
|
console.error('加载用户数据失败:', error);
|
||||||
message.error('加载用户数据失败');
|
message.error('加载用户数据失败');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -89,18 +111,24 @@ const SalesRecordModal: React.FC<SalesRecordModalProps> = ({ visible, onCancel,
|
|||||||
const method = salesRecord ? 'PUT' : 'POST';
|
const method = salesRecord ? 'PUT' : 'POST';
|
||||||
const url = salesRecord ? `/api/backstage/sales/${salesRecord._id}` : '/api/backstage/sales';
|
const url = salesRecord ? `/api/backstage/sales/${salesRecord._id}` : '/api/backstage/sales';
|
||||||
|
|
||||||
await axios({
|
const response = await fetch(url, {
|
||||||
method: method,
|
method: method,
|
||||||
url: url,
|
headers: {
|
||||||
data: {
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
...values,
|
...values,
|
||||||
团队: userInfo.团队?._id, // 将团队ID包含在请求数据中
|
团队: userInfo.团队?._id, // 将团队ID包含在请求数据中
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
message.success('销售记录操作成功');
|
message.success('销售记录操作成功');
|
||||||
onOk(); // 直接调用 onOk 通知外部重新加载
|
onOk(); // 直接调用 onOk 通知外部重新加载
|
||||||
} catch (info) {
|
} catch (info: unknown) {
|
||||||
console.error('Validate Failed:', info);
|
console.error('Validate Failed:', info);
|
||||||
message.error('销售记录操作失败');
|
message.error('销售记录操作失败');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user