added environment variables for spider page

This commit is contained in:
Marvin Zhang
2019-04-10 22:16:25 +08:00
parent 312df546c0
commit f004c1a70a
9 changed files with 120 additions and 8 deletions

View File

@@ -0,0 +1,75 @@
<template>
<div class="environment-list">
<el-row>
<div class="button-group">
<el-button type="primary" @click="addEnv" icon="el-icon-plus">{{$t('Add Environment Variables')}}</el-button>
<el-button type="success" @click="save">{{$t('Save')}}</el-button>
</div>
</el-row>
<el-row>
<el-table :data="spiderForm.envs">
<el-table-column :label="$t('Variable')">
<template slot-scope="scope">
<el-input v-model="scope.row.name" :placeholder="$t('Variable')"></el-input>
</template>
</el-table-column>
<el-table-column :label="$t('Value')">
<template slot-scope="scope">
<el-input v-model="scope.row.value" :placeholder="$t('Value')"></el-input>
</template>
</el-table-column>
<el-table-column :label="$t('Action')">
<template slot-scope="scope">
<el-button size="mini" icon="el-icon-delete" type="danger" @click="deleteEnv(scope.$index)"></el-button>
</template>
</el-table-column>
</el-table>
</el-row>
</div>
</template>
<script>
import {
mapState
} from 'vuex'
export default {
name: 'EnvironmentList',
computed: {
...mapState('spider', [
'spiderForm'
])
},
methods: {
addEnv () {
if (!this.spiderForm.envs) {
this.$set(this.spiderForm, 'envs', [])
}
this.spiderForm.envs.push({
name: '',
value: ''
})
console.log(this.spiderForm)
},
deleteEnv (index) {
this.spiderForm.envs.splice(index, 1)
},
save () {
this.$store.dispatch('spider/updateSpiderEnvs')
.then(() => {
this.$message.success(this.$t('Spider info has been saved successfully'))
})
.catch(error => {
this.$message.error(error)
})
}
}
}
</script>
<style scoped>
.button-group {
width: 100%;
text-align: right;
}
</style>

View File

@@ -16,6 +16,7 @@ export default {
'Deployed Spiders': '已部署爬虫',
'Log': '日志',
'Results': '结果',
'Environment': '环境',
// 选择
Spider: '爬虫',
@@ -79,6 +80,9 @@ export default {
'Language': '语言',
'Schedule Enabled': '是否开启定时任务',
'Schedule Cron': '定时任务',
'Variable': '变量',
'Value': '值',
'Add Environment Variables': '添加环境变量',
// 爬虫列表
'Name': '名称',

View File

@@ -5,7 +5,7 @@ const state = {
spiderList: [],
// active spider data
spiderForm: { _id: {} },
spiderForm: {},
// node to deploy/run
activeNode: {},
@@ -77,6 +77,11 @@ const actions = {
dispatch('getSpiderList')
})
},
updateSpiderEnvs ({ state }) {
return request.post(`/spiders/${state.spiderForm._id}/update_envs`, {
envs: JSON.stringify(state.spiderForm.envs)
})
},
getSpiderData ({ state, commit }, id) {
return request.get(`/spiders/${id}`)
.then(response => {

View File

@@ -16,6 +16,9 @@
<el-tab-pane :label="$t('Files')" name="files">
<file-list/>
</el-tab-pane>
<el-tab-pane :label="$t('Environment')" name="environment">
<environment-list/>
</el-tab-pane>
</el-tabs>
</div>
</template>
@@ -26,10 +29,12 @@ import {
} from 'vuex'
import FileList from '../../components/FileList/FileList'
import SpiderOverview from '../../components/Overview/SpiderOverview'
import EnvironmentList from '../../components/Environment/EnvironmentList'
export default {
name: 'NodeDetail',
components: {
EnvironmentList,
FileList,
SpiderOverview
},