封装AXIOS,添加接口
- 今日体检统计信息 - 营收数据统计
This commit is contained in:
48
src/api/his.ts
Normal file
48
src/api/his.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import request from './request';
|
||||
import type {
|
||||
InputTodayExamStatisticsInfo,
|
||||
TodayExamStatisticsResponse,
|
||||
InputRevenueStatisticsInfo,
|
||||
RevenueStatisticsResponse,
|
||||
} from './types';
|
||||
|
||||
/**
|
||||
* 自助机HIS接口
|
||||
* 基础路径: /api/his-web/self-service-machine/
|
||||
*/
|
||||
const HIS_BASE_PATH = '/api/his-web/self-service-machine';
|
||||
|
||||
/**
|
||||
* 体检中心HIS接口
|
||||
* 基础路径: /api/his-web/medical-exam-center-app/
|
||||
*/
|
||||
const MEDICAL_EXAM_BASE_PATH = '/api/his-web/medical-exam-center-app';
|
||||
|
||||
/**
|
||||
* 今日体检统计信息
|
||||
* @param data 请求参数(空对象)
|
||||
* @returns 今日体检统计信息
|
||||
*/
|
||||
export const getTodayExamStatistics = (
|
||||
data: InputTodayExamStatisticsInfo = {}
|
||||
): Promise<TodayExamStatisticsResponse> => {
|
||||
return request.post<TodayExamStatisticsResponse>(
|
||||
`${MEDICAL_EXAM_BASE_PATH}/today-exam-statistics`,
|
||||
data
|
||||
).then(res => res.data);
|
||||
};
|
||||
|
||||
/**
|
||||
* 营收数据统计
|
||||
* @param data 请求参数(空对象)
|
||||
* @returns 营收数据统计信息
|
||||
*/
|
||||
export const getRevenueStatistics = (
|
||||
data: InputRevenueStatisticsInfo = {}
|
||||
): Promise<RevenueStatisticsResponse> => {
|
||||
return request.post<RevenueStatisticsResponse>(
|
||||
`${MEDICAL_EXAM_BASE_PATH}/revenue-statistics`,
|
||||
data
|
||||
).then(res => res.data);
|
||||
};
|
||||
|
||||
7
src/api/index.ts
Normal file
7
src/api/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* API 模块统一导出
|
||||
*/
|
||||
export * from './request';
|
||||
export * from './types';
|
||||
export * from './his';
|
||||
|
||||
83
src/api/request.ts
Normal file
83
src/api/request.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import axios from 'axios';
|
||||
import type { AxiosInstance, AxiosResponse } from 'axios';
|
||||
|
||||
// API 配置
|
||||
const API_CONFIG = {
|
||||
// 内网地址(HTTP)
|
||||
INTERNAL_URL: 'http://10.1.5.118:8077/platform-api',
|
||||
// 外网地址(HTTPS)
|
||||
EXTERNAL_URL: 'https://apihis.circleharmonyhospital.cn:8982/platform-api',
|
||||
// 默认使用外网地址,可根据环境变量切换
|
||||
// 开发环境使用内网,生产环境使用外网
|
||||
BASE_URL: import.meta.env.NODE_ENV === 'development'
|
||||
? 'http://10.1.5.118:8077/platform-api'
|
||||
: 'http://apihis.circleharmonyhospital.cn:8982/platform-api',
|
||||
// 请求超时时间(30秒)
|
||||
TIMEOUT: 30000,
|
||||
};
|
||||
|
||||
// 创建 axios 实例
|
||||
const request: AxiosInstance = axios.create({
|
||||
baseURL: API_CONFIG.BASE_URL,
|
||||
timeout: API_CONFIG.TIMEOUT,
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
});
|
||||
|
||||
// 请求拦截器
|
||||
request.interceptors.request.use(
|
||||
(config) => {
|
||||
// 可以在这里添加 token 等认证信息
|
||||
// const token = localStorage.getItem('token');
|
||||
// if (token && config.headers) {
|
||||
// config.headers.Authorization = `Bearer ${token}`;
|
||||
// }
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 响应拦截器
|
||||
request.interceptors.response.use(
|
||||
(response: AxiosResponse) => {
|
||||
return response;
|
||||
},
|
||||
(error) => {
|
||||
// 统一错误处理
|
||||
if (error.response) {
|
||||
const { status, data } = error.response;
|
||||
switch (status) {
|
||||
case 400:
|
||||
console.error('请求参数错误', data);
|
||||
break;
|
||||
case 401:
|
||||
console.error('未授权,请重新登录', data);
|
||||
// 可以在这里处理登录跳转
|
||||
break;
|
||||
case 403:
|
||||
console.error('拒绝访问', data);
|
||||
break;
|
||||
case 404:
|
||||
console.error('请求地址不存在', data);
|
||||
break;
|
||||
case 500:
|
||||
console.error('服务器内部错误', data);
|
||||
break;
|
||||
default:
|
||||
console.error('请求失败', data);
|
||||
}
|
||||
} else if (error.request) {
|
||||
console.error('请求超时或网络错误');
|
||||
} else {
|
||||
console.error('请求配置错误', error.message);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default request;
|
||||
export { API_CONFIG };
|
||||
|
||||
87
src/api/types.ts
Normal file
87
src/api/types.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 通用接口返回状态码类型
|
||||
*/
|
||||
export type CommonActionResultStatusCode = 200 | 400 | 401 | 403 | 500 | 4011 | -1;
|
||||
|
||||
/**
|
||||
* 状态码常量(用于运行时访问)
|
||||
*/
|
||||
export const StatusCode = {
|
||||
Success: 200,
|
||||
BadRequest: 400,
|
||||
Unauthorized: 401,
|
||||
Forbidden: 403,
|
||||
InternalException: 500,
|
||||
Unidentified: 4011,
|
||||
Fail: -1,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 通用接口返回数据实体
|
||||
*/
|
||||
export interface CommonActionResult<T = any> {
|
||||
Status: CommonActionResultStatusCode;
|
||||
Message?: string | null;
|
||||
Data?: T;
|
||||
TraceId?: string | null;
|
||||
CopyRight?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 今日体检统计信息入参
|
||||
*/
|
||||
export interface InputTodayExamStatisticsInfo {
|
||||
// 空对象,无需参数
|
||||
}
|
||||
|
||||
/**
|
||||
* 今日体检统计信息出参
|
||||
*/
|
||||
export interface OutputTodayExamStatisticsInfo {
|
||||
/** 今日预约人数 */
|
||||
today_appointment_count?: number | null;
|
||||
/** 今日签到人数 */
|
||||
today_signin_count?: number | null;
|
||||
/** 今日签在检人数 */
|
||||
today_in_exam_count?: number | null;
|
||||
/** 今日签打印导检单 */
|
||||
today_print_guide_count?: number | null;
|
||||
/** 今日签已完成人数 */
|
||||
today_completed_count?: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 今日体检统计信息接口返回
|
||||
*/
|
||||
export type TodayExamStatisticsResponse = CommonActionResult<OutputTodayExamStatisticsInfo>;
|
||||
|
||||
/**
|
||||
* 营收数据统计入参
|
||||
*/
|
||||
export interface InputRevenueStatisticsInfo {
|
||||
// 空对象,无需参数
|
||||
}
|
||||
|
||||
/**
|
||||
* 营收数据统计出参
|
||||
*/
|
||||
export interface OutputRevenueStatisticsInfo {
|
||||
/** 体检收入 */
|
||||
physical_exam_income?: number | null;
|
||||
/** 加项收入 */
|
||||
add_item_income?: number | null;
|
||||
/** 整体收入 */
|
||||
total_income?: number | null;
|
||||
/** 目标收入 */
|
||||
target_income?: number | null;
|
||||
/** 完成百分比 */
|
||||
completion_percentage?: string | null;
|
||||
/** 缺口金额 */
|
||||
gap_amount?: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 营收数据统计接口返回
|
||||
*/
|
||||
export type RevenueStatisticsResponse = CommonActionResult<OutputRevenueStatisticsInfo>;
|
||||
|
||||
Reference in New Issue
Block a user