101 lines
2.9 KiB
Plaintext
101 lines
2.9 KiB
Plaintext
import {
|
|
Component,
|
|
lazy,
|
|
Suspense,
|
|
useState,
|
|
type ErrorInfo,
|
|
type ReactNode,
|
|
} from 'react'
|
|
|
|
const ManufacturingPanel = lazy(() =>
|
|
import('./HicadManufacturingPanel').then((module) => ({
|
|
default: module.HicadManufacturingPanel,
|
|
}))
|
|
)
|
|
|
|
class ManufacturingBoundary extends Component<
|
|
{
|
|
children: ReactNode
|
|
onClose: () => void
|
|
},
|
|
{ failed: boolean }
|
|
> {
|
|
state = { failed: false }
|
|
|
|
static getDerivedStateFromError() {
|
|
return { failed: true }
|
|
}
|
|
|
|
componentDidCatch(error: unknown, info: ErrorInfo) {
|
|
console.error('[HiCAD Manufacturing] Extension failed safely', error, info)
|
|
}
|
|
|
|
render() {
|
|
if (!this.state.failed) return this.props.children
|
|
return (
|
|
<div
|
|
className="fixed inset-0 z-[100] grid place-items-center bg-black/50 p-4"
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-label="工程工具加载失败"
|
|
>
|
|
<div className="w-full max-w-md border border-chalkboard-30 bg-chalkboard-10 p-6 shadow-2xl dark:border-chalkboard-70 dark:bg-chalkboard-100">
|
|
<h2 className="text-lg font-semibold">工程工具暂时无法打开</h2>
|
|
<p className="mt-2 text-sm text-chalkboard-60 dark:text-chalkboard-40">
|
|
HiCAD 主编辑器没有受到影响。关闭后可以继续建模并稍后重试。
|
|
</p>
|
|
<button
|
|
type="button"
|
|
className="mt-5 h-9 bg-chalkboard-100 px-4 text-sm font-medium text-chalkboard-10 dark:bg-chalkboard-10 dark:text-chalkboard-100"
|
|
onClick={this.props.onClose}
|
|
>
|
|
关闭
|
|
</button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
export function HicadManufacturingLauncher({
|
|
projectName,
|
|
}: {
|
|
projectName: string
|
|
}) {
|
|
const [active, setActive] = useState(false)
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
type="button"
|
|
data-testid="hicad-manufacturing-trigger"
|
|
onClick={() => setActive(true)}
|
|
className="absolute right-4 top-14 z-20 h-9 border border-chalkboard-30 bg-chalkboard-10 px-3 text-sm font-medium shadow-sm hover:bg-chalkboard-20 dark:border-chalkboard-70 dark:bg-chalkboard-90 dark:hover:bg-chalkboard-80"
|
|
>
|
|
工程出图
|
|
</button>
|
|
|
|
{active && (
|
|
<ManufacturingBoundary onClose={() => setActive(false)}>
|
|
<Suspense
|
|
fallback={
|
|
<div className="fixed inset-0 z-[100] grid place-items-center bg-black/50">
|
|
<div className="border border-chalkboard-30 bg-chalkboard-10 px-5 py-4 text-sm shadow-xl dark:border-chalkboard-70 dark:bg-chalkboard-100">
|
|
正在加载工程工具…
|
|
</div>
|
|
</div>
|
|
}
|
|
>
|
|
<ManufacturingPanel
|
|
hideTrigger
|
|
initialOpen
|
|
onRequestClose={() => setActive(false)}
|
|
projectName={projectName}
|
|
/>
|
|
</Suspense>
|
|
</ManufacturingBoundary>
|
|
)}
|
|
</>
|
|
)
|
|
}
|