diff --git a/src/components/DenseFramework.vue b/src/components/DenseFramework.vue index bc742b5..b9b91fd 100644 --- a/src/components/DenseFramework.vue +++ b/src/components/DenseFramework.vue @@ -6,11 +6,55 @@ import { ResizablePanelGroup, } from '~/components/ui/resizable' -defineProps<{ - imageResult: ImageResult +const props = defineProps<{ + imageQuery: string + extraErrorHandle?: (resp: Response) => { + type: string + message: string + } + extraResponseHandle?: (resp: Response) => Promise }>() defineEmits(['submit']) +const imageResult = reactive({ + result: 'idle', + resourceId: '', + message: '请你选择一个模式和日期', +}) + +const urlRef = computed(() => { + return props.imageQuery +}) + +const { onFetchResponse, onFetchError, isFetching, execute } = baseFetch( + urlRef, + { immediate: false }, +) +watch(isFetching, (fetching) => { + if (fetching) { + imageResult.result = 'pending' + } +}) + +onFetchResponse(async (resp) => { + if (props.extraResponseHandle) { + const newResult = await props.extraResponseHandle(resp) + imageResult.result = newResult.result + imageResult.resourceId = newResult.resourceId + imageResult.message = newResult.message + } + else { + const blob = await resp.blob() + const url = URL.createObjectURL(blob) + imageResult.result = 'success' + imageResult.resourceId = url + } +}) + +onFetchError(async (error) => { + imageResult.result = 'error' + imageResult.message = error +})