mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
加入爬虫列表排序
This commit is contained in:
6
backend/constants/common.go
Normal file
6
backend/constants/common.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package constants
|
||||
|
||||
const (
|
||||
ASCENDING = "ascending"
|
||||
DESCENDING = "descending"
|
||||
)
|
||||
@@ -107,13 +107,13 @@ func (spider *Spider) Delete() error {
|
||||
}
|
||||
|
||||
// 获取爬虫列表
|
||||
func GetSpiderList(filter interface{}, skip int, limit int) ([]Spider, int, error) {
|
||||
func GetSpiderList(filter interface{}, skip int, limit int, sortStr string) ([]Spider, int, error) {
|
||||
s, c := database.GetCol("spiders")
|
||||
defer s.Close()
|
||||
|
||||
// 获取爬虫列表
|
||||
var spiders []Spider
|
||||
if err := c.Find(filter).Skip(skip).Limit(limit).Sort("+name").All(&spiders); err != nil {
|
||||
if err := c.Find(filter).Skip(skip).Limit(limit).Sort(sortStr).All(&spiders); err != nil {
|
||||
debug.PrintStack()
|
||||
return spiders, 0, err
|
||||
}
|
||||
|
||||
@@ -27,22 +27,38 @@ import (
|
||||
)
|
||||
|
||||
func GetSpiderList(c *gin.Context) {
|
||||
pageNum, _ := c.GetQuery("pageNum")
|
||||
pageSize, _ := c.GetQuery("pageSize")
|
||||
pageNum, _ := c.GetQuery("page_num")
|
||||
pageSize, _ := c.GetQuery("page_size")
|
||||
keyword, _ := c.GetQuery("keyword")
|
||||
t, _ := c.GetQuery("type")
|
||||
sortKey, _ := c.GetQuery("sort_key")
|
||||
sortDirection, _ := c.GetQuery("sort_direction")
|
||||
|
||||
// 筛选
|
||||
filter := bson.M{
|
||||
"name": bson.M{"$regex": bson.RegEx{Pattern: keyword, Options: "im"}},
|
||||
}
|
||||
|
||||
if t != "" && t != "all" {
|
||||
filter["type"] = t
|
||||
}
|
||||
|
||||
// 排序
|
||||
sortStr := "-_id"
|
||||
if sortKey != "" && sortDirection != "" {
|
||||
if sortDirection == constants.DESCENDING {
|
||||
sortStr = "-" + sortKey
|
||||
} else if sortDirection == constants.ASCENDING {
|
||||
sortStr = "+" + sortKey
|
||||
} else {
|
||||
HandleErrorF(http.StatusBadRequest, c, "invalid sort_direction")
|
||||
}
|
||||
}
|
||||
|
||||
// 分页
|
||||
page := &entity.Page{}
|
||||
page.GetPage(pageNum, pageSize)
|
||||
results, count, err := model.GetSpiderList(filter, page.Skip, page.Limit)
|
||||
|
||||
results, count, err := model.GetSpiderList(filter, page.Skip, page.Limit, sortStr)
|
||||
if err != nil {
|
||||
HandleError(http.StatusInternalServerError, c, err)
|
||||
return
|
||||
|
||||
@@ -143,7 +143,7 @@ func ReadFileByStep(filePath string, handle func([]byte, *mgo.GridFile), fileCre
|
||||
// 发布所有爬虫
|
||||
func PublishAllSpiders() {
|
||||
// 获取爬虫列表
|
||||
spiders, _, _ := model.GetSpiderList(nil, 0, constants.Infinite)
|
||||
spiders, _, _ := model.GetSpiderList(nil, 0, constants.Infinite, "-_id")
|
||||
if len(spiders) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,67 +169,86 @@
|
||||
<!--./tabs-->
|
||||
|
||||
<!--table list-->
|
||||
<el-table :data="spiderList"
|
||||
class="table"
|
||||
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white'}"
|
||||
border
|
||||
@row-click="onRowClick"
|
||||
<el-table
|
||||
:data="spiderList"
|
||||
class="table"
|
||||
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white'}"
|
||||
border
|
||||
@row-click="onRowClick"
|
||||
@sort-change="onSortChange"
|
||||
>
|
||||
<template v-for="col in columns">
|
||||
<el-table-column v-if="col.name === 'type'"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
align="left"
|
||||
:width="col.width">
|
||||
<el-table-column
|
||||
v-if="col.name === 'type'"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
align="left"
|
||||
:width="col.width"
|
||||
:sortable="col.sortable"
|
||||
>
|
||||
<template slot-scope="scope">
|
||||
{{$t(scope.row.type)}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-else-if="col.name === 'last_5_errors'"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
:width="col.width"
|
||||
align="center">
|
||||
<el-table-column
|
||||
v-else-if="col.name === 'last_5_errors'"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
:width="col.width"
|
||||
:sortable="col.sortable"
|
||||
align="center"
|
||||
>
|
||||
<template slot-scope="scope">
|
||||
<div :style="{color:scope.row[col.name]>0?'red':''}">
|
||||
{{scope.row[col.name]}}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-else-if="col.name === 'cmd'"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
:width="col.width"
|
||||
align="left">
|
||||
<el-table-column
|
||||
v-else-if="col.name === 'cmd'"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
:width="col.width"
|
||||
:sortable="col.sortable"
|
||||
align="left"
|
||||
>
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="scope.row[col.name]"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-else-if="col.name.match(/_ts$/)"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
:sortable="col.sortable"
|
||||
:align="col.align"
|
||||
:width="col.width">
|
||||
<el-table-column
|
||||
v-else-if="col.name.match(/_ts$/)"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
:sortable="col.sortable"
|
||||
:align="col.align"
|
||||
:width="col.width"
|
||||
>
|
||||
<template slot-scope="scope">
|
||||
{{getTime(scope.row[col.name])}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-else-if="col.name === 'last_status'"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
align="left" :width="col.width">
|
||||
<el-table-column
|
||||
v-else-if="col.name === 'last_status'"
|
||||
:key="col.name"
|
||||
:label="$t(col.label)"
|
||||
align="left"
|
||||
:width="col.width"
|
||||
:sortable="col.sortable"
|
||||
>
|
||||
<template slot-scope="scope">
|
||||
<status-tag :status="scope.row.last_status"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-else
|
||||
:key="col.name"
|
||||
:property="col.name"
|
||||
:label="$t(col.label)"
|
||||
:sortable="col.sortable"
|
||||
:align="col.align || 'left'"
|
||||
:width="col.width">
|
||||
<el-table-column
|
||||
v-else
|
||||
:key="col.name"
|
||||
:property="col.name"
|
||||
:label="$t(col.label)"
|
||||
:sortable="col.sortable"
|
||||
:align="col.align || 'left'"
|
||||
:width="col.width"
|
||||
>
|
||||
</el-table-column>
|
||||
</template>
|
||||
<el-table-column :label="$t('Action')" align="left" fixed="right">
|
||||
@@ -300,10 +319,14 @@ export default {
|
||||
keyword: '',
|
||||
type: 'all'
|
||||
},
|
||||
sort: {
|
||||
sortKey: '',
|
||||
sortDirection: null
|
||||
},
|
||||
types: [],
|
||||
columns: [
|
||||
{ name: 'display_name', label: 'Name', width: '160', align: 'left' },
|
||||
{ name: 'type', label: 'Spider Type', width: '120' },
|
||||
{ name: 'display_name', label: 'Name', width: '160', align: 'left', sortable: true },
|
||||
{ name: 'type', label: 'Spider Type', width: '120', sortable: true },
|
||||
{ name: 'last_status', label: 'Last Status', width: '120' },
|
||||
{ name: 'last_run_ts', label: 'Last Run', width: '140' },
|
||||
// { name: 'update_ts', label: 'Update Time', width: '140' },
|
||||
@@ -543,14 +566,21 @@ export default {
|
||||
onRowClick (row, column, event) {
|
||||
this.onView(row, event)
|
||||
},
|
||||
onSortChange ({ column, prop, order }) {
|
||||
this.sort.sortKey = order ? prop : ''
|
||||
this.sort.sortDirection = order
|
||||
this.getList()
|
||||
},
|
||||
onClickTab (tab) {
|
||||
this.filter.type = tab.name
|
||||
this.getList()
|
||||
},
|
||||
getList () {
|
||||
let params = {
|
||||
pageNum: this.pagination.pageNum,
|
||||
pageSize: this.pagination.pageSize,
|
||||
page_num: this.pagination.pageNum,
|
||||
page_size: this.pagination.pageSize,
|
||||
sort_key: this.sort.sortKey,
|
||||
sort_direction: this.sort.sortDirection,
|
||||
keyword: this.filter.keyword,
|
||||
type: this.filter.type
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user