生产管理系统 - 禁用、启用接口联调

This commit is contained in:
2025-11-03 17:49:39 +08:00
parent 0305bd64a7
commit c690d50baa
2 changed files with 120 additions and 19 deletions

View File

@@ -22,7 +22,7 @@ import { Building2, Eye, Power, PowerOff, Search, FileText, CreditCard, User, Re
import { toast } from 'sonner';
import { enterpriseReducer, initialState, EnterpriseState, EnterpriseAction } from './components/enterpriseReducer';
import { fetchTenants, transformTenantData, TenantsQueryParams, Enterprise } from './components/enterpriseApi';
import { fetchTenants, transformTenantData, enableTenant, disableTenant, TenantsQueryParams, Enterprise } from './components/enterpriseApi';
// Utility functions
const getStatusBadge = (status: 'active' | 'inactive') => {
@@ -67,6 +67,9 @@ export default function EnterpriseManagement() {
const response = await fetchTenants(params);
const transformedData = response.data.map(transformTenantData);
console.log('API Response:', response);
console.log('Transformed Data:', transformedData);
dispatch({
type: 'SET_ENTERPRISES',
payload: {
@@ -143,27 +146,49 @@ export default function EnterpriseManagement() {
dispatch({ type: 'TOGGLE_STATUS_DIALOG', payload: true });
};
const confirmStatusChange = () => {
const confirmStatusChange = async () => {
if (!state.selectedEnterprise) return;
// 这里应该调用API来更新企业状态
// 暂时更新本地状态
const newStatus = state.statusAction === 'enable' ? 'active' : 'inactive';
try {
dispatch({ type: 'SET_LOADING', payload: true });
dispatch({
type: 'SET_ENTERPRISES',
payload: {
data: state.enterprises.map(ent =>
ent.id === state.selectedEnterprise?.id
? { ...ent, status: newStatus }
: ent
),
pagination: state.pagination
const tenantId = state.selectedEnterprise.id;
let updatedTenant;
if (state.statusAction === 'enable') {
updatedTenant = await enableTenant(tenantId);
toast.success('企业已启用');
} else {
updatedTenant = await disableTenant(tenantId);
toast.success('企业已禁用');
}
});
dispatch({ type: 'TOGGLE_STATUS_DIALOG', payload: false });
toast.success(state.statusAction === 'enable' ? '企业已启用' : '企业已禁用');
// 验证返回的数据是否正确更新了状态
console.log('API返回的更新数据:', updatedTenant);
// 更新本地状态
const updatedEnterprise = transformTenantData(updatedTenant);
dispatch({
type: 'SET_ENTERPRISES',
payload: {
data: state.enterprises.map(ent =>
ent.id === tenantId ? updatedEnterprise : ent
),
pagination: state.pagination
}
});
dispatch({ type: 'TOGGLE_STATUS_DIALOG', payload: false });
// 不需要立即刷新,因为本地状态已经更新
// 如果用户需要看到最新数据,可以手动点击刷新按钮
} catch (error) {
console.error('Status change failed:', error);
const errorMessage = error instanceof Error ? error.message : '状态更新失败';
toast.error(errorMessage);
} finally {
dispatch({ type: 'SET_LOADING', payload: false });
}
};
return (