From ef7283a9fd0bb30f3f346455a155ba937544cf89 Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 12 Apr 2023 00:45:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BE=9D=E8=B5=96=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=88=9D=E5=A7=8B=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/dependence.ts | 1 + back/loaders/initData.ts | 2 +- back/services/dependence.ts | 27 +++++++++++------ src/pages/dependence/index.tsx | 54 +++++++++++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/back/data/dependence.ts b/back/data/dependence.ts index cf9c8f05..ab06ce83 100644 --- a/back/data/dependence.ts +++ b/back/data/dependence.ts @@ -28,6 +28,7 @@ export enum DependenceStatus { 'removing', 'removed', 'removeFailed', + 'queued', } export enum DependenceTypes { diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 617b545c..a3e9541c 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -42,7 +42,7 @@ export default async () => { raw: true, }).then(async (docs) => { await DependenceModel.update( - { status: DependenceStatus.installing, log: [] }, + { status: DependenceStatus.queued, log: [] }, { where: { id: docs.map((x) => x.id!) } }, ); dependenceService.installDependenceOneByOne(docs); diff --git a/back/services/dependence.ts b/back/services/dependence.ts index c718e687..52e2c24c 100644 --- a/back/services/dependence.ts +++ b/back/services/dependence.ts @@ -24,7 +24,7 @@ export default class DependenceService { public async create(payloads: Dependence[]): Promise { const tabs = payloads.map((x) => { - const tab = new Dependence({ ...x, status: DependenceStatus.installing }); + const tab = new Dependence({ ...x, status: DependenceStatus.queued }); return tab; }); const docs = await this.insert(tabs); @@ -45,7 +45,7 @@ export default class DependenceService { const tab = new Dependence({ ...doc, ...other, - status: DependenceStatus.installing, + status: DependenceStatus.queued, }); const newDoc = await this.updateDb(tab); this.installDependenceOneByOne([newDoc]); @@ -59,7 +59,7 @@ export default class DependenceService { public async remove(ids: number[], force = false): Promise { await DependenceModel.update( - { status: DependenceStatus.removing, log: [] }, + { status: DependenceStatus.queued, log: [] }, { where: { id: ids } }, ); const docs = await DependenceModel.findAll({ where: { id: ids } }); @@ -105,17 +105,24 @@ export default class DependenceService { force: boolean = false, ) { concurrentRun( - docs.map( - (dep) => async () => - await this.installOrUninstallDependencies([dep], isInstall, force), - ), + docs.map((dep) => async () => { + const status = isInstall + ? DependenceStatus.installing + : DependenceStatus.removing; + await DependenceModel.update({ status }, { where: { id: dep.id } }); + return await this.installOrUninstallDependencies( + [dep], + isInstall, + force, + ); + }), 1, ); } public async reInstall(ids: number[]): Promise { await DependenceModel.update( - { status: DependenceStatus.installing, log: [] }, + { status: DependenceStatus.queued, log: [] }, { where: { id: ids } }, ); @@ -132,7 +139,9 @@ export default class DependenceService { return docs; } - public async getDb(query: FindOptions['where']): Promise { + public async getDb( + query: FindOptions['where'], + ): Promise { const doc: any = await DependenceModel.findOne({ where: { ...query } }); return doc && (doc.get({ plain: true }) as Dependence); } diff --git a/src/pages/dependence/index.tsx b/src/pages/dependence/index.tsx index ddc86ff6..a4adceda 100644 --- a/src/pages/dependence/index.tsx +++ b/src/pages/dependence/index.tsx @@ -19,6 +19,8 @@ import { DeleteFilled, BugOutlined, FileTextOutlined, + CloseCircleOutlined, + ClockCircleOutlined, } from '@ant-design/icons'; import config from '@/utils/config'; import { PageContainer } from '@ant-design/pro-layout'; @@ -42,6 +44,7 @@ enum Status { '删除中', '已删除', '删除失败', + '队列中', } enum StatusColor { @@ -50,6 +53,37 @@ enum StatusColor { 'error', } +const StatusMap: Record = { + 0: { + icon: , + color: 'processing', + }, + 1: { + icon: , + color: 'success', + }, + 2: { + icon: , + color: 'error', + }, + 3: { + icon: , + color: 'processing', + }, + 4: { + icon: , + color: 'success', + }, + 5: { + icon: , + color: 'error', + }, + 6: { + icon: , + color: 'default', + }, +}; + const Dependence = () => { const { headerStyle, isPhone, socketMessage } = useOutletContext(); @@ -74,7 +108,8 @@ const Dependence = () => { return ( {Status[record.status]} @@ -366,6 +401,23 @@ const Dependence = () => { useEffect(() => { if (!socketMessage) return; const { type, message, references } = socketMessage; + if ( + type === 'installDependence' && + message.includes('开始时间') && + references.length > 0 + ) { + const result = [...value]; + for (let i = 0; i < references.length; i++) { + const index = value.findIndex((x) => x.id === references[i]); + if (index !== -1) { + result.splice(index, 1, { + ...value[index], + status: message.includes('安装') ? Status.安装中 : Status.删除中, + }); + } + } + setValue(result); + } if ( type === 'installDependence' && message.includes('结束时间') &&