Initial commit: ERP system with advance verification fixes
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import axios from 'axios';
|
||||
import type { AxiosInstance, AxiosRequestConfig } from 'axios';
|
||||
import { API_CONFIG } from '../config/api.config';
|
||||
|
||||
class ApiService {
|
||||
private instance: AxiosInstance;
|
||||
|
||||
constructor() {
|
||||
this.instance = axios.create(API_CONFIG);
|
||||
this.setupInterceptors();
|
||||
}
|
||||
|
||||
private setupInterceptors() {
|
||||
// 请求拦截器
|
||||
this.instance.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 响应拦截器
|
||||
this.instance.interceptors.response.use(
|
||||
(response) => {
|
||||
return response.data;
|
||||
},
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
// 未授权,跳转到登录页
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
window.location.href = '/login';
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async get<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.get(url, config);
|
||||
}
|
||||
|
||||
async post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.post(url, data, config);
|
||||
}
|
||||
|
||||
async put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.put(url, data, config);
|
||||
}
|
||||
|
||||
async delete<T>(url: string, config?: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.delete(url, config);
|
||||
}
|
||||
}
|
||||
|
||||
export const apiService = new ApiService();
|
||||
@@ -0,0 +1,49 @@
|
||||
import { apiService } from './api.service';
|
||||
|
||||
interface LoginResponse {
|
||||
access_token: string;
|
||||
user: {
|
||||
id: string;
|
||||
username: string;
|
||||
name: string;
|
||||
email: string;
|
||||
role: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface RegisterData {
|
||||
username: string;
|
||||
password: string;
|
||||
name: string;
|
||||
email: string;
|
||||
roleId: string;
|
||||
}
|
||||
|
||||
export const authService = {
|
||||
async login(username: string, password: string): Promise<LoginResponse> {
|
||||
const response = await apiService.post<LoginResponse>('/auth/login', { username, password });
|
||||
if (response.access_token) {
|
||||
localStorage.setItem('token', response.access_token);
|
||||
localStorage.setItem('user', JSON.stringify(response.user));
|
||||
}
|
||||
return response;
|
||||
},
|
||||
|
||||
async register(data: RegisterData): Promise<any> {
|
||||
return apiService.post('/auth/register', data);
|
||||
},
|
||||
|
||||
logout(): void {
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
},
|
||||
|
||||
isAuthenticated(): boolean {
|
||||
return !!localStorage.getItem('token');
|
||||
},
|
||||
|
||||
getUser(): any {
|
||||
const userStr = localStorage.getItem('user');
|
||||
return userStr ? JSON.parse(userStr) : null;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
import axios from 'axios';
|
||||
import { API_CONFIG } from '../config/api.config';
|
||||
|
||||
const API_URL = API_CONFIG.baseURL;
|
||||
|
||||
export interface Customer {
|
||||
id: string;
|
||||
name: string;
|
||||
contact_person: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
address: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export const customerService = {
|
||||
async getCustomers(): Promise<Customer[]> {
|
||||
const response = await axios.get(`${API_URL}/customers`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async getCustomer(id: string): Promise<Customer> {
|
||||
const response = await axios.get(`${API_URL}/customers/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async getCustomerWithProjects(id: string): Promise<any> {
|
||||
const response = await axios.get(`${API_URL}/customers/${id}/projects`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async getCustomerWithQuotations(id: string): Promise<any> {
|
||||
const response = await axios.get(`${API_URL}/customers/${id}/quotations`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createCustomer(customer: Omit<Customer, 'id' | 'created_at' | 'updated_at'>): Promise<Customer> {
|
||||
const response = await axios.post(`${API_URL}/customers`, customer);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateCustomer(id: string, customer: Partial<Customer>): Promise<Customer> {
|
||||
const response = await axios.patch(`${API_URL}/customers/${id}`, customer);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteCustomer(id: string): Promise<void> {
|
||||
await axios.delete(`${API_URL}/customers/${id}`);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,113 @@
|
||||
import { apiService } from './api.service';
|
||||
|
||||
const financeService = {
|
||||
// 报销申请相关
|
||||
createExpenseClaim: async (data: any) => {
|
||||
return await apiService.post('/finance/expense-claims', data);
|
||||
},
|
||||
|
||||
getExpenseClaims: async (filter?: any) => {
|
||||
return await apiService.get('/finance/expense-claims', { params: filter });
|
||||
},
|
||||
|
||||
getExpenseClaimById: async (id: string) => {
|
||||
return await apiService.get(`/finance/expense-claims/${id}`);
|
||||
},
|
||||
|
||||
approveExpenseClaim: async (id: string, notes?: string) => {
|
||||
return await apiService.put(`/finance/expense-claims/${id}/approve`, { notes });
|
||||
},
|
||||
|
||||
rejectExpenseClaim: async (id: string, notes?: string) => {
|
||||
return await apiService.put(`/finance/expense-claims/${id}/reject`, { notes });
|
||||
},
|
||||
|
||||
// 预支款相关
|
||||
createAdvancePayment: async (data: any) => {
|
||||
return await apiService.post('/finance/advance-payments', data);
|
||||
},
|
||||
|
||||
getAdvancePayments: async (filter?: any) => {
|
||||
return await apiService.get('/finance/advance-payments', { params: filter });
|
||||
},
|
||||
|
||||
getAdvancePaymentById: async (id: string) => {
|
||||
return await apiService.get(`/finance/advance-payments/${id}`);
|
||||
},
|
||||
|
||||
approveAdvancePayment: async (id: string, notes?: string) => {
|
||||
return await apiService.put(`/finance/advance-payments/${id}/approve`, { notes });
|
||||
},
|
||||
|
||||
rejectAdvancePayment: async (id: string, notes?: string) => {
|
||||
return await apiService.put(`/finance/advance-payments/${id}/reject`, { notes });
|
||||
},
|
||||
|
||||
updateAdvancePaymentUsage: async (id: string, usedAmount: number) => {
|
||||
return await apiService.put(`/finance/advance-payments/${id}/usage`, { used_amount: usedAmount });
|
||||
},
|
||||
|
||||
// 凭证相关
|
||||
uploadVoucher: async (data: any) => {
|
||||
return await apiService.post('/finance/vouchers', data);
|
||||
},
|
||||
|
||||
getVouchers: async (filter?: any) => {
|
||||
return await apiService.get('/finance/vouchers', { params: filter });
|
||||
},
|
||||
|
||||
// 财务审批相关
|
||||
createFinanceApproval: async (data: any) => {
|
||||
return await apiService.post('/finance/approvals', data);
|
||||
},
|
||||
|
||||
getFinanceApprovals: async (filter?: any) => {
|
||||
return await apiService.get('/finance/approvals', { params: filter });
|
||||
},
|
||||
|
||||
approveFinanceApproval: async (id: string, notes?: string) => {
|
||||
return await apiService.put(`/finance/approvals/${id}/approve`, { notes });
|
||||
},
|
||||
|
||||
rejectFinanceApproval: async (id: string, notes?: string) => {
|
||||
return await apiService.put(`/finance/approvals/${id}/reject`, { notes });
|
||||
},
|
||||
|
||||
// 公司账目管理
|
||||
getCompanyFinancialRecords: async (filter?: any) => {
|
||||
return await apiService.get('/finance/company-records', { params: filter });
|
||||
},
|
||||
|
||||
// 项目财务记录
|
||||
getProjectFinancialRecords: async (projectId: string) => {
|
||||
return await apiService.get(`/finance/project-records/${projectId}`);
|
||||
},
|
||||
|
||||
// 员工个人记账
|
||||
getEmployeeFinancialRecords: async () => {
|
||||
return await apiService.get('/finance/employee-records');
|
||||
},
|
||||
|
||||
// 汇率管理相关
|
||||
getCurrencyRates: async () => {
|
||||
return await apiService.get('/finance/currency-rates');
|
||||
},
|
||||
|
||||
createOrUpdateCurrencyRate: async (data: any) => {
|
||||
return await apiService.post('/finance/currency-rates', data);
|
||||
},
|
||||
|
||||
updateCurrencyRateStatus: async (id: string, is_active: boolean) => {
|
||||
return await apiService.put(`/finance/currency-rates/${id}/status`, { is_active });
|
||||
},
|
||||
|
||||
getSupportedCurrencies: async () => {
|
||||
return await apiService.get('/finance/currencies');
|
||||
},
|
||||
|
||||
convertCurrency: async (amount: number, from_currency: string, to_currency: string) => {
|
||||
return await apiService.post('/finance/convert-currency', { amount, from_currency, to_currency });
|
||||
},
|
||||
};
|
||||
|
||||
export default financeService;
|
||||
@@ -0,0 +1,31 @@
|
||||
import { apiService } from './api.service';
|
||||
|
||||
export const projectService = {
|
||||
async getProjects(query: any = {}) {
|
||||
return apiService.get<any>('/projects', { params: query });
|
||||
},
|
||||
|
||||
async getProjectById(id: string) {
|
||||
return apiService.get<any>(`/projects/${id}`);
|
||||
},
|
||||
|
||||
async createProject(projectData: any) {
|
||||
return apiService.post<any>('/projects', projectData);
|
||||
},
|
||||
|
||||
async updateProject(id: string, projectData: any) {
|
||||
return apiService.put<any>(`/projects/${id}`, projectData);
|
||||
},
|
||||
|
||||
async deleteProject(id: string) {
|
||||
return apiService.delete<any>(`/projects/${id}`);
|
||||
},
|
||||
|
||||
async calculateDuration(id: string) {
|
||||
return apiService.get<any>(`/projects/${id}/calculate-duration`);
|
||||
},
|
||||
|
||||
async updateStatus(id: string, status: string) {
|
||||
return apiService.put<any>(`/projects/${id}/update-status`, { status });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import axios from 'axios';
|
||||
import { API_CONFIG } from '../config/api.config';
|
||||
|
||||
const API_URL = API_CONFIG.baseURL;
|
||||
|
||||
export interface Subcontractor {
|
||||
id: string;
|
||||
name: string;
|
||||
contact_person: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
address: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export const subcontractorService = {
|
||||
async getSubcontractors(): Promise<Subcontractor[]> {
|
||||
const response = await axios.get(`${API_URL}/subcontractors`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async getSubcontractor(id: string): Promise<Subcontractor> {
|
||||
const response = await axios.get(`${API_URL}/subcontractors/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async getSubcontractorWithSubcontracts(id: string): Promise<any> {
|
||||
const response = await axios.get(`${API_URL}/subcontractors/${id}/subcontracts`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createSubcontractor(subcontractor: Omit<Subcontractor, 'id' | 'created_at' | 'updated_at'>): Promise<Subcontractor> {
|
||||
const response = await axios.post(`${API_URL}/subcontractors`, subcontractor);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateSubcontractor(id: string, subcontractor: Partial<Subcontractor>): Promise<Subcontractor> {
|
||||
const response = await axios.patch(`${API_URL}/subcontractors/${id}`, subcontractor);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteSubcontractor(id: string): Promise<void> {
|
||||
await axios.delete(`${API_URL}/subcontractors/${id}`);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
import axios from 'axios';
|
||||
import { API_CONFIG } from '../config/api.config';
|
||||
|
||||
const API_URL = API_CONFIG.baseURL;
|
||||
|
||||
export interface Supplier {
|
||||
id: string;
|
||||
name: string;
|
||||
contact_person: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
address: string;
|
||||
type: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export const supplierService = {
|
||||
async getSuppliers(): Promise<Supplier[]> {
|
||||
const response = await axios.get(`${API_URL}/suppliers`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async getSupplier(id: string): Promise<Supplier> {
|
||||
const response = await axios.get(`${API_URL}/suppliers/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async getSupplierWithPurchases(id: string): Promise<any> {
|
||||
const response = await axios.get(`${API_URL}/suppliers/${id}/purchases`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async createSupplier(supplier: Omit<Supplier, 'id' | 'created_at' | 'updated_at'>): Promise<Supplier> {
|
||||
const response = await axios.post(`${API_URL}/suppliers`, supplier);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async updateSupplier(id: string, supplier: Partial<Supplier>): Promise<Supplier> {
|
||||
const response = await axios.patch(`${API_URL}/suppliers/${id}`, supplier);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async deleteSupplier(id: string): Promise<void> {
|
||||
await axios.delete(`${API_URL}/suppliers/${id}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user