refactor: remove recovery. (#93)

pull/94/head
Ryan Wang 2020-03-11 13:48:24 +08:00 committed by GitHub
parent 3136ab9467
commit 50a2800277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 186 deletions

View File

@ -1,15 +0,0 @@
import service from '@/utils/service'
const baseUrl = '/api/admin/recoveries'
const recoveryApi = {}
recoveryApi.migrate = formData => {
return service({
url: `${baseUrl}/migrations/v0_4_3`,
data: formData,
method: 'post'
})
}
export default recoveryApi

View File

@ -1,112 +0,0 @@
<template>
<div>
<a-upload-dragger
v-if="draggable"
:name="name"
:multiple="multiple"
:accept="accept"
:customRequest="handleUpload"
:remove="handleRemove"
@change="handleChange"
>
<slot
role="button"
class="ant-upload ant-upload-btn"
/>
</a-upload-dragger>
<a-upload
v-else
:name="name"
:multiple="multiple"
:accept="accept"
:customRequest="handleUpload"
:remove="handleRemove"
@change="handleChange"
>
<slot />
</a-upload>
</div>
</template>
<script>
import axios from 'axios'
export default {
name: 'Upload',
props: {
name: {
type: String,
required: false,
default: 'file'
},
multiple: {
type: Boolean,
required: false,
default: false
},
draggable: {
type: Boolean,
required: false,
default: true
},
accept: {
type: String,
required: false,
default: ''
},
uploadHandler: {
type: Function,
required: true
}
},
methods: {
handleChange(info) {
this.$emit('change', info)
},
handleRemove(file) {
this.$log.debug('Removed file', file)
this.$emit('remove', file)
},
handleUpload(option) {
this.$log.debug('Uploading option', option)
const CancelToken = axios.CancelToken
const source = CancelToken.source()
const data = new FormData()
data.append(this.name, option.file)
this.uploadHandler(
data,
progressEvent => {
if (progressEvent.total > 0) {
progressEvent.percent = (progressEvent.loaded / progressEvent.total) * 100
}
this.$log.debug('Uploading percent: ', progressEvent.percent)
option.onProgress(progressEvent)
},
source.token,
option.file
)
.then(response => {
this.$log.debug('Uploaded successfully', response)
option.onSuccess(response, option.file)
this.$emit('success', response, option.file)
})
.catch(error => {
this.$log.debug('Failed to upload file', error)
option.onError(error, error.response)
this.$emit('failure', error, option.file)
})
return {
abort: () => {
this.$log.debug('Upload operation aborted by the user')
source.cancel('Upload operation canceled by the user.')
}
}
}
}
}
</script>
<style>
</style>

View File

@ -3,13 +3,11 @@ import Vue from 'vue'
// pro components
import Ellipsis from '@/components/Ellipsis'
import FooterToolbar from '@/components/FooterToolbar'
import Upload from '@/components/Upload/Upload'
import FilePondUpload from '@/components/Upload/FilePondUpload'
const _components = {
Ellipsis,
FooterToolbar,
Upload,
FilePondUpload
}

View File

@ -41,7 +41,6 @@ import {
Tag,
TimePicker,
Tooltip,
Upload,
Drawer,
Skeleton,
Comment,
@ -91,7 +90,6 @@ Vue.use(Tabs)
Vue.use(Tag)
Vue.use(TimePicker)
Vue.use(Tooltip)
Vue.use(Upload)
Vue.use(Skeleton)
Vue.use(Comment)
Vue.use(ConfigProvider)

View File

@ -24,8 +24,6 @@
</a-step>
<a-step title="博客信息">
</a-step>
<a-step title="数据迁移">
</a-step>
</a-steps>
<a-divider dashed />
<!-- Blogger info -->
@ -161,30 +159,6 @@
</a-form-item>
</a-form>
<!-- Data migration -->
<div v-show="stepCurrent == 2">
<a-alert
style="margin-bottom: 1rem"
message="如果有迁移需求,请点击并选择'迁移文件'"
type="info"
class="animated fadeInUp"
/>
<Upload
:name="migrationUploadName"
accept="application/json"
:uploadHandler="handleMigrationUpload"
@remove="handleMigrationFileRemove"
class="animated fadeIn"
:style="{'animation-delay': '0.2s'}"
>
<p class="ant-upload-drag-icon">
<a-icon type="inbox" />
</p>
<p class="ant-upload-text">点击选择文件或将文件拖拽到此处</p>
<p class="ant-upload-hint">仅支持单个文件上传</p>
</Upload>
</div>
<a-row
class="install-action"
type="flex"
@ -220,14 +194,11 @@
<script>
import adminApi from '@/api/admin'
import recoveryApi from '@/api/recovery'
export default {
data() {
return {
installation: {},
migrationUploadName: 'file',
migrationData: null,
stepCurrent: 0,
bloggerForm: this.$form.createForm(this)
}
@ -255,22 +226,6 @@ export default {
}
})
},
handleMigrationUpload(data) {
this.$log.debug('Selected data', data)
this.migrationData = data
return new Promise((resolve, reject) => {
this.$log.debug('Handle uploading')
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() {
adminApi.install(this.installation).then(response => {
this.$log.debug('Installation response', response)
@ -292,16 +247,7 @@ export default {
return
}
// Handle migration
if (this.migrationData) {
recoveryApi.migrate(this.migrationData).then(response => {
this.$log.debug('Migrated successfullly')
this.$message.success('数据迁移成功!')
this.install()
})
} else {
this.install()
}
}
}
}