diff --git a/backend/main.go b/backend/main.go index 5edf4e6c..cc7ed140 100644 --- a/backend/main.go +++ b/backend/main.go @@ -162,6 +162,7 @@ func main() { authGroup.POST("/spiders/:id", routes.PostSpider) // 修改爬虫 authGroup.POST("/spiders/:id/publish", routes.PublishSpider) // 发布爬虫 authGroup.POST("/spiders/:id/upload", routes.UploadSpiderFromId) // 上传爬虫(ID) + authGroup.DELETE("/spiders", routes.DeleteSelectedSpider) // 删除选择的爬虫 authGroup.DELETE("/spiders/:id", routes.DeleteSpider) // 删除爬虫 authGroup.GET("/spiders/:id/tasks", routes.GetSpiderTasks) // 爬虫任务列表 authGroup.GET("/spiders/:id/file/tree", routes.GetSpiderFileTree) // 爬虫文件目录树读取 diff --git a/backend/routes/spider.go b/backend/routes/spider.go index d53d9715..d1d84e54 100644 --- a/backend/routes/spider.go +++ b/backend/routes/spider.go @@ -482,6 +482,36 @@ func DeleteSpider(c *gin.Context) { }) } +func DeleteSelectedSpider(c *gin.Context) { + type ReqBody struct { + SpiderIds []string `json:"spider_ids"` + } + + var reqBody ReqBody + if err := c.ShouldBindJSON(&reqBody); err != nil { + HandleErrorF(http.StatusBadRequest, c, "invalid request") + return + } + + for _, spiderId := range reqBody.SpiderIds { + if err := services.RemoveSpider(spiderId); err != nil { + HandleError(http.StatusInternalServerError, c, err) + return + } + } + + // 更新 GitCron + if err := services.GitCron.Update(); err != nil { + HandleError(http.StatusInternalServerError, c, err) + return + } + + c.JSON(http.StatusOK, Response{ + Status: "ok", + Message: "success", + }) +} + func GetSpiderTasks(c *gin.Context) { id := c.Param("id") diff --git a/frontend/src/components/File/FileList.vue b/frontend/src/components/File/FileList.vue index 935dc0fe..0a8ac7a0 100644 --- a/frontend/src/components/File/FileList.vue +++ b/frontend/src/components/File/FileList.vue @@ -415,7 +415,9 @@ export default { const data = node.data this.onFileClick(data) node.parent.expanded = true + this.$set(this.nodeExpandedDict, node.parent.data.path, true) node.parent.parent.expanded = true + this.$set(this.nodeExpandedDict, node.parent.parent.data.path, true) }, clickPipeline () { const filename = 'pipelines.py' @@ -428,6 +430,7 @@ export default { if (dataLv2.path.match(filename)) { this.onFileClick(dataLv2) nodeLv1.expanded = true + this.$set(this.nodeExpandedDict, dataLv1.path, true) return } } diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js index 01759c8a..21a93801 100644 --- a/frontend/src/i18n/zh.js +++ b/frontend/src/i18n/zh.js @@ -558,6 +558,8 @@ docker run -d --restart always --name crawlab_worker \\ 'Git has been reset successfully': 'Git 已经成功重置', 'This would delete all files of the spider. Are you sure to continue?': '重置将删除该爬虫所有文件,您希望继续吗?', 'SSH Public Key is copied to the clipboard': 'SSH 公钥已粘贴到剪切板', + 'Removed successfully': '已成功删除', + 'Are you sure to delete selected items?': '您是否确认删除所选项?', // 其他 'Star crawlab-team/crawlab on GitHub': '在 GitHub 上为 Crawlab 加星吧' diff --git a/frontend/src/views/spider/SpiderList.vue b/frontend/src/views/spider/SpiderList.vue index 049a9b26..f36f5d0f 100644 --- a/frontend/src/views/spider/SpiderList.vue +++ b/frontend/src/views/spider/SpiderList.vue @@ -336,8 +336,38 @@