From 03ba594601d2d697c0aa831bcf4393778ffdb1ab Mon Sep 17 00:00:00 2001 From: ylj20011123 Date: Tue, 6 May 2025 19:41:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20feat(=E6=A8=A1=E5=9D=97):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=AA=E5=BE=88=E6=A3=92=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/KeepAliveOutlet/index.tsx | 51 ++++ src/layouts/index.tsx | 10 +- src/pages/examine/errorRecord/index.tsx | 4 +- src/pages/examine/modal/index.tsx | 4 +- .../record/components/recordDetail.tsx | 211 ++++++++-------- src/pages/examine/record/index.tsx | 80 +++--- src/pages/examine/recordSummary/index.tsx | 232 ++++++++++-------- 7 files changed, 333 insertions(+), 259 deletions(-) create mode 100644 src/components/KeepAliveOutlet/index.tsx diff --git a/src/components/KeepAliveOutlet/index.tsx b/src/components/KeepAliveOutlet/index.tsx new file mode 100644 index 0000000..3375928 --- /dev/null +++ b/src/components/KeepAliveOutlet/index.tsx @@ -0,0 +1,51 @@ +import React, { useEffect, useState } from 'react'; +import { Outlet, useLocation, useOutlet, connect } from 'umi'; + +interface CacheItem { + outlet: React.ReactNode; + pathname: string; +} + +// 创建一个缓存路由组件,用于保持路由组件的状态 +const KeepAliveOutlet: React.FC<{ global: any }> = (props) => { + const [cacheOutlets, setCacheOutlets] = useState([]); + const location = useLocation(); + const { pathname } = location; + const currentOutlet = useOutlet(); + const { tabsRoutes = [] } = props.global || {}; + + // 获取当前打开的所有标签页路径 + const activePaths = tabsRoutes.map((tab: any) => tab.path); + + // 使用字符串比较来避免不必要的重渲染 + const activePathsString = JSON.stringify(activePaths); + + useEffect(() => { + // 如果当前路径已经在缓存中,则不需要再次添加 + if (!cacheOutlets.find(item => item.pathname === pathname)) { + setCacheOutlets(prev => [...prev, { outlet: currentOutlet, pathname }]); + } + }, [pathname, currentOutlet]); + + // 单独处理缓存清理逻辑,避免不必要的重渲染 + useEffect(() => { + // 清理已关闭标签页的缓存 + if (cacheOutlets.length > 0) { + setCacheOutlets(prev => prev.filter(item => activePaths.includes(item.pathname))); + } + }, [activePathsString]); + + return ( + <> + {cacheOutlets.map(item => ( +
+ {item.outlet} +
+ ))} + + ); +}; + +export default connect(({ global }: { global: any }) => ({ + global, +}))(KeepAliveOutlet); \ No newline at end of file diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 24b5754..035d7d2 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -4,6 +4,7 @@ import { useState, useEffect } from 'react'; import { Dropdown, Layout, Menu, Tabs, Tooltip } from 'antd'; import type { MenuProps } from 'antd'; import { Outlet, Link, useLocation, connect, history } from 'umi'; +import KeepAliveOutlet from '@/components/KeepAliveOutlet'; import PageAccess from '@/components/PageAccess'; import type { UserConnectedProps, UserModelState } from '@/models/user'; import LayoutWrapper from '@/components/LayoutWrapper'; @@ -367,6 +368,7 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc onEdit={handleEdit} size="small" className='main-tab' + destroyInactiveTabPane={false} // 不销毁不活动的标签页面板,保持状态 tabBarExtraContent={ + style={{ padding: 24, paddingTop: 0 }} + forceRender={true} /* 强制渲染标签页内容,即使不可见也保持渲染状态 */ + > { //统一对所有有效路由做页面鉴权的处理 validMenuItem ? ( - +
+ +
) : diff --git a/src/pages/examine/errorRecord/index.tsx b/src/pages/examine/errorRecord/index.tsx index 18a2f13..0cf8193 100644 --- a/src/pages/examine/errorRecord/index.tsx +++ b/src/pages/examine/errorRecord/index.tsx @@ -260,14 +260,14 @@ const ErrorRecord: React.FC<{ currentUser: any }> = (props) => { } - { deleteRecord(record?.id) }} > 删除 - + */} } diff --git a/src/pages/examine/modal/index.tsx b/src/pages/examine/modal/index.tsx index 3af0cf6..c1a30d2 100644 --- a/src/pages/examine/modal/index.tsx +++ b/src/pages/examine/modal/index.tsx @@ -230,14 +230,14 @@ const examineModal: React.FC<{ currentUser: any }> = (props) => { setCurrentRow(record) handleShowDetail(true) }}>详情 */} - { deleteQuestion(record?.id) }} > 删除 - + */} { console.log('currentRow', record); setCurrentRow(record) diff --git a/src/pages/examine/record/components/recordDetail.tsx b/src/pages/examine/record/components/recordDetail.tsx index 2736a4e..fde95e7 100644 --- a/src/pages/examine/record/components/recordDetail.tsx +++ b/src/pages/examine/record/components/recordDetail.tsx @@ -612,7 +612,7 @@ const RecordDetail = ({ parentRow, show, detailType, currentUser, onRef, showErr request={async () => { const req = { SERVERPART_ID: formRes.serverPartId, - PROVINCE_CODE: currentUser.provinceCode, + PROVINCE_CODE: currentUser.provinceCode || '510000', } const data = await handleGetDealerList(req) console.log('data', data) @@ -727,127 +727,132 @@ const RecordDetail = ({ parentRow, show, detailType, currentUser, onRef, showErr : "" } - { - handlePrintTable() - }}> - 打印 - - ] - }} - scroll={{ x: "100%", y: 'calc(100vh - 300px)' }} - pagination={false} - options={false} - request={async () => { - let res = detailType === 'modal' ? parentRow?.questionnaireTemplateQuestions - || [] : parentRow?.questionResponses || [] - console.log('parentRow', parentRow); - console.log('res', res); + { + formRes && formRes.situation === 1 ? + { + handlePrintTable() + }}> + 打印 + + ] + }} + scroll={{ x: "100%", y: 'calc(100vh - 300px)' }} + pagination={false} + options={false} + request={async () => { + let res = detailType === 'modal' ? parentRow?.questionnaireTemplateQuestions + || [] : parentRow?.questionResponses || [] + console.log('parentRow', parentRow); + console.log('res', res); - let obj: any = {} - let typeData = await handleGetExamineTypeTreeList({}) - console.log('typeData', typeData); - if (typeData && typeData.length > 0) { - typeData.forEach((item: any) => { - obj[item.id] = item.name - if (item.children && item.children.length > 0) { - item.children.forEach((subItem: any) => { - obj[subItem.id] = subItem.name + let obj: any = {} + let typeData = await handleGetExamineTypeTreeList({}) + console.log('typeData', typeData); + if (typeData && typeData.length > 0) { + typeData.forEach((item: any) => { + obj[item.id] = item.name + if (item.children && item.children.length > 0) { + item.children.forEach((subItem: any) => { + obj[subItem.id] = subItem.name + }) + } }) } - }) - } - setExamineObj(obj) - let tableData = await handeGetTableData(typeData, res) - // 拿到整个数据之后 递归取出tableData中有 question 数据的那一层数据变为一个数组 - let tableRes = await handleGetTableRes(tableData, obj) - console.log('tableRes', tableRes); + setExamineObj(obj) + let tableData = await handeGetTableData(typeData, res) + // 拿到整个数据之后 递归取出tableData中有 question 数据的那一层数据变为一个数组 + let tableRes = await handleGetTableRes(tableData, obj) + console.log('tableRes', tableRes); - let newTableRes: any = [] - if (tableRes && tableRes.length > 0) { - tableRes.forEach((item: any) => { - if (item.score === 0) { - newTableRes.push(item) + let newTableRes: any = [] + if (tableRes && tableRes.length > 0) { + tableRes.forEach((item: any) => { + if (item.score === 0) { + newTableRes.push(item) + } + }) } - }) - } - // 显示的 - // 处理表格数据,为合并单元格做准备 - let processedData = processTableDataForMerge(newTableRes); + // 显示的 + // 处理表格数据,为合并单元格做准备 + let processedData = processTableDataForMerge(newTableRes); - // 打印的 - let printData = processTableDataForMerge(tableRes) + // 打印的 + let printData = processTableDataForMerge(tableRes) - setTableData(processedData) - setPrintTableData(printData) + setTableData(processedData) + setPrintTableData(printData) - if (processedData && processedData.length > 0) { - return { data: processedData, success: true } - } - return [] + if (processedData && processedData.length > 0) { + return { data: processedData, success: true } + } + return [] - // let categoriesObj: any = {} // 子父级关系的缓存对象 - // let categoriesTypeObj: any = {} // 类型的对象 + // let categoriesObj: any = {} // 子父级关系的缓存对象 + // let categoriesTypeObj: any = {} // 类型的对象 - // let categoriesIdObj = session.get('categoriesIdObj') - // let categoriesTypeSessionObj = session.get('categoriesTypeObj') + // let categoriesIdObj = session.get('categoriesIdObj') + // let categoriesTypeSessionObj = session.get('categoriesTypeObj') - // if (categoriesIdObj) { - // categoriesObj = categoriesIdObj - // categoriesTypeObj = categoriesTypeSessionObj - // } else { - // let typeData = await handleGetExamineTypeTreeList({}) - // // 走动式的大类包括小类的缓存 categoriesIdObj - // if (typeData && typeData.length > 0) { - // typeData.forEach((item: any) => { - // let list: any = [] - // categoriesTypeObj[item.id] = item.name - // if (item.children && item.children.length > 0) { - // item.children.forEach((subItem: any) => { - // list.push(subItem.id) - // categoriesTypeObj[subItem.id] = item.name - // }) - // } - // categoriesObj[item.id] = list - // }) - // } + // if (categoriesIdObj) { + // categoriesObj = categoriesIdObj + // categoriesTypeObj = categoriesTypeSessionObj + // } else { + // let typeData = await handleGetExamineTypeTreeList({}) + // // 走动式的大类包括小类的缓存 categoriesIdObj + // if (typeData && typeData.length > 0) { + // typeData.forEach((item: any) => { + // let list: any = [] + // categoriesTypeObj[item.id] = item.name + // if (item.children && item.children.length > 0) { + // item.children.forEach((subItem: any) => { + // list.push(subItem.id) + // categoriesTypeObj[subItem.id] = item.name + // }) + // } + // categoriesObj[item.id] = list + // }) + // } - // session.set('categoriesIdObj', categoriesObj) - // session.set('categoriesTypeObj', categoriesTypeObj) - // } + // session.set('categoriesIdObj', categoriesObj) + // session.set('categoriesTypeObj', categoriesTypeObj) + // } - // console.log('categoriesObj', categoriesObj); - // console.log('categoriesTypeObj', categoriesTypeObj); + // console.log('categoriesObj', categoriesObj); + // console.log('categoriesTypeObj', categoriesTypeObj); - // let res = parentRow?.questionResponses || [] - // // 在res的数组里面拿到最大一个类型的数据 - // if (res && res.length > 0) { - // res.forEach((item: any) => { - // for (let key in categoriesObj) { - // let list = categoriesObj[key] - // if (list && list.length > 0) { - // if (list.indexOf(Number(item.question.categoryId)) !== -1) { - // item.parentCategoryId = key - // } - // } - // } + // let res = parentRow?.questionResponses || [] + // // 在res的数组里面拿到最大一个类型的数据 + // if (res && res.length > 0) { + // res.forEach((item: any) => { + // for (let key in categoriesObj) { + // let list = categoriesObj[key] + // if (list && list.length > 0) { + // if (list.indexOf(Number(item.question.categoryId)) !== -1) { + // item.parentCategoryId = key + // } + // } + // } + + // }) + // } + // console.log('table', res); + + }} + /> : "" + } - // }) - // } - // console.log('table', res); - }} - /> {/* 移除打印设置弹窗 */} diff --git a/src/pages/examine/record/index.tsx b/src/pages/examine/record/index.tsx index 2434736..53e3140 100644 --- a/src/pages/examine/record/index.tsx +++ b/src/pages/examine/record/index.tsx @@ -122,6 +122,43 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => { return {record.situation === 1 ? '异常' : record.situation === 0 ? '正常' : ''} } }, + { + title:
处理状态
, + dataIndex: "errorStatus", + hideInSearch: true, + width: 100, + ellipsis: true, + align: 'center', + render: (_, record) => { + // let res: any = record.extend ? JSON.parse(record.extend) : "-" + return record?.situation !== 0 ? { + record.errorStatus === 0 + ? "待处理" + : record.errorStatus === 1 + ? "处理中" + : record.errorStatus === 2 + ? "已处理" + : "-" + } : "" + } + }, + { + title:
现场图片
, + dataIndex: "placeName", + hideInSearch: true, + width: 150, + ellipsis: true, + align: 'center', + render: (_, record) => { + // let extendObj = record?.extend ? JSON.parse(record?.extend) : "" + let imgList = record.imgsList + return imgList && imgList.length > 0 ? + : "-" + } + }, { title:
巡查内容
, dataIndex: "uploadResult", @@ -182,43 +219,6 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => { ellipsis: true, align: 'center', }, - { - title:
处理状态
, - dataIndex: "errorStatus", - hideInSearch: true, - width: 100, - ellipsis: true, - align: 'center', - render: (_, record) => { - // let res: any = record.extend ? JSON.parse(record.extend) : "-" - return record?.situation !== 0 ? { - record.errorStatus === 0 - ? "待处理" - : record.errorStatus === 1 - ? "处理中" - : record.errorStatus === 2 - ? "已处理" - : "-" - } : "" - } - }, - { - title:
现场图片
, - dataIndex: "placeName", - hideInSearch: true, - width: 150, - ellipsis: true, - align: 'center', - render: (_, record) => { - // let extendObj = record?.extend ? JSON.parse(record?.extend) : "" - let imgList = record.imgsList - return imgList && imgList.length > 0 ? - : "-" - } - }, { title: '操作', dataIndex: 'option', @@ -248,16 +248,14 @@ const examineRecord: React.FC<{ currentUser: any }> = (props) => { }}> 详情
} - - - { deleteRecord(record?.id) }} > 删除 - + */} } diff --git a/src/pages/examine/recordSummary/index.tsx b/src/pages/examine/recordSummary/index.tsx index 98c80bb..ad3c1c8 100644 --- a/src/pages/examine/recordSummary/index.tsx +++ b/src/pages/examine/recordSummary/index.tsx @@ -86,14 +86,14 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { width: 150, ellipsis: true, render: (_, record) => { - return record?.id && record?.inspectionNumber > 0 ? + return record?.id && record?.inspectionNumber > 0 && record?.type !== 'servicePart' && record?.type !== 'district' ? { setCurrentRow(record) - setShowType(1) + // setShowType(1) setShowDetail(true) }}> - {record?.inspectionNumber || '-'} - / {record?.allDay} + {record?.inspectionNumber || '-'} / {record?.allDay} + : record?.allDay ? {record?.inspectionNumber || '-'} / {record?.allDay} @@ -101,14 +101,14 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { } }, { - title:
巡查完成率
, + title:
巡查完成率(%)
, dataIndex: "inspectionRate", align: 'center', hideInSearch: true, width: 150, ellipsis: true, render: (_, record) => { - return record?.inspectionRate ? record?.inspectionRate * 100 + '%' : "" + return record?.inspectionRate ? (record?.inspectionRate * 100).toFixed(2) : "" } }, { @@ -119,13 +119,17 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { width: 150, ellipsis: true, render: (_, record) => { - return record?.template && record?.template.id && record?.normalNumber > 0 ? { - setCurrentRow(record) - setShowType(2) - setShowDetail(true) - }}> - {record?.normalNumber || '-'} - : {record?.normalNumber || '-'} + return record?.template && record?.template.id && record?.normalNumber > 0 ? + {record?.normalNumber || '-'} : "" + + // { + // setCurrentRow(record) + // setShowType(2) + // setShowDetail(true) + // }}> + // {record?.normalNumber || '-'} + // : '' + // {record?.normalNumber || '-'} } }, { @@ -136,13 +140,16 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { width: 150, ellipsis: true, render: (_, record) => { - return record?.template && record?.template.id && record?.errorNumber > 0 ? { - setCurrentRow(record) - setShowType(3) - setShowDetail(true) - }}> - {record?.errorNumber || '-'} - : "" + return record?.template && record?.template.id && record?.errorNumber > 0 ? + {record?.errorNumber || '-'} : "" + + // { + // setCurrentRow(record) + // setShowType(3) + // setShowDetail(true) + // }}> + // {record?.errorNumber || '-'} + // : "" // {record?.errorNumber || '-'} } }, @@ -171,13 +178,15 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { width: 150, ellipsis: true, render: (_, record) => { - return record?.template ? record?.template.errorStatus01 > 0 ? { - setCurrentRow(record) - setShowType(5) - setShowDetail(true) - }}> - {record?.template.errorStatus01 || '-'} - : {record?.template.errorStatus01 || '-'} : "" + return record?.template && record?.template.errorStatus01 > 0 ? + {record?.template.errorStatus01 || '-'} : "" + // { + // setCurrentRow(record) + // setShowType(5) + // setShowDetail(true) + // }}> + // {record?.template.errorStatus01 || '-'} + // : {record?.template.errorStatus01 || '-'} : "" } }, // { @@ -211,29 +220,29 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { // } // } { - title:
未完成率
, + title:
未完成率(%)
, dataIndex: "unfinishedRate", align: 'center', hideInSearch: true, width: 150, ellipsis: true, render: (_, record) => { - return record?.template && record?.template.unfinishedRate ? {record?.template.unfinishedRate * 100}% : "-" + return record?.template && record?.template.unfinishedRate ? {(record?.template.unfinishedRate * 100).toFixed(2)} : "-" } } ] const drawerColumns: any = [ - // { - // title: "巡查类型", - // dataIndex: "inspectionType", - // hideInTable: true, - // valueType: "select", - // valueEnum: { - // "1": '异常', - // "0": "正常" - // } - // }, + { + title: "巡查类型", + dataIndex: "inspectionType", + hideInTable: true, + valueType: "select", + valueEnum: { + "1": '异常', + "0": "正常" + } + }, { title:
巡查时间
, dataIndex: "createdAt", @@ -291,6 +300,21 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { } : "" } }, + { + title:
现场图片
, + dataIndex: "placeName", + hideInSearch: true, + width: 150, + ellipsis: true, + align: 'center', + render: (_, record) => { + return record.imgsList && record.imgsList.length > 0 ? + : "-" + } + }, { title:
巡查内容
, dataIndex: "uploadResult", @@ -343,21 +367,7 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { ellipsis: true, align: 'center', }, - { - title:
现场图片
, - dataIndex: "placeName", - hideInSearch: true, - width: 150, - ellipsis: true, - align: 'center', - render: (_, record) => { - return record.imgsList && record.imgsList.length > 0 ? - : "-" - } - } + ] @@ -542,7 +552,7 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { thirdItem.processingNumber = thirdItem.template.errorStatus1 thirdItem.processedNumber = thirdItem.template.errorStatus2 - normalNumberSum += thirdItem.template.situation0 + normalNumberSum = allDay errorNumberSum += thirdItem.template.situation1 pendingProcessNumberSum += thirdItem.pendingProcessNumber processingNumberSum += thirdItem.processingNumber @@ -560,7 +570,7 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { bigSuccessSum += Number(subItem.inspectionRate) inspectionNumberItemSum += subItem.inspectionNumber - normalNumberItemSum += subItem.normalNumber + normalNumberItemSum = allDay errorNumberItemSum += subItem.errorNumber pendingProcessNumberItemSum += subItem.pendingProcessNumber processingNumberItemSum += subItem.processingNumber @@ -651,9 +661,6 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { headerTitle={考核记录管理} search={{ span: 6 }} request={async (params) => { - - console.log('searchParams', searchParams); - console.log('currentRow', currentRow); if (!currentRow?.serverPartId) { return } @@ -665,59 +672,66 @@ const recordSummary: React.FC<{ currentUser: any }> = (props) => { serverPartIds: [currentRow?.serverPartId], startTime: searchParams?.startTime ? `${searchParams?.startTime}` : "", endTime: searchParams?.endTime ? `${searchParams?.endTime}` : "", - extend: showType === 1 ? [ - { - key: "templateId", - value: currentRow?.template.id, - } - ] : showType === 2 ? [ + extend: params?.inspectionType ? [ { key: "situation", - value: 0, - }, - { - key: "templateId", - value: currentRow?.template.id, + value: params?.inspectionType } - ] : showType === 3 ? [ - { - key: "situation", - value: 1, - }, - { - key: "templateId", - value: currentRow?.template.id, - } - ] : showType === 4 ? [ - { - key: "errorStatus", - value: 0, - }, - { - key: "templateId", - value: currentRow?.template.id, - } - ] : - showType === 5 ? [ - { - key: "errorStatus01", - value: 1, - }, - { - key: "templateId", - value: currentRow?.template.id, - } - ] : - showType === 6 ? [ - { - key: "errorStatus", - value: 2, - }, - { - key: "templateId", - value: currentRow?.template.id, - } - ] : undefined + ] : undefined + + // showType === 1 ? [ + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : showType === 2 ? [ + // { + // key: "situation", + // value: 0, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : showType === 3 ? [ + // { + // key: "situation", + // value: 1, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : showType === 4 ? [ + // { + // key: "errorStatus", + // value: 0, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : + // showType === 5 ? [ + // { + // key: "errorStatus01", + // value: 1, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : + // showType === 6 ? [ + // { + // key: "errorStatus", + // value: 2, + // }, + // { + // key: "templateId", + // value: currentRow?.template.id, + // } + // ] : undefined } console.log('req', req); const data = await handleNewSummaryList(req)