Commit 0c0b7062 authored by liaozan's avatar liaozan 🏀

feat: axios loading

parent 96a035a6
......@@ -3,4 +3,4 @@
</template>
<script lang="ts" setup>
import Starter from "./components/starter.vue";</script>
\ No newline at end of file
import Starter from "./components/starter.vue"</script>
\ No newline at end of file
......@@ -30,7 +30,7 @@
</template>
<script lang="ts" setup>
import {reactive, ref, computed} from 'vue'
import {computed, reactive, ref} from 'vue'
import type {TreeProps} from 'ant-design-vue';
import {FormInstance, message} from "ant-design-vue";
import request, {isLoading} from "../utils/request";
......@@ -91,16 +91,10 @@ const onPreview = async () => {
}
const onDownload = async (id: number) => {
try {
loading.value = true
let res = await request.get(`/archetype/download/${id}`, {responseType: 'blob'})
const {headers, data} = res
const fileName = headers['content-disposition'].replace(/\w+;\sfilename="(.*)"/, '$1')
downloadGeneratedProject(data, fileName)
} catch (e) {
console.log('err:', e)
loading.value = false
}
let res = await request.get(`/archetype/download/${id}`, {responseType: 'blob'})
const {headers, data} = res
const fileName = headers['content-disposition'].replace(/\w+;\sfilename="(.*)"/, '$1')
downloadGeneratedProject(data, fileName)
}
const downloadGeneratedProject = (data: BlobPart, fileName: string) => {
......@@ -113,7 +107,6 @@ const downloadGeneratedProject = (data: BlobPart, fileName: string) => {
link.click()
URL.revokeObjectURL(link.href)
document.body.removeChild(link)
loading.value = false
}
const fetchFileList = async (id: number) => {
......@@ -174,4 +167,4 @@ const createTreeData = (fileNodeList: FileNode[]): any => {
border-radius: 6px;
}
}
</style>
</style>
\ No newline at end of file
import type { AxiosRequestConfig, AxiosResponse } from "axios";
import type {AxiosRequestConfig, AxiosResponse} from "axios";
import axios from "axios";
import {message} from "ant-design-vue";
import { ref } from 'vue'
import {ref} from 'vue'
export const isLoading = ref(false)
......@@ -20,7 +20,7 @@ axios.interceptors.response.use((config: AxiosResponse) => {
case 0:
return Promise.resolve(data)
default:
message.error(data.message)
message.error(data.message).then()
return Promise.reject(data)
}
} else {
......@@ -28,4 +28,4 @@ axios.interceptors.response.use((config: AxiosResponse) => {
}
})
export default axios
export default axios
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment