diff --git a/spug_web/src/pages/pipeline/console/Ask.js b/spug_web/src/pages/pipeline/console/Ask.js index 976a322..3b06ff9 100644 --- a/spug_web/src/pages/pipeline/console/Ask.js +++ b/spug_web/src/pages/pipeline/console/Ask.js @@ -5,32 +5,51 @@ */ import React, { useState } from 'react'; import { observer } from 'mobx-react'; -import { Button, Form, Upload } from 'antd'; -import { ArrowRightOutlined, UploadOutlined } from '@ant-design/icons'; +import { Button, Form, Upload, message } from 'antd'; +import { ThunderboltOutlined, UploadOutlined } from '@ant-design/icons'; import Parameter from '../modules/Parameter'; import { http, X_TOKEN } from 'libs'; import S from './store'; +import lds from 'lodash'; function Ask(props) { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); function handleOk() { - const params = form.getFieldsValue(); + const data = form.getFieldsValue(); + const params = {}; + for (let item of S.dynamicParams) { + if (item.required && lds.isEmpty(data[item.variable])) { + message.error(`请设置参数 ${item.name}`); + return + } + if (item.type !== 'upload') params[item.variable] = data[item.variable] + } setLoading(true) - http.patch('/api/pipeline/do/', {id: 1, token: S.token, params}) + http.patch('/api/pipeline/do/', {id: S.record.id, token: S.token, params}) .then(res => { S.dynamicParams = null - }) - .finally(() => setLoading(false)) + }, () => setLoading(false)) + } + + function beforeUpload(file, size) { + if (size) { + const fileSize = file.size / 1024 / 1024; + if (fileSize > size) { + message.error(`上传文件大小不能超过 ${size}MB`); + return Upload.LIST_IGNORE; + } + } } return (
{(S.dynamicParams ?? []).map((item, idx) => item.type === 'upload' ? ( - - + Array.isArray(e) ? e : e?.fileList}> + beforeUpload(file, item.size)}> @@ -40,7 +59,7 @@ function Ask(props) { ))} - +
) diff --git a/spug_web/src/pages/pipeline/console/Body.js b/spug_web/src/pages/pipeline/console/Body.js index e3caf51..39cfaa6 100644 --- a/spug_web/src/pages/pipeline/console/Body.js +++ b/spug_web/src/pages/pipeline/console/Body.js @@ -78,7 +78,6 @@ function Body() { } } socket.onerror = () => setWSState('2') - socket.onclose = () => setWSState('2') return () => socket && socket.close() // eslint-disable-next-line react-hooks/exhaustive-deps }, []) diff --git a/spug_web/src/pages/pipeline/console/index.js b/spug_web/src/pages/pipeline/console/index.js index 647df08..c372c8f 100644 --- a/spug_web/src/pages/pipeline/console/index.js +++ b/spug_web/src/pages/pipeline/console/index.js @@ -14,20 +14,18 @@ import css from './index.module.less'; function Index() { function handleClose() { - S.open = false - S.dynamicParams = null + S.record = null } return ( {S.dynamicParams ? ( diff --git a/spug_web/src/pages/pipeline/console/store.js b/spug_web/src/pages/pipeline/console/store.js index 93a68aa..10fc8c1 100644 --- a/spug_web/src/pages/pipeline/console/store.js +++ b/spug_web/src/pages/pipeline/console/store.js @@ -9,7 +9,7 @@ import { transfer } from '../utils'; class Store { host_id = null; @observable token = null; - @observable open = false; + @observable record = null; @observable node = {}; @observable nodes = []; @observable outputs = {}; @@ -22,12 +22,6 @@ class Store { @computed get matrixNodes() { return transfer(this.nodes) } - - initial = () => { - this.node = {} - this.nodes = [] - this.outputs = {} - } } export default new Store()