From c47896e787de465afe03ffdf5b4cf5d1b1af7781 Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 14 Feb 2024 16:41:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9D=E8=B5=96=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/dependence.ts | 15 ++++++++---- src/pages/dependence/index.tsx | 39 ++++++++++++------------------- src/pages/dependence/logModal.tsx | 11 +++++++-- src/pages/dependence/type.ts | 10 ++++++++ 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/back/services/dependence.ts b/back/services/dependence.ts index 02af2b25..1a623105 100644 --- a/back/services/dependence.ts +++ b/back/services/dependence.ts @@ -153,10 +153,17 @@ export default class DependenceService { const docs = await DependenceModel.findAll({ where: { id: ids } }); for (const doc of docs) { taskLimit.removeQueuedDependency(doc); - const depRunCommand = InstallDependenceCommandTypes[doc.type]; - const cmd = `${depRunCommand} ${doc.name.trim()}`; - const pid = await getPid(cmd); - pid && (await killTask(pid)); + const depInstallCommand = InstallDependenceCommandTypes[doc.type]; + const depUnInstallCommand = unInstallDependenceCommandTypes[doc.type]; + const installCmd = `${depInstallCommand} ${doc.name.trim()}`; + const unInstallCmd = `${depUnInstallCommand} ${doc.name.trim()}`; + const pids = await Promise.all([ + getPid(installCmd), + getPid(unInstallCmd), + ]); + for (const pid of pids) { + pid && (await killTask(pid)); + } } await this.removeDb(ids); } diff --git a/src/pages/dependence/index.tsx b/src/pages/dependence/index.tsx index 9824b560..8f6572b9 100644 --- a/src/pages/dependence/index.tsx +++ b/src/pages/dependence/index.tsx @@ -36,22 +36,12 @@ import { SharedContext } from '@/layouts'; import useTableScrollHeight from '@/hooks/useTableScrollHeight'; import dayjs from 'dayjs'; import WebSocketManager from '@/utils/websocket'; -import { DependenceStatus } from './type'; +import { DependenceStatus, Status } from './type'; import IconFont from '@/components/iconfont'; const { Text } = Typography; const { Search } = Input; -enum Status { - '安装中', - '已安装', - '安装失败', - '删除中', - '已删除', - '删除失败', - '队列中', -} - enum StatusColor { 'processing', 'success', @@ -186,23 +176,24 @@ const Dependence = () => { const isPc = !isPhone; return ( - - { - setLogDependence({ ...record, timestamp: Date.now() }); - }} - > - - - - {[Status.队列中, Status.安装中].includes(record.status) && ( + {![Status.队列中].includes(record.status) && ( + + { + setLogDependence({ ...record, timestamp: Date.now() }); + }} + > + + + + )} + {[Status.队列中, Status.安装中, Status.删除中].includes(record.status) ? ( cancelDependence(record)}> - )} - {![Status.安装中, Status.删除中].includes(record.status) && ( + ) : ( <> reInstallDependence(record, index)}> @@ -487,7 +478,7 @@ const Dependence = () => { } return _result; }); - }, 5000); + }, 300); return; } } diff --git a/src/pages/dependence/logModal.tsx b/src/pages/dependence/logModal.tsx index afb16bcb..f972c03d 100644 --- a/src/pages/dependence/logModal.tsx +++ b/src/pages/dependence/logModal.tsx @@ -10,6 +10,7 @@ import { import { PageLoading } from '@ant-design/pro-layout'; import Ansi from 'ansi-to-react'; import WebSocketManager from '@/utils/websocket'; +import { Status } from './type'; const DependenceLogModal = ({ dependence, @@ -96,7 +97,11 @@ const DependenceLogModal = ({ const handleMessage = (payload: any) => { const { message, references } = payload; - if (references.length > 0 && references.includes(dependence.id)) { + if ( + references.length > 0 && + references.includes(dependence.id) && + [Status.删除中, Status.安装中].includes(dependence.status) + ) { if (message.includes('结束时间')) { setExecuting(false); setIsRemoveFailed(message.includes('删除失败')); @@ -108,11 +113,13 @@ const DependenceLogModal = ({ useEffect(() => { const ws = WebSocketManager.getInstance(); ws.subscribe('installDependence', handleMessage); + ws.subscribe('uninstallDependence', handleMessage); return () => { ws.unsubscribe('installDependence', handleMessage); + ws.unsubscribe('uninstallDependence', handleMessage); }; - }, []); + }, [dependence]); useEffect(() => { setIsPhone(document.body.clientWidth < 768); diff --git a/src/pages/dependence/type.ts b/src/pages/dependence/type.ts index e9913986..518e401e 100644 --- a/src/pages/dependence/type.ts +++ b/src/pages/dependence/type.ts @@ -7,3 +7,13 @@ export enum DependenceStatus { 'removeFailed', 'queued', } + +export enum Status { + '安装中', + '已安装', + '安装失败', + '删除中', + '已删除', + '删除失败', + '队列中', +} \ No newline at end of file