import React, { FC, useEffect, useState } from 'react'; import styles from './index.less'; import { Input, Progress, message } from 'antd'; import { countType } from '@/utils/sysType'; import { useParams } from 'umi'; import DEV from '@/utils/env/dev'; interface PageProps { open: boolean; onCancel: (name?: string) => void; setInstallExe: (index: number, text: string) => void; } const CodeManage: FC = ({ open = false, onCancel, setInstallExe }) => { const [active, setActive] = useState(1); const [percentVal, setPercentVal] = useState(0); const urlParams = useParams(); useEffect(() => { if (open) setActive(1) }, [open]) // 监听是否到安装进度条步骤 useEffect(() => { if (active == 3) { const interval = setInterval(() => { setPercentVal((val) => { const randomStep = Math.round(Math.random() * (100 / 10)); const newPercent = val + randomStep; if (newPercent >= 100) { clearInterval(interval); setValue() return 100; } return newPercent; }); }, 500); return () => clearInterval(interval); } }, [active]) // 设置安装步骤进度 const setValue = () => { setActive((e) => { return e + 1 }) } const getName = () => { return urlParams?.fileType == 'offLine' ? '离线版' : '在线版' } // 在指定的目录下安装快捷方式 const installSuccess = async () => { try { const response = await fetch('http://127.0.0.1:8081/createShortcut', { method: 'POST', headers: { 'Content-Type': 'application/json' }, mode: "cors", body: JSON.stringify({ folderPath: `${DEV.FILE_URL}/${getName()}/${countType[urlParams?.fileType]}`, shortcutName: '专用核心密码综合管理系统', shortcutURL: `${DEV.LOCAL_URL}/initialSystem/${urlParams?.fileType}` }), }); const data = await response.text(); setInstallExe(13, data) onCancel() } catch (error) { message.error(error); // 处理请求错误 } } return <> { open &&
{ onCancel('一体化密码机管理软件') }}>
{[1, 2].includes(active) &&
一体化密码机管理软件 安装程序
} {![1, 2].includes(active) &&
一体化密码机管理软件 安装程序
} {active == 1 &&
一体化密码机管理软件安装程序
} {active == 2 &&
一体化密码机管理软件
} {active == 4 &&
一体化密码机管理软件
} {[1, 2].includes(active) &&
setValue()}>
} {active == 3 &&
} {active == 4 &&
installSuccess()}>
}
} }; export default CodeManage;