💥 feat(模块): 添加了个很棒的功能
This commit is contained in:
parent
f3966ac2c9
commit
b021eff28f
@ -103,6 +103,8 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
||||
: item.name,
|
||||
}),
|
||||
);
|
||||
console.log('consumableMenuconsumableMenuconsumableMenu', consumableMenu);
|
||||
|
||||
// const consumableMenu: MenuDataItem[] = [
|
||||
// {
|
||||
// path: '/',
|
||||
@ -213,6 +215,8 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
||||
console.log('tabsRoutes', tabsRoutes);
|
||||
console.log('location', location);
|
||||
console.log('consumableMenu', consumableMenu);
|
||||
console.log('oneFloorListoneFloorListoneFloorListoneFloorList', oneFloorList);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
@ -280,10 +284,9 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
||||
actionsRender={() => <nav />}
|
||||
onPageChange={(location) => {
|
||||
console.log('location', location);
|
||||
|
||||
if (location?.pathname && location?.pathname !== '/') {
|
||||
|
||||
const nextModule: any = oneFloorList.filter(n => location?.pathname === n?.path)
|
||||
|
||||
let title = ''
|
||||
if (nextModule && nextModule.length > 0) {
|
||||
title = nextModule[0].name
|
||||
|
||||
@ -60,9 +60,9 @@ const AddBigType = ({ parentRow, onRef, openAddModal, currentUser, setOpenAddMod
|
||||
}
|
||||
console.log('req', req);
|
||||
console.log('data', data);
|
||||
if (data.code === 200) {
|
||||
if (data.Result_Code === 100) {
|
||||
modalRef.current?.resetFields()
|
||||
message.success(data.message)
|
||||
message.success(`${parentRow?.id ? '编辑' : '新增'}成功!`)
|
||||
setOpenAddModal(false)
|
||||
if (parentActionRef) {
|
||||
parentActionRef.current?.reload()
|
||||
@ -75,7 +75,7 @@ const AddBigType = ({ parentRow, onRef, openAddModal, currentUser, setOpenAddMod
|
||||
afterAdd()
|
||||
}
|
||||
} else {
|
||||
message.error(data.message)
|
||||
message.error(data.Result_Desc)
|
||||
}
|
||||
})
|
||||
}}
|
||||
|
||||
@ -119,10 +119,16 @@ const examineIndex: React.FC<{ currentUser: any }> = (props) => {
|
||||
|
||||
// 删除分类
|
||||
const handleDeleteType = async (id: number) => {
|
||||
const data = await handleGetDeleteExamineType(id)
|
||||
if (data.code === 200) {
|
||||
message.success(data.message)
|
||||
let req: any = {
|
||||
id: id
|
||||
}
|
||||
console.log('req', req);
|
||||
const data = await handleGetDeleteExamineType(req)
|
||||
if (data.Result_Code === 100) {
|
||||
message.success('删除成功!')
|
||||
actionRef.current?.reload()
|
||||
} else {
|
||||
message.error(data.Result_Desc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
import request from "@/utils/request"
|
||||
|
||||
// import request from "@/utils/request"
|
||||
import request from "@/utils/requestJava"
|
||||
|
||||
|
||||
// 拿到类别列表接口
|
||||
export async function handleGetExamineTypeList(params?: any) {
|
||||
const data = await request.get('/question-categories', {params})
|
||||
if (data.code === 200) {
|
||||
return data.data
|
||||
const data = await request.get('/question-categories/getList', { params })
|
||||
if (data.Result_Code === 100) {
|
||||
return data.Result_Data.list
|
||||
}
|
||||
return []
|
||||
}
|
||||
@ -12,26 +15,26 @@ export async function handleGetExamineTypeList(params?: any) {
|
||||
// 拿树形的
|
||||
export async function handleGetExamineTypeTreeList(params?: any) {
|
||||
const data = await request.get('/question-categories/tree', params)
|
||||
if (data.code === 200) {
|
||||
return data.data
|
||||
if (data.Result_Code === 100) {
|
||||
return data.Result_Data.list
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
// 新增类别列表接口
|
||||
export async function handleGetAddExamineType(params: any) {
|
||||
const data = await request.post('/question-categories', params)
|
||||
const data = await request.post('/question-categories/save', params)
|
||||
return data
|
||||
}
|
||||
|
||||
// 删除类别接口
|
||||
export async function handleGetDeleteExamineType(params: any) {
|
||||
const data = await request.get(`/question-categories/delete/${params}`)
|
||||
const data = await request.get(`/question-categories/delete`, { params })
|
||||
return data
|
||||
}
|
||||
|
||||
// 编辑分类接口
|
||||
export async function handleGetEditExamineType(params: any) {
|
||||
const data = await request.post(`/question-categories/${params.id}`, params)
|
||||
const data = await request.post(`/question-categories/update`, params)
|
||||
return data
|
||||
}
|
||||
@ -293,8 +293,8 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
||||
// 删除模版
|
||||
const deleteQuestion = async (id: number) => {
|
||||
const data = await handleDeleteTemplates({ id: id })
|
||||
if (data.code === 200) {
|
||||
message.success(data.message)
|
||||
if (data.Result_Code === 100) {
|
||||
message.success(data.Result_Desc)
|
||||
actionRef.current?.reload()
|
||||
}
|
||||
}
|
||||
@ -316,6 +316,8 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
||||
children: child.children || []
|
||||
})) || []
|
||||
})) : [];
|
||||
console.log('formattedData', formattedData);
|
||||
|
||||
setBigTypeList(formattedData);
|
||||
};
|
||||
|
||||
@ -413,6 +415,7 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
||||
modalRef.current?.validateFields().then(async (res) => {
|
||||
console.log('res', res);
|
||||
console.log('currentRow', currentRow);
|
||||
console.log('selectedQuestionDetail', selectedQuestionDetail);
|
||||
let req = {}
|
||||
let data = {}
|
||||
if (currentRow?.id) {
|
||||
@ -467,7 +470,7 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
||||
if (selectedQuestionDetail && selectedQuestionDetail.length > 0) {
|
||||
selectedQuestionDetail.forEach((item) => {
|
||||
questions.push({
|
||||
questionId: item.id,
|
||||
questionId: item.questionId,
|
||||
isRequired: item.required,
|
||||
sortOrder: item.sortOrder
|
||||
})
|
||||
@ -481,38 +484,39 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
||||
serverPartName: serviceObj ? serviceObj[res.serverPartId] : "",
|
||||
serverPartId: res.serverPartId,
|
||||
// qrUrl: "",
|
||||
questions: questions && questions.length > 0 ? questions : "",
|
||||
questions: questions && questions.length > 0 ? questions : [],
|
||||
operator: currentUser?.operator,
|
||||
status: res.status,
|
||||
description: res.description
|
||||
}
|
||||
data = await handleAddTemplates(req)
|
||||
console.log('datadsadsa1', data.data);
|
||||
const myQRCodeDataUrl = await QRCode.toDataURL(`pages/walkAroundManager/index?id=${data.data.id}`);
|
||||
const file = base64ToFile(myQRCodeDataUrl, `wenjuan${data.data.id}.png`);
|
||||
console.log('datadsadsa1', data);
|
||||
const myQRCodeDataUrl = await QRCode.toDataURL(`pages/walkAroundManager/index?id=${data.Result_Data.id}`);
|
||||
const file = base64ToFile(myQRCodeDataUrl, `wenjuan${data.Result_Data.id}.png`);
|
||||
console.log('file', file);
|
||||
const formData = new FormData();
|
||||
formData.append("file", file, `wenjuan${data.data.id}.png`); // 确保文件名也传递
|
||||
formData.append("file", file, `wenjuan${data.Result_Data.id}.png`); // 确保文件名也传递
|
||||
|
||||
const fileData = await handleUploadFile(formData)
|
||||
console.log('fileData', fileData);
|
||||
let imgUrl: string = `https://es.eshangtech.com/${fileData.data.path}`
|
||||
await handleUpdateTemplates({
|
||||
...data.data,
|
||||
...data.Result_Data,
|
||||
qrUrl: imgUrl
|
||||
})
|
||||
setQrCodeUrl(imgUrl)
|
||||
|
||||
// setQrCodeUrl(myQRCodeDataUrl)
|
||||
}
|
||||
console.log('datadsadsa', data);
|
||||
if (data.code === 200) {
|
||||
if (data.Result_Code === 100) {
|
||||
modalRef.current?.resetFields()
|
||||
message.success(data.message)
|
||||
message.success('新增成功!')
|
||||
setShowPlaceModal(false)
|
||||
actionRef.current?.reload()
|
||||
setCurrentRow(undefined)
|
||||
} else {
|
||||
message.error(data.message)
|
||||
message.error(data.Result_Desc)
|
||||
}
|
||||
|
||||
})
|
||||
@ -771,42 +775,46 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => {
|
||||
onOk={() => {
|
||||
console.log('selectedCloneId', selectedCloneId);
|
||||
console.log('selectedCloneDetail', selectedCloneDetail);
|
||||
if (selectedCloneDetail && selectedCloneDetail.length > 0) {
|
||||
let res: any = []
|
||||
let detailList: any = []
|
||||
let idList: any = []
|
||||
let list: any = selectedCloneDetail[0].questionnaireTemplateQuestions
|
||||
if (list && list.length > 0) {
|
||||
list.forEach((item: any) => {
|
||||
detailList.push(item)
|
||||
idList.push(item.question.id.toString())
|
||||
if (item.question) {
|
||||
let obj = JSON.parse(JSON.stringify(item.question))
|
||||
|
||||
let res: any = []
|
||||
let detailList: any = []
|
||||
let idList: any = []
|
||||
let list: any = selectedCloneDetail[0].questionnaireTemplateQuestions
|
||||
if (list && list.length > 0) {
|
||||
list.forEach((item: any) => {
|
||||
detailList.push(item)
|
||||
idList.push(item.question.id.toString())
|
||||
if (item.question) {
|
||||
let obj = JSON.parse(JSON.stringify(item.question))
|
||||
let str: string = ''
|
||||
if (obj.options && obj?.options.length > 0) {
|
||||
obj.options.forEach((subItem: any, index: number) => {
|
||||
str += `${index > 0 ? ',' : ''}选项${index + 1}:${subItem.text}`
|
||||
})
|
||||
}
|
||||
|
||||
let str: string = ''
|
||||
if (obj.options && obj?.options.length > 0) {
|
||||
obj.options.forEach((subItem: any, index: number) => {
|
||||
str += `${index > 0 ? ',' : ''}选项${index + 1}:${subItem.text}`
|
||||
})
|
||||
obj.text = obj.title
|
||||
obj.mark = JSON.stringify(obj.options)
|
||||
obj.showText = str
|
||||
res.push(obj)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
obj.text = obj.title
|
||||
obj.mark = JSON.stringify(obj.options)
|
||||
obj.showText = str
|
||||
res.push(obj)
|
||||
}
|
||||
setSelectedQuestionDetail(detailList)
|
||||
console.log('idList', idList);
|
||||
|
||||
setSelectedQuestionId(idList)
|
||||
|
||||
modalRef.current?.setFieldsValue({
|
||||
questions: res
|
||||
})
|
||||
handleShowCloneModal(false)
|
||||
} else {
|
||||
handleShowCloneModal(false)
|
||||
}
|
||||
|
||||
setSelectedQuestionDetail(detailList)
|
||||
console.log('idList', idList);
|
||||
|
||||
setSelectedQuestionId(idList)
|
||||
|
||||
modalRef.current?.setFieldsValue({
|
||||
questions: res
|
||||
})
|
||||
handleShowCloneModal(false)
|
||||
}}
|
||||
onCancel={() => {
|
||||
handleShowCloneModal(false)
|
||||
|
||||
@ -1,54 +1,55 @@
|
||||
import requestOld from "@/utils/requestOld"
|
||||
import request from "@/utils/request"
|
||||
|
||||
// import request from "@/utils/request"
|
||||
import requestNode from "@/utils/request"
|
||||
import request from "@/utils/requestJava"
|
||||
|
||||
// 拿到模版id列表 去绑定服务区的多个站点信息 的列表接口
|
||||
export async function handleGetTemplatesList(params?: any) {
|
||||
const data = await request.get('/questionnaire-templates', { params })
|
||||
if (data.code === 200) {
|
||||
return data.data
|
||||
if (data.Result_Code === 200) {
|
||||
return data.Result_Data.list
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
// 新建模版
|
||||
export async function handleAddTemplates(params?: any) {
|
||||
const data = await request.post('/questionnaire-templates', params)
|
||||
const data = await request.post('/questionnaire-templates/save', params)
|
||||
return data
|
||||
}
|
||||
|
||||
// 更新模版
|
||||
export async function handleUpdateTemplates(params?: any) {
|
||||
const data = await request.post(`/questionnaire-templates/${params.id}`, params)
|
||||
const data = await request.post(`/questionnaire-templates/update`, params)
|
||||
return data
|
||||
}
|
||||
|
||||
// 删除模版
|
||||
export async function handleDeleteTemplates(params?: any) {
|
||||
const data = await request.get(`/questionnaire-templates/delete/${params.id}`)
|
||||
const data = await request.get(`/questionnaire-templates/delete`,{params})
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
export async function handleGetQuestionList(params?: any) {
|
||||
const data = await request.get(`/questions?categoryId=${params.categoryId}`,)
|
||||
if (data.code === 200) {
|
||||
return data.data
|
||||
const data = await request.get('/questions/getList', params)
|
||||
if (data.Result_Code === 100) {
|
||||
return data.Result_Data.list
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
// 上传图片的oss接口
|
||||
export async function handleUploadFile(params?: any) {
|
||||
const data = await request.post(`/oss/upload`, params)
|
||||
const data = await requestNode.post(`/oss/upload`, params)
|
||||
return data
|
||||
}
|
||||
|
||||
// 模版树的查询
|
||||
export async function handleSearchModalTree(params?: any) {
|
||||
const data = await request.post(`/questionnaire-templates/search/tree`, params)
|
||||
if (data.code === 200) {
|
||||
return data.data
|
||||
if (data.Result_Code === 100) {
|
||||
return data.Result_Data.list
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
@ -51,7 +51,8 @@ const addQuestion = ({ parentRow, onRef, currentUser, showQuestionModal, setShow
|
||||
options: res.options,
|
||||
status: res.status,
|
||||
operator: currentUser?.operator,
|
||||
description: `${res.categoryId && categoryIdObj ? categoryIdObj[res.categoryId] : ''}`
|
||||
description: `${res.categoryId && categoryIdObj ? categoryIdObj[res.categoryId] : ''}`,
|
||||
category: undefined
|
||||
}
|
||||
console.log('req', req);
|
||||
|
||||
@ -73,11 +74,11 @@ const addQuestion = ({ parentRow, onRef, currentUser, showQuestionModal, setShow
|
||||
data = await handleAddQuestion(req)
|
||||
}
|
||||
console.log('datadsadsa', data);
|
||||
if (data.code === 200) {
|
||||
if (data.Result_Code === 100) {
|
||||
if (modalRef) {
|
||||
modalRef.current?.resetFields()
|
||||
}
|
||||
message.success(data.message)
|
||||
message.success(data.Result_Desc)
|
||||
setShowQuestionModal(false)
|
||||
if (parentActionRef) {
|
||||
parentActionRef.current?.reload()
|
||||
@ -89,7 +90,7 @@ const addQuestion = ({ parentRow, onRef, currentUser, showQuestionModal, setShow
|
||||
afterAdd()
|
||||
}
|
||||
} else {
|
||||
message.error(data.message)
|
||||
message.error(data.Result_Desc)
|
||||
}
|
||||
|
||||
})
|
||||
@ -136,10 +137,12 @@ const addQuestion = ({ parentRow, onRef, currentUser, showQuestionModal, setShow
|
||||
let obj: any = {}
|
||||
const labelList = await handleGetExamineTypeList()
|
||||
if (labelList && labelList.length > 0) {
|
||||
labelList.forEach((item) => {
|
||||
labelList.forEach((item: any) => {
|
||||
obj[item.id] = item.name
|
||||
})
|
||||
}
|
||||
console.log('objobjobjobj', obj);
|
||||
|
||||
setCategoryIdObj(obj)
|
||||
return data
|
||||
}}
|
||||
|
||||
@ -168,9 +168,11 @@ const examineQuestion: React.FC<{ currentUser: any }> = (props) => {
|
||||
// 删除分类
|
||||
const deleteQuestion = async (id: number) => {
|
||||
const data = await handleDeleteQuestion({ id: id })
|
||||
if (data.code === 200) {
|
||||
message.success(data.message)
|
||||
if (data.Result_Code === 100) {
|
||||
message.success('删除成功!')
|
||||
actionRef.current?.reload()
|
||||
} else {
|
||||
message.error(data.Result_Desc)
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,6 +195,9 @@ const examineQuestion: React.FC<{ currentUser: any }> = (props) => {
|
||||
|
||||
// 检查当前节点是否匹配list中的categoryId
|
||||
const matchedItems = itemsToInsert.filter(item => item.categoryId === node.id);
|
||||
console.log('node', node);
|
||||
|
||||
console.log('matchedItems', matchedItems);
|
||||
|
||||
if (matchedItems.length > 0) {
|
||||
// 如果匹配到,初始化children数组(如果不存在)
|
||||
|
||||
@ -1,29 +1,30 @@
|
||||
import request from "@/utils/request"
|
||||
// import request from "@/utils/request"
|
||||
import request from "@/utils/requestJava"
|
||||
|
||||
// 拿到问题列表接口
|
||||
export async function handleGetQuestionList(params?: any) {
|
||||
const data = await request.post('/questions/search/many', params)
|
||||
if (data.code === 200) {
|
||||
return data.data
|
||||
if (data.Result_Code === 100) {
|
||||
return data.Result_Data.list
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
// 新增问题接口
|
||||
export async function handleAddQuestion(params?: any) {
|
||||
const data = await request.post('/questions', params)
|
||||
const data = await request.post('/questions/save', params)
|
||||
return data
|
||||
}
|
||||
|
||||
// 编辑问题接口
|
||||
export async function handleEditQuestion(params?: any) {
|
||||
const data = await request.post(`/questions/${params.id}`, params)
|
||||
const data = await request.post(`/questions/update`, params)
|
||||
return data
|
||||
}
|
||||
|
||||
// 删除问题
|
||||
export async function handleDeleteQuestion(params?: any) {
|
||||
const data = await request.get(`/questions/delete/${params.id}`)
|
||||
const data = await request.get(`/questions/delete`, { params })
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@ -269,8 +269,8 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
|
||||
// 删除记录
|
||||
const deleteRecord = async (id: any) => {
|
||||
const data = await handleDeleteRecord({ id: id })
|
||||
if (data.code === 200) {
|
||||
message.success(data.message)
|
||||
if (data.Result_Code === 100) {
|
||||
message.success(data.Result_Desc)
|
||||
actionRef.current?.reload()
|
||||
}
|
||||
}
|
||||
@ -311,8 +311,8 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
|
||||
|
||||
const req: any = {
|
||||
serverPartIds: selectedId && selectedId.length > 0 ? selectedId : [],
|
||||
startTime: params?.staticDate ? `${params?.staticDate}T00:00:00` : "",
|
||||
endTime: params?.staticDate ? `${params?.staticDate}T23:59:59` : "",
|
||||
startTime: params?.staticDate ? `${params?.staticDate}` : "",
|
||||
endTime: params?.staticDate ? `${params?.staticDate}` : "",
|
||||
// serverPartId: params?.serverPartId ? params?.serverPartId : undefined,
|
||||
extend: params?.inspectionType ? [{
|
||||
key: "situation",
|
||||
@ -406,14 +406,14 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
|
||||
};
|
||||
|
||||
const data = await handleUpdateExtend(recordDetailRef.current?.formRes.id, { extend: JSON.stringify(req) })
|
||||
if (data.code === 200) {
|
||||
if (data.Result_Code === 100) {
|
||||
message.success('提交成功')
|
||||
setShowDetail(false)
|
||||
setShowAbnormal(false)
|
||||
actionRef.current?.reload()
|
||||
setCurrentRow(undefined)
|
||||
} else {
|
||||
message.error(data.message)
|
||||
message.error(data.Result_Desc)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -439,14 +439,14 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => {
|
||||
};
|
||||
|
||||
const data = await handleUpdateExtend(recordDetailRef.current?.formRes.id, { extend: JSON.stringify(req) })
|
||||
if (data.code === 200) {
|
||||
if (data.Result_Code === 100) {
|
||||
message.success('提交成功')
|
||||
setShowDetail(false)
|
||||
setShowAbnormal(false)
|
||||
actionRef.current?.reload()
|
||||
setCurrentRow(undefined)
|
||||
} else {
|
||||
message.error(data.message)
|
||||
message.error(data.Result_Desc)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import request from "@/utils/request"
|
||||
// import request from "@/utils/request"
|
||||
import request from "@/utils/requestJava"
|
||||
import requestMap from '@/utils/requestMap'
|
||||
|
||||
// 拿到记录
|
||||
export async function handleGetRecordList(params?: any) {
|
||||
const data = await request.post('/questionnaire-responses/search/many', params)
|
||||
if (data.code === 200) {
|
||||
return data.data
|
||||
if (data.Result_Code === 100) {
|
||||
return data.Result_Data.list
|
||||
}
|
||||
return []
|
||||
}
|
||||
@ -13,8 +14,8 @@ export async function handleGetRecordList(params?: any) {
|
||||
// 拿到记录的树型结构
|
||||
export async function handleGetRecordTreeList(params?: any) {
|
||||
const data = await request.post('/questionnaire-responses/tree', params)
|
||||
if (data.code === 200) {
|
||||
return data.data
|
||||
if (data.Result_Code === 100) {
|
||||
return data.Result_Data.list
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
@ -215,6 +215,18 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => {
|
||||
// "0": "正常"
|
||||
// }
|
||||
// },
|
||||
{
|
||||
title: <div style={{ textAlign: 'center' }}>巡查时间</div>,
|
||||
dataIndex: "createdAt",
|
||||
hideInSearch: true,
|
||||
width: 150,
|
||||
ellipsis: true,
|
||||
fixed: 'left',
|
||||
align: 'center',
|
||||
render: (_, record) => {
|
||||
return record?.createdAt ? moment(record?.createdAt).format('YYYY-MM-DD HH:mm:ss') : '-'
|
||||
}
|
||||
},
|
||||
{
|
||||
title: <div style={{ textAlign: 'center' }}>服务区名称</div>,
|
||||
dataIndex: "serverPartName",
|
||||
@ -279,17 +291,7 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => {
|
||||
width: 100,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: <div style={{ textAlign: 'center' }}>巡查时间</div>,
|
||||
dataIndex: "createdAt",
|
||||
hideInSearch: true,
|
||||
width: 150,
|
||||
ellipsis: true,
|
||||
align: 'center',
|
||||
render: (_, record) => {
|
||||
return record?.createdAt ? moment(record?.createdAt).format('YYYY-MM-DD HH:mm:ss') : '-'
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title: <div style={{ textAlign: 'center' }}>巡查人</div>,
|
||||
dataIndex: "userName",
|
||||
|
||||
159
src/utils/requestJava.ts
Normal file
159
src/utils/requestJava.ts
Normal file
@ -0,0 +1,159 @@
|
||||
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: 'http://home.robot-z.cn:7001/' });
|
||||
// 修改baseURL为完整的API地址,确保在生产环境中正确访问
|
||||
// const instance = axios.create({ baseURL: 'https://es.robot-z.cn' });
|
||||
|
||||
const instance = axios.create({ baseURL: 'http://10.104.1.161:8070/platform' });
|
||||
|
||||
instance.interceptors.request.use(
|
||||
(config) => {
|
||||
// 对data数据进行加密
|
||||
// if (config.data) {
|
||||
// config.data = preprocessData(JSON.stringify(config.data)); // 调用预处理函数
|
||||
//
|
||||
|
||||
const isUpload = config.url?.includes("/oss/upload");
|
||||
|
||||
let token = localStorage.getItem('Authorization') || ''
|
||||
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
Authorization: token ? `Bearer ${token}` : "",
|
||||
"Content-Type": isUpload ? "multipart/form-data" : "application/json;charset=utf-8",
|
||||
} as AxiosRequestHeaders;
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => Promise.reject(error),
|
||||
);
|
||||
|
||||
instance.interceptors.response.use(
|
||||
//状态码为2xx的时候执行
|
||||
(response) => {
|
||||
const { data } = response;
|
||||
|
||||
if (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({
|
||||
Result_Code: response?.status || 500,
|
||||
Result_Desc: 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