From 5381995c837b2bd5ff7e80b3f464e12871758113 Mon Sep 17 00:00:00 2001 From: "yunpeng.zhang" Date: Mon, 8 Apr 2024 13:31:54 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=E9=83=A8=E7=BD=B2=E4=B8=8A=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Chart/AddChart/index.tsx | 77 +++++++++++++++---------- src/pages/Chart/AddChartAsync/index.tsx | 52 ++++++++--------- 2 files changed, 71 insertions(+), 58 deletions(-) diff --git a/src/pages/Chart/AddChart/index.tsx b/src/pages/Chart/AddChart/index.tsx index 1430e1d..d1f20f3 100644 --- a/src/pages/Chart/AddChart/index.tsx +++ b/src/pages/Chart/AddChart/index.tsx @@ -1,10 +1,22 @@ import { genChartByAiUsingPOST } from '@/services/answerbi/chartController'; import { UploadOutlined } from '@ant-design/icons'; -import { Button, Card, Col, Divider, Form, Input, Row, Select, Space, Spin, Upload, message } from 'antd'; +import { + Button, + Card, + Col, + Divider, + Form, + Input, + message, + Row, + Select, + Space, + Spin, + Upload, +} from 'antd'; import TextArea from 'antd/es/input/TextArea'; -import React, { useState } from 'react'; import ReactECharts from 'echarts-for-react'; - +import React, { useState } from 'react'; const AddChart: React.FC = () => { //定义状态,用来接收后端返回值,让它实时展示再页面上 @@ -12,9 +24,8 @@ const AddChart: React.FC = () => { const [option, setOption] = useState(); const [submitting, setSubmitting] = useState(false); - const onFinish = async (values: any) => { - if(submitting) return; + if (submitting) return; setSubmitting(true); setChart(undefined); setOption(undefined); @@ -23,79 +34,81 @@ const AddChart: React.FC = () => { ...values, file: undefined, }; - try{ + try { //需要取到上传的原始数据 file->file->originFileObj const res = await genChartByAiUsingPOST(params, {}, values.file.file.originFileObj); //正常情况下,如果没有返回值就分析失败,有就分析成功 - if(!res?.data){ - message.error(res.message ??'分析失败'); - }else{ + if (!res?.data) { + message.error(res.message ?? '分析失败'); + } else { message.success('分析成功'); //解析成对象 console.log(res.data.genChart); const chartOption = JSON.parse(res.data.genChart ?? ''); console.log(chartOption); - if(!chartOption){ - throw new Error('图表代码解析错误') - }else{ + if (!chartOption) { + throw new Error('图表代码解析错误'); + } else { setChart(res.data); setOption(chartOption); } } - }catch(e: any){ + } catch (e: any) { //异常情况下,提示分析失败+具体失败原因 message.error('分析失败,' + e.message); } setSubmitting(false); }; - + return ( -
+
- -