From 70b3ed5884b2f1066ad2d2354dccb690fdbe965c Mon Sep 17 00:00:00 2001 From: R4v3zn Date: Wed, 1 Jul 2020 11:14:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=95=9C=E5=83=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vulfocus-api/dockerapi/serializers.py | 6 +- vulfocus-api/dockerapi/views.py | 4 +- vulfocus-frontend/.env.development | 4 +- vulfocus-frontend/src/views/image/index.vue | 82 ++++++++++++++++++--- 4 files changed, 80 insertions(+), 16 deletions(-) diff --git a/vulfocus-api/dockerapi/serializers.py b/vulfocus-api/dockerapi/serializers.py index c3c2ef67..af5ae2dc 100644 --- a/vulfocus-api/dockerapi/serializers.py +++ b/vulfocus-api/dockerapi/serializers.py @@ -104,6 +104,7 @@ class Meta: class ContainerVulSerializer(serializers.ModelSerializer): rank = serializers.SerializerMethodField('ranktocon') name = serializers.SerializerMethodField('conname') + image_id = serializers.SerializerMethodField("get_image_id") user_name = serializers.SerializerMethodField('get_user_name') vul_name = serializers.SerializerMethodField('get_vul_name') vul_desc = serializers.SerializerMethodField('get_vul_desc') @@ -112,7 +113,7 @@ class ContainerVulSerializer(serializers.ModelSerializer): class Meta: model = ContainerVul fields = ['name', 'container_id', 'container_status', 'vul_host', 'create_date', 'is_check', 'is_check_date', - 'rank', 'user_name', 'vul_name', 'vul_desc'] + 'rank', 'user_name', 'vul_name', 'vul_desc', "image_id"] def get_vul_name(self,obj): return obj.image_id.image_vul_name @@ -140,6 +141,9 @@ def get_user_name(self, obj): user_info = UserProfile.objects.get(id=user_id) return user_info.username + def get_image_id(self, obj): + return str(obj.image_id.image_id) + class SysLogSerializer(serializers.ModelSerializer): diff --git a/vulfocus-api/dockerapi/views.py b/vulfocus-api/dockerapi/views.py index d22a242a..5810aa07 100644 --- a/vulfocus-api/dockerapi/views.py +++ b/vulfocus-api/dockerapi/views.py @@ -181,11 +181,13 @@ def delete_image(self, request, pk=None): sys_log.save() image_id = img_info.image_id container_vul = ContainerVul.objects.filter(image_id=image_id) + data_json = ContainerVulSerializer(container_vul, many=True) + print(data_json.data) if container_vul.count() == 0: img_info.delete() return JsonResponse(R.ok()) else: - return JsonResponse(R.build(msg="镜像正在使用,无法删除!")) + return JsonResponse(R.build(msg="镜像正在使用,无法删除!", data=data_json.data)) @action(methods=["post", "get"], detail=True, url_path="start") def start_container(self, request, pk=None): diff --git a/vulfocus-frontend/.env.development b/vulfocus-frontend/.env.development index 649624b2..b7724d67 100644 --- a/vulfocus-frontend/.env.development +++ b/vulfocus-frontend/.env.development @@ -3,8 +3,8 @@ ENV = 'development' # base api #VUE_APP_BASE_API = '/dev-api' -VUE_APP_BASE_API = 'http://127.0.0.1:8000' -#VUE_APP_BASE_API = 'http://10.10.10.172:8000' +#VUE_APP_BASE_API = 'http://127.0.0.1:8000' +VUE_APP_BASE_API = 'http://10.10.10.172:8000' # vue-cli uses the VUE_CLI_BABEL_TRANSPILE_MODULES environment variable, # to control whether the babel-plugin-dynamic-import-node plugin is enabled. # It only does one thing by converting all import() to require(). diff --git a/vulfocus-frontend/src/views/image/index.vue b/vulfocus-frontend/src/views/image/index.vue index 9722f7aa..3974d04c 100644 --- a/vulfocus-frontend/src/views/image/index.vue +++ b/vulfocus-frontend/src/views/image/index.vue @@ -82,6 +82,27 @@ + + + + + + + + + + + + + + +
@@ -156,6 +177,7 @@ import { ImgList } from "@/api/docker" import { search } from "@/api/utils" import { ImageAdd, ImageDelete,ImageLocal,ImageLocalAdd,ImageShare } from "@/api/image" + import { containerDel } from '@/api/container' import { getTask,batchTask,progressTask } from '@/api/tasks' export default { @@ -185,6 +207,8 @@ selectLocalImages: [], progressShow: false, progressLoading: false, + deleteShow: false, + deleteContainerList: [], progress:{ "title":"", "layer":[], @@ -397,14 +421,16 @@ ImageDelete(row.image_id).then(response => { let data = response.data if(data.status === 200){ - this.$notify({ + this.$message({ title: '成功', message: '删除成功!', type: 'success' }); this.initTableData() }else{ - this.$notify({ + this.deleteShow = true + this.deleteContainerList = data.data + this.$message({ title: '失败', message: data.msg, type: 'error' @@ -561,26 +587,16 @@ message: msg, type: 'success' }); - // this.$message({message: msg,type: "success",duration: 1.5 * 1000}) } this.centerDialogVisible = false this.initTableData() }else if(status === 201){ - // this.$message({ - // message: rsp["msg"], - // type: "info", - // }) this.$notify({ title: '失败', message: rsp["msg"], type: 'info' }); }else{ - // this.$message({ - // message: rsp["msg"], - // type: "error", - // duration: 3 * 1000 - // }) this.$notify({ title: '失败', message: rsp["msg"], @@ -588,6 +604,48 @@ }); } }) + }, + delContainer(row){ + containerDel(row.container_id).then(response => { + let taskId = response.data["data"] + let tmpDeleteContainerInterval = window.setInterval(() => { + setTimeout(()=>{ + getTask(taskId).then(response=>{ + let responseStatus = response.data["status"] + let responseData = response.data + if (responseStatus === 1001){ + // 一直轮训 + }else{ + clearInterval(tmpDeleteContainerInterval) + if (responseStatus === 200) { + this.$message({ + type: 'success', + message: '删除成功' + }); + ImageDelete(row.image_id).then(response => { + let data = response.data + if(data.status !== 200){ + this.deleteContainerList = data.data + }else{ + this.$message({ + type: 'success', + message: '删除成功' + }); + this.deleteShow = false + this.initTableData() + } + }) + }else{ + this.$message({ + message: responseData["msg"], + type: "error", + }) + } + } + }) + },1) + },1000) + }) } } }