加入Git同步

This commit is contained in:
marvzhang
2020-02-18 12:15:40 +08:00
parent 3bb1fe2a74
commit 2ce289c8f3
9 changed files with 296 additions and 11 deletions

View File

@@ -180,7 +180,9 @@ export default {
this.$message.success(this.$t('Spider info has been saved successfully'))
}
await this.$store.dispatch('spider/getSpiderData', this.$route.params.id)
await this.$store.dispatch('spider/getSpiderScrapySpiders', this.$route.params.id)
if (this.spiderForm.is_scrapy) {
await this.$store.dispatch('spider/getSpiderScrapySpiders', this.$route.params.id)
}
})
this.$st.sendEv('爬虫详情', '概览', '保存')
},

View File

@@ -98,6 +98,34 @@
/>
</el-select>
</el-form-item>
<el-form-item
v-if="spiderForm.git_sync_error"
:label="$t('Error Message')"
prop="git_git_sync_error"
>
<el-alert
type="error"
:closable="false"
>
{{spiderForm.git_sync_error}}
</el-alert>
</el-form-item>
<el-form-item
v-if="sshPublicKey"
:label="$t('SSH Public Key')"
>
<el-alert
type="info"
:closable="false"
>
{{sshPublicKey}}
</el-alert>
<span class="copy" @click="copySshPublicKey">
<i class="el-icon-copy-document"></i>
{{$t('Copy')}}
</span>
<input id="ssh-public-key" v-model="sshPublicKey" v-show="true">
</el-form-item>
</el-form>
<div class="action-wrapper">
<el-button
@@ -147,7 +175,8 @@ export default {
{ label: '6h', value: '0 0 0/6 * * *' },
{ label: '12h', value: '0 0 0/12 * * *' },
{ label: '1d', value: '0 0 0 0 * *' }
]
],
sshPublicKey: ''
}
},
computed: {
@@ -169,12 +198,15 @@ export default {
async onGitUrlChange () {
if (!this.spiderForm.git_url) return
this.isGitBranchesLoading = true
const res = await this.$request.get('/git/branches', { url: this.spiderForm.git_url })
this.gitBranches = res.data.data
if (!this.spiderForm.git_branch && this.gitBranches.length > 0) {
this.$set(this.spiderForm, 'git_branch', this.gitBranches[0])
try {
const res = await this.$request.get('/git/branches', { url: this.spiderForm.git_url })
this.gitBranches = res.data.data
if (!this.spiderForm.git_branch && this.gitBranches.length > 0) {
this.$set(this.spiderForm, 'git_branch', this.gitBranches[0])
}
} finally {
this.isGitBranchesLoading = false
}
this.isGitBranchesLoading = false
},
async onSync () {
this.isGitSyncLoading = true
@@ -185,6 +217,7 @@ export default {
}
} finally {
this.isGitSyncLoading = false
await this.$store.dispatch('spider/getSpiderData', this.$route.params.id)
}
},
onReset () {
@@ -207,12 +240,24 @@ export default {
this.isGitResetLoading = false
}
})
},
async getSshPublicKey () {
const res = await this.$request.get('/git/public-key')
this.sshPublicKey = res.data.data
},
copySshPublicKey () {
const el = document.querySelector('#ssh-public-key')
el.focus()
el.setSelectionRange(0, this.sshPublicKey.length)
document.execCommand('copy')
this.$message.success(this.$t('SSH Public Key is copied to the clipboard'))
}
},
async created () {
if (this.spiderForm.git_url) {
this.onGitUrlChange()
}
await this.getSshPublicKey()
}
}
</script>
@@ -226,6 +271,39 @@ export default {
width: 640px;
}
.git-settings .git-settings-form >>> .el-alert {
padding: 0 5px;
margin: 0;
}
.git-settings .git-settings-form >>> .el-alert__description {
padding: 0;
margin: 0;
font-size: 14px;
line-height: 24px;
}
.git-settings .git-settings-form .copy {
display: inline;
line-height: 14px;
position: absolute;
top: 5px;
right: 5px;
cursor: pointer;
}
.git-settings .git-settings-form .copy {
}
#ssh-public-key {
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 0;
/*visibility: hidden;*/
}
.git-settings .title {
border-bottom: 1px solid #DCDFE6;
padding-bottom: 15px;

View File

@@ -77,6 +77,7 @@ export default {
'Auto Sync': '自动同步',
'Sync Frequency': '同步频率',
'Reset': '重置',
'Copy': '复制',
// 主页
'Total Tasks': '总任务数',
@@ -208,6 +209,7 @@ export default {
'Git Username': 'Git 用户名',
'Git Password': 'Git 密码',
'Has Credential': '需要验证',
'SSH Public Key': 'SSH 公钥',
// 爬虫列表
'Name': '名称',
@@ -542,6 +544,7 @@ docker run -d --restart always --name crawlab_worker \\
'Git has been synchronized successfully': 'Git 已经成功同步',
'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 公钥已粘贴到剪切板',
// 其他
'Star crawlab-team/crawlab on GitHub': ' GitHub 上为 Crawlab 加星吧'