diff --git a/backend/model/spider.go b/backend/model/spider.go index 8b44481e..d6ff72d4 100644 --- a/backend/model/spider.go +++ b/backend/model/spider.go @@ -74,6 +74,7 @@ type Spider struct { Config entity.ConfigSpiderData `json:"config"` // 可配置爬虫配置 LatestTasks []Task `json:"latest_tasks"` // 最近任务列表 Username string `json:"username"` // 用户名称 + ProjectName string `json:"project_name"` // 项目名称 // 时间 UserId bson.ObjectId `json:"user_id" bson:"user_id"` @@ -183,7 +184,6 @@ func GetSpiderList(filter interface{}, skip int, limit int, sortStr string) ([]S if err != nil { log.Errorf(err.Error()) debug.PrintStack() - continue } // 获取正在运行的爬虫 @@ -191,17 +191,27 @@ func GetSpiderList(filter interface{}, skip int, limit int, sortStr string) ([]S if err != nil { log.Errorf(err.Error()) debug.PrintStack() - continue } // 获取用户 var user User - if spider.UserId.Valid() { + if spider.UserId.Valid() && spider.UserId.Hex() != constants.ObjectIdNull { user, err = GetUser(spider.UserId) if err != nil { log.Errorf(err.Error()) debug.PrintStack() - continue + } + } + + // 获取项目 + var project Project + if spider.ProjectId.Valid() && spider.ProjectId.Hex() != constants.ObjectIdNull { + project, err = GetProject(spider.ProjectId) + if err != nil { + if err != mgo.ErrNotFound { + log.Errorf(err.Error()) + debug.PrintStack() + } } } @@ -210,6 +220,7 @@ func GetSpiderList(filter interface{}, skip int, limit int, sortStr string) ([]S spiders[i].LastStatus = task.Status spiders[i].LatestTasks = latestTasks spiders[i].Username = user.Username + spiders[i].ProjectName = project.Name } count, _ := c.Find(filter).Count() diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js index 14a08293..91ba5a3b 100644 --- a/frontend/src/i18n/zh.js +++ b/frontend/src/i18n/zh.js @@ -236,6 +236,7 @@ export default { 'De-Duplication': '去重', 'Same Above': '同上', 'Batch Run': '批量运行', + 'Set Projects': '设置项目', // 爬虫列表 'Name': '名称', diff --git a/frontend/src/store/modules/spider.js b/frontend/src/store/modules/spider.js index e393f03a..11d3aa63 100644 --- a/frontend/src/store/modules/spider.js +++ b/frontend/src/store/modules/spider.js @@ -343,6 +343,13 @@ const actions = { const id = payload ? payload.id : state.spiderForm._id const res = await request.get(`/spiders/${id}/file/tree`) commit('SET_FILE_TREE', res.data.data) + }, + async setProjects({ state }, payload) { + const { projectId, spiderIds } = payload + await request.post(`/spiders-set-projects`, { + project_id: projectId, + spider_ids: spiderIds + }) } } diff --git a/frontend/src/views/spider/SpiderList.vue b/frontend/src/views/spider/SpiderList.vue index 80317a47..8d4a2f8c 100644 --- a/frontend/src/views/spider/SpiderList.vue +++ b/frontend/src/views/spider/SpiderList.vue @@ -323,6 +323,38 @@ /> + + + + + + + + + + + + +
@@ -396,6 +428,17 @@ > {{ $t('Batch Run') }} + + {{ $t('Set Projects') }} + { + if (!valid) return + await this.$store.dispatch('spider/setProjects', { + projectId: this.form.projectId, + spiderIds: this.selectedSpiders.map(d => d._id) + }) + this.setProjectsVisible = false + this.isMultiple = false + await this.getList() + }) } } }