Skip to content

Commit 1a07c43

Browse files
committed
chore: type declaration
1 parent 976a8d5 commit 1a07c43

File tree

9 files changed

+58
-63
lines changed

9 files changed

+58
-63
lines changed

src/api/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
// export * from "./job.ts"
99
export * from "./mock.ts";
1010
export * from "./qgis.ts";
11+
12+
// TODO: interface definition of api

src/api/job.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,31 @@
33
* @Author: Chris
44
* @Date: 2024/7/1
55
*/
6-
import {AxiosInstanceConfig, createAxiosInstance} from "@/api/axios.ts";
6+
import { AxiosInstanceConfig, createAxiosInstance } from "@/api/axios.ts";
77

88
const BASE_URL = "http://121.196.198.27:32580/";
99

1010
const axiosConfig: AxiosInstanceConfig = {
1111
baseURL: BASE_URL,
1212
timeout: 100000,
13-
}
13+
};
1414

15-
const axiosInstance = createAxiosInstance(axiosConfig)
15+
const axiosInstance = createAxiosInstance(axiosConfig);
1616

1717
/**
1818
* 获取 Job
1919
* @param data
2020
*/
21-
export function fetchJob(data: any) {
22-
return axiosInstance.post("gis_agent_backend/simple/task_plan/", data)
21+
export function fetchJob(data: string) {
22+
return axiosInstance.post("gis_agent_backend/simple/task_plan/", data);
2323
}
2424

2525
/**
2626
* 根据 toolId 获取工具
2727
* @param toolId
2828
*/
2929
export function fetchTool(toolId: string) {
30-
return axiosInstance.get("gis_agent_backend/test_tool/get_tool/?tool_id=" + toolId)
31-
}
30+
return axiosInstance.get(
31+
"gis_agent_backend/test_tool/get_tool/?tool_id=" + toolId,
32+
);
33+
}

src/api/mock.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { MOCK_JOB, MOCK_TOOL } from "@/constant";
88

99
export const fetchJob = (task: string) =>
10-
new Promise((resolve, _reject) => {
10+
new Promise<{ data: any }>((resolve, _reject) => {
1111
setTimeout(
1212
() =>
1313
resolve({
@@ -23,7 +23,7 @@ export const fetchJob = (task: string) =>
2323
});
2424

2525
export const fetchTool = (_toolId: string) =>
26-
new Promise((resolve, _reject) => {
26+
new Promise<{ data: any }>((resolve, _reject) => {
2727
setTimeout(
2828
() =>
2929
resolve({

src/components/taskConfig/index.vue src/components/TaskConfig.vue

+25-30
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { useTaskStore } from "@/store/task.ts";
44
import { storeToRefs } from "pinia";
55
import { reactive, ref } from "vue";
66
import { downloadFile, process } from "@/api";
7+
import { Response } from "@/type.ts";
78
89
const taskStore = useTaskStore();
910
const { tool } = storeToRefs(taskStore);
10-
1111
const argConfig = reactive<
1212
{
1313
name: string;
@@ -16,44 +16,40 @@ const argConfig = reactive<
1616
input: string;
1717
}[]
1818
>([]);
19-
2019
const processConfig = reactive<{
2120
[key: string]: string;
2221
}>({});
23-
24-
interface Response {
25-
code: string;
26-
message: string;
27-
data: { OUTPUT: string };
28-
}
29-
3022
let res = ref<Response>();
3123
32-
for (const [, arg] of tool.value.args.entries()) {
33-
argConfig.push(Object.assign(arg, { input: "" }));
34-
}
35-
36-
async function onExecute(id: string, input: typeof argConfig) {
37-
for (const [, arg] of input.entries()) {
24+
async function onExecute(id: string | undefined, input: typeof argConfig) {
25+
input.forEach((arg) => {
3826
processConfig[arg.name] = arg.input;
27+
});
28+
if (id) {
29+
res.value = (await process(id, processConfig)).data as Response;
3930
}
40-
console.log(processConfig);
41-
res.value = (await process(id, processConfig)).data as Response;
42-
console.log(res.value);
4331
}
4432
4533
function onCancel() {
4634
taskStore.close();
4735
}
4836
4937
async function download() {
50-
console.log(res.value);
51-
const response = await downloadFile(res.value!.data.OUTPUT);
52-
const url = window.URL.createObjectURL(new Blob([response.data]));
53-
const link = document.createElement("a");
54-
link.href = url;
55-
link.setAttribute("download", "sample.txt");
56-
link.click();
38+
console.log("download: ", res.value);
39+
if (res.value?.data?.OUTPUT) {
40+
const response = await downloadFile(res.value.data.OUTPUT || "");
41+
const url = window.URL.createObjectURL(new Blob([response.data]));
42+
const link = document.createElement("a");
43+
link.href = url;
44+
link.setAttribute("download", "sample.txt");
45+
link.click();
46+
}
47+
}
48+
49+
if (tool.value) {
50+
tool.value.args.forEach((arg) => {
51+
argConfig.push(Object.assign(arg, { input: "" }));
52+
});
5753
}
5854
</script>
5955
<template>
@@ -72,10 +68,10 @@ async function download() {
7268
<el-form label-position="top" style="margin: 20px">
7369
<el-descriptions direction="vertical" :column="1">
7470
<el-descriptions-item label="Tool name">
75-
{{ tool.name }}
71+
{{ tool?.name }}
7672
</el-descriptions-item>
7773
<el-descriptions-item label="Tool description">
78-
{{ tool.description }}
74+
{{ tool?.description }}
7975
</el-descriptions-item>
8076
</el-descriptions>
8177
<el-form-item label="Args">
@@ -103,7 +99,7 @@ async function download() {
10399
type="primary"
104100
:icon="Download"
105101
circle
106-
v-if="res.message"
102+
v-if="res.data?.OUTPUT"
107103
style="float: right"
108104
@click="download()"
109105
/>
@@ -115,7 +111,7 @@ async function download() {
115111
<el-form-item>
116112
<div style="width: 100%; display: flex; justify-content: space-between">
117113
<el-button @click="onCancel">Cancel</el-button>
118-
<el-button type="primary" @click="onExecute(tool.id, argConfig)"
114+
<el-button type="primary" @click="onExecute(tool?.id, argConfig)"
119115
>Execute
120116
</el-button>
121117
</div>
@@ -125,7 +121,6 @@ async function download() {
125121
</template>
126122

127123
<style scoped lang="less">
128-
@import "./index.less";
129124
.header-cell-class {
130125
background-color: aqua;
131126
border-color: aqua;

src/components/taskConfig/index.less

Whitespace-only changes.

src/pages/Home/components/RightBox.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts" setup>
22
import WorkflowChart from "@/components/WorkflowChart.vue";
3-
import TaskConfig from "@/components/taskConfig/index.vue";
3+
import TaskConfig from "@/components/TaskConfig.vue";
44
import { useTaskStore } from "@/store/task.ts";
55
import { useSessionStore } from "@/store/session.ts";
66

src/store/job.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import {defineStore} from "pinia";
2-
import {job2G6TreeGraph, jobLeafNode2G6Graph} from "@/utils/graphUtil.ts";
3-
import {computed} from "vue";
4-
import {fetchJob} from "@/api";
5-
import {Task} from "@/type.ts";
1+
import { defineStore } from "pinia";
2+
import { job2G6TreeGraph, jobLeafNode2G6Graph } from "@/utils/graphUtil.ts";
3+
import { computed } from "vue";
4+
import { fetchJob } from "@/api";
5+
import { Task } from "@/type.ts";
66

77
export const useJobStore = defineStore("job", () => {
88
let _job: Task;
99

1010
async function updateData(question: string) {
11-
const res = ((await fetchJob(question)) as { data: any }).data;
11+
const res = (await fetchJob(question)).data;
1212
// localData = (await axios.fetchJob(`{"question":"${question}"}`)).data;
1313
console.debug("res", res);
1414
_job = convertData(res);
@@ -30,5 +30,5 @@ export const useJobStore = defineStore("job", () => {
3030

3131
const workflowData = computed(() => jobLeafNode2G6Graph(_job));
3232

33-
return {updateData, breakdownData, workflowData};
33+
return { updateData, breakdownData, workflowData };
3434
});

src/store/task.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import { Task } from "@/type.ts";
44
import { fetchTool } from "@/api";
55

66
export const useTaskStore = defineStore("node", () => {
7-
let _task = ref<Task>({} as Task);
7+
let _task = ref<Task>();
88

9-
const tool = computed(() => _task.value.tool);
9+
const tool = computed(() => _task.value?.tool);
1010

1111
let isShowed = ref(false);
1212

1313
async function updateData(task: Task) {
1414
_task.value = task;
1515
// TODO Fetch the tool
1616
// const res = await fetchTool(node.tool.id).data;
17-
_task.value.tool = (
18-
(await fetchTool(_task.value.tool.id)) as { data: any }
19-
).data;
17+
_task.value.tool = (await fetchTool(_task.value.tool.id)).data;
2018
console.log(_task.value);
2119
}
2220

src/type.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ export class Tool {
3232
}
3333
}
3434

35-
export type Node = {
36-
id: string;
37-
name: string;
38-
description: string;
39-
// props: Task;
40-
args: {
41-
name: string;
42-
description: string;
43-
required: boolean;
44-
}[];
45-
};
35+
export interface Response {
36+
code: string;
37+
message: string;
38+
data: ResponseData;
39+
}
40+
41+
interface ResponseData {
42+
OUTPUT?: string;
43+
}

0 commit comments

Comments
 (0)