chore: 统一代码风格并配置ESLint和Prettier
配置ESLint和Prettier规则 添加前端和后端的忽略文件 统一代码格式和缩进 修复代码风格问题
This commit is contained in:
+77
-80
@@ -9,7 +9,7 @@ const cacheManager = (() => {
|
||||
return `${method}:${url}:${paramsStr}`;
|
||||
};
|
||||
|
||||
const isExpired = (key) => {
|
||||
const isExpired = key => {
|
||||
const timestamp = cacheTimestamps.get(key);
|
||||
if (!timestamp) return true;
|
||||
const ttl = config.get(key)?.ttl || defaultTTL;
|
||||
@@ -34,7 +34,7 @@ const cacheManager = (() => {
|
||||
return key;
|
||||
};
|
||||
|
||||
const invalidate = (url) => {
|
||||
const invalidate = url => {
|
||||
const keysToDelete = [];
|
||||
cache.forEach((_, key) => {
|
||||
if (key.includes(url)) {
|
||||
@@ -49,7 +49,7 @@ const cacheManager = (() => {
|
||||
return keysToDelete.length;
|
||||
};
|
||||
|
||||
const invalidatePattern = (pattern) => {
|
||||
const invalidatePattern = pattern => {
|
||||
const regex = new RegExp(pattern);
|
||||
const keysToDelete = [];
|
||||
cache.forEach((_, key) => {
|
||||
@@ -78,7 +78,7 @@ const cacheManager = (() => {
|
||||
const getStats = () => {
|
||||
return {
|
||||
size: cache.size,
|
||||
keys: Array.from(cache.keys())
|
||||
keys: Array.from(cache.keys()),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -90,37 +90,29 @@ const cacheManager = (() => {
|
||||
clear,
|
||||
setTTL,
|
||||
getStats,
|
||||
defaultTTL
|
||||
defaultTTL,
|
||||
};
|
||||
})();
|
||||
|
||||
const cacheInterceptor = (api) => {
|
||||
const cacheInterceptor = api => {
|
||||
const requestCache = new Set();
|
||||
const pendingRequests = new Map();
|
||||
|
||||
api.interceptors.request.use(
|
||||
(config) => {
|
||||
config => {
|
||||
if (config.method?.toLowerCase() === 'get') {
|
||||
const cacheKey = cacheManager.generateKey(
|
||||
config.method,
|
||||
config.url,
|
||||
config.params
|
||||
);
|
||||
const cacheKey = cacheManager.generateKey(config.method, config.url, config.params);
|
||||
|
||||
if (requestCache.has(cacheKey)) {
|
||||
config.adapter = () => {
|
||||
const cachedData = cacheManager.get(
|
||||
config.method,
|
||||
config.url,
|
||||
config.params
|
||||
);
|
||||
const cachedData = cacheManager.get(config.method, config.url, config.params);
|
||||
if (cachedData) {
|
||||
return Promise.resolve({
|
||||
data: cachedData,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {},
|
||||
config
|
||||
config,
|
||||
});
|
||||
}
|
||||
requestCache.delete(cacheKey);
|
||||
@@ -130,11 +122,11 @@ const cacheInterceptor = (api) => {
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => Promise.reject(error)
|
||||
error => Promise.reject(error)
|
||||
);
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => {
|
||||
response => {
|
||||
if (response.config.method?.toLowerCase() === 'get') {
|
||||
const cacheKey = cacheManager.generateKey(
|
||||
response.config.method,
|
||||
@@ -151,7 +143,7 @@ const cacheInterceptor = (api) => {
|
||||
}
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
if (error.config) {
|
||||
const cacheKey = cacheManager.generateKey(
|
||||
error.config.method,
|
||||
@@ -178,108 +170,113 @@ export const cachedAPI = {
|
||||
});
|
||||
},
|
||||
|
||||
post: (url, data) => api.post(url, data).then(data => {
|
||||
cacheManager.invalidate(url);
|
||||
return data;
|
||||
}),
|
||||
post: (url, data) =>
|
||||
api.post(url, data).then(data => {
|
||||
cacheManager.invalidate(url);
|
||||
return data;
|
||||
}),
|
||||
|
||||
put: (url, data) => api.put(url, data).then(data => {
|
||||
cacheManager.invalidate(url);
|
||||
return data;
|
||||
}),
|
||||
put: (url, data) =>
|
||||
api.put(url, data).then(data => {
|
||||
cacheManager.invalidate(url);
|
||||
return data;
|
||||
}),
|
||||
|
||||
delete: (url) => api.delete(url).then(data => {
|
||||
cacheManager.invalidate(url);
|
||||
return data;
|
||||
}),
|
||||
delete: url =>
|
||||
api.delete(url).then(data => {
|
||||
cacheManager.invalidate(url);
|
||||
return data;
|
||||
}),
|
||||
|
||||
invalidate: (url) => cacheManager.invalidate(url),
|
||||
invalidate: url => cacheManager.invalidate(url),
|
||||
|
||||
invalidatePattern: (pattern) => cacheManager.invalidatePattern(pattern),
|
||||
invalidatePattern: pattern => cacheManager.invalidatePattern(pattern),
|
||||
|
||||
clearCache: () => cacheManager.clear(),
|
||||
|
||||
setCacheTTL: (url, ttl) => cacheManager.setTTL(url, ttl),
|
||||
|
||||
getCacheStats: () => cacheManager.getStats()
|
||||
getCacheStats: () => cacheManager.getStats(),
|
||||
};
|
||||
|
||||
export const deviceAPI = {
|
||||
list: (params) => cachedAPI.get('/devices', params),
|
||||
get: (deviceId) => cachedAPI.get(`/devices/${deviceId}`),
|
||||
create: (data) => cachedAPI.post('/devices', data),
|
||||
list: params => cachedAPI.get('/devices', params),
|
||||
get: deviceId => cachedAPI.get(`/devices/${deviceId}`),
|
||||
create: data => cachedAPI.post('/devices', data),
|
||||
update: (deviceId, data) => cachedAPI.put(`/api/devices/${deviceId}`, data),
|
||||
delete: (deviceId) => cachedAPI.delete(`/api/devices/${deviceId}`),
|
||||
batchOffline: (data) => cachedAPI.post('/devices/batch-offline', data),
|
||||
batchDelete: (data) => cachedAPI.delete('/devices/batch-delete', { data }),
|
||||
export: (params) => api.get('/devices/export', { params, responseType: 'blob' }),
|
||||
import: (formData) => api.post('/devices/import', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
delete: deviceId => cachedAPI.delete(`/api/devices/${deviceId}`),
|
||||
batchOffline: data => cachedAPI.post('/devices/batch-offline', data),
|
||||
batchDelete: data => cachedAPI.delete('/devices/batch-delete', { data }),
|
||||
export: params => api.get('/devices/export', { params, responseType: 'blob' }),
|
||||
import: formData =>
|
||||
api.post('/devices/import', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
}),
|
||||
};
|
||||
|
||||
export const rackAPI = {
|
||||
list: (params) => cachedAPI.get('/racks', params),
|
||||
get: (rackId) => cachedAPI.get(`/racks/${rackId}`),
|
||||
create: (data) => cachedAPI.post('/racks', data),
|
||||
list: params => cachedAPI.get('/racks', params),
|
||||
get: rackId => cachedAPI.get(`/racks/${rackId}`),
|
||||
create: data => cachedAPI.post('/racks', data),
|
||||
update: (rackId, data) => cachedAPI.put(`/racks/${rackId}`, data),
|
||||
delete: (rackId) => cachedAPI.delete(`/racks/${rackId}`),
|
||||
import: (formData) => api.post('/racks/import', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
delete: rackId => cachedAPI.delete(`/racks/${rackId}`),
|
||||
import: formData =>
|
||||
api.post('/racks/import', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
}),
|
||||
};
|
||||
|
||||
export const roomAPI = {
|
||||
list: (params) => cachedAPI.get('/rooms', params),
|
||||
get: (roomId) => cachedAPI.get(`/rooms/${roomId}`),
|
||||
create: (data) => cachedAPI.post('/rooms', data),
|
||||
list: params => cachedAPI.get('/rooms', params),
|
||||
get: roomId => cachedAPI.get(`/rooms/${roomId}`),
|
||||
create: data => cachedAPI.post('/rooms', data),
|
||||
update: (roomId, data) => cachedAPI.put(`/rooms/${roomId}`, data),
|
||||
delete: (roomId) => cachedAPI.delete(`/rooms/${roomId}`)
|
||||
delete: roomId => cachedAPI.delete(`/rooms/${roomId}`),
|
||||
};
|
||||
|
||||
export const deviceFieldAPI = {
|
||||
list: () => cachedAPI.get('/deviceFields'),
|
||||
get: (fieldId) => cachedAPI.get(`/deviceFields/${fieldId}`),
|
||||
create: (data) => cachedAPI.post('/deviceFields', data),
|
||||
get: fieldId => cachedAPI.get(`/deviceFields/${fieldId}`),
|
||||
create: data => cachedAPI.post('/deviceFields', data),
|
||||
update: (fieldId, data) => cachedAPI.put(`/deviceFields/${fieldId}`, data),
|
||||
delete: (fieldId) => cachedAPI.delete(`/deviceFields/${fieldId}`),
|
||||
updateConfig: (data) => cachedAPI.post('/deviceFields/config', data)
|
||||
delete: fieldId => cachedAPI.delete(`/deviceFields/${fieldId}`),
|
||||
updateConfig: data => cachedAPI.post('/deviceFields/config', data),
|
||||
};
|
||||
|
||||
export const consumableAPI = {
|
||||
list: (params) => cachedAPI.get('/consumables', params),
|
||||
get: (consumableId) => cachedAPI.get(`/consumables/${consumableId}`),
|
||||
create: (data) => cachedAPI.post('/consumables', data),
|
||||
list: params => cachedAPI.get('/consumables', params),
|
||||
get: consumableId => cachedAPI.get(`/consumables/${consumableId}`),
|
||||
create: data => cachedAPI.post('/consumables', data),
|
||||
update: (consumableId, data) => cachedAPI.put(`/consumables/${consumableId}`, data),
|
||||
delete: (consumableId) => cachedAPI.delete(`/consumables/${consumableId}`),
|
||||
import: (data) => cachedAPI.post('/consumables/import', data),
|
||||
quickInOut: (data) => cachedAPI.post('/consumables/quick-inout', data),
|
||||
delete: consumableId => cachedAPI.delete(`/consumables/${consumableId}`),
|
||||
import: data => cachedAPI.post('/consumables/import', data),
|
||||
quickInOut: data => cachedAPI.post('/consumables/quick-inout', data),
|
||||
getStatistics: () => cachedAPI.get('/consumables/statistics/summary'),
|
||||
getLowStock: () => cachedAPI.get('/consumables/low-stock')
|
||||
getLowStock: () => cachedAPI.get('/consumables/low-stock'),
|
||||
};
|
||||
|
||||
export const consumableCategoryAPI = {
|
||||
list: (params) => cachedAPI.get('/consumable-categories', params),
|
||||
getList: (params) => cachedAPI.get('/consumable-categories/list', params),
|
||||
create: (data) => cachedAPI.post('/consumable-categories', data),
|
||||
list: params => cachedAPI.get('/consumable-categories', params),
|
||||
getList: params => cachedAPI.get('/consumable-categories/list', params),
|
||||
create: data => cachedAPI.post('/consumable-categories', data),
|
||||
update: (id, data) => cachedAPI.put(`/consumable-categories/${id}`, data),
|
||||
delete: (id) => cachedAPI.delete(`/consumable-categories/${id}`)
|
||||
delete: id => cachedAPI.delete(`/consumable-categories/${id}`),
|
||||
};
|
||||
|
||||
export const consumableLogAPI = {
|
||||
list: (params) => cachedAPI.get('/consumables/logs', params),
|
||||
create: (data) => cachedAPI.post('/consumables/logs', data),
|
||||
export: (params) => api.get('/consumables/logs/export', { params, responseType: 'blob' }),
|
||||
import: (data) => cachedAPI.post('/consumables/logs/import', data)
|
||||
list: params => cachedAPI.get('/consumables/logs', params),
|
||||
create: data => cachedAPI.post('/consumables/logs', data),
|
||||
export: params => api.get('/consumables/logs/export', { params, responseType: 'blob' }),
|
||||
import: data => cachedAPI.post('/consumables/logs/import', data),
|
||||
};
|
||||
|
||||
export const ticketCategoryAPI = {
|
||||
list: (params) => cachedAPI.get('/ticket-categories', params),
|
||||
create: (data) => cachedAPI.post('/ticket-categories', data),
|
||||
list: params => cachedAPI.get('/ticket-categories', params),
|
||||
create: data => cachedAPI.post('/ticket-categories', data),
|
||||
update: (code, data) => cachedAPI.put(`/ticket-categories/${code}`, data),
|
||||
delete: (code) => cachedAPI.delete(`/ticket-categories/${code}`),
|
||||
delete: code => cachedAPI.delete(`/ticket-categories/${code}`),
|
||||
getTree: () => cachedAPI.get('/ticket-categories/tree'),
|
||||
init: () => cachedAPI.post('/ticket-categories/init')
|
||||
init: () => cachedAPI.post('/ticket-categories/init'),
|
||||
};
|
||||
|
||||
export { cacheManager };
|
||||
|
||||
+48
-48
@@ -6,17 +6,17 @@ const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
api.interceptors.request.use(
|
||||
(config) => {
|
||||
config => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
|
||||
// 开发环境下安全日志:过滤敏感字段
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
const sensitiveFields = ['password', 'oldPassword', 'newPassword', 'confirmPassword'];
|
||||
@@ -28,26 +28,26 @@ api.interceptors.request.use(
|
||||
}
|
||||
console.log(`[API] ${config.method?.toUpperCase()} ${config.url}`, safeData || '');
|
||||
}
|
||||
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => {
|
||||
response => {
|
||||
return response.data;
|
||||
},
|
||||
(error) => {
|
||||
error => {
|
||||
if (error.response) {
|
||||
const { status, data } = error.response;
|
||||
|
||||
|
||||
if (status === 401) {
|
||||
const currentPath = window.location.pathname;
|
||||
console.log('[API] 401 error, current path:', currentPath);
|
||||
|
||||
|
||||
if (!currentPath.startsWith('/login')) {
|
||||
const savedToken = localStorage.getItem('token');
|
||||
if (savedToken) {
|
||||
@@ -58,96 +58,96 @@ api.interceptors.response.use(
|
||||
window.location.href = '/login';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Promise.reject(data.message || '请求失败');
|
||||
}
|
||||
|
||||
|
||||
if (error.code === 'ECONNABORTED') {
|
||||
return Promise.reject('请求超时,请稍后重试');
|
||||
}
|
||||
|
||||
|
||||
return Promise.reject('网络错误,请检查网络连接');
|
||||
}
|
||||
);
|
||||
|
||||
export const authAPI = {
|
||||
checkAdmin: () => api.get('/auth/check-admin'),
|
||||
register: (data) => api.post('/auth/register', data),
|
||||
login: (data) => api.post('/auth/login', data),
|
||||
unlock: (data) => api.post('/auth/unlock', data),
|
||||
register: data => api.post('/auth/register', data),
|
||||
login: data => api.post('/auth/login', data),
|
||||
unlock: data => api.post('/auth/unlock', data),
|
||||
getProfile: () => api.get('/auth/profile'),
|
||||
updateProfile: (data) => api.put('/auth/profile', data),
|
||||
changePassword: (data) => api.put('/auth/password', data)
|
||||
updateProfile: data => api.put('/auth/profile', data),
|
||||
changePassword: data => api.put('/auth/password', data),
|
||||
};
|
||||
|
||||
export const userAPI = {
|
||||
list: (params) => api.get('/users', { params }),
|
||||
list: params => api.get('/users', { params }),
|
||||
all: () => api.get('/users/all'),
|
||||
get: (userId) => api.get(`/users/${userId}`),
|
||||
create: (data) => api.post('/users', data),
|
||||
get: userId => api.get(`/users/${userId}`),
|
||||
create: data => api.post('/users', data),
|
||||
update: (userId, data) => api.put(`/users/${userId}`, data),
|
||||
resetPassword: (userId, data) => api.put(`/users/${userId}/password`, data),
|
||||
delete: (userId) => api.delete(`/users/${userId}`),
|
||||
delete: userId => api.delete(`/users/${userId}`),
|
||||
uploadAvatar: (userId, file) => {
|
||||
const formData = new FormData();
|
||||
formData.append('avatar', file);
|
||||
return api.post(`/users/${userId}/avatar`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
},
|
||||
deleteAvatar: (userId) => api.delete(`/users/${userId}/avatar`),
|
||||
approve: (userId) => api.put(`/users/${userId}/approve`),
|
||||
reject: (userId) => api.put(`/users/${userId}/reject`)
|
||||
deleteAvatar: userId => api.delete(`/users/${userId}/avatar`),
|
||||
approve: userId => api.put(`/users/${userId}/approve`),
|
||||
reject: userId => api.put(`/users/${userId}/reject`),
|
||||
};
|
||||
|
||||
export const roleAPI = {
|
||||
list: (params) => api.get('/roles', { params }),
|
||||
list: params => api.get('/roles', { params }),
|
||||
all: () => api.get('/roles/all'),
|
||||
get: (roleId) => api.get(`/roles/${roleId}`),
|
||||
create: (data) => api.post('/roles', data),
|
||||
get: roleId => api.get(`/roles/${roleId}`),
|
||||
create: data => api.post('/roles', data),
|
||||
update: (roleId, data) => api.put(`/roles/${roleId}`, data),
|
||||
delete: (roleId) => api.delete(`/roles/${roleId}`),
|
||||
initRoles: () => api.post('/roles/init-roles')
|
||||
delete: roleId => api.delete(`/roles/${roleId}`),
|
||||
initRoles: () => api.post('/roles/init-roles'),
|
||||
};
|
||||
|
||||
export const loginHistoryAPI = {
|
||||
list: (params) => api.get('/login-history', { params }),
|
||||
list: params => api.get('/login-history', { params }),
|
||||
getByUser: (userId, params) => api.get(`/login-history/user/${userId}`, { params }),
|
||||
delete: (id) => api.delete(`/login-history/${id}`),
|
||||
clear: (data) => api.delete('/login-history', { data })
|
||||
delete: id => api.delete(`/login-history/${id}`),
|
||||
clear: data => api.delete('/login-history', { data }),
|
||||
};
|
||||
|
||||
export const operationLogAPI = {
|
||||
list: (params) => api.get('/operation-logs', { params }),
|
||||
list: params => api.get('/operation-logs', { params }),
|
||||
getActions: () => api.get('/operation-logs/actions'),
|
||||
getModules: () => api.get('/operation-logs/modules'),
|
||||
delete: (id) => api.delete(`/operation-logs/${id}`),
|
||||
clear: (data) => api.delete('/operation-logs', { data })
|
||||
delete: id => api.delete(`/operation-logs/${id}`),
|
||||
clear: data => api.delete('/operation-logs', { data }),
|
||||
};
|
||||
|
||||
export const ticketAPI = {
|
||||
list: (params) => api.get('/tickets', { params }),
|
||||
get: (ticketId) => api.get(`/tickets/${ticketId}`),
|
||||
create: (data) => api.post('/tickets', data),
|
||||
list: params => api.get('/tickets', { params }),
|
||||
get: ticketId => api.get(`/tickets/${ticketId}`),
|
||||
create: data => api.post('/tickets', data),
|
||||
update: (ticketId, data) => api.put(`/tickets/${ticketId}`, data),
|
||||
delete: (ticketId) => api.delete(`/tickets/${ticketId}`),
|
||||
delete: ticketId => api.delete(`/tickets/${ticketId}`),
|
||||
assign: (ticketId, data) => api.put(`/tickets/${ticketId}/assign`, data),
|
||||
transfer: (ticketId, data) => api.put(`/tickets/${ticketId}/transfer`, data),
|
||||
process: (ticketId, data) => api.put(`/tickets/${ticketId}/process`, data),
|
||||
close: (ticketId, data) => api.put(`/tickets/${ticketId}/close`, data),
|
||||
reopen: (ticketId, data) => api.put(`/tickets/${ticketId}/reopen`, data),
|
||||
getOperations: (ticketId) => api.get(`/tickets/${ticketId}/operations`),
|
||||
getStatistics: (params) => api.get('/tickets/statistics', { params })
|
||||
getOperations: ticketId => api.get(`/tickets/${ticketId}/operations`),
|
||||
getStatistics: params => api.get('/tickets/statistics', { params }),
|
||||
};
|
||||
|
||||
export const ticketCategoryAPI = {
|
||||
list: (params) => api.get('/ticket-categories', { params }),
|
||||
get: (code) => api.get(`/ticket-categories/${code}`),
|
||||
create: (data) => api.post('/ticket-categories', data),
|
||||
list: params => api.get('/ticket-categories', { params }),
|
||||
get: code => api.get(`/ticket-categories/${code}`),
|
||||
create: data => api.post('/ticket-categories', data),
|
||||
update: (code, data) => api.put(`/ticket-categories/${code}`, data),
|
||||
delete: (code) => api.delete(`/ticket-categories/${code}`),
|
||||
delete: code => api.delete(`/ticket-categories/${code}`),
|
||||
tree: () => api.get('/ticket-categories/tree'),
|
||||
init: () => api.post('/ticket-categories/init')
|
||||
init: () => api.post('/ticket-categories/init'),
|
||||
};
|
||||
|
||||
export default api;
|
||||
|
||||
Reference in New Issue
Block a user