From 87d9f38c02b4dd3e1ac9f8546cb4002a5a4d187e Mon Sep 17 00:00:00 2001 From: uiujun Date: Wed, 29 Apr 2026 17:03:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=90=84?= =?UTF-8?q?=E7=A7=8D=E4=BA=A4=E4=BA=92=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/layout/MyPageContainer.tsx | 256 ++++------------- .../attendance/attendance_shifts/index.tsx | 67 ++--- .../attendance_shifts/modals/Create.tsx | 156 +++++++++++ .../attendance_shifts/modals/Update.tsx | 206 ++++++++++++++ .../attendance_shifts/pages/create.tsx | 259 ----------------- .../attendance_shifts/pages/update.tsx | 263 ------------------ src/pages/charge/standard/modals/Show.tsx | 17 +- .../contract/contract_bills/pages/create.tsx | 2 +- .../contract/contract_bills/pages/update.tsx | 2 +- src/pages/contract/contracts/show/$id.tsx | 2 +- .../show/components/ContractBillObjects.tsx | 2 +- src/pages/contract/contracts_add/show/$id.tsx | 2 +- .../show/components/ContractBillObjects.tsx | 2 +- src/pages/meter/common_meter/index.tsx | 28 +- src/pages/quality/emergency/index.tsx | 39 +-- .../emergency/modals/CategoriesModal.tsx | 27 ++ .../quality/emergency/modals/LevelsModal.tsx | 27 ++ .../quality/emergency/modals/TeamsModal.tsx | 27 ++ src/pages/quality/emergency/teams/index.tsx | 154 +++++----- src/pages/quality/renovation/index.tsx | 24 +- .../quality/renovation/modals/AuditModal.tsx | 27 ++ .../modals/InspectionRulesModal.tsx | 27 ++ src/pages/quality/renovation/pages/create.tsx | 4 +- src/pages/quality/renovation/pages/update.tsx | 4 +- .../quality/survey/modals/SurveysListShow.tsx | 1 - 25 files changed, 690 insertions(+), 935 deletions(-) create mode 100644 src/pages/attendance/attendance_shifts/modals/Create.tsx create mode 100644 src/pages/attendance/attendance_shifts/modals/Update.tsx delete mode 100644 src/pages/attendance/attendance_shifts/pages/create.tsx delete mode 100644 src/pages/attendance/attendance_shifts/pages/update.tsx create mode 100644 src/pages/quality/emergency/modals/CategoriesModal.tsx create mode 100644 src/pages/quality/emergency/modals/LevelsModal.tsx create mode 100644 src/pages/quality/emergency/modals/TeamsModal.tsx create mode 100644 src/pages/quality/renovation/modals/AuditModal.tsx create mode 100644 src/pages/quality/renovation/modals/InspectionRulesModal.tsx diff --git a/src/common/components/layout/MyPageContainer.tsx b/src/common/components/layout/MyPageContainer.tsx index bb6e7eb..adc7faa 100644 --- a/src/common/components/layout/MyPageContainer.tsx +++ b/src/common/components/layout/MyPageContainer.tsx @@ -1,227 +1,60 @@ -import { HomeOutlined } from '@ant-design/icons'; +import { HomeOutlined, LeftOutlined } from '@ant-design/icons'; import { PageContainer, PageContainerProps } from '@ant-design/pro-components'; import { useLocation, useNavigate } from '@umijs/max'; -import { Breadcrumb, Space } from 'antd'; -import { useEffect, useState } from 'react'; -// import './MyPageContainer.scss'; +import { Breadcrumb, Button, Space, Tooltip } from 'antd'; +import { useCallback, useEffect, useRef, useState } from 'react'; -export interface TabItem { - key: string; - label: string; - path: string; - closable?: boolean; -} interface BreadcrumbItem { title: string; path: string; - onClick?: () => void; } export interface MyPageContainerProps extends PageContainerProps { + /* 多标签页功能已废弃,此参数不再生效,保留以避免破坏现有调用方 */ enableTabs?: boolean; + /* 多标签页功能已废弃,此参数不再生效,保留以避免破坏现有调用方 */ tabKey?: string; + /* 多标签页功能已废弃,此参数不再生效,保留以避免破坏现有调用方 */ tabLabel?: string; + /* 多标签页功能已废弃,此参数不再生效,保留以避免破坏现有调用方 */ onTabChange?: (activeKey: string) => void; } -// 注释掉标签页管理相关代码,不再使用 -// // 全局标签页状态管理 -// class TabsManager { -// private tabs: TabItem[] = []; -// private activeKey: string = ''; -// private listeners: Set<() => void> = new Set(); - -// subscribe(listener: () => void) { -// this.listeners.add(listener); -// return () => this.listeners.delete(listener); -// } - -// private notify() { -// this.listeners.forEach((listener) => listener()); -// } - -// getTabs() { -// return this.tabs; -// } - -// getActiveKey() { -// return this.activeKey; -// } - -// addTab(tab: TabItem) { -// const existingIndex = this.tabs.findIndex((t) => t.key === tab.key); -// if (existingIndex === -1) { -// // 如果是新标签页,插入到当前激活标签页的右边 -// const currentActiveIndex = this.tabs.findIndex( -// (t) => t.key === this.activeKey, -// ); -// if (currentActiveIndex !== -1) { -// // 在当前激活标签页的右边插入新标签页 -// this.tabs.splice(currentActiveIndex + 1, 0, tab); -// } else { -// // 如果没有当前激活标签页,添加到末尾 -// this.tabs.push(tab); -// } -// } else { -// // 如果标签页已存在,更新其信息 -// this.tabs[existingIndex] = { ...this.tabs[existingIndex], ...tab }; -// } -// this.activeKey = tab.key; -// this.notify(); -// } - -// addTabNext(tab: TabItem) { -// const existingIndex = this.tabs.findIndex((t) => t.key === tab.key); -// if (existingIndex === -1) { -// // 强制在当前激活标签页的右边插入新标签页 -// const currentActiveIndex = this.tabs.findIndex( -// (t) => t.key === this.activeKey, -// ); -// if (currentActiveIndex !== -1) { -// this.tabs.splice(currentActiveIndex + 1, 0, tab); -// } else { -// this.tabs.push(tab); -// } -// } else { -// // 如果标签页已存在,移动到当前激活标签页的右边 -// const existingTab = this.tabs[existingIndex]; -// this.tabs.splice(existingIndex, 1); // 先移除原位置的标签页 -// const currentActiveIndex = this.tabs.findIndex( -// (t) => t.key === this.activeKey, -// ); -// if (currentActiveIndex !== -1) { -// this.tabs.splice(currentActiveIndex + 1, 0, { ...existingTab, ...tab }); -// } else { -// this.tabs.push({ ...existingTab, ...tab }); -// } -// } -// this.activeKey = tab.key; -// this.notify(); -// } - -// removeTab(targetKey: string) { -// const targetIndex = this.tabs.findIndex((tab) => tab.key === targetKey); -// if (targetIndex === -1) return; - -// const newTabs = this.tabs.filter((tab) => tab.key !== targetKey); - -// if (newTabs.length === 0) { -// this.tabs = []; -// this.activeKey = ''; -// history.push('/'); -// } else { -// this.tabs = newTabs; -// if (this.activeKey === targetKey) { -// // 如果关闭的是当前激活的标签,激活相邻的标签 -// const newActiveKey = -// targetIndex > 0 ? newTabs[targetIndex - 1].key : newTabs[0].key; -// this.activeKey = newActiveKey; -// const targetTab = newTabs.find((tab) => tab.key === newActiveKey); -// if (targetTab) { -// history.push(targetTab.path); -// } -// } -// } -// this.notify(); -// } - -// setActiveKey(key: string) { -// this.activeKey = key; -// const targetTab = this.tabs.find((tab) => tab.key === key); -// if (targetTab) { -// history.push(targetTab.path); -// } -// this.notify(); -// } - -// closeOtherTabs(currentKey: string) { -// const currentTab = this.tabs.find((tab) => tab.key === currentKey); -// if (currentTab) { -// this.tabs = [currentTab]; -// this.activeKey = currentKey; -// this.notify(); -// } -// } - -// closeLeftTabs(currentKey: string) { -// const currentIndex = this.tabs.findIndex((tab) => tab.key === currentKey); -// if (currentIndex > 0) { -// this.tabs = this.tabs.slice(currentIndex); -// this.notify(); -// } -// } - -// closeRightTabs(currentKey: string) { -// const currentIndex = this.tabs.findIndex((tab) => tab.key === currentKey); -// if (currentIndex !== -1) { -// this.tabs = this.tabs.slice(0, currentIndex + 1); -// this.notify(); -// } -// } - -// refreshTab(key: string) { -// // 通过路由跳转的方式刷新当前标签页,避免整个页面刷新导致标签页状态丢失 -// const targetTab = this.tabs.find((tab) => tab.key === key); -// if (targetTab) { -// const originalPath = targetTab.path; -// // 移除可能存在的刷新参数,确保获取干净的原始路径 -// const cleanPath = originalPath -// .replace(/[?&]_refresh=\d+/g, '') -// .replace(/\?$/, ''); - -// // 添加时间戳参数强制刷新 -// const refreshPath = cleanPath.includes('?') -// ? `${cleanPath}&_refresh=${Date.now()}` -// : `${cleanPath}?_refresh=${Date.now()}`; - -// // 先更新为带刷新参数的路径并跳转 -// targetTab.path = refreshPath; -// this.setActiveKey(key); - -// // 延迟恢复原始路径,确保路由跳转完成 -// setTimeout(() => { -// // 恢复为干净的原始路径 -// targetTab.path = cleanPath; -// // 再次跳转到干净路径,移除URL中的刷新参数 -// history.push(cleanPath); -// this.notify(); -// }, 300); -// } -// } -// } - -// // 全局标签页管理器实例 -// const tabsManager = new TabsManager(); - export function MyPageContainer({ title, children, - enableTabs = false, // 默认关闭多标签页功能 - tabKey, - tabLabel, - onTabChange, + enableTabs: _enableTabs, + tabKey: _tabKey, + tabLabel: _tabLabel, + onTabChange: _onTabChange, ...rest }: MyPageContainerProps) { const navigate = useNavigate(); - const location = useLocation(); // 使用useLocation钩子 - const [dataBre, setDataBre] = useState( + const location = useLocation(); + const [dataBre, setDataBre] = useState( JSON.parse(sessionStorage.getItem('breadcrumbs') || '[]'), ); + const timeoutRef = useRef | null>(null); - // 简化的面包屑更新逻辑 - const updateBreadcrumbs = () => { + const canGoBack = location.pathname !== '/'; + + const handleGoBack = useCallback(() => { + navigate(-1); + }, [navigate]); + + const updateBreadcrumbs = useCallback(() => { try { - // 获取当前路径和标题 const currentPath = location.pathname + location.search; const currentTitle = typeof title === 'string' ? title - : String(title?.props?.children || ''); + : String( + (title as { props?: { children?: unknown } })?.props?.children ?? + '', + ); - // 清空无效的面包屑数据(重置逻辑) const newBreadcrumbs: BreadcrumbItem[] = []; - // 只添加当前页面的面包屑 if (currentPath && currentTitle) { newBreadcrumbs.push({ title: currentTitle, @@ -229,30 +62,31 @@ export function MyPageContainer({ }); } - // 更新sessionStorage try { sessionStorage.setItem('breadcrumbs', JSON.stringify(newBreadcrumbs)); } catch (storageError) { console.error('存储到sessionStorage失败:', storageError); } - // 更新状态 setDataBre(newBreadcrumbs); } catch (error) { console.error('更新面包屑时出错:', error); - // 出错时重置面包屑 setDataBre([]); } - }; + }, [location.pathname, location.search, title]); useEffect(() => { - console.log('title', title); - setTimeout(() => { + timeoutRef.current = setTimeout(() => { updateBreadcrumbs(); }, 250); - }, [location.pathname, location.search, title]); - // 不再需要标签页相关的状态和逻辑 - // 直接返回简化版的PageContainer + + return () => { + if (timeoutRef.current) { + clearTimeout(timeoutRef.current); + } + }; + }, [updateBreadcrumbs]); + return ( + {canGoBack && ( + +