// API基础配置和服务
|
import axios from 'axios';
|
import { generateSign } from '../utils/encrypt';
|
|
// 创建axios实例
|
const api = axios.create({
|
// baseURL: process.env.REACT_APP_API_BASE_URL || 'http://localhost:9002/grid-hub',
|
// baseURL: process.env.REACT_APP_API_BASE_URL || 'http://hkcsdn.hkrxd.com/grid-hub-prod',
|
baseURL: process.env.REACT_APP_API_BASE_URL || 'http://sqyy.spoc.haikou.gov.in:9094/grid-hub-prod',
|
timeout: 10000,
|
headers: {
|
'Content-Type': 'application/json',
|
},
|
});
|
|
// 请求拦截器
|
api.interceptors.request.use(
|
(config) => {
|
// 添加token到请求头
|
const token = localStorage.getItem('token');
|
if (token) {
|
config.headers.Authorization = `Bearer ${token}`;
|
}
|
|
// 添加Sign请求头:对"zyz-时间戳"进行AES加密
|
const sign = generateSign();
|
if (sign) {
|
config.headers.Sign = sign;
|
}
|
|
return config;
|
},
|
(error) => {
|
return Promise.reject(error);
|
}
|
);
|
|
// 响应拦截器
|
api.interceptors.response.use(
|
(response) => {
|
const { data } = response;
|
// 统一处理响应格式
|
if (data.code === 0) {
|
return data;
|
} else {
|
// 业务错误
|
return Promise.reject(new Error(data.msg || '请求失败'));
|
}
|
},
|
(error) => {
|
// 处理HTTP错误
|
if (error.response) {
|
const { status, data } = error.response;
|
switch (status) {
|
case 401:
|
// 未授权,清除token并跳转到登录页
|
localStorage.removeItem('token');
|
localStorage.removeItem('user');
|
window.location.href = '/login';
|
break;
|
case 403:
|
return Promise.reject(new Error('没有权限访问'));
|
case 404:
|
return Promise.reject(new Error('请求的资源不存在'));
|
case 500:
|
return Promise.reject(new Error('服务器内部错误'));
|
default:
|
return Promise.reject(new Error(data?.msg || '请求失败'));
|
}
|
} else if (error.request) {
|
return Promise.reject(new Error('网络连接失败'));
|
} else {
|
return Promise.reject(new Error(error.message));
|
}
|
}
|
);
|
|
// 管理员相关API
|
export const adminAPI = {
|
// 管理员登录
|
login: (data) => api.post('/web/api/admins/login', data),
|
|
// 管理员列表查询(分页)
|
getAdminList: (params) => api.get('/web/api/admins/pageQuery', { params }),
|
|
// 根据ID查询管理员详情
|
getAdminById: (id) => api.get('/web/api/admins/getById', { params: { id } }),
|
|
// 保存/更新管理员
|
saveAdmin: (data) => api.post('/web/api/admins/saveAdmin', data),
|
|
// 删除管理员
|
deleteAdmins: (ids) => api.get('/web/api/admins/removeByIds', { params: { ids } }),
|
|
// 重置密码
|
resetPassword: (id, newPassword) => api.post('/web/api/admins/resetPassword', null, {
|
params: { id, newPassword }
|
}),
|
};
|
|
// 用户管理相关API
|
export const userAPI = {
|
// 用户列表查询(分页)
|
getUserList: (params) => api.get('/web/api/users/pageQuery', { params }),
|
|
// 根据ID查询用户详情
|
getUserById: (id) => api.get('/web/api/users/getById', { params: { id } }),
|
|
// 保存/更新用户
|
saveUser: (data) => api.post('/web/api/users/saveUser', data),
|
|
// 删除用户
|
deleteUsers: (ids) => api.get('/web/api/users/removeByIds', { params: { ids } }),
|
};
|
|
// 志愿者申请管理API
|
export const applicationAPI = {
|
// 志愿者申请列表查询(分页)
|
getApplicationList: (params) => api.get('/web/api/applications/pageQuery', { params }),
|
|
// 根据ID查询申请详情
|
getApplicationById: (id) => api.get('/web/api/applications/getById', { params: { id } }),
|
|
// 审核志愿者申请
|
reviewApplication: (data) => api.post('/web/api/applications/review', data),
|
|
// 保存/更新申请
|
saveApplication: (data) => api.post('/web/api/applications/saveApplication', data),
|
|
// 删除申请
|
deleteApplications: (ids) => api.get('/web/api/applications/removeByIds', { params: { ids } }),
|
};
|
|
// 活动管理相关API
|
export const activityAPI = {
|
// 活动列表查询(分页)
|
getActivityList: (params) => api.get('/web/api/activities/pageQuery', { params }),
|
|
// 根据ID查询活动详情
|
getActivityById: (id) => api.get('/web/api/activities/getById', { params: { id } }),
|
|
// 保存/更新活动
|
saveActivity: (data) => api.post('/web/api/activities/saveActivity', data),
|
|
// 删除活动
|
deleteActivities: (ids) => api.get('/web/api/activities/removeByIds', { params: { ids } }),
|
|
// 更新活动状态
|
updateActivityStatus: (id, status) => api.post('/web/api/activities/updateStatus', null, {
|
params: { id, status }
|
}),
|
};
|
|
// 活动报名管理API
|
export const activityUserAPI = {
|
// 根据活动ID查询报名列表
|
getRegistrationsByActivityId: (activityId) => api.get('/web/api/activityUser/getByActivityId', {
|
params: { activity_id: activityId }
|
}),
|
|
// 签到
|
checkIn: (data) => api.post('/web/api/activityUser/checkIn', data),
|
|
// 签退
|
checkOut: (data) => api.post('/web/api/activityUser/checkOut', data),
|
|
// 报名列表查询(分页)
|
getRegistrationList: (params) => api.get('/web/api/activityUser/pageQuery', { params }),
|
|
// 根据ID查询报名详情
|
getRegistrationById: (id) => api.get('/web/api/activityUser/getById', { params: { id } }),
|
|
// 保存/更新报名
|
saveRegistration: (data) => api.post('/web/api/activityUser/saveActivityUser', data),
|
|
// 删除报名
|
deleteRegistrations: (ids) => api.get('/web/api/activityUser/removeByIds', { params: { ids } }),
|
};
|
|
// 积分申报管理API
|
export const pointDeclarationAPI = {
|
// 积分申报列表查询(分页)
|
getDeclarationList: (params) => api.get('/web/api/pointDeclarations/pageQuery', { params }),
|
|
// 根据ID查询申报详情
|
getDeclarationById: (id) => api.get('/web/api/pointDeclarations/getById', { params: { id } }),
|
|
// 审核积分申报
|
reviewDeclaration: (data) => api.post('/web/api/pointDeclarations/review', data),
|
|
// 保存/更新申报
|
saveDeclaration: (data) => api.post('/web/api/pointDeclarations/savePointDeclaration', data),
|
|
// 删除申报
|
deleteDeclarations: (ids) => api.get('/web/api/pointDeclarations/removeByIds', { params: { ids } }),
|
};
|
|
// 统计分析API
|
export const statisticsAPI = {
|
// 获取数据概览
|
getOverview: () => api.get('/web/api/statistics/getOverview'),
|
|
// 积分趋势分析
|
getPointsTrend: (period = 'month') => api.get('/web/api/statistics/getPointsTrend', {
|
params: { period }
|
}),
|
|
// 活动参与度分析
|
getActivityParticipation: () => api.get('/web/api/statistics/getActivityParticipation'),
|
|
// 志愿者活跃度统计
|
getVolunteerActivity: () => api.get('/web/api/statistics/getVolunteerActivity'),
|
|
// 积分排行榜
|
getPointsRanking: (limit = 10) => api.get('/web/api/statistics/getPointsRanking', {
|
params: { limit }
|
}),
|
|
// 社区活跃度统计
|
getCommunityActivity: () => api.get('/web/api/statistics/getCommunityActivity'),
|
};
|
|
// Dashboard专用API
|
export const dashboardAPI = {
|
// 获取最新活动列表
|
getRecentActivities: (limit = 5) => api.get('/web/api/dashboard/getRecentActivities', {
|
params: { limit }
|
}),
|
|
// 获取最新志愿者列表
|
getRecentVolunteers: (limit = 5) => api.get('/web/api/dashboard/getRecentVolunteers', {
|
params: { limit }
|
}),
|
|
// 获取待处理事项统计
|
getPendingItems: () => api.get('/web/api/dashboard/getPendingItems'),
|
|
// 获取系统概览数据
|
getSystemOverview: () => api.get('/web/api/dashboard/getSystemOverview'),
|
|
// 获取热门活动
|
getPopularActivities: (limit = 5) => api.get('/web/api/dashboard/getPopularActivities', {
|
params: { limit }
|
}),
|
|
// 获取积分统计
|
getPointsStatistics: () => api.get('/web/api/dashboard/getPointsStatistics'),
|
};
|
|
// 申报项目配置管理API
|
export const declarationConfigAPI = {
|
// 申报项目配置列表查询(分页)
|
getDeclarationConfigList: (params) => api.get('/web/api/declarationConfigs/pageQuery', { params }),
|
|
// 根据ID查询申报项目配置详情
|
getDeclarationConfigById: (id) => api.get('/web/api/declarationConfigs/getById', { params: { id } }),
|
|
// 保存/更新申报项目配置
|
saveDeclarationConfig: (data) => api.post('/web/api/declarationConfigs/saveDeclarationConfig', data),
|
|
// 删除申报项目配置
|
deleteDeclarationConfigs: (ids) => api.get('/web/api/declarationConfigs/removeByIds', { params: { ids } }),
|
|
// 批量更新申报项目配置状态
|
updateDeclarationConfigStatus: (data) => api.post('/web/api/declarationConfigs/updateStatus', data),
|
|
// 获取申报项目配置分类列表
|
getDeclarationConfigCategories: () => api.get('/web/api/declarationConfigs/getCategories'),
|
|
// 根据分类获取二级选项
|
getSecondaryOptions: (category) => api.get('/web/api/declarationConfigs/getSecondaryOptions', { params: { category } }),
|
|
// 复制申报项目配置
|
copyDeclarationConfig: (data) => api.post('/web/api/declarationConfigs/copyConfig', data),
|
|
// 获取申报项目配置统计信息
|
getDeclarationConfigStatistics: () => api.get('/web/api/declarationConfigs/getStatistics'),
|
|
// 导出申报项目配置
|
exportDeclarationConfigs: (params) => api.get('/web/api/declarationConfigs/export', { params }),
|
};
|
|
export default api;
|