diff --git a/src/pages/Product/TestProduct/EnterEnv.tsx b/src/pages/Product/TestProduct/EnterEnv.tsx new file mode 100644 index 0000000000000000000000000000000000000000..78bd6319849cf6f413f420ac63fe3361549252c5 --- /dev/null +++ b/src/pages/Product/TestProduct/EnterEnv.tsx @@ -0,0 +1,81 @@ +import React from "react"; +import { Form, Modal, Input, Space, Row, Button } from "antd"; + +const EnterEnv: React.ForwardRefRenderFunction = (props, ref) => { + const { onOk, onCancel } = props + const [open, setOpen] = React.useState(false) + + const [form] = Form.useForm() + + React.useImperativeHandle(ref, () => ({ + show() { + setOpen(true) + } + })) + + const handleCancel = () => { + setOpen(false) + form.resetFields() + onCancel?.() + } + + const handleOk = () => { + form.validateFields() + .then(async (values) => { + onOk?.(values) + .then(() => { + console.log("ok") + handleCancel() + }) + }) + } + + return ( + + + + + + + } + > +
+ ({ + validator(rule, value) { + if (value) { + const reg = /^(\w+=((('[^']+'|"[^"]+")|.+)( |\n)))*\w+=(('[^']+'|"[^"]+")|.+)$/ + return reg.test(value) ? + Promise.resolve() : + Promise.reject('格式:key=value,多个用空格或换行分割'); + } + else + return Promise.resolve() + }, + }) + ]} + > + + +
+
+ ) +} + +export default React.forwardRef(EnterEnv) \ No newline at end of file diff --git a/src/pages/Product/TestProduct/ProductCard.tsx b/src/pages/Product/TestProduct/ProductCard.tsx index 1f07c0d66dda8335f8d9f45642e3ee104a549e3d..40d1cda8b1f5fb5a71f892881406fed906144b2c 100644 --- a/src/pages/Product/TestProduct/ProductCard.tsx +++ b/src/pages/Product/TestProduct/ProductCard.tsx @@ -1,12 +1,13 @@ import { Dropdown, Space, Tag, Typography, Menu, Divider, Button, Row, Col, message } from "antd" import React from "react" import styled from "styled-components" -import { MoreOutlined } from "@ant-design/icons" +import { MoreOutlined, DownOutlined } from "@ant-design/icons" import EditProduct from "@/pages/Product/TestProduct/CreateProduct" import { CardCls } from "../styled" import { history, useAccess } from "@umijs/max" import { deleteOneProduct, runOneProduct } from "./services" import DeleteModal from '@/pages/Outline/components/DeleteModal'; +import EnterEnv from "./EnterEnv" /* @ts-ignore */ const HoverMenu = styled(Menu)` @@ -44,6 +45,7 @@ const ProductCard: React.FC = ({ const access = useAccess() const editRef = React.useRef(null) as any const deleteModalRef = React.useRef(null) as any + const enterEnvRef = React.useRef(null) as any const handleDeleteProduct = async () => { const { code, msg } = await deleteOneProduct(id) @@ -58,8 +60,8 @@ const ProductCard: React.FC = ({ } } - const hanldeRun = async () => { - const { code, msg } = await runOneProduct(id) + const hanldeRun = async (params?: any) => { + const { code, msg } = await runOneProduct({ ...params, test_product_id: id }) if (code !== 200) return message.error(msg) history.push(`/product/record`) } @@ -68,6 +70,13 @@ const ProductCard: React.FC = ({ refresh?.() } + const handleClickMenu = ({ key }: any) => { + switch (key) { + case "run": return hanldeRun() + case "enter_env_run": return enterEnvRef.current?.show() + } + } + return ( = ({ overlay={ } > @@ -120,14 +127,36 @@ const ProductCard: React.FC = ({ - + + + 直接运行 + + + 写入配置并运行 + + + } + > + + + ) } diff --git a/src/pages/Product/TestProduct/services.ts b/src/pages/Product/TestProduct/services.ts index 07895204b99d9dfdb676b422bfe8d1fd7cf36fc6..1b4db81a2ba7a484294cf43d50a7c6bdb421218e 100644 --- a/src/pages/Product/TestProduct/services.ts +++ b/src/pages/Product/TestProduct/services.ts @@ -32,8 +32,8 @@ export const deleteOneProduct = async (test_product_id: string | number) => { return request(`/api/product/${test_product_id}`, { method: 'delete' }); }; -export const runOneProduct = async (test_product_id: string | number | number) => { - return request(`/api/product/run/${test_product_id}`); +export const runOneProduct = async (data: any) => { + return request(`/api/product/run/`, { method: "post", data }); }; export const queryCategoryList = async () => {