diff --git a/config/routes.ts b/config/routes.ts index ea00e5c..4f18f7c 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -13,6 +13,12 @@ export default [ icon: 'barChart', component: './Chart/AddChart' }, + { + name: '智能分析(异步)', + path: '/analyze/async', + icon: 'barChart', + component: './Chart/AddChartAsync' + }, { name: '我的图表', path: '/my_chart', diff --git a/src/pages/Chart/AddChart/index.tsx b/src/pages/Chart/AddChart/index.tsx index f5f0f89..dcbec25 100644 --- a/src/pages/Chart/AddChart/index.tsx +++ b/src/pages/Chart/AddChart/index.tsx @@ -56,6 +56,9 @@ const AddChart: React.FC = () => {
diff --git a/src/pages/Chart/AddChartAsync/index.tsx b/src/pages/Chart/AddChartAsync/index.tsx new file mode 100644 index 0000000..c0f34fe --- /dev/null +++ b/src/pages/Chart/AddChartAsync/index.tsx @@ -0,0 +1,93 @@ +import { genChartByAiAsyncUsingPOST } from '@/services/answerbi/chartController'; +import { UploadOutlined } from '@ant-design/icons'; +import { Button, Card, Form, Input, Select, Space, Upload, message } from 'antd'; +import { useForm } from 'antd/es/form/Form'; +import TextArea from 'antd/es/input/TextArea'; +import React, { useState } from 'react'; + + +const AddChartAsync: React.FC = () => { + //定义状态,用来接收后端返回值,让它实时展示再页面上 + const [form] = useForm(); + const [submitting, setSubmitting] = useState(false); + + + const onFinish = async (values: any) => { + if(submitting) return; + setSubmitting(true); + //对接后端,上传数据 + const params = { + ...values, + file: undefined, + }; + try{ + //需要取到上传的原始数据 file->file->originFileObj + const res = await genChartByAiAsyncUsingPOST(params, {}, values.file.file.originFileObj); + //正常情况下,如果没有返回值就分析失败,有就分析成功 + if(!res?.data){ + message.error('分析失败'); + }else{ + message.success('分析任务提交成功,稍后请在我的图表页面查看'); + form.resetFields(); + } + }catch(e: any){ + //异常情况下,提示分析失败+具体失败原因 + message.error('分析失败,' + e.message); + } + setSubmitting(false); + }; + + return ( +
+ + + +