feat: 分析当前仓库
Co-authored-by: traeagent <traeagent@users.noreply.github.com>
This commit is contained in:
@@ -49,9 +49,9 @@ import {
|
|||||||
FilterOutlined,
|
FilterOutlined,
|
||||||
DeleteFilled,
|
DeleteFilled,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import axios from 'axios';
|
|
||||||
import { designTokens } from '../config/theme';
|
import { designTokens } from '../config/theme';
|
||||||
import CloseButton from '../components/CloseButton';
|
import CloseButton from '../components/CloseButton';
|
||||||
|
import api from '../api';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
const { Title, Text } = Typography;
|
const { Title, Text } = Typography;
|
||||||
@@ -321,7 +321,7 @@ function RackManagement() {
|
|||||||
async (page = 1, pageSize = 10) => {
|
async (page = 1, pageSize = 10) => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const response = await axios.get('/api/racks', {
|
const response = await api.get('/racks', {
|
||||||
params: {
|
params: {
|
||||||
page,
|
page,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -330,7 +330,7 @@ function RackManagement() {
|
|||||||
keyword: debouncedSearchKeyword || undefined,
|
keyword: debouncedSearchKeyword || undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { racks: data, total } = response.data;
|
const { racks: data, total } = response;
|
||||||
setRacks(data);
|
setRacks(data);
|
||||||
setPagination(prev => ({ ...prev, current: page, pageSize, total }));
|
setPagination(prev => ({ ...prev, current: page, pageSize, total }));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -345,8 +345,8 @@ function RackManagement() {
|
|||||||
|
|
||||||
const fetchRooms = useCallback(async () => {
|
const fetchRooms = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('/api/rooms');
|
const response = await api.get('/rooms');
|
||||||
setRooms(response.data.rooms || []);
|
setRooms(response.rooms || []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error('获取机房列表失败');
|
message.error('获取机房列表失败');
|
||||||
console.error('获取机房列表失败:', error);
|
console.error('获取机房列表失败:', error);
|
||||||
@@ -389,10 +389,10 @@ function RackManagement() {
|
|||||||
const handleSubmit = async values => {
|
const handleSubmit = async values => {
|
||||||
try {
|
try {
|
||||||
if (editingRack) {
|
if (editingRack) {
|
||||||
await axios.put(`/api/racks/${editingRack.rackId}`, values);
|
await api.put(`/racks/${editingRack.rackId}`, values);
|
||||||
message.success('机柜更新成功');
|
message.success('机柜更新成功');
|
||||||
} else {
|
} else {
|
||||||
await axios.post('/api/racks', values);
|
await api.post('/racks', values);
|
||||||
message.success('机柜创建成功');
|
message.success('机柜创建成功');
|
||||||
}
|
}
|
||||||
setModalVisible(false);
|
setModalVisible(false);
|
||||||
@@ -413,7 +413,7 @@ function RackManagement() {
|
|||||||
cancelText: '取消',
|
cancelText: '取消',
|
||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
try {
|
try {
|
||||||
await axios.delete(`/api/racks/${rackId}`);
|
await api.delete(`/racks/${rackId}`);
|
||||||
message.success('机柜删除成功');
|
message.success('机柜删除成功');
|
||||||
fetchRacks();
|
fetchRacks();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -440,7 +440,7 @@ function RackManagement() {
|
|||||||
onOk: async () => {
|
onOk: async () => {
|
||||||
try {
|
try {
|
||||||
const results = await Promise.allSettled(
|
const results = await Promise.allSettled(
|
||||||
selectedRackIds.map(id => axios.delete(`/api/racks/${id}`))
|
selectedRackIds.map(id => api.delete(`/racks/${id}`))
|
||||||
);
|
);
|
||||||
const succeeded = results.filter(r => r.status === 'fulfilled').length;
|
const succeeded = results.filter(r => r.status === 'fulfilled').length;
|
||||||
const failed = results.filter(r => r.status === 'rejected');
|
const failed = results.filter(r => r.status === 'rejected');
|
||||||
@@ -448,7 +448,7 @@ function RackManagement() {
|
|||||||
message.success(`成功删除 ${succeeded} 个机柜`);
|
message.success(`成功删除 ${succeeded} 个机柜`);
|
||||||
}
|
}
|
||||||
if (failed.length > 0) {
|
if (failed.length > 0) {
|
||||||
const firstError = failed[0].reason.response?.data?.error || '部分机柜删除失败';
|
const firstError = failed[0].reason.error || '部分机柜删除失败';
|
||||||
message.error(`${firstError}(${failed.length} 个失败)`);
|
message.error(`${firstError}(${failed.length} 个失败)`);
|
||||||
}
|
}
|
||||||
setSelectedRackIds([]);
|
setSelectedRackIds([]);
|
||||||
@@ -476,12 +476,12 @@ function RackManagement() {
|
|||||||
try {
|
try {
|
||||||
message.loading('正在导出租机柜数据...', 0);
|
message.loading('正在导出租机柜数据...', 0);
|
||||||
|
|
||||||
const response = await axios.get('/api/racks/export', {
|
const response = await api.get('/racks/export', {
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
});
|
});
|
||||||
|
|
||||||
// 创建下载链接
|
// 创建下载链接
|
||||||
const blob = new Blob([response.data], {
|
const blob = new Blob([response], {
|
||||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
});
|
});
|
||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
@@ -524,14 +524,14 @@ function RackManagement() {
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|
||||||
const response = await axios.post('/api/racks/import', formData, {
|
const response = await api.post('/racks/import', formData, {
|
||||||
headers: { 'Content-Type': 'multipart/form-data' },
|
headers: { 'Content-Type': 'multipart/form-data' },
|
||||||
});
|
});
|
||||||
|
|
||||||
setImportProgress(100);
|
setImportProgress(100);
|
||||||
setImportPhase('导入完成');
|
setImportPhase('导入完成');
|
||||||
|
|
||||||
const resData = response.data;
|
const resData = response;
|
||||||
const importResult = {
|
const importResult = {
|
||||||
total: resData.total || 0,
|
total: resData.total || 0,
|
||||||
successCount: resData.imported || 0,
|
successCount: resData.imported || 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user