7 changed files with 40 additions and 598 deletions
@ -1,43 +0,0 @@ |
|||||
import { axios } from "@/axios/request"; |
|
||||
import { AxiosPromise } from "axios"; |
|
||||
|
|
||||
|
|
||||
//get
|
|
||||
export function getAction (url: string, parameter?: unknown): AxiosPromise |
|
||||
{ |
|
||||
return axios({ |
|
||||
url: url, |
|
||||
method: 'get', |
|
||||
params: parameter |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
//post
|
|
||||
export function postAction (url: string, parameter?: unknown): AxiosPromise |
|
||||
{ |
|
||||
return axios({ |
|
||||
url: url, |
|
||||
method: 'post', |
|
||||
data: parameter |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
//put
|
|
||||
export function putAction (url: string, parameter?: unknown): AxiosPromise |
|
||||
{ |
|
||||
return axios({ |
|
||||
url: url, |
|
||||
method: 'put', |
|
||||
data: parameter |
|
||||
}) |
|
||||
} |
|
||||
|
|
||||
//delete
|
|
||||
export function deleteAction (url: string, parameter?: unknown): AxiosPromise |
|
||||
{ |
|
||||
return axios({ |
|
||||
url: url, |
|
||||
method: 'delete', |
|
||||
params: parameter |
|
||||
}) |
|
||||
} |
|
@ -1,436 +0,0 @@ |
|||||
import { deleteAction, getAction, postAction, putAction } from '@/axios/action' |
|
||||
import { AxiosPromise } from 'axios'; |
|
||||
// import {
|
|
||||
// DEVICE_STREAM_TYPE,
|
|
||||
// NET_PROTO_TYPE,
|
|
||||
// PTZ_CONTROL_ACTION,
|
|
||||
// STREAM_TRANS_TYPE,
|
|
||||
// STREAM_TYPE
|
|
||||
// } from '@/utils/emun/videoControlEnum';
|
|
||||
|
|
||||
const url = { |
|
||||
camera: { |
|
||||
getCameraList: '/area/api/getCameraList', |
|
||||
// getCameraList: '/area/api/cameraByToken?token=Bearer eyJ' +
|
|
||||
// 'hbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhZG1pb' +
|
|
||||
// 'iIsInN1YiI6InNvbWVib2R5IiwiYXVkIjpbInNvbWVib2R5X2Vs' +
|
|
||||
// 'c2UiXSwiZXhwIjoxNjYyNzE1MDYyLCJuYmYiOjE2NjI2Mjg2NjI' +
|
|
||||
// 'sImlhdCI6MTY2MjYyODY2MiwianRpIjoiMSJ9.0GyQ1qZZPcVOT' +
|
|
||||
// 'jNYe7NgsZYwKaMOGRkb-itK9fqC-Ug',
|
|
||||
}, |
|
||||
/* 监控点模块 */ |
|
||||
label: { |
|
||||
addLabel: '/military/msAreaLabel/add', |
|
||||
getLabel: '/military/msAreaLabel/list', |
|
||||
deleteCamera: '/military/msAreaLabel/deleteCamera', |
|
||||
editLabel: '/military/msAreaLabel/edit' |
|
||||
}, |
|
||||
areaFence: { |
|
||||
add: "/military/msAreaFence/add", |
|
||||
//添加防区及相机
|
|
||||
addAndDevice: "/military/msAreaFence/addFenceAndRelation", |
|
||||
//获取预置点接口
|
|
||||
selectPreset: "area/api/selectPreset", |
|
||||
fenceList: "/military/msAreaFence/list", |
|
||||
queryFenceById: "/military/msAreaFence/queryFenceAndeRelationById", |
|
||||
deleteFence: "/military/msAreaFence/deleteFenceAndRelation", |
|
||||
editFence: "/military/msAreaFence/editFenceAndRelation", |
|
||||
}, |
|
||||
cameraVideo: { |
|
||||
addCameraVideo: '/military/msAreaCameraVideo/add', |
|
||||
getCameraVideoList: '/military/msAreaCameraVideo/list', |
|
||||
getCameraVideoById: '/military/msAreaCameraVideo/queryByLabelId', |
|
||||
editCameraVideo: '/military/msAreaCameraVideo/edit', |
|
||||
}, |
|
||||
dict: { |
|
||||
getBuilding: '/sys/dict/getDictItems/ms_building_info', |
|
||||
}, |
|
||||
path: { |
|
||||
addRoamPath: '/military/msAreaRoamPath/add', |
|
||||
RoamPathList: '/military/msAreaRoamPath/list', |
|
||||
deleteRoamPath: '/military/msAreaRoamPath/delete', |
|
||||
editRoamPath: '/military/msAreaRoamPath/edit', |
|
||||
msAreaCustomPrimitiveList: '/military/msAreaCustomPrimitive/list', |
|
||||
msAreaCustomPrimitiveDel: '/military/msAreaCustomPrimitive/delete', |
|
||||
msAreaCustomPrimitiveEdit: '/military/msAreaCustomPrimitive/edit' |
|
||||
}, |
|
||||
patrolVideo: { |
|
||||
addPatrolVideo: '/military/msAreaCustomPrimitive/add', |
|
||||
}, |
|
||||
videoControl: { |
|
||||
getRealPlayUrl: 'area/api/getRealPlayUrl', |
|
||||
ptzControl: 'area/api/ptzControl', |
|
||||
}, |
|
||||
device: { |
|
||||
list: '/military/msDeviceInfo/list', |
|
||||
}, |
|
||||
warn: { |
|
||||
//监控报警信息(从中光学获取)
|
|
||||
getAlarmInfos: '/area/api/qryAlarmInfos', |
|
||||
getAlarmCount: '/area/api/countAlarm', |
|
||||
//报警信息(本地获取)
|
|
||||
getWarnList: '/warn/list', |
|
||||
getWarnCount: '/warn/getWarnCount', |
|
||||
getFenceWarn: "/military/msDeviceInfo/downCmd" |
|
||||
}, |
|
||||
haplochromatization: { |
|
||||
list: '/military/msAreaHaplochromatization/list', |
|
||||
add: '/military/msAreaHaplochromatization/add', |
|
||||
edit: '/military/msAreaHaplochromatization/edit', |
|
||||
delete: '/military/msAreaHaplochromatization/delete', |
|
||||
deleteBatch: '/military/msAreaHaplochromatization/deleteBatch' |
|
||||
}, |
|
||||
delCache: '/area/api/delCache', |
|
||||
// 添加模型
|
|
||||
models: { |
|
||||
addModel: "/models/msModels/add", |
|
||||
selectModel: "/models/msModels/list", |
|
||||
editModel: "/models/msModels/edit", |
|
||||
//批量删除
|
|
||||
deleteModels: "/models/msModels/deleteBatch", |
|
||||
deleteModel: "/models/msModels/delete", |
|
||||
}, |
|
||||
// 测试登录
|
|
||||
login: 'http://127.0.0.1:8088/', |
|
||||
loginChecked: 'http://127.0.0.1:8088/checked', |
|
||||
|
|
||||
/* 看板模块 */ |
|
||||
board: { |
|
||||
//看板
|
|
||||
getBoard: '/api/rpt/sensorbydevicecode2', |
|
||||
//看板编号
|
|
||||
getBoardType: "/api/rpt/boardtype", |
|
||||
//看板信息
|
|
||||
getBoardInfo: "/models/msModelsBoardApi/list", |
|
||||
//看板数据接口
|
|
||||
getBoardData: '/api/rpt/boarddata', |
|
||||
}, |
|
||||
/* iot设备 */ |
|
||||
iotDevice: { |
|
||||
getNode: "/api/iot/nodelist", |
|
||||
getSensor: "/api/iot/sensorlist", |
|
||||
getSensorInfo: "/api/iot/sensorbyid", |
|
||||
}, |
|
||||
|
|
||||
modelsinfo: { |
|
||||
getModels3DGroup: '/api/models/models3dgroup', |
|
||||
getModels3D: '/api/models/modelsinfo3d', |
|
||||
getModelsImageGroup: '/api/models/modelsimagegroup', |
|
||||
getModelsImage: '/api/models/modelsinfoimage', |
|
||||
|
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
interface LabelEntity { |
|
||||
labelAttr: number, |
|
||||
labelName: string, |
|
||||
labelLon: number, |
|
||||
labelLat: number, |
|
||||
labelHeight: number, |
|
||||
labelStatus: number, |
|
||||
labelImgUrl: string, |
|
||||
deviceUid: string, |
|
||||
cameraVideoFlag: number, |
|
||||
belongTo: string, |
|
||||
} |
|
||||
|
|
||||
interface LabelQueryList { |
|
||||
labelStatus: number, |
|
||||
id?: string, |
|
||||
belongTo?: string, |
|
||||
pageNo?: number, |
|
||||
pageSize?: number, |
|
||||
// selectArea?: string,
|
|
||||
} |
|
||||
|
|
||||
interface CameraVideoEntity { |
|
||||
lon: number, |
|
||||
lat: number, |
|
||||
height: number, |
|
||||
yaw: number, |
|
||||
pitch: number, |
|
||||
roll: number, |
|
||||
fovh: number, |
|
||||
fovv: number, |
|
||||
near: number, |
|
||||
far: number, |
|
||||
videourl: string, |
|
||||
maskurl: string, |
|
||||
// 相机id
|
|
||||
labelId: string, |
|
||||
} |
|
||||
|
|
||||
interface CameraVideoQueryList { |
|
||||
labelId: string, |
|
||||
} |
|
||||
|
|
||||
type PatrolVideo = { |
|
||||
/**经度*/ |
|
||||
lon: number, |
|
||||
/**纬度*/ |
|
||||
lat: number; |
|
||||
/**高度*/ |
|
||||
height: number; |
|
||||
/**偏航角*/ |
|
||||
yaw: number; |
|
||||
/**俯仰角*/ |
|
||||
pitch: number; |
|
||||
/**翻转角*/ |
|
||||
roll: number; |
|
||||
/**漫游路径id*/ |
|
||||
pathId: string; |
|
||||
/**相机设备Id*/ |
|
||||
deviceUid: string; |
|
||||
} |
|
||||
|
|
||||
// 云台控制
|
|
||||
// 获取摄像头实时视频播放地址 参数
|
|
||||
// interface GetRealPlayUrlParams {
|
|
||||
// // 摄像机UID
|
|
||||
// deviceId: string,
|
|
||||
// // 传输协议
|
|
||||
// streamTransType: STREAM_TRANS_TYPE,
|
|
||||
// // 码流
|
|
||||
// streamType: STREAM_TYPE,
|
|
||||
// // 是否转hls 默认false
|
|
||||
// enableHls: boolean,
|
|
||||
// // 是否mp4录制 默认false
|
|
||||
// enableMp4: boolean,
|
|
||||
// // 拉流时,拉流方式 默认 0:tcp
|
|
||||
// netProto: NET_PROTO_TYPE,
|
|
||||
// // 拉流超时时间,单位秒 默认10
|
|
||||
// timeoutSec: number,
|
|
||||
// // 失败时重试的次数
|
|
||||
// retryCount: number,
|
|
||||
// // 传输协议 (添加海康私有流时使用该字段:6-TRANS_PROTO_PRIVATE)
|
|
||||
// deviceStreamType: DEVICE_STREAM_TYPE,
|
|
||||
// }
|
|
||||
|
|
||||
// // 云台控制 参数
|
|
||||
// interface PtzControlParams {
|
|
||||
// deviceId: string,
|
|
||||
// // 云台控制命令 (0-199)
|
|
||||
// ptzCommand: PTZ_CONTROL_ACTION,
|
|
||||
// // 云台控制参数(云台速度)
|
|
||||
// arguments: number,
|
|
||||
// }
|
|
||||
|
|
||||
interface AlarmInfoParams { |
|
||||
deviceId: string, |
|
||||
startTime: string, |
|
||||
stopTime: string, |
|
||||
eventType?: number, |
|
||||
targetType?: number, |
|
||||
pageIndex: number, |
|
||||
pageSize: number, |
|
||||
alarmLevel?: number, |
|
||||
alarmMode?: number |
|
||||
} |
|
||||
|
|
||||
interface AlarmCountParams { |
|
||||
deviceId: string, |
|
||||
startTime: string, |
|
||||
stopTime: string, |
|
||||
eventType: number, |
|
||||
targetType: number, |
|
||||
dateUnit: number |
|
||||
} |
|
||||
|
|
||||
interface DeviceParams { |
|
||||
deviceType: number, |
|
||||
} |
|
||||
interface WarnInfoParams { |
|
||||
cameraId: string, |
|
||||
column?: string, |
|
||||
order?: string, |
|
||||
pageNo?: number, |
|
||||
pageSize?: number |
|
||||
} |
|
||||
|
|
||||
interface WarnCountParams { |
|
||||
cameraId: string, |
|
||||
startTime: string, |
|
||||
endTime: string, |
|
||||
warnType?: number, |
|
||||
warnLevel?: number |
|
||||
} |
|
||||
|
|
||||
interface HaplochromatizationParams { |
|
||||
id: string, |
|
||||
name: string, |
|
||||
positions: string, |
|
||||
height: number, |
|
||||
extrudedHeight: number, |
|
||||
color: string, |
|
||||
showobj: number, |
|
||||
showhelper: number, |
|
||||
belongTo: string | null, |
|
||||
} |
|
||||
interface Models { |
|
||||
"createBy"?: string, |
|
||||
"createTime"?: string, |
|
||||
"height"?: number, |
|
||||
"id"?: string, |
|
||||
"isShow"?: number, |
|
||||
"lat"?: number, |
|
||||
"lon"?: number, |
|
||||
"modelCode"?: string, |
|
||||
"modelGroup"?: string, |
|
||||
"modelName"?: string, |
|
||||
"modelSceneCode"?: string, |
|
||||
"modelType"?: string, |
|
||||
"modelUrl1"?: string, |
|
||||
"modelUrl2"?: string, |
|
||||
"modelX"?: number, |
|
||||
"modelY"?: number, |
|
||||
"modelZ"?: number, |
|
||||
"pitch"?: number, |
|
||||
"roll"?: number, |
|
||||
"sysOrgCode"?: string, |
|
||||
"template"?: string, |
|
||||
"updateBy"?: string, |
|
||||
"updateTime"?: string, |
|
||||
"url"?: string, |
|
||||
"urlcondition"?: string, |
|
||||
"yaw"?: number, |
|
||||
"pageNo"?: number, |
|
||||
"pageSize"?: number |
|
||||
"boardNo"?: string |
|
||||
"boardType"?: string |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
class Api { |
|
||||
/* 相机模块 */ |
|
||||
public static camera = { |
|
||||
getCameraList: (params?: { token: string }): AxiosPromise => getAction(url.camera.getCameraList, params), |
|
||||
} |
|
||||
/* 监控点模块 */ |
|
||||
public static label = { |
|
||||
addLabel: (params: LabelEntity | any): AxiosPromise => postAction(url.label.addLabel, params), |
|
||||
getLabel: (params: LabelQueryList): AxiosPromise => getAction(url.label.getLabel, params), |
|
||||
deleteLabel: (params: { id: string }): AxiosPromise => deleteAction(url.label.deleteCamera, params), |
|
||||
editLabel: (params: LabelEntity): AxiosPromise => putAction(url.label.editLabel, params), |
|
||||
} |
|
||||
/* 视频融合模块 */ |
|
||||
public static cameraVideo = { |
|
||||
addCameraVideo: (params?: CameraVideoEntity): AxiosPromise => postAction(url.cameraVideo.addCameraVideo, params), |
|
||||
getCameraVideoById: (params?: { labelId: string }): AxiosPromise => getAction(url.cameraVideo.getCameraVideoById, params), |
|
||||
getCameraVideoList: (params?: CameraVideoQueryList): AxiosPromise => getAction(url.cameraVideo.getCameraVideoList, params), |
|
||||
editCameraVideo: (params?: CameraVideoEntity): AxiosPromise => putAction(url.cameraVideo.editCameraVideo, params), |
|
||||
deleteCameraVideo: (params?: { id: string }): AxiosPromise => deleteAction(url.cameraVideo.editCameraVideo, params), |
|
||||
} |
|
||||
/* 数据字典 */ |
|
||||
public static dict = { |
|
||||
getBuilding: (): AxiosPromise => getAction(url.dict.getBuilding), |
|
||||
} |
|
||||
/* 巡检模块 */ |
|
||||
public static path = { |
|
||||
addRoamPath: (params?: unknown): AxiosPromise => postAction(url.path.addRoamPath, params), |
|
||||
RoamPathList: (params?: { pageNo: number, pageSize: number, selectArea: string }): AxiosPromise => getAction(url.path.RoamPathList, params), |
|
||||
deleteRoamPath: (params?: unknown): AxiosPromise => deleteAction(url.path.deleteRoamPath, params), |
|
||||
editRoamPath: (params?: unknown): AxiosPromise => putAction(url.path.editRoamPath, params), |
|
||||
msAreaCustomPrimitiveList: (params?: unknown): AxiosPromise => getAction(url.path.msAreaCustomPrimitiveList, params), |
|
||||
msAreaCustomPrimitiveDel: (params?: unknown): AxiosPromise => deleteAction(url.path.msAreaCustomPrimitiveDel, params), |
|
||||
msAreaCustomPrimitiveEdit: (params?: unknown): AxiosPromise => putAction(url.path.msAreaCustomPrimitiveEdit, params), |
|
||||
} |
|
||||
|
|
||||
/*巡检视频模块*/ |
|
||||
public static patrolVideo = { |
|
||||
addPatrolVideo: (params?: PatrolVideo): AxiosPromise => postAction(url.patrolVideo.addPatrolVideo, params), |
|
||||
} |
|
||||
/* 云台控制模块 */ |
|
||||
// public static videoControl = {
|
|
||||
// // 获取摄像头实时视频播放地址
|
|
||||
// getRealPlayUrl: (params?: GetRealPlayUrlParams): AxiosPromise => getAction(url.videoControl.getRealPlayUrl, params),
|
|
||||
// // 云台控制
|
|
||||
// ptzControl: (params?: PtzControlParams): AxiosPromise => getAction(url.videoControl.ptzControl, params),
|
|
||||
// }
|
|
||||
/* 设备信息模块*/ |
|
||||
public static device = { |
|
||||
getDeviceList: (params?: DeviceParams): AxiosPromise => getAction(url.device.list, params) |
|
||||
} |
|
||||
/* 警示模块*/ |
|
||||
public static warn = { |
|
||||
getAlarmInfos: (params?: AlarmInfoParams): AxiosPromise => getAction(url.warn.getAlarmInfos, params), |
|
||||
getAlarmCount: (params?: AlarmCountParams): AxiosPromise => getAction(url.warn.getAlarmCount, params), |
|
||||
getWarnList: (params?: WarnInfoParams): AxiosPromise => getAction(url.warn.getWarnList, params), |
|
||||
getWarnCount: (params?: WarnCountParams): AxiosPromise => getAction(url.warn.getWarnCount, params), |
|
||||
getFenceWarn: (params?: WarnCountParams): AxiosPromise => getAction(url.warn.getFenceWarn, params), |
|
||||
} |
|
||||
/* 缓存 */ |
|
||||
public static cache = { |
|
||||
delCache: (): AxiosPromise => deleteAction(url.delCache), |
|
||||
} |
|
||||
/* 单体化 */ |
|
||||
public static haplochromatization = { |
|
||||
list: (params?: unknown): AxiosPromise => getAction(url.haplochromatization.list, params), |
|
||||
add: (params?: HaplochromatizationParams): AxiosPromise => postAction(url.haplochromatization.add, params), |
|
||||
edit: (params?: HaplochromatizationParams): AxiosPromise => putAction(url.haplochromatization.edit, params), |
|
||||
delete: (params: { id: string }): AxiosPromise => deleteAction(url.haplochromatization.delete, params), |
|
||||
deleteBatch: (params: { ids: string }): AxiosPromise => deleteAction(url.haplochromatization.delete, params), |
|
||||
} |
|
||||
/* 模型 */ |
|
||||
public static models = { |
|
||||
add: (params: Models): AxiosPromise => postAction(url.models.addModel, params), |
|
||||
list: (params: Models): AxiosPromise => getAction(url.models.selectModel, params), |
|
||||
edit: (params: Models): AxiosPromise => postAction(url.models.editModel, params), |
|
||||
deleteBatch: (params: { ids: string }): AxiosPromise => deleteAction(url.models.deleteModels, params), |
|
||||
delete: (params: { id: string }): AxiosPromise => deleteAction(url.models.deleteModel, params), |
|
||||
} |
|
||||
/* 用户登录 */ |
|
||||
public static Login = { |
|
||||
login: (params: any): AxiosPromise => getAction(url.login, params), |
|
||||
loginChecked: (params: any): AxiosPromise => getAction(url.loginChecked, params), |
|
||||
} |
|
||||
/* 看板模块 */ |
|
||||
public static board = { |
|
||||
getBoardList: (params?: any): AxiosPromise => getAction(url.board.getBoard, params), |
|
||||
getBoardTypeList: (params?: any): AxiosPromise => getAction(url.board.getBoardType, params), |
|
||||
getBoardInfo: (params?: any): AxiosPromise => getAction(url.board.getBoardInfo, params), |
|
||||
getBoardDataList: (params: { boardtype: string }): AxiosPromise => getAction(url.board.getBoardData, params), |
|
||||
} |
|
||||
/* 防区 */ |
|
||||
public static areaFence = { |
|
||||
add: (params?: any): AxiosPromise => postAction(url.areaFence.add, params), |
|
||||
addAndDevice: (params?: any): AxiosPromise => postAction(url.areaFence.addAndDevice, params), |
|
||||
selectPreset: (params?: any): AxiosPromise => getAction(url.areaFence.selectPreset, params), |
|
||||
getFenceList: (params?: any): AxiosPromise => getAction(url.areaFence.fenceList, params), |
|
||||
queryFenceById: (params?: { id: string }): AxiosPromise => getAction(url.areaFence.queryFenceById, params), |
|
||||
deleteFence: (params: { id: string }): AxiosPromise => deleteAction(url.areaFence.deleteFence, params), |
|
||||
editFence: (params: any): AxiosPromise => putAction(url.areaFence.editFence, params), |
|
||||
} |
|
||||
/* 相机模块 */ |
|
||||
public static modelsinfo = { |
|
||||
getModels3DGroup: (params?: { token: string }): AxiosPromise => getAction(url.modelsinfo.getModels3DGroup, params), |
|
||||
getModels3D: (params?: { token: string }): AxiosPromise => getAction(url.modelsinfo.getModels3D, params), |
|
||||
getModelsImageGroup: (params?: { token: string }): AxiosPromise => getAction(url.modelsinfo.getModelsImageGroup, params), |
|
||||
getModelsImage: (params?: { token: string }): AxiosPromise => getAction(url.modelsinfo.getModelsImage, params), |
|
||||
|
|
||||
} |
|
||||
/*iot设备*/ |
|
||||
public static iotDevice = { |
|
||||
//设备列表
|
|
||||
getNodeList: (params?: any): AxiosPromise => getAction(url.iotDevice.getNode, params), |
|
||||
//传感器列表信息
|
|
||||
getSensorList: (params?: { nodeid: string }): AxiosPromise => getAction(url.iotDevice.getSensor, params), |
|
||||
//传感器
|
|
||||
getSensorInfo: (params?: { id: string }): AxiosPromise => getAction(url.iotDevice.getSensorInfo, params), |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
export default Api |
|
||||
export { |
|
||||
Api, |
|
||||
// LabelEntity,
|
|
||||
// LabelQueryList,
|
|
||||
// CameraVideoEntity,
|
|
||||
// CameraVideoQueryList,
|
|
||||
// GetRealPlayUrlParams,
|
|
||||
// PtzControlParams,
|
|
||||
// HaplochromatizationParams,
|
|
||||
// AlarmInfoParams,
|
|
||||
// AlarmCountParams,
|
|
||||
} |
|
@ -1,114 +0,0 @@ |
|||||
import axios, { AxiosResponse, AxiosRequestConfig, Canceler } from 'axios' |
|
||||
import { message, notification } from 'ant-design-vue' |
|
||||
|
|
||||
/** |
|
||||
* http请求工具类 |
|
||||
* |
|
||||
* 请求拦截器 负责将客户端标识token值存储并放置在头部提交给服务端 |
|
||||
* 响应拦截器 负责全局处理业务请求的网络或者业务错误 |
|
||||
*/ |
|
||||
// 开启跨域
|
|
||||
axios.defaults.withCredentials = true |
|
||||
// 创建 axios 实例
|
|
||||
const service = axios.create({ |
|
||||
baseURL: process.env.VUE_APP_API_BASE_URL, // api base_url
|
|
||||
timeout: 30 * 1000, // 请求超时时间
|
|
||||
// withCredentials: true, // 跨域请求时发送 cookies
|
|
||||
// headers: {
|
|
||||
// "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
|
|
||||
// },
|
|
||||
}); |
|
||||
const ACCESS_TOKEN = 'Access-Token' |
|
||||
|
|
||||
//请求失败后的错误统一处理
|
|
||||
const errorHandle = (error: any) => { |
|
||||
if (error.response) { |
|
||||
const data: any = error.response.data |
|
||||
const token: string | null = localStorage.getItem(ACCESS_TOKEN) |
|
||||
console.log("------异常响应------", token) |
|
||||
console.log("------异常响应------", error.response.status) |
|
||||
switch (error.response.status) { |
|
||||
case 401: |
|
||||
message.error("登录状态失效,请重新登录"); |
|
||||
break |
|
||||
case 403: |
|
||||
message.error("拒绝访问"); |
|
||||
break |
|
||||
case 404: |
|
||||
message.error("资源不存在"); |
|
||||
break |
|
||||
case 405: |
|
||||
message.error("请求类型有误"); |
|
||||
break |
|
||||
case 408: |
|
||||
message.error("请求超时"); |
|
||||
break |
|
||||
case 415: |
|
||||
message.error("服务器无法处理请求附带的媒体格式"); |
|
||||
break |
|
||||
case 500: |
|
||||
message.error("服务器内部错误"); |
|
||||
break |
|
||||
case 502: |
|
||||
message.error("网关错误"); |
|
||||
break; |
|
||||
case 503: |
|
||||
message.error("服务不可用"); |
|
||||
break; |
|
||||
case 504: |
|
||||
message.error("网关超时"); |
|
||||
break |
|
||||
default: |
|
||||
notification.error({ |
|
||||
message: '系统提示', |
|
||||
description: data.message, |
|
||||
duration: 4 |
|
||||
}) |
|
||||
break |
|
||||
} |
|
||||
} |
|
||||
return Promise.reject(error) |
|
||||
}; |
|
||||
|
|
||||
// 取消请求 cancelToken
|
|
||||
const CancelToken = axios.CancelToken; |
|
||||
// 请求拦截
|
|
||||
service.interceptors.request.use((config: AxiosRequestConfig) => { |
|
||||
// 设置 token 到请求头
|
|
||||
const token: string | null = localStorage.getItem(ACCESS_TOKEN) |
|
||||
if (token) { |
|
||||
axios.defaults.headers.post['X-Access-Token'] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
||||
} |
|
||||
// 设置取消请求
|
|
||||
config.cancelToken = new CancelToken((cancel: Canceler) => { |
|
||||
const url = config.url; |
|
||||
let str = url?.split('/'); |
|
||||
str = Array.from(new Set(str)); |
|
||||
const index = str.length - 1; |
|
||||
const funName = str[index]; |
|
||||
|
|
||||
// store.dispatch('setCancel', { cancel, funName: funName }).catch(err => {
|
|
||||
// console.log('存储 CancelToken 出错:', err);
|
|
||||
// });
|
|
||||
}) |
|
||||
return config; |
|
||||
}, err => { |
|
||||
Promise.reject(err).catch(r => { |
|
||||
console.log('请求拦截器出错:', r); |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
// 响应拦截
|
|
||||
service.interceptors.response.use((response: AxiosResponse) => { |
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||
// @ts-ignore
|
|
||||
|
|
||||
// store.dispatch("response", response).catch(err => {
|
|
||||
// console.log('移除 CancelToken 出错:', err);
|
|
||||
// });
|
|
||||
return response.data |
|
||||
}, errorHandle) |
|
||||
|
|
||||
export { |
|
||||
service as axios |
|
||||
} |
|
Loading…
Reference in new issue