mirror of https://github.com/halo-dev/halo-admin
refactor: remove recovery. (#93)
parent
3136ab9467
commit
50a2800277
|
@ -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
|
|
|
@ -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>
|
|
|
@ -3,13 +3,11 @@ import Vue from 'vue'
|
||||||
// pro components
|
// pro components
|
||||||
import Ellipsis from '@/components/Ellipsis'
|
import Ellipsis from '@/components/Ellipsis'
|
||||||
import FooterToolbar from '@/components/FooterToolbar'
|
import FooterToolbar from '@/components/FooterToolbar'
|
||||||
import Upload from '@/components/Upload/Upload'
|
|
||||||
import FilePondUpload from '@/components/Upload/FilePondUpload'
|
import FilePondUpload from '@/components/Upload/FilePondUpload'
|
||||||
|
|
||||||
const _components = {
|
const _components = {
|
||||||
Ellipsis,
|
Ellipsis,
|
||||||
FooterToolbar,
|
FooterToolbar,
|
||||||
Upload,
|
|
||||||
FilePondUpload
|
FilePondUpload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ import {
|
||||||
Tag,
|
Tag,
|
||||||
TimePicker,
|
TimePicker,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Upload,
|
|
||||||
Drawer,
|
Drawer,
|
||||||
Skeleton,
|
Skeleton,
|
||||||
Comment,
|
Comment,
|
||||||
|
@ -91,7 +90,6 @@ Vue.use(Tabs)
|
||||||
Vue.use(Tag)
|
Vue.use(Tag)
|
||||||
Vue.use(TimePicker)
|
Vue.use(TimePicker)
|
||||||
Vue.use(Tooltip)
|
Vue.use(Tooltip)
|
||||||
Vue.use(Upload)
|
|
||||||
Vue.use(Skeleton)
|
Vue.use(Skeleton)
|
||||||
Vue.use(Comment)
|
Vue.use(Comment)
|
||||||
Vue.use(ConfigProvider)
|
Vue.use(ConfigProvider)
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
</a-step>
|
</a-step>
|
||||||
<a-step title="博客信息">
|
<a-step title="博客信息">
|
||||||
</a-step>
|
</a-step>
|
||||||
<a-step title="数据迁移">
|
|
||||||
</a-step>
|
|
||||||
</a-steps>
|
</a-steps>
|
||||||
<a-divider dashed />
|
<a-divider dashed />
|
||||||
<!-- Blogger info -->
|
<!-- Blogger info -->
|
||||||
|
@ -161,30 +159,6 @@
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</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
|
<a-row
|
||||||
class="install-action"
|
class="install-action"
|
||||||
type="flex"
|
type="flex"
|
||||||
|
@ -220,14 +194,11 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import adminApi from '@/api/admin'
|
import adminApi from '@/api/admin'
|
||||||
import recoveryApi from '@/api/recovery'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
installation: {},
|
installation: {},
|
||||||
migrationUploadName: 'file',
|
|
||||||
migrationData: null,
|
|
||||||
stepCurrent: 0,
|
stepCurrent: 0,
|
||||||
bloggerForm: this.$form.createForm(this)
|
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() {
|
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)
|
||||||
|
@ -292,16 +247,7 @@ export default {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle migration
|
this.install()
|
||||||
if (this.migrationData) {
|
|
||||||
recoveryApi.migrate(this.migrationData).then(response => {
|
|
||||||
this.$log.debug('Migrated successfullly')
|
|
||||||
this.$message.success('数据迁移成功!')
|
|
||||||
this.install()
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.install()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue