fix: failed to upload theme and plugin

pull/606/head^2
Ryan Wang 2022-09-08 11:40:30 +08:00
parent 4759468df6
commit fdc60e9c40
2 changed files with 60 additions and 66 deletions

View File

@ -1,10 +1,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { VModal } from "@halo-dev/components"; import { VModal } from "@halo-dev/components";
import VueFilePond from "vue-filepond"; import FilePondUpload from "@/components/upload/FilePondUpload.vue";
import "filepond/dist/filepond.min.css";
import { apiClient } from "@halo-dev/admin-shared"; import { apiClient } from "@halo-dev/admin-shared";
import { computed, ref } from "vue";
const FilePond = VueFilePond();
withDefaults( withDefaults(
defineProps<{ defineProps<{
@ -20,26 +18,25 @@ const emit = defineEmits<{
(event: "close"): void; (event: "close"): void;
}>(); }>();
const FilePondUploadRef = ref();
const handleVisibleChange = (visible: boolean) => { const handleVisibleChange = (visible: boolean) => {
emit("update:visible", visible); emit("update:visible", visible);
if (!visible) { if (!visible) {
emit("close"); emit("close");
FilePondUploadRef.value.handleRemoveFiles();
} }
}; };
const server = { const uploadHandler = computed(() => {
process: (fieldName, file, metadata, load) => { return (file, config) =>
const formData = new FormData(); apiClient.theme.installTheme(
formData.append(fieldName, file, file.name); {
file: file,
apiClient.theme.installTheme(file).then((response) => {
load(response);
handleVisibleChange(false);
});
return {};
}, },
}; config
);
});
</script> </script>
<template> <template>
<VModal <VModal
@ -48,12 +45,11 @@ const server = {
title="安装主题" title="安装主题"
@update:visible="handleVisibleChange" @update:visible="handleVisibleChange"
> >
<file-pond <FilePondUpload
ref="pond" ref="FilePondUploadRef"
:allow-multiple="false" :allow-multiple="false"
:server="server" :handler="uploadHandler"
label-idle="Drop ZIP file here..." label-idle="点击选择文件或者拖拽文件到此处"
name="file"
/> />
</VModal> </VModal>
</template> </template>

View File

@ -1,11 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useDialog, VModal } from "@halo-dev/components"; import { useDialog, VModal } from "@halo-dev/components";
import VueFilePond from "vue-filepond"; import FilePondUpload from "@/components/upload/FilePondUpload.vue";
import "filepond/dist/filepond.min.css";
import { apiClient } from "@halo-dev/admin-shared"; import { apiClient } from "@halo-dev/admin-shared";
import type { Plugin } from "@halo-dev/api-client"; import type { Plugin } from "@halo-dev/api-client";
import { computed, ref } from "vue";
const FilePond = VueFilePond(); import type { AxiosResponse } from "axios";
withDefaults( withDefaults(
defineProps<{ defineProps<{
@ -22,26 +21,29 @@ const emit = defineEmits<{
}>(); }>();
const dialog = useDialog(); const dialog = useDialog();
const FilePondUploadRef = ref();
const handleVisibleChange = (visible: boolean) => { const handleVisibleChange = (visible: boolean) => {
emit("update:visible", visible); emit("update:visible", visible);
if (!visible) { if (!visible) {
emit("close"); emit("close");
FilePondUploadRef.value.handleRemoveFiles();
} }
}; };
const server = { const uploadHandler = computed(() => {
process: (fieldName, file, metadata, load) => { return (file, config) =>
const formData = new FormData(); apiClient.plugin.installPlugin(
formData.append(fieldName, file, file.name); {
file: file,
apiClient.plugin.installPlugin(file).then((response) => { },
load(response); config
);
const plugin: Plugin = response.data as unknown as Plugin; });
const onUploaded = async (response: AxiosResponse) => {
const plugin = response.data as Plugin;
handleVisibleChange(false); handleVisibleChange(false);
dialog.success({ dialog.success({
title: "上传成功", title: "上传成功",
description: "是否启动当前安装的插件?", description: "是否启动当前安装的插件?",
@ -64,10 +66,6 @@ const server = {
} }
}, },
}); });
});
return {};
},
}; };
</script> </script>
<template> <template>
@ -77,12 +75,12 @@ const server = {
title="安装插件" title="安装插件"
@update:visible="handleVisibleChange" @update:visible="handleVisibleChange"
> >
<file-pond <FilePondUpload
ref="pond" ref="FilePondUploadRef"
:allow-multiple="false" :allow-multiple="false"
:server="server" :handler="uploadHandler"
label-idle="Drop JAR file here..." label-idle="点击选择文件或者拖拽文件到此处"
name="file" @uploaded="onUploaded"
/> />
</VModal> </VModal>
</template> </template>