diff --git a/src/pages/Sys/Suite/components/AddModal.tsx b/src/pages/Sys/Suite/components/AddModal.tsx index cf65c1c5c20950a77163ad507468d59d851a24ac..b44ea7ae910a9fc97fe521f5315ab5c155e9dd18 100644 --- a/src/pages/Sys/Suite/components/AddModal.tsx +++ b/src/pages/Sys/Suite/components/AddModal.tsx @@ -1,5 +1,6 @@ import React from "react" -import { Modal, Form, Input, Space, Button } from "antd" +import { Modal, Form, Input, Space, Button, message } from "antd" +import { addSuite, putSuite } from "../services"; type IProps = { onOk: () => void; @@ -31,24 +32,38 @@ const ReactComponent: React.ForwardRefRenderFunction = (props, re setVisible(false) setLoading(false) setSource(undefined) + form.resetFields() } const handleOk = async () => { if (loading) return setLoading(true) - onOk() - handleCancel() + + form.validateFields() + .then( + async (values) => { + const { msg, code } = source ? await putSuite({ id: source.id, ...values }) : await addSuite(values) + setLoading(false) + if (code !== 200) return message.error(msg) + message.success("操作成功!") + onOk() + handleCancel() + } + ) + .catch(err => { + setLoading(false) + }) } return ( - + } onCancel={handleCancel} @@ -57,9 +72,12 @@ const ReactComponent: React.ForwardRefRenderFunction = (props, re
- - + + + {/* + + */}
) diff --git a/src/pages/Sys/Suite/index.tsx b/src/pages/Sys/Suite/index.tsx index 2dde64760578e0752ef3f34d3bd3132b4256557f..67a31ccb6a9d4da5c0a4d7d05c66385e40b94c65 100644 --- a/src/pages/Sys/Suite/index.tsx +++ b/src/pages/Sys/Suite/index.tsx @@ -1,20 +1,24 @@ import React from "react" -import { Table, Space, Typography, Row, Button } from "antd" -import { queryList } from "./services" +import { Table, Space, Typography, Row, Button, Input, message } from "antd" +import { queryList, deleteTestSuite } from "./services" import { useRequest } from "ahooks" import AddModal from "./components/AddModal" +import { useAccess, Access } from "umi" +import DeleteModal from "@/pages/Outline/components/DeleteModal"; const DEFAULT_PAGE_QUERY = { page_size: 20, page_num: 1 } const TableList: React.FC = () => { - const [pageQuery, setPageQuery] = React.useState(DEFAULT_PAGE_QUERY) + const access = useAccess() + const [pageQuery, setPageQuery] = React.useState<{ [k: string]: any }>(DEFAULT_PAGE_QUERY) const { data: dataSource, loading, refresh } = useRequest( (params = pageQuery) => queryList(params), - { refreshDeps: [pageQuery], manual: true } + { refreshDeps: [pageQuery] } ) const addModalRef = React.useRef(null) as any + const delModalRef = React.useRef(null) as any const handleAdd = async () => { addModalRef.current?.show() @@ -25,13 +29,39 @@ const TableList: React.FC = () => { } const handleDelete = async (row: any) => { - + delModalRef.current?.show(row) } - const columns = [{ - title: "", - dataIndex: "", - }, { + const columns: any = [{ + title: "测试套名称", + dataIndex: "name", + render(_: any) { + return _ || "-" + } + }, + /* { + title: "备注", + dataIndex: "desc", + render(_: any) { + return _ || "-" + } + }, */ + { + title: "创建人", + dataIndex: "creator", + render(_: any) { + return _ || "-" + } + }, + { + title: "创建时间", + dataIndex: "gmt_created", + render(_: any) { + return _ || "-" + } + }, + access.canTestAdmin() && + { title: "操作", render(row: any) { return ( @@ -40,12 +70,26 @@ const TableList: React.FC = () => { 编辑 handleDelete(row)}> - 删除 + 删除 ) } - }] + }].filter(Boolean) + + const onDelete = async (row: any) => { + const { code, msg } = await deleteTestSuite({ ids: [row.id] }) + if (code !== 200) return message.error(msg) + const { page_size = 10, page_num = 1 } = pageQuery + const totalPage: number = Math.ceil((dataSource.total - 1) / page_size) || 1 + + if (totalPage <= page_num) { + pageQuery.page_num = totalPage + setPageQuery(pageQuery) + } else { + refresh() + } + } return ( @@ -53,8 +97,23 @@ const TableList: React.FC = () => { 测试套管理 - - + + setPageQuery({ ...DEFAULT_PAGE_QUERY, name: val })} + /> + + + + + { ref={addModalRef} onOk={refresh} /> - + + ) } diff --git a/src/pages/Sys/Suite/services.ts b/src/pages/Sys/Suite/services.ts index dc9b6e334cb43508e36ef68c9bd890b597989445..ada71515b2ce34bd8bfe542081042a0821208fa3 100644 --- a/src/pages/Sys/Suite/services.ts +++ b/src/pages/Sys/Suite/services.ts @@ -1,5 +1,29 @@ import { request } from "umi"; -export const queryList = async (params: any) => { - return request(`/api/`, { params }) +type TestSuiteQueryProps = { + page_size?: number; + page_num?: number; + name?: string; + is_paginate?: boolean +} + +/* ○ page_size:页面大小,默认1 +○ page_num 分页页数,默认50 +○ name:标签前缀 +○ is_paginate */ + +export const queryList = async (params: TestSuiteQueryProps) => { + return request(`/api/case/suites/`, { params }) +} + +export const deleteTestSuite = async (params: any) => { + return request(`/api/case/suite`, { params, method: "delete" }) +} + +export const putSuite = async (data: any) => { + return request(`/api/case/suite/rename/`, { data, method: "post" }) +} + +export const addSuite = async (data: any) => { + return request(`/api/case/suite`, { data, method: "post" }) } \ No newline at end of file