-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
864 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2021 Hengyang Zhang | ||
* | ||
* This software is released under the MIT License. | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import { t } from "@app/locale" | ||
import { Upload } from "@element-plus/icons-vue" | ||
import Immigration from "@service/components/immigration" | ||
import { deserialize } from "@util/file" | ||
import { ElButton, ElLoading, ElMessage } from "element-plus" | ||
import { Ref, defineComponent, h, ref } from "vue" | ||
|
||
const immigration: Immigration = new Immigration() | ||
|
||
async function handleFileSelected(fileInputRef: Ref<HTMLInputElement>, callback: () => void) { | ||
const files: FileList | null = fileInputRef?.value?.files | ||
if (!files || !files.length) { | ||
return | ||
} | ||
const loading = ElLoading.service({ fullscreen: true }) | ||
const file: File = files[0] | ||
const fileText = await file.text() | ||
const data = deserialize(fileText) | ||
if (!data) { | ||
ElMessage.error(t(msg => msg.dataManage.importError)) | ||
} | ||
await immigration.importData(data) | ||
loading.close() | ||
callback?.() | ||
ElMessage.success(t(msg => msg.dataManage.migrated)) | ||
} | ||
|
||
const _default = defineComponent({ | ||
emits: { | ||
import: () => true | ||
}, | ||
setup(_, ctx) { | ||
const fileInputRef = ref<HTMLInputElement>() | ||
return () => h(ElButton, { | ||
size: 'large', | ||
type: 'primary', | ||
icon: Upload, | ||
onClick: () => fileInputRef.value.click() | ||
}, () => [ | ||
t(msg => msg.item.operation.importWholeData), | ||
h('input', { | ||
ref: fileInputRef, | ||
type: 'file', | ||
accept: '.json', | ||
style: { display: 'none' }, | ||
onChange: () => handleFileSelected(fileInputRef, () => ctx.emit('import')) | ||
}) | ||
]) | ||
} | ||
}) | ||
|
||
export default _default |
36 changes: 36 additions & 0 deletions
36
src/app/components/data-manage/migration/import-other-button/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { t } from "@app/locale" | ||
import { Upload } from "@element-plus/icons-vue" | ||
import { ElButton, ElDialog } from "element-plus" | ||
import { Ref, defineComponent, h, ref } from "vue" | ||
import Sop from "./sop" | ||
import "./style" | ||
|
||
const _default = defineComponent({ | ||
emits: { | ||
import: () => true | ||
}, | ||
setup(_) { | ||
const dialogVisible: Ref<boolean> = ref(false) | ||
const close = () => dialogVisible.value = false | ||
return () => [ | ||
h(ElButton, { | ||
size: 'large', | ||
type: 'warning', | ||
icon: Upload, | ||
onClick: () => dialogVisible.value = true | ||
}, () => t(msg => msg.item.operation.importOtherData)), | ||
h(ElDialog, { | ||
top: '10vh', | ||
modelValue: dialogVisible.value, | ||
title: t(msg => msg.item.operation.importOtherData), | ||
width: '80%', | ||
closeOnClickModal: false, | ||
}, () => h(Sop, { | ||
onCancel: close, | ||
onImport: close, | ||
})) | ||
] | ||
} | ||
}) | ||
|
||
export default _default |
Oops, something went wrong.