From 5975924e824ec6e67b12c2323ed1907f0eb450c4 Mon Sep 17 00:00:00 2001 From: wulibaibao <13366578180@163.com> Date: Fri, 2 Sep 2022 15:58:16 +0800 Subject: [PATCH 1/2] feat: add task support tone clustor --- config/routes.ts | 11 +++++---- src/app.tsx | 9 +++++--- src/components/Header/index.tsx | 5 +++-- src/pages/Auth/Login/index.tsx | 2 +- src/pages/Task/components/AddTaskModal.tsx | 5 ++--- src/pages/Task/components/ServerSelect.tsx | 26 +++++++++++++++++----- src/pages/Task/services.ts | 7 ++++++ 7 files changed, 46 insertions(+), 19 deletions(-) diff --git a/config/routes.ts b/config/routes.ts index 51b9c07..4f661e2 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -2,6 +2,7 @@ export default [ { path: '/outline', name: 'outline', + access: "canMember", title: 'outline', component: './Outline', }, @@ -9,11 +10,13 @@ export default [ path: '/demand', name: 'demand', title: 'demand', + access: "canMember", component: './Demand', }, { path: '/plan', name: 'plan', + access: "canMember", title: 'plan', routes: [ { @@ -56,6 +59,7 @@ export default [ { path: '/cases', name: 'suite', + access: "canMember", title: 'suite', component: './Suite', routes: [ @@ -69,6 +73,7 @@ export default [ { path: '/task', name: 'task', + access: "canMember", title: 'task', routes: [ { @@ -111,6 +116,7 @@ export default [ path: '/sys', name: 'sys', title: 'sys', + access: "canMember", component: './Sys', routes: [ { @@ -169,13 +175,10 @@ export default [ }, { path: "", - redirect: '/outline', + component: './404', }, { path: "*", - redirect: '/outline', - }, - { component: './404', }, ]; diff --git a/src/app.tsx b/src/app.tsx index 933a2e4..d8c39b7 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -57,17 +57,20 @@ export const layout = (props: any) => { menu: { locale: false, }, - onPageChange: () => { + onPageChange: (_props: any) => { + const { pathname } = _props + if (initialState.currentUser?.role === "visitor" && pathname === "/") + return history.push(`/product/list`) /* group login & regist disabled */ if (siteEnv === "group") { - if (ignorePathname.includes(location.pathname)) { + if (ignorePathname.includes(pathname)) { history.push("/") } } setInitialState({ ...initialState, location }) // 如果没有登录,重定向到 login - if (!initialState?.currentUser && !ignorePathname.includes(location.pathname)) { + if (!initialState?.currentUser && !ignorePathname.includes(pathname)) { toLoginPage() } }, diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index 92e14e7..25cfbf5 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -1,7 +1,7 @@ import React from "react" import { HeaderCls } from './headerStyled'; import { Avatar, Typography, Space, Col, Menu, Row } from "antd" -import { history } from '@umijs/max'; +import { history, useModel } from '@umijs/max'; import type { MenuProps } from "antd" import RightContent from '@/components/RightContent'; import { switchMenuIcon } from "./MenuItemRender"; @@ -21,6 +21,7 @@ const passRoute = (list: any[]) => list.filter(ignorePathFilter) .filter(noLocaleFilter) const Header: React.FC> = (props) => { + const { initialState } = useModel("@@initialState") const { menuData, matchMenuKeys, logo } = props const renderMenuData = passRoute(menuData) @@ -72,7 +73,7 @@ const Header: React.FC> = (props) => { align="center" style={{ width: 96, marginRight: 16, cursor: "pointer" }} size={12} - onClick={() => history.push("/")} + onClick={() => history.push(initialState.currentUser?.role === "visitor" ? "/product/list" : "/")} > { } setInitialState((p: any) => ({ ...p, currentUser: info })) .then(() => { - setTimeout(() => history.push(`/`), 150) + setTimeout(() => history.push(info?.role === "visitor" ? "/product/list" : `/`), 150) }) } catch (error) { diff --git a/src/pages/Task/components/AddTaskModal.tsx b/src/pages/Task/components/AddTaskModal.tsx index 4dbf3d7..b6aee76 100644 --- a/src/pages/Task/components/AddTaskModal.tsx +++ b/src/pages/Task/components/AddTaskModal.tsx @@ -72,7 +72,7 @@ const ReactComponent: React.ForwardRefRenderFunction = (props, re const [workspaceId, setWorkspaceId] = React.useState(null) const [caseList, setCaseList] = React.useState([]) - const { data: cases, run: queryCases } = useRequest(() => request(`/api/case/search/`), { initialData: [], manual: true }) + const { data: cases } = useRequest(() => request(`/api/case/search/`), { initialData: [] }) const planFetcher = async (content?: string): Promise => { const { data } = await request(`/api/plan`, { params: { content, status: "init" } }) @@ -178,10 +178,9 @@ const ReactComponent: React.ForwardRefRenderFunction = (props, re }, [visible, form, query?.test_type]) React.useImperativeHandle(ref, () => ({ - show(_: any) { + async show(_: any) { setVisible(true) getWorkspaces() - queryCases() if (_ && JSON.stringify(_) !== "{}") { if (!~location.pathname.indexOf("/plan/")) setSource(_) diff --git a/src/pages/Task/components/ServerSelect.tsx b/src/pages/Task/components/ServerSelect.tsx index 1c6ec5e..6c5dcb3 100644 --- a/src/pages/Task/components/ServerSelect.tsx +++ b/src/pages/Task/components/ServerSelect.tsx @@ -2,11 +2,12 @@ import React from "react" import { Col, Form, Input, Row, Select } from "antd" import { useRequest } from "@umijs/max" import type { FormInstance } from "antd" -import { getToneServer, getToneTags } from "../services" +import { getToneClusterServer, getToneServer, getToneTags } from "../services" const columns = [ { label: "随机", value: "" }, { label: "指定", value: "device_ip" }, + { label: "集群", value: "cluster" }, { label: "标签", value: "tags" } ] @@ -14,12 +15,15 @@ type Props = { ws_id?: string | null | undefined; device_ip?: string; tags?: string; - form?: FormInstance + form?: FormInstance; + cluster?: string } type Refs = Record -const ServerSelect: React.ForwardRefRenderFunction = ({ ws_id, device_ip, tags, form }, ref) => { +const ServerSelect: React.ForwardRefRenderFunction = (props, ref) => { + const { ws_id, device_ip, tags, form, cluster } = props + const [optVal, setOptVal] = React.useState("") const [options, setOptions] = React.useState([]) @@ -41,12 +45,21 @@ const ServerSelect: React.ForwardRefRenderFunction = ({ ws_id, devi setOptions(data.map((i: any) => ({ label: i, value: i }))) }) } + if (optVal === "tags") { queryTagList(ws_id).then((data) => { if (Object.prototype.toString.call(data) === "[object Array]") setOptions(data.map((i: any) => ({ label: i, value: i }))) }) } + + if (optVal === "cluster") { + getToneClusterServer(ws_id, "aligroup").then((data) => { + const { data: list } = data + if (Object.prototype.toString.call(list) === "[object Array]") + setOptions(list.map((i: any) => ({ label: i, value: i }))) + }) + } } React.useEffect(() => { @@ -56,12 +69,13 @@ const ServerSelect: React.ForwardRefRenderFunction = ({ ws_id, devi React.useEffect(() => { if (device_ip) setOptVal("device_ip") if (tags) setOptVal("tags") - if (!device_ip && !tags) setOptVal("") - }, [device_ip, tags, ws_id]) + if (cluster) setOptVal("cluster") + if (!device_ip && !tags && !cluster) setOptVal("") + }, [device_ip, tags, ws_id, cluster]) const hanldeLeftOptionChange = (v: string) => { setOptVal(v) - form?.resetFields(["device_ip", "tags"]) + form?.resetFields(["device_ip", "tags", "cluster"]) } return ( diff --git a/src/pages/Task/services.ts b/src/pages/Task/services.ts index 512c06d..a4137ab 100644 --- a/src/pages/Task/services.ts +++ b/src/pages/Task/services.ts @@ -54,6 +54,13 @@ export const getToneServer = async ( return request(`/api/tone/server_list/${ws_id}/${provider}/${run_mode}`); }; +export const getToneClusterServer = async ( + ws_id: string, + provider: "aligroup" | "aliyun" +) => { + return request(`/api/tone/cluster_list/${ws_id}/${provider}`) +} + export const getToneTags = async (ws_id: string) => { return request(`/api/tone/server_tag/${ws_id}/`); }; -- Gitee From b1c6e609ffa1f411b9299c2d01e7868514cb7dd2 Mon Sep 17 00:00:00 2001 From: wulibaibao <13366578180@163.com> Date: Fri, 2 Sep 2022 16:28:44 +0800 Subject: [PATCH 2/2] fix: empty route direct to outline --- src/app.tsx | 7 ++++++- src/components/Header/index.tsx | 2 +- src/pages/Auth/Login/index.tsx | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index d8c39b7..7598dd7 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -59,12 +59,14 @@ export const layout = (props: any) => { }, onPageChange: (_props: any) => { const { pathname } = _props + if (initialState.currentUser?.role === "visitor" && pathname === "/") return history.push(`/product/list`) + /* group login & regist disabled */ if (siteEnv === "group") { if (ignorePathname.includes(pathname)) { - history.push("/") + history.push("/outline") } } @@ -73,6 +75,9 @@ export const layout = (props: any) => { if (!initialState?.currentUser && !ignorePathname.includes(pathname)) { toLoginPage() } + + if (["/", ""].includes(pathname)) + history.push('/outline') }, layout: "top", contentStyle: { diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index 25cfbf5..d989899 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -73,7 +73,7 @@ const Header: React.FC> = (props) => { align="center" style={{ width: 96, marginRight: 16, cursor: "pointer" }} size={12} - onClick={() => history.push(initialState.currentUser?.role === "visitor" ? "/product/list" : "/")} + onClick={() => history.push(initialState.currentUser?.role === "visitor" ? "/product/list" : "/outline")} > { } setInitialState((p: any) => ({ ...p, currentUser: info })) .then(() => { - setTimeout(() => history.push(info?.role === "visitor" ? "/product/list" : `/`), 150) + setTimeout(() => history.push(info?.role === "visitor" ? "/product/list" : `/outline`), 150) }) } catch (error) { -- Gitee