资产接口更换的一版
This commit is contained in:
parent
1ecc6f8377
commit
cbcadc63fa
@ -38,6 +38,13 @@ export default [
|
|||||||
name: '服务区资产管理',
|
name: '服务区资产管理',
|
||||||
component: "@/pages/serverpartAssets/index",
|
component: "@/pages/serverpartAssets/index",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/previewFile/index',
|
||||||
|
name: '预览附件',
|
||||||
|
component: "@/pages/previewFile/index",
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -257,6 +257,12 @@ const UserModel: UserModelType = {
|
|||||||
name: '服务区资产管理',
|
name: '服务区资产管理',
|
||||||
component: "@/pages/serverpartAssets/index",
|
component: "@/pages/serverpartAssets/index",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/previewFile/index',
|
||||||
|
redirect: '',
|
||||||
|
name: '预览附件',
|
||||||
|
component: "@/pages/previewFile/index",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +337,8 @@ const UserModel: UserModelType = {
|
|||||||
"/InvoiceInquiry/index",
|
"/InvoiceInquiry/index",
|
||||||
"/redReversal/index",
|
"/redReversal/index",
|
||||||
"/InvoiceSearch/index",
|
"/InvoiceSearch/index",
|
||||||
"/serverpartAssets/index"
|
"/serverpartAssets/index",
|
||||||
|
"/previewFile/index",
|
||||||
// '/examine/index',
|
// '/examine/index',
|
||||||
// '/examine/modal',
|
// '/examine/modal',
|
||||||
// '/examine/question',
|
// '/examine/question',
|
||||||
|
|||||||
@ -6,6 +6,7 @@ const authority: PageAuthority = {
|
|||||||
'/redReversal/index': ['/redReversal/index'],
|
'/redReversal/index': ['/redReversal/index'],
|
||||||
'/InvoiceSearch/index': ['/InvoiceSearch/index'],
|
'/InvoiceSearch/index': ['/InvoiceSearch/index'],
|
||||||
'/serverpartAssets/index': ['/serverpartAssets/index'],
|
'/serverpartAssets/index': ['/serverpartAssets/index'],
|
||||||
|
'/previewFile/index': ['/previewFile/index'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
17
src/pages/previewFile/index.tsx
Normal file
17
src/pages/previewFile/index.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// 预览附件的页面
|
||||||
|
import { connect } from "umi";
|
||||||
|
import { ConnectState } from "@/models/global";
|
||||||
|
|
||||||
|
const previewFile = () => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
111
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default connect(({ user }: ConnectState) => ({
|
||||||
|
currentUser: user.data
|
||||||
|
}))(previewFile);
|
||||||
@ -449,9 +449,12 @@ const LeftSelectTree = ({ onShow, handleClose, setOnShow, currentUser, id, paren
|
|||||||
{
|
{
|
||||||
onlyRead ? '' :
|
onlyRead ? '' :
|
||||||
<>
|
<>
|
||||||
<Button type={"primary"} style={{ marginRight: '8px' }} onClick={() => {
|
{
|
||||||
|
currentRow?.PROPERTYASSETS_ID ? <Button type={"primary"} style={{ marginRight: '8px' }} onClick={() => {
|
||||||
setShowHistory(true)
|
setShowHistory(true)
|
||||||
}}>历史关联门店</Button>
|
}}>历史关联门店</Button> : ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
currentRow?.PROPERTYASSETS_ID ? '' :
|
currentRow?.PROPERTYASSETS_ID ? '' :
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { wrapTreeNode } from "@/components/leftSelectTree/service";
|
import { wrapTreeNode } from "@/components/leftSelectTree/service";
|
||||||
import requestAHYD from "@/utils/requestAHYD";
|
import requestAHYD from "@/utils/requestAHYD";
|
||||||
import requestCode from "@/utils/requestCode";
|
import requestCode from "@/utils/requestCode";
|
||||||
|
import requestSamember from "@/utils/requestOld";
|
||||||
|
import requestSamemberCode from "@/utils/requestOldCode";
|
||||||
import request from "@/utils/requestMain";
|
import request from "@/utils/requestMain";
|
||||||
import session from "@/utils/session";
|
import session from "@/utils/session";
|
||||||
import numeral from 'numeral'
|
import numeral from 'numeral'
|
||||||
@ -9,7 +11,7 @@ export async function getFieldEnumTree(params: any) {
|
|||||||
const sessionName = `${params.sessionName ? params.sessionName : params.FieldExplainField}Tree`;
|
const sessionName = `${params.sessionName ? params.sessionName : params.FieldExplainField}Tree`;
|
||||||
const FieldExplain = session.get(sessionName);
|
const FieldExplain = session.get(sessionName);
|
||||||
|
|
||||||
const data = await request(`/FrameWork/GetFieldEnumTree`, {
|
const data = await requestSamember(`/FrameWork/GetFieldEnumTree`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
@ -36,7 +38,7 @@ export function formateTreeField(list: any[]) {
|
|||||||
|
|
||||||
// 删除服务区资产表
|
// 删除服务区资产表
|
||||||
export async function handleDeletePROPERTYASSETS(params?: any) {
|
export async function handleDeletePROPERTYASSETS(params?: any) {
|
||||||
const data = await request(`/BaseInfo/DeletePROPERTYASSETS`, {
|
const data = await requestSamember(`/BaseInfo/DeletePROPERTYASSETS`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -56,7 +58,7 @@ export async function handleDeletePROPERTYASSETS(params?: any) {
|
|||||||
|
|
||||||
// 将门店批量与资产关联
|
// 将门店批量与资产关联
|
||||||
export async function handleGetBatchPROPERTYSHOP(params?: any) {
|
export async function handleGetBatchPROPERTYSHOP(params?: any) {
|
||||||
const data = await request(`/BaseInfo/BatchPROPERTYSHOP`, {
|
const data = await requestSamember(`/BaseInfo/BatchPROPERTYSHOP`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -76,7 +78,7 @@ export async function handleGetBatchPROPERTYSHOP(params?: any) {
|
|||||||
|
|
||||||
// 获取服务区资产表树形列表
|
// 获取服务区资产表树形列表
|
||||||
export async function handleGetPROPERTYASSETSTreeList(params?: any) {
|
export async function handleGetPROPERTYASSETSTreeList(params?: any) {
|
||||||
const data = await request(`/BaseInfo/GetPROPERTYASSETSTreeList`, {
|
const data = await requestSamember(`/BaseInfo/GetPROPERTYASSETSTreeList`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -96,7 +98,7 @@ export async function handleGetPROPERTYASSETSTreeList(params?: any) {
|
|||||||
|
|
||||||
// 获取服务区资产表列表
|
// 获取服务区资产表列表
|
||||||
export async function handleGetProvinceVehicleDetail(params?: any) {
|
export async function handleGetProvinceVehicleDetail(params?: any) {
|
||||||
const data = await request(`/BaseInfo/GetPROPERTYASSETSList`, {
|
const data = await requestSamember(`/BaseInfo/GetPROPERTYASSETSList`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -115,7 +117,7 @@ export async function handleGetProvinceVehicleDetail(params?: any) {
|
|||||||
}
|
}
|
||||||
// 同步服务区资产表
|
// 同步服务区资产表
|
||||||
export async function handleSynchroPROPERTYASSETS(params?: any) {
|
export async function handleSynchroPROPERTYASSETS(params?: any) {
|
||||||
const data = await request(`/BaseInfo/SynchroPROPERTYASSETS`, {
|
const data = await requestSamember(`/BaseInfo/SynchroPROPERTYASSETS`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -129,7 +131,7 @@ export async function handleSynchroPROPERTYASSETS(params?: any) {
|
|||||||
|
|
||||||
// 获取服务区资产表明细
|
// 获取服务区资产表明细
|
||||||
export async function handleGetPROPERTYASSETSDetail(params?: any) {
|
export async function handleGetPROPERTYASSETSDetail(params?: any) {
|
||||||
const data = await request(`/BaseInfo/GetPROPERTYASSETSDetail`, {
|
const data = await requestSamember(`/BaseInfo/GetPROPERTYASSETSDetail`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params
|
params
|
||||||
});
|
});
|
||||||
@ -148,7 +150,7 @@ export async function handleGetPROPERTYASSETSDetail(params?: any) {
|
|||||||
}
|
}
|
||||||
// 拿到经营项目列表
|
// 拿到经营项目列表
|
||||||
export async function handleGetBusinessProjectList(params?: any) {
|
export async function handleGetBusinessProjectList(params?: any) {
|
||||||
const data = await request(`/BusinessProject/GetBusinessProjectList`, {
|
const data = await requestSamember(`/BusinessProject/GetBusinessProjectList`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -161,7 +163,7 @@ export async function handleGetBusinessProjectList(params?: any) {
|
|||||||
}
|
}
|
||||||
// 将资产和门店相关联
|
// 将资产和门店相关联
|
||||||
export async function handleGetSynchroPROPERTYSHOP(params?: any) {
|
export async function handleGetSynchroPROPERTYSHOP(params?: any) {
|
||||||
const data = await request(`/BaseInfo/SynchroPROPERTYSHOP`, {
|
const data = await requestSamember(`/BaseInfo/SynchroPROPERTYSHOP`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -181,7 +183,7 @@ export async function handleGetSynchroPROPERTYSHOP(params?: any) {
|
|||||||
|
|
||||||
// 拿到图片列表
|
// 拿到图片列表
|
||||||
export async function handleGetPictureList(params: any) {
|
export async function handleGetPictureList(params: any) {
|
||||||
const data = await request(`/Picture/GetPictureList`, {
|
const data = await requestSamember(`/Picture/GetPictureList`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
@ -195,7 +197,7 @@ export async function handleGetPictureList(params: any) {
|
|||||||
// 拿到服务区的方位详情
|
// 拿到服务区的方位详情
|
||||||
export async function handleGetServerpartInfo(params: any) {
|
export async function handleGetServerpartInfo(params: any) {
|
||||||
|
|
||||||
const data = await requestCode(`/BaseInfo/GetServerpartInfo`, {
|
const data = await requestSamemberCode(`/BaseInfo/GetServerpartInfo`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
@ -209,7 +211,7 @@ export async function handleGetServerpartInfo(params: any) {
|
|||||||
|
|
||||||
// 拿到服务区列表
|
// 拿到服务区列表
|
||||||
export async function handleGetServerpartTree(params?: any) {
|
export async function handleGetServerpartTree(params?: any) {
|
||||||
const data = await request(`/BaseInfo/GetServerpartTree`, {
|
const data = await requestSamember(`/BaseInfo/GetServerpartTree`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params
|
params
|
||||||
});
|
});
|
||||||
@ -228,7 +230,7 @@ export async function handleGetServerpartTree(params?: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getFieldEnumTreeNoSession(params: any) {
|
export async function getFieldEnumTreeNoSession(params: any) {
|
||||||
const data = await request(`/FrameWork/GetFieldEnumTree`, {
|
const data = await requestSamember(`/FrameWork/GetFieldEnumTree`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
@ -242,7 +244,7 @@ export async function getFieldEnumTreeNoSession(params: any) {
|
|||||||
|
|
||||||
|
|
||||||
export async function uploadAHYDPicture(uploadFilds?: any) {
|
export async function uploadAHYDPicture(uploadFilds?: any) {
|
||||||
return await request(`/Picture/UploadPicture`, {
|
return await requestSamember(`/Picture/UploadPicture`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: uploadFilds
|
data: uploadFilds
|
||||||
})
|
})
|
||||||
@ -251,7 +253,7 @@ export async function uploadAHYDPicture(uploadFilds?: any) {
|
|||||||
// 删除图片
|
// 删除图片
|
||||||
export async function handleDeletePicture(params: any) {
|
export async function handleDeletePicture(params: any) {
|
||||||
|
|
||||||
const data = await request(`/Picture/DeletePicture`, {
|
const data = await requestSamember(`/Picture/DeletePicture`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
@ -268,7 +270,7 @@ export async function getFieldEnum(params: any): Promise<{ label: string; value:
|
|||||||
// if (FieldExplain) {
|
// if (FieldExplain) {
|
||||||
// return [...FieldExplain];
|
// return [...FieldExplain];
|
||||||
// }
|
// }
|
||||||
const data = await request(`/FrameWork/GetFieldEnumByField`, {
|
const data = await requestSamember(`/FrameWork/GetFieldEnumByField`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
@ -298,7 +300,7 @@ export function formateField(list: { label: string; value: string | number }[])
|
|||||||
|
|
||||||
// 获取详细数据
|
// 获取详细数据
|
||||||
export async function getDetail(RegisterCompactId: any) {
|
export async function getDetail(RegisterCompactId: any) {
|
||||||
const data = await request(
|
const data = await requestSamember(
|
||||||
`/Contract/GetRegisterCompactDetail?RegisterCompactId=${RegisterCompactId}`, {
|
`/Contract/GetRegisterCompactDetail?RegisterCompactId=${RegisterCompactId}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
},
|
},
|
||||||
@ -311,7 +313,7 @@ export async function getDetail(RegisterCompactId: any) {
|
|||||||
}
|
}
|
||||||
// 查询附属合同详细信息
|
// 查询附属合同详细信息
|
||||||
export async function getSubDetail(RegisterCompactId: any) {
|
export async function getSubDetail(RegisterCompactId: any) {
|
||||||
const data = await request(
|
const data = await requestSamember(
|
||||||
`/Contract/GetRegisterCompactSubDetail?RegisterCompactId=${RegisterCompactId}`, {
|
`/Contract/GetRegisterCompactSubDetail?RegisterCompactId=${RegisterCompactId}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
},
|
},
|
||||||
@ -329,7 +331,7 @@ export async function getProjectList(params?: any) {
|
|||||||
searchParameter: { ...params }, keyWord: params.keyWord || null,
|
searchParameter: { ...params }, keyWord: params.keyWord || null,
|
||||||
PageIndex: params.current, sortstr: params.sortstr, pagesize: params.pageSize
|
PageIndex: params.current, sortstr: params.sortstr, pagesize: params.pageSize
|
||||||
} : {};
|
} : {};
|
||||||
const data = await request(`/BusinessProject/GetBusinessProjectList`, {
|
const data = await requestSamember(`/BusinessProject/GetBusinessProjectList`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: search,
|
data: search,
|
||||||
});
|
});
|
||||||
@ -359,7 +361,7 @@ export function tableList(list: any) {
|
|||||||
}
|
}
|
||||||
// 获取附件图片
|
// 获取附件图片
|
||||||
export async function getPictureList(id: number, TableType?: string) {
|
export async function getPictureList(id: number, TableType?: string) {
|
||||||
const data = await request(`/Picture/GetPictureList?TableId=${id}&TableType=${TableType || ''}`, {
|
const data = await requestSamember(`/Picture/GetPictureList?TableId=${id}&TableType=${TableType || ''}`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -377,7 +379,7 @@ export async function getPictureList(id: number, TableType?: string) {
|
|||||||
|
|
||||||
// 获得关联合同列表
|
// 获得关联合同列表
|
||||||
export async function handleGetRelatedList(params: any) {
|
export async function handleGetRelatedList(params: any) {
|
||||||
const data = await request(`/Contract/GetRegisterCompactList`, {
|
const data = await requestSamember(`/Contract/GetRegisterCompactList`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params,
|
data: params,
|
||||||
});
|
});
|
||||||
@ -388,7 +390,7 @@ export async function handleGetRelatedList(params: any) {
|
|||||||
}
|
}
|
||||||
// 删除门店关联
|
// 删除门店关联
|
||||||
export async function handleDeletePROPERTYSHOP(params?: any) {
|
export async function handleDeletePROPERTYSHOP(params?: any) {
|
||||||
const data = await request(`/BaseInfo/DeletePROPERTYSHOP`, {
|
const data = await requestSamember(`/BaseInfo/DeletePROPERTYSHOP`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -402,7 +404,7 @@ export async function handleDeletePROPERTYSHOP(params?: any) {
|
|||||||
|
|
||||||
// 拿到门店列表
|
// 拿到门店列表
|
||||||
export async function handleGetServerpartShopList(params?: any) {
|
export async function handleGetServerpartShopList(params?: any) {
|
||||||
const data = await request(`/BaseInfo/GetServerpartShopList`, {
|
const data = await requestSamember(`/BaseInfo/GetServerpartShopList`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -422,7 +424,7 @@ export async function handleGetServerpartShopList(params?: any) {
|
|||||||
|
|
||||||
// 历史经营项目的勾选数据
|
// 历史经营项目的勾选数据
|
||||||
export async function handleGetPROPERTYSHOPList(params?: any) {
|
export async function handleGetPROPERTYSHOPList(params?: any) {
|
||||||
const data = await request(`/BaseInfo/GetPROPERTYSHOPList`, {
|
const data = await requestSamember(`/BaseInfo/GetPROPERTYSHOPList`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -435,7 +437,7 @@ export async function handleGetPROPERTYSHOPList(params?: any) {
|
|||||||
}
|
}
|
||||||
// 资产变更记录
|
// 资产变更记录
|
||||||
export async function handleGetPROPERTYASSETSLOGList(params?: any) {
|
export async function handleGetPROPERTYASSETSLOGList(params?: any) {
|
||||||
const data = await request(`/BaseInfo/GetPROPERTYASSETSLOGList`, {
|
const data = await requestSamember(`/BaseInfo/GetPROPERTYASSETSLOGList`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
@ -545,7 +547,7 @@ export async function handleGetBusinessDate(params: any) {
|
|||||||
// 获取门店详情
|
// 获取门店详情
|
||||||
export async function handleGetServerPartShopNewDetail(params?: any) {
|
export async function handleGetServerPartShopNewDetail(params?: any) {
|
||||||
|
|
||||||
const data = await request(`/BaseInfo/GetServerPartShopNewDetail`, {
|
const data = await requestSamember(`/BaseInfo/GetServerPartShopNewDetail`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
@ -562,7 +564,7 @@ export async function handleGetServerPartShopNewDetail(params?: any) {
|
|||||||
// 获取门店详情
|
// 获取门店详情
|
||||||
export async function handleGetServerpartList(params?: any) {
|
export async function handleGetServerpartList(params?: any) {
|
||||||
|
|
||||||
const data = await requestCode(`/BaseInfo/GetServerpartList`, {
|
const data = await requestSamemberCode(`/BaseInfo/GetServerpartList`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -22,8 +22,6 @@ instance.interceptors.request.use(
|
|||||||
|
|
||||||
config.headers = {
|
config.headers = {
|
||||||
...config.headers,
|
...config.headers,
|
||||||
Authorization: `Bearer ${localStorage.getItem('Authorization') || ''}`,
|
|
||||||
"Content-Type": "application/json;charset=utf-8"
|
|
||||||
} as AxiosRequestHeaders;
|
} as AxiosRequestHeaders;
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
150
src/utils/requestOldCode.ts
Normal file
150
src/utils/requestOldCode.ts
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import { getDvaApp } from 'umi';
|
||||||
|
import { notification } from 'antd';
|
||||||
|
import type { AxiosRequestHeaders } from 'axios/index';
|
||||||
|
import CryptoJS from "crypto-js";
|
||||||
|
|
||||||
|
const { UMI_APP_BASEURL } = process.env;
|
||||||
|
|
||||||
|
// const instance = axios.create({ baseURL: UMI_APP_BASEURL });
|
||||||
|
// const instance = axios.create({ baseURL: 'https://api.eshangtech.com/EShangApiMain' });
|
||||||
|
const instance = axios.create({ baseURL: 'https://samember.yciccloud.com:8999/CommercialApi' });
|
||||||
|
// const instance = axios.create({ baseURL: '/auth' });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
instance.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
// 对data数据进行加密
|
||||||
|
// if (config.data) {
|
||||||
|
// config.data = preprocessData(JSON.stringify(config.data)); // 调用预处理函数
|
||||||
|
// }
|
||||||
|
|
||||||
|
config.headers = {
|
||||||
|
...config.headers,
|
||||||
|
} as AxiosRequestHeaders;
|
||||||
|
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => Promise.reject(error),
|
||||||
|
);
|
||||||
|
|
||||||
|
instance.interceptors.response.use(
|
||||||
|
//状态码为2xx的时候执行
|
||||||
|
(response) => {
|
||||||
|
const { data } = response;
|
||||||
|
|
||||||
|
if (data.code !== 200 && data.Result_Code !== 100) {
|
||||||
|
notification.error({
|
||||||
|
message: data.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const timestamp = getFormattedDate()
|
||||||
|
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
//状态码不是2xx的时候执行
|
||||||
|
(error) => {
|
||||||
|
const { response } = error;
|
||||||
|
|
||||||
|
if (response && response.status === 401) {
|
||||||
|
// // 清除本地存储的token
|
||||||
|
// localStorage.removeItem('Authorization');
|
||||||
|
// // 重定向到登录页
|
||||||
|
// window.location.href = '/user/login';
|
||||||
|
// notification.error({
|
||||||
|
// message: response?.data?.message || '请求失败',
|
||||||
|
// description: error.message
|
||||||
|
// });
|
||||||
|
} else {
|
||||||
|
notification.error({
|
||||||
|
message: response?.data?.message || '请求失败',
|
||||||
|
description: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject({
|
||||||
|
code: response?.status || 500,
|
||||||
|
message: response?.data?.message || '请求失败'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
const encryptAESECB = (data: string, key: string) => {
|
||||||
|
// const cipher = CryptoJS.createCipheriv('aes-128-ecb', key, null); // ECB 模式不需要 IV
|
||||||
|
const newKey = CryptoJS.enc.Utf8.parse(key); // 密钥必须是 16 字节
|
||||||
|
const cipher = CryptoJS.AES.encrypt(data, newKey, {
|
||||||
|
mode: CryptoJS.mode.ECB,
|
||||||
|
padding: CryptoJS.pad.Pkcs7
|
||||||
|
});
|
||||||
|
let encrypted = cipher.ciphertext.toString(CryptoJS.enc.Hex);
|
||||||
|
// let encrypted = cipher.update(data, 'utf8', 'hex');
|
||||||
|
// encrypted += cipher.final('hex');
|
||||||
|
return encrypted;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
const decryptAESECB = (data: string, key: string) => {
|
||||||
|
// const decipher = CryptoJS.createDecipheriv('aes-128-ecb', key, null);
|
||||||
|
// let decrypted = decipher.update(data, 'hex', 'utf8');
|
||||||
|
// decrypted += decipher.final('utf8');
|
||||||
|
const newKey = CryptoJS.enc.Utf8.parse(key);
|
||||||
|
|
||||||
|
const encryptedData = CryptoJS.enc.Hex.parse(data);
|
||||||
|
|
||||||
|
// 解密操作
|
||||||
|
const decrypted = CryptoJS.AES.decrypt({ ciphertext: encryptedData }, newKey, {
|
||||||
|
mode: CryptoJS.mode.ECB, // ECB 模式
|
||||||
|
padding: CryptoJS.pad.Pkcs7 // PKCS7 填充方式
|
||||||
|
});
|
||||||
|
// 将解密后的结果转为 UTF-8 字符串
|
||||||
|
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
|
||||||
|
return decryptedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
// md5 签名
|
||||||
|
const md5 = (key: string, data: string, timestamp: string) => {
|
||||||
|
const text = "s" + key + data + timestamp;
|
||||||
|
return CryptoJS.MD5(text).toString(CryptoJS.enc.Hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成签名戳
|
||||||
|
const getFormattedDate = () => {
|
||||||
|
const date = new Date();
|
||||||
|
const year = date.getFullYear(); // 获取年份 (yyyy)
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份 (MM)
|
||||||
|
const day = String(date.getDate()).padStart(2, '0'); // 获取日期 (dd)
|
||||||
|
const hours = String(date.getHours()).padStart(2, '0'); // 获取小时 (HH)
|
||||||
|
return `es0${year}${month}${day}${hours}0es`; // 拼接成 yyyyMMddHH 格式
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加密方法
|
||||||
|
const preprocessData = (data: string) => {
|
||||||
|
console.log('data', data);
|
||||||
|
// YYYYMMDD
|
||||||
|
let timestamp = getFormattedDate()
|
||||||
|
console.log('timestamp', timestamp);
|
||||||
|
// 秒为单位的时间戳
|
||||||
|
let timeSecond = parseInt((new Date().getTime() / 1000).toString())
|
||||||
|
console.log('timeSecond', timeSecond);
|
||||||
|
// 数据的加密
|
||||||
|
let encryptionData = encryptAESECB(data, timestamp)
|
||||||
|
console.log('encryptionData', encryptionData);
|
||||||
|
// md5签名方法
|
||||||
|
let md5Data = md5(timestamp, encryptionData, timestamp)
|
||||||
|
console.log('md5Data', md5Data);
|
||||||
|
|
||||||
|
let res = {
|
||||||
|
data: encryptionData,
|
||||||
|
timestamp: timeSecond,
|
||||||
|
sign: md5Data
|
||||||
|
}
|
||||||
|
console.log('res', res);
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
export default instance;
|
||||||
Loading…
x
Reference in New Issue
Block a user