Perfect installation

pull/9/head
johnniang 2019-04-28 22:28:22 +08:00
parent 1e5283db84
commit 72c3977252
2 changed files with 52 additions and 18 deletions

View File

@ -6,6 +6,7 @@
:multiple="multiple" :multiple="multiple"
:accept="accept" :accept="accept"
:customRequest="handleUpload" :customRequest="handleUpload"
:remove="handleRemove"
@change="handleChange" @change="handleChange"
> >
<slot <slot
@ -19,6 +20,7 @@
:multiple="multiple" :multiple="multiple"
:accept="accept" :accept="accept"
:customRequest="handleUpload" :customRequest="handleUpload"
:remove="handleRemove"
@change="handleChange" @change="handleChange"
> >
<slot /> <slot />
@ -61,13 +63,17 @@ export default {
handleChange(info) { handleChange(info) {
this.$emit('change', info) this.$emit('change', info)
}, },
handleRemove(file) {
this.$log.debug('Removed file', file)
this.$emit('remove', file)
},
handleUpload(option) { handleUpload(option) {
this.$log.debug('Uploading option', option) this.$log.debug('Uploading option', option)
const CancelToken = axios.CancelToken const CancelToken = axios.CancelToken
const source = CancelToken.source() const source = CancelToken.source()
const data = new FormData() const data = new FormData()
data.append('file', option.file) data.append(this.name, option.file)
this.uploadHandler( this.uploadHandler(
data, data,
@ -78,18 +84,22 @@ export default {
this.$log.debug('Uploading percent: ', progressEvent.percent) this.$log.debug('Uploading percent: ', progressEvent.percent)
option.onProgress(progressEvent) option.onProgress(progressEvent)
}, },
source.token source.token,
option.file
) )
.then(response => { .then(response => {
this.$log.debug('Uploaded successfully', response)
option.onSuccess(response, option.file) option.onSuccess(response, option.file)
this.$emit('success', response, option.file) this.$emit('success', response, option.file)
}) })
.catch(error => { .catch(error => {
this.$log.debug('Failed to upload file', error)
option.onError(error, error.response) option.onError(error, error.response)
this.$emit('failure', error, option.file) this.$emit('failure', error, option.file)
}) })
return { return {
abort: () => { abort: () => {
this.$log.debug('Upload operation aborted by the user')
source.cancel('Upload operation canceled by the user.') source.cancel('Upload operation canceled by the user.')
} }
} }

View File

@ -117,6 +117,26 @@
layout="horizontal" layout="horizontal"
v-show="stepCurrent == 1" v-show="stepCurrent == 1"
> >
<a-form-item>
<a-input
v-model="installation.url"
placeholder="博客地址(选填)"
>
<a-icon
slot="prefix"
type="link"
style="color: rgba(0,0,0,.25)"
/>
<a-select
slot="addonBefore"
defaultValue="http://"
style="width: 90px"
>
<a-select-option value="http://">http://</a-select-option>
<a-select-option value="https://">https://</a-select-option>
</a-select>
</a-input>
</a-form-item>
<a-form-item> <a-form-item>
<a-input <a-input
v-model="installation.title" v-model="installation.title"
@ -129,25 +149,20 @@
/> />
</a-input> </a-input>
</a-form-item> </a-form-item>
<a-form-item>
<a-input
v-model="installation.url"
placeholder="博客地址"
>
<a-icon
slot="prefix"
type="link"
style="color: rgba(0,0,0,.25)"
/>
</a-input>
</a-form-item>
</a-form> </a-form>
<!-- Data migration --> <!-- Data migration -->
<div v-show="stepCurrent == 2"> <div v-show="stepCurrent == 2">
<a-alert
style="margin-bottom: 1rem"
message="如果有迁移需求,请点击并选择'迁移文件'"
type="info"
/>
<Upload <Upload
:uploadHandler="handleMigrationUpload" :name="migrationUploadName"
accept="application/json" accept="application/json"
:uploadHandler="handleMigrationUpload"
@remove="handleMigrationFileRemove"
> >
<p class="ant-upload-drag-icon"> <p class="ant-upload-drag-icon">
<a-icon type="inbox" /> <a-icon type="inbox" />
@ -212,6 +227,7 @@ export default {
} }
}, },
installation: {}, installation: {},
migrationUploadName: 'file',
migrationData: null, migrationData: null,
stepCurrent: 0 stepCurrent: 0
} }
@ -220,11 +236,19 @@ export default {
handleMigrationUpload(data) { handleMigrationUpload(data) {
this.$log.debug('Selected data', data) this.$log.debug('Selected data', data)
this.migrationData = data this.migrationData = data
return new Promise(resolve => { return new Promise((resolve, reject) => {
this.$log.debug('Handle uploading') this.$log.debug('Handle uploading')
resolve.resolve() resolve()
}) })
}, },
handleMigrationFileRemove(file) {
this.$log.debug('Removed file', file)
this.$log.debug('Migration file from data', this.migrationData.get(this.migrationUploadName))
if (this.migrationData.get(this.migrationUploadName).uid === file.uid) {
this.migrationData = null
this.migrationFile = null
}
},
install() { install() {
adminApi.install(this.installation).then(response => { adminApi.install(this.installation).then(response => {
this.$log.debug('Installation response', response) this.$log.debug('Installation response', response)
@ -247,7 +271,7 @@ export default {
} }
// Handle migration // Handle migration
if (this.migrationData) { if (this.migrationFile) {
recoveryApi.migrate(this.migrationData).then(response => { recoveryApi.migrate(this.migrationData).then(response => {
this.$log.debug('Migrated successfullly') this.$log.debug('Migrated successfullly')
this.$message.success('数据迁移成功') this.$message.success('数据迁移成功')