mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
加入批量删除爬虫
This commit is contained in:
@@ -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) // 爬虫文件目录树读取
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 加星吧'
|
||||
|
||||
@@ -336,8 +336,38 @@
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="right">
|
||||
<el-button size="small" v-if="false" type="primary" icon="fa fa-download" @click="openImportDialog">
|
||||
{{$t('Import Spiders')}}
|
||||
<el-button
|
||||
v-if="this.selectedSpiders.length"
|
||||
size="small"
|
||||
type="danger"
|
||||
icon="el-icon-video-play"
|
||||
class="btn add"
|
||||
@click="onRunSelectedSpiders"
|
||||
style="font-weight: bolder"
|
||||
>
|
||||
{{$t('Run')}}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="this.selectedSpiders.length"
|
||||
size="small"
|
||||
type="info"
|
||||
:icon="isStopLoading ? 'el-icon-loading' : 'el-icon-video-pause'"
|
||||
class="btn add"
|
||||
@click="onStopSelectedSpiders"
|
||||
style="font-weight: bolder"
|
||||
>
|
||||
{{$t('Stop')}}
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="this.selectedSpiders.length"
|
||||
size="small"
|
||||
type="danger"
|
||||
:icon="isRemoveLoading ? 'el-icon-loading' : 'el-icon-delete'"
|
||||
class="btn add"
|
||||
@click="onRemoveSelectedSpiders"
|
||||
style="font-weight: bolder"
|
||||
>
|
||||
{{$t('Remove')}}
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
@@ -349,7 +379,6 @@
|
||||
>
|
||||
{{$t('Add Spider')}}
|
||||
</el-button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!--./filter-->
|
||||
@@ -371,11 +400,20 @@
|
||||
<el-table
|
||||
:data="spiderList"
|
||||
class="table"
|
||||
ref="table"
|
||||
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white'}"
|
||||
border
|
||||
row-key="_id"
|
||||
@row-click="onRowClick"
|
||||
@sort-change="onSortChange"
|
||||
@selection-change="onSpiderSelect"
|
||||
>
|
||||
<el-table-column
|
||||
type="selection"
|
||||
width="45"
|
||||
align="center"
|
||||
reserve-selection
|
||||
/>
|
||||
<template v-for="col in columns">
|
||||
<el-table-column
|
||||
v-if="col.name === 'type'"
|
||||
@@ -740,7 +778,10 @@ export default {
|
||||
}
|
||||
},
|
||||
handle: undefined,
|
||||
activeSpiderTaskStatus: 'running'
|
||||
activeSpiderTaskStatus: 'running',
|
||||
selectedSpiders: [],
|
||||
isStopLoading: false,
|
||||
isRemoveLoading: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -1077,6 +1118,31 @@ export default {
|
||||
if (value) {
|
||||
this.spiderForm.cmd = 'scrapy crawl'
|
||||
}
|
||||
},
|
||||
onSpiderSelect (spiders) {
|
||||
this.selectedSpiders = spiders
|
||||
},
|
||||
async onRemoveSelectedSpiders () {
|
||||
this.$confirm(this.$t('Are you sure to delete selected items?'), this.$t('Notification'), {
|
||||
confirmButtonText: this.$t('Confirm'),
|
||||
cancelButtonText: this.$t('Cancel'),
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
this.isRemoveLoading = true
|
||||
try {
|
||||
const res = await this.$request.delete('/spiders', {
|
||||
spider_ids: this.selectedSpiders.map(d => d._id)
|
||||
})
|
||||
if (!res.data.error) {
|
||||
this.$message.success('Delete successfully')
|
||||
this.$refs['table'].clearSelection()
|
||||
await this.getList()
|
||||
}
|
||||
} finally {
|
||||
this.isRemoveLoading = false
|
||||
}
|
||||
this.$st.sendEv('爬虫列表', '批量删除爬虫')
|
||||
})
|
||||
}
|
||||
},
|
||||
async created () {
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
@row-click="onRowClick"
|
||||
@selection-change="onSelectionChange">
|
||||
>
|
||||
<el-table-column type="selection" width="55" reserve-selection/>
|
||||
<el-table-column type="selection" width="45" align="center" reserve-selection/>
|
||||
<template v-for="col in columns">
|
||||
<el-table-column v-if="col.name === 'spider_name'"
|
||||
:key="col.name"
|
||||
|
||||
Reference in New Issue
Block a user