feat: add Theme Branches/Releases Control (halo issue 515&592) (halo-dev/console#186)

* halo issue 515&592

* beautify UI

Co-authored-by: Ryan Wang <i@ryanc.cc>
pull/3445/head
BigBang019 2020-07-10 12:09:11 +08:00 committed by GitHub
parent 3ab982c7cc
commit 6b6e50dc7f
2 changed files with 159 additions and 6 deletions

View File

@ -130,6 +130,63 @@ themeApi.fetching = url => {
})
}
themeApi.fetchingBranches = url => {
return service({
url: `${baseUrl}/fetchingBranches`,
timeout: 60000,
params: {
uri: url
},
method: 'post'
})
}
themeApi.fetchingReleases = url => {
return service({
url: `${baseUrl}/fetchingReleases`,
timeout: 60000,
params: {
uri: url
},
method: 'post'
})
}
themeApi.fetchingBranch = (url, branchName) => {
return service({
url: `${baseUrl}/fetchBranch`,
timeout: 60000,
params: {
uri: url,
branch: branchName
},
method: 'get'
})
}
themeApi.fetchingLatestRelease = url => {
return service({
url: `${baseUrl}/fetchLatestRelease`,
timeout: 60000,
params: {
uri: url
},
method: 'get'
})
}
themeApi.fetchingRelease = (url, tagName) => {
return service({
url: `${baseUrl}/fetchingRelease`,
timeout: 60000,
params: {
uri: url,
tag: tagName
},
method: 'get'
})
}
themeApi.getContent = path => {
return service({
url: `${baseUrl}/files/content`,

View File

@ -181,7 +181,10 @@
tab="远程拉取"
key="2"
>
<a-form layout="vertical">
<a-form
v-if="!fetchBranches"
layout="vertical"
>
<a-form-item label="远程地址:">
<a-input v-model="fetchingUrl" />
</a-form-item>
@ -190,9 +193,64 @@
type="primary"
@click="handleFetching"
:loading="fetchButtonLoading"
>下载</a-button>
>获取</a-button>
</a-form-item>
</a-form>
<a-tabs
v-else
>
<a-tab-pane
tab="稳定版"
key="1"
>
<a-form layout="vertical">
<a-form-item>
<a-select
style="width: 120px"
@change="onSelectChange"
>
<a-select-option
v-for="(item, index) in releases"
:key="index"
:value="index"
>{{ item.branch }}</a-select-option>
</a-select>
</a-form-item>
<a-form-item>
<a-button
type="primary"
@click="handleReleaseFetching"
>下载</a-button>
</a-form-item>
</a-form>
</a-tab-pane>
<a-tab-pane
tab="开发版"
key="2"
>
<a-form layout="vertical">
<a-form-item>
<a-select
style="width: 120px"
@change="onSelectChange"
>
<a-select-option
v-for="(item, index) in branches"
:key="index"
:value="index"
>{{ item.branch }}</a-select-option>
</a-select>
</a-form-item>
<a-form-item>
<a-button
type="primary"
@click="handleBranchFetching"
>下载</a-button>
</a-form-item>
</a-form>
</a-tab-pane>
</a-tabs>
<a-alert
type="info"
closable
@ -245,9 +303,13 @@ export default {
uploadThemeVisible: false,
uploadNewThemeVisible: false,
fetchButtonLoading: false,
fetchBranches: false,
themes: [],
branches: [],
releases: [],
themeSettingVisible: false,
selectedTheme: {},
selectedBranch: null,
fetchingUrl: null,
uploadHandler: themeApi.upload,
updateByUploadHandler: themeApi.updateByUpload,
@ -316,6 +378,9 @@ export default {
if (this.uploadNewThemeVisible) {
this.uploadNewThemeVisible = false
}
if (this.fetchBranches) {
this.fetchBranches = false
}
this.loadThemes()
},
handleEditClick(theme) {
@ -334,16 +399,38 @@ export default {
}
this.fetchButtonLoading = true
themeApi
.fetching(this.fetchingUrl)
.fetchingBranches(this.fetchingUrl)
.then(response => {
this.$message.success('拉取成功!')
this.uploadThemeVisible = false
this.loadThemes()
this.branches = response.data.data
this.fetchBranches = true
})
themeApi
.fetchingReleases(this.fetchingUrl)
.then(response => {
this.releases = response.data.data
})
.finally(() => {
this.fetchButtonLoading = false
})
},
handleBranchFetching() {
themeApi
.fetchingBranch(this.fetchingUrl, this.branches[this.selectedBranch].branch)
.then(response => {
this.$message.success('拉取成功')
this.uploadThemeVisible = false
this.loadThemes()
})
},
handleReleaseFetching() {
themeApi
.fetchingRelease(this.fetchingUrl, this.releases[this.selectedBranch].branch)
.then(response => {
this.$message.success('拉取成功')
this.uploadThemeVisible = false
this.loadThemes()
})
},
handleReload() {
themeApi.reload().then(response => {
this.loadThemes()
@ -382,6 +469,9 @@ export default {
onCancel() {}
})
},
onSelectChange(value) {
this.selectedBranch = value
},
onThemeUploadClose() {
if (this.uploadThemeVisible) {
this.$refs.upload.handleClearFileList()
@ -389,6 +479,12 @@ export default {
if (this.uploadNewThemeVisible) {
this.$refs.updateByupload.handleClearFileList()
}
if (this.fetchBranches) {
this.fetchBranches = false
}
if (this.selectedBranch) {
this.selectedBranch = null
}
this.loadThemes()
},
onThemeSettingsClose() {