Skip to content

Commit

Permalink
feat(taskConfig): download
Browse files Browse the repository at this point in the history
  • Loading branch information
martsimq committed Jul 5, 2024
1 parent 949948f commit 40c1840
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
33 changes: 17 additions & 16 deletions src/api/qgis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,52 @@
* @Author: Chris
* @Date: 2024/7/2
*/
import {AxiosInstanceConfig, createAxiosInstance} from "@/api/axios.ts";
import { AxiosInstanceConfig, createAxiosInstance } from "@/api/axios.ts";

const BASE_URL = "http://47.96.77.183:8000/";

const axiosConfig: AxiosInstanceConfig = {
baseURL: BASE_URL,
}
};

const axiosInstance = createAxiosInstance(axiosConfig)
const axiosInstance = createAxiosInstance(axiosConfig);

/**
* 获取指定路径的目录
* @param dir
*/
export function fetchDir(dir: string) {
return axiosInstance.get("qgis/process/list_dir_with_structure/?dir=" + dir)
return axiosInstance.get("qgis/process/list_dir_with_structure/?dir=" + dir);
}

/**
* 清空工作空间
*/
export function clearWorkspace() {
return axiosInstance.delete("qgis/process/clear_qgis_temp_dir/")
return axiosInstance.delete("qgis/process/clear_qgis_temp_dir/");
}

/**
* 上传多文件
* @param files
*/
export function uploadFiles(files: File[]) {
let formData = new FormData()
files.forEach(file => {
formData.append("file_list", file)
})
let formData = new FormData();
files.forEach((file) => {
formData.append("file_list", file);
});

const config = {
headers: {
'Content-Type': 'multipart/form-data'
}
}
return axiosInstance.post("qgis/process/upload_files/", formData, config)
"Content-Type": "multipart/form-data",
},
};
return axiosInstance.post("qgis/process/upload_files/", formData, config);
}

// TODO download file
export function downloadFile() {
export function downloadFile(fileName: string) {
return axiosInstance.get("qgis/process/download_file/?filepath=" + fileName);
}

/**
Expand All @@ -59,6 +60,6 @@ export function process(toolId: string, inputs: {}) {
const data = {
algorithm_id: toolId,
parameter_dictionary: inputs,
}
return axiosInstance.post("qgis/process/qgis_process", data)
};
return axiosInstance.post("qgis/process/qgis_process", data);
}
14 changes: 10 additions & 4 deletions src/components/taskConfig/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Close, Download } from "@element-plus/icons-vue";
import { useTaskStore } from "@/store/task.ts";
import { storeToRefs } from "pinia";
import { reactive, ref } from "vue";
import { process } from "@/api";
import { downloadFile, process } from "@/api";
const taskStore = useTaskStore();
const { tool } = storeToRefs(taskStore);
Expand Down Expand Up @@ -46,8 +46,14 @@ function onCancel() {
taskStore.close();
}
function handleClick() {
console.log("click");
async function download() {
console.log(res.value);
const response = await downloadFile(res.value.data.OUTPUT);

Check failure on line 51 in src/components/taskConfig/index.vue

View workflow job for this annotation

GitHub Actions / build (18.x, chrisgray0626/gis-agent-frontend, 0.1)

'res.value' is possibly 'undefined'.

Check failure on line 51 in src/components/taskConfig/index.vue

View workflow job for this annotation

GitHub Actions / build (18.x, chrisgray0626/gis-agent-frontend, 0.1)

Property 'data' does not exist on type 'Response'.
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", "sample.txt");
link.click();
}
</script>
<template>
Expand Down Expand Up @@ -99,7 +105,7 @@ function handleClick() {
circle
v-if="res.message"
style="float: right"
@click="handleClick"
@click="download()"
/>
</template>
{{ res?.message }}
Expand Down
2 changes: 1 addition & 1 deletion src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ export const TOOL_EXAMPLE = {
],
};
export const MOCK_JOB = `{"task":"Extract water body from Landsat-8 images","subtasks":[{"task":"Import Landsat-8 imagery into QGIS","toolId":"gdal:translate","subtasks":[],"toolName":"gdal:translate"},{"task":"Assign projection to the imported raster if it does not already have one","toolId":"gdal:assignprojection","subtasks":[],"toolName":"gdal:assignprojection"},{"task":"Select an appropriate spectral band combination for water body extraction","toolId":"gdal:rearrange_bands","subtasks":[],"toolName":"gdal:rearrange_bands"},{"task":"Apply threshold to identify water bodies","toolId":"gdal:rastercalculator","subtasks":[],"toolName":"gdal:rastercalculator"},{"task":"Convert the raster of threshold values to vector format for precise delineation","toolId":"gdal:polygonize","subtasks":[],"toolName":"gdal:polygonize"},{"task":"Refine the resultant vector layer by removing small erroneous polygons","toolId":"native:deleteholes","subtasks":[],"toolName":"native:deleteholes"}],"toolId":"","toolName":""}`;
export const MOCK_TOOL = `{"id":"qgis:basicstatisticsforfields","name":"Basic_statistics_for_fields","description":"Generates basic statistics for a field of the attribute table of a vector layer.","args":[{"name":"INPUT_LAYER","type":"[vector: any]","description":"Vector layer to calculate the statistics on.","required":true},{"name":"FIELD_NAME","type":"[tablefield: any]","description":"The name of the field that will be added to the input table.","required":true},{"name":"OUTPUT_HTML_FILE","type":"[html]","description":"Specification of the file for the calculated statistics. One of: Skip Output,Save to a Temporary File,Save to File.","required":false}]}`;
export const MOCK_TOOL = `{"id":"qgis:randompointsinsidepolygons","name":"qgis:randompointsinsidepolygons","description":"Generates basic statistics for a field of the attribute table of a vector layer.","args":[{"name":"INPUT","type":"[vector: any]","description":"Vector layer to calculate the statistics on.","required":true},{"name":"POINTS_NUMBER","type":"[html]","description":"Specification of the file for the calculated statistics. One of: Skip Output,Save to a Temporary File,Save to File.","required":false},{"name":"MIN_DISTANCE","type":"[html]","description":"Specification of the file for the calculated statistics. One of: Skip Output,Save to a Temporary File,Save to File.","required":false},{"name":"OUTPUT","description":"xxxxxxx"}]}`;

0 comments on commit 40c1840

Please sign in to comment.