code cleanup

This commit is contained in:
marvzhang
2020-07-15 11:17:07 +08:00
parent a3d82c40c0
commit 061fed4bbd
10 changed files with 33 additions and 405 deletions

View File

@@ -1,15 +0,0 @@
<template>
<div class="">
NodeDetail
</div>
</template>
<script>
export default {
name: 'NodeDetail'
}
</script>
<style scoped>
</style>

View File

@@ -1,197 +0,0 @@
<template>
<div class="app-container">
<!--filter-->
<div class="filter">
<el-input
v-model="filter.keyword"
prefix-icon="el-icon-search"
:placeholder="$t('Search')"
class="filter-search"
@change="onSearch"
/>
<div class="right">
<el-button
type="success"
icon="el-icon-refresh"
class="refresh"
@click="onRefresh"
>
{{ $t('Refresh') }}
</el-button>
</div>
</div>
<!--table list-->
<el-table
:data="filteredTableData"
class="table"
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white'}"
border
>
<template v-for="col in columns">
<el-table-column
v-if="col.name === 'spider_name'"
:key="col.name"
:label="$t(col.label)"
:sortable="col.sortable"
align="center"
:width="col.width"
>
<template slot-scope="scope">
<a class="a-tag" href="javascript:" @click="onClickSpider(scope.row)">{{ scope.row[col.name] }}</a>
</template>
</el-table-column>
<el-table-column
v-else-if="col.name === 'node_id'"
:key="col.name"
:label="$t(col.label)"
:sortable="col.sortable"
align="center"
:width="col.width"
>
<template slot-scope="scope">
<a class="a-tag" href="javascript:" @click="onClickNode(scope.row)">{{ scope.row[col.name] }}</a>
</template>
</el-table-column>
<el-table-column
v-else
:key="col.name"
:property="col.name"
:label="$t(col.label)"
:sortable="col.sortable"
align="center"
:width="col.width"
/>
</template>
<el-table-column :label="$t('Action')" align="center" width="160">
<template slot-scope="scope">
<el-tooltip :content="$t('View')" placement="top">
<el-button type="primary" icon="el-icon-search" size="mini" @click="onView(scope.row)" />
</el-tooltip>
</template>
</el-table-column>
</el-table>
<div class="pagination">
<el-pagination
:current-page.sync="pagination.pageNum"
:page-sizes="[10, 20, 50, 100]"
:page-size.sync="pagination.pageSize"
layout="sizes, prev, pager, next"
:total="deployList.length"
@current-change="onPageChange"
@size-change="onPageChange"
/>
</div>
</div>
</template>
<script>
import {
mapState
} from 'vuex'
export default {
name: 'DeployList',
data() {
return {
pagination: {
pageNum: 0,
pageSize: 10
},
filter: {
keyword: ''
},
// tableData,
columns: [
// { name: 'version', label: 'Version', width: '180' },
// { name: 'ip', label: 'IP', width: '160' },
// { name: 'port', label: 'Port', width: '80' },
{ name: 'finish_ts', label: 'Time', width: '180' },
{ name: 'spider_name', label: 'Spider', width: '180', sortable: true },
{ name: 'node_id', label: 'Node', width: 'auto' }
],
nodeFormRules: {
name: [{ required: true, message: 'Required Field', trigger: 'change' }]
}
}
},
computed: {
...mapState('deploy', [
'deployList',
'deployForm'
]),
filteredTableData() {
return this.deployList.filter(d => {
if (!this.filter.keyword) return true
for (let i = 0; i < this.columns.length; i++) {
const colName = this.columns[i].name
if (d[colName] && d[colName].toLowerCase().indexOf(this.filter.keyword.toLowerCase()) > -1) {
return true
}
}
return false
})
.filter((d, index) => {
// pagination
const { pageNum, pageSize } = this.pagination
return (pageSize * (pageNum - 1) <= index) && (index < pageSize * pageNum)
})
}
},
created() {
this.$store.dispatch('deploy/getDeployList')
},
methods: {
onSearch(value) {
console.log(value)
},
onRefresh() {
this.$store.dispatch('deploy/getDeployList')
this.$st.sendEv('部署', '刷新')
},
onView(row) {
this.$router.push(`/deploys/${row._id}`)
},
onClickSpider(row) {
this.$router.push(`/spiders/${row.spider_id}`)
},
onClickNode(row) {
this.$router.push(`/nodes/${row.node_id}`)
},
onPageChange() {
this.$store.dispatch('deploy/getDeployList')
}
}
}
</script>
<style scoped lang="scss">
.filter {
display: flex;
justify-content: space-between;
.filter-search {
width: 240px;
}
.add {
}
}
.table {
margin-top: 20px;
border-radius: 5px;
}
.delete-confirm {
background-color: red;
}
.el-table .el-button {
padding: 7px;
}
.el-table .a-tag {
text-decoration: underline;
}
</style>

View File

@@ -68,7 +68,7 @@
@change="onSpiderChange"
>
<el-option
v-for="op in spiderList"
v-for="op in allSpiderList"
:key="op._id"
:value="op._id"
:label="`${op.display_name} (${op.name})`"
@@ -84,7 +84,7 @@
:disabled="isDisabledSpiderSchedule"
>
<el-option
v-for="op in spiderList"
v-for="op in allSpiderList"
:key="op._id"
:value="op._id"
:label="`${op.display_name} (${op.name})`"
@@ -368,7 +368,6 @@
dialogVisible: false,
cronDialogVisible: false,
expression: '',
spiderList: [],
nodeList: [],
isShowCron: false,
isLoading: false,
@@ -496,6 +495,7 @@
},
computed: {
...mapState('spider', [
'allSpiderList',
'spiderForm'
]),
...mapState('schedule', [
@@ -512,9 +512,9 @@
return this.scheduleList
},
spider() {
for (let i = 0; i < this.spiderList.length; i++) {
if (this.spiderList[i]._id === this.scheduleForm.spider_id) {
return this.spiderList[i]
for (let i = 0; i < this.allSpiderList.length; i++) {
if (this.allSpiderList[i]._id === this.scheduleForm.spider_id) {
return this.allSpiderList[i]
}
}
return {}
@@ -540,10 +540,7 @@
})
// 爬虫列表
request.get('/spiders', { owner_type: 'all' })
.then(response => {
this.spiderList = response.data.data.list || []
})
this.$store.dispatch('spider/getAllSpiderList')
},
mounted() {
if (!this.isDisabledSpiderSchedule) {

View File

@@ -13,7 +13,7 @@
<div class="selector">
<label class="label">{{ $t('Spider') }}: </label>
<el-select id="spider-select" v-model="spiderForm._id" @change="onSpiderChange">
<el-option v-for="op in spiderList" :key="op._id" :value="op._id" :label="op.name" />
<el-option v-for="op in allSpiderList" :key="op._id" :value="op._id" :label="op.name" />
</el-select>
</div>
@@ -167,10 +167,10 @@
redirectType: ''
}
},
computed: {
...mapState('spider', [
'spiderList',
'allSpiderList',
'spiderForm',
'configListTs'
]),
@@ -209,7 +209,7 @@
await this.$store.dispatch('spider/getTaskList', this.$route.params.id)
// get spider list
await this.$store.dispatch('spider/getSpiderList', { owner_type: 'all' })
await this.$store.dispatch('spider/getAllSpiderList', { owner_type: 'all' })
},
mounted() {
if (!this.$utils.tour.isFinishedTour('spider-detail')) {

View File

@@ -1,10 +1,16 @@
<script>
import {
mapState
} from 'vuex'
import ScheduleList from '../schedule/ScheduleList'
export default {
name: 'SpiderSchedules',
extends: ScheduleList,
computed: {
...mapState('spider', [
'allSpiderList'
]),
isDisabledSpiderSchedule() {
return true
},
@@ -22,7 +28,7 @@
this.getNodeList()
// 爬虫列表
this.getSpiderList()
this.$store.dispatch('spider/getAllSpiderList')
},
methods: {
getNodeList() {
@@ -38,12 +44,6 @@
})
})
},
getSpiderList() {
this.$request.get('/spiders', {})
.then(response => {
this.spiderList = response.data.data.list || []
})
},
onAdd() {
this.isEdit = false
this.dialogVisible = true

View File

@@ -29,7 +29,7 @@
@change="onFilterChange"
>
<el-option value="" :label="$t('All')" />
<el-option v-for="spider in spiderList" :key="spider._id" :value="spider._id" :label="spider.name" />
<el-option v-for="spider in allSpiderList" :key="spider._id" :value="spider._id" :label="spider.name" />
</el-select>
</el-form-item>
<el-form-item prop="status" :label="$t('Status')">
@@ -310,7 +310,7 @@
'taskForm'
]),
...mapState('spider', [
'spiderList'
'allSpiderList'
]),
...mapState('node', [
'nodeList'
@@ -350,7 +350,7 @@
},
created() {
this.$store.dispatch('task/getTaskList')
this.$store.dispatch('spider/getSpiderList')
this.$store.dispatch('spider/getAllSpiderList')
this.$store.dispatch('node/getNodeList')
},
mounted() {