Commit ca93d0f2 authored by chenshouchao's avatar chenshouchao

feat: 代码整理

parent 2489ece8
...@@ -21,7 +21,6 @@ const theme = createTheme({ ...@@ -21,7 +21,6 @@ const theme = createTheme({
MuiMenu: { MuiMenu: {
styleOverrides: { styleOverrides: {
root: { root: {
// maxHeight: "260px",
overflowY: "scroll", overflowY: "scroll",
}, },
}, },
......
// import * as React from "react";
// import { ReactNode, useEffect } from "react";
// import Box from "@mui/material/Box";
// import ButtonComponent from "./Button";
// import tipsIcon from "@/assets/project/information-outline.svg";
// import Popper from "@mui/material/Popper";
// type IMyPopconfirmProps = {
// title: string | ReactNode;
// cancelText?: string;
// okText?: string;
// showCancel?: boolean;
// onCancel?: any;
// onConfirm?: any;
// children: ReactNode;
// };
// const MyPopconfirm = (props: IMyPopconfirmProps) => {
// const {
// title,
// cancelText = "取消",
// okText = "确认",
// showCancel = true,
// onCancel,
// onConfirm,
// } = props;
// const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
// const handleClick = (event: React.MouseEvent<HTMLElement>) => {
// event.nativeEvent.stopImmediatePropagation();
// setAnchorEl(anchorEl ? null : event.currentTarget);
// };
// const open = Boolean(anchorEl);
// const id = open ? "simple-popper" : undefined;
// const handleCancel = () => {
// setAnchorEl(null);
// onCancel && onCancel();
// };
// const handleOk = () => {
// setAnchorEl(null);
// onConfirm && onConfirm();
// };
// useEffect(() => {
// document.addEventListener("click", (e) => {
// setAnchorEl(null);
// });
// }, []);
// return (
// <div>
// <div aria-describedby={id} onClick={handleClick}>
// {props.children && props.children}
// </div>
// <Popper
// id={id}
// open={open}
// anchorEl={anchorEl}
// sx={{
// zIndex: 2000,
// bgcolor: "#fff",
// minWidth: "200px",
// borderRadius: "2px",
// padding: "20px 16px",
// boxShadow: "0px 3px 10px 0px rgba(0, 24, 57, 0.14)",
// }}
// >
// {/* "0 3px 6px -4px #0000001f, 0 6px 16px #00000014, 0 9px 28px 8px #0000000d", */}
// <Box sx={{ marginBottom: "16px" }}>
// <img
// style={{ marginRight: "12px", position: "relative", top: "3px" }}
// src={tipsIcon}
// alt=""
// />
// {title}
// </Box>
// <Box sx={{ display: "flex", justifyContent: "flex-end" }}>
// {showCancel && (
// <ButtonComponent
// text={cancelText}
// // variant="text"
// size="small"
// color="inherit"
// click={handleCancel}
// style={{ marginRight: "12px" }}
// ></ButtonComponent>
// )}
// <ButtonComponent
// text={okText}
// // variant="text"
// size="small"
// click={handleOk}
// ></ButtonComponent>
// </Box>
// </Popper>
// </div>
// );
// };
// export default MyPopconfirm;
// 确认提示框, 支持同一页面多个提示框 // 确认提示框, 支持同一页面多个提示框
import * as React from "react"; import * as React from "react";
import { ReactNode, useMemo } from "react"; import { ReactNode, useMemo } from "react";
......
...@@ -83,7 +83,7 @@ export type IValidator = { ...@@ -83,7 +83,7 @@ export type IValidator = {
}; };
export interface IChoice { export interface IChoice {
key: string; label: string;
value: boolean | string | number; value: boolean | string | number;
} }
......
...@@ -151,7 +151,7 @@ const templateConfigInfoMock = [ ...@@ -151,7 +151,7 @@ const templateConfigInfoMock = [
name: "senior", name: "senior",
required: true, required: true,
defaultValue: "", defaultValue: "",
domType: "select", domType: "checkbox",
classType: "STRING", classType: "STRING",
classTypeName: "String", classTypeName: "String",
value: "", value: "",
...@@ -168,7 +168,20 @@ const templateConfigInfoMock = [ ...@@ -168,7 +168,20 @@ const templateConfigInfoMock = [
regex: "^.[s][m][i]$", regex: "^.[s][m][i]$",
}, },
], ],
choices: [], choices: [
{
label: "123",
value: "123",
},
{
label: "456",
value: "456",
},
{
label: "789",
value: "789",
},
],
parameterGroup: "senior", parameterGroup: "senior",
}, },
{ {
...@@ -177,7 +190,7 @@ const templateConfigInfoMock = [ ...@@ -177,7 +190,7 @@ const templateConfigInfoMock = [
name: "hardware", name: "hardware",
required: true, required: true,
defaultValue: "", defaultValue: "",
domType: "select", domType: "radio",
classType: "STRING", classType: "STRING",
classTypeName: "String", classTypeName: "String",
value: "", value: "",
...@@ -194,7 +207,20 @@ const templateConfigInfoMock = [ ...@@ -194,7 +207,20 @@ const templateConfigInfoMock = [
regex: "^.[s][m][i]$", regex: "^.[s][m][i]$",
}, },
], ],
choices: [], choices: [
{
label: "123",
value: "123",
},
{
label: "456",
value: "456",
},
{
label: "789",
value: "789",
},
],
parameterGroup: "hardware", parameterGroup: "hardware",
}, },
], ],
...@@ -251,18 +277,21 @@ const ParameterSetting = (props: IParameterSettingProps) => { ...@@ -251,18 +277,21 @@ const ParameterSetting = (props: IParameterSettingProps) => {
return item.id === taskId; return item.id === taskId;
}); });
if (taskIndex !== -1) { if (taskIndex !== -1) {
let isCheck = true;
result[taskIndex].parameters.forEach((parameter) => { result[taskIndex].parameters.forEach((parameter) => {
if (parameter.id === parameterId) { if (parameter.id === parameterId) {
console.log(e.target.checked); console.log(e.target.checked);
parameter.hidden = !e.target.checked; parameter.hidden = !e.target.checked;
const checkResult = getCustomTemplateParameterCheckResult( const checkResult =
parameter, getCustomTemplateParameterCheckResult(parameter);
parameter.defaultValue
);
parameter.error = checkResult.error; parameter.error = checkResult.error;
parameter.helperText = checkResult.helperText; parameter.helperText = checkResult.helperText;
} }
if (getCustomTemplateParameterCheckResult(parameter).error === true) {
isCheck = false;
}
}); });
result[taskIndex].isCheck = isCheck;
} }
setTemplateConfigInfo(result); setTemplateConfigInfo(result);
}, },
...@@ -271,24 +300,25 @@ const ParameterSetting = (props: IParameterSettingProps) => { ...@@ -271,24 +300,25 @@ const ParameterSetting = (props: IParameterSettingProps) => {
const handleParameterChange = useCallback( const handleParameterChange = useCallback(
(e: any, parameterId: string) => { (e: any, parameterId: string) => {
console.log(e.target.value, taskId, parameterId);
const result: ITask[] = _.cloneDeep(templateConfigInfo); const result: ITask[] = _.cloneDeep(templateConfigInfo);
console.log(result);
const taskIndex = result.findIndex((item) => { const taskIndex = result.findIndex((item) => {
return item.id === taskId; return item.id === taskId;
}); });
if (taskIndex !== -1) { if (taskIndex !== -1) {
let isCheck = true;
result[taskIndex].parameters.forEach((parameter) => { result[taskIndex].parameters.forEach((parameter) => {
if (parameter.id === parameterId) { if (parameter.id === parameterId) {
parameter.defaultValue = e.target.value; parameter.defaultValue = e.target.value;
const checkResult = getCustomTemplateParameterCheckResult( const checkResult =
parameter, getCustomTemplateParameterCheckResult(parameter);
e.target.value
);
parameter.error = checkResult.error; parameter.error = checkResult.error;
parameter.helperText = checkResult.helperText; parameter.helperText = checkResult.helperText;
} }
if (getCustomTemplateParameterCheckResult(parameter).error === true) {
isCheck = false;
}
}); });
result[taskIndex].isCheck = isCheck;
} }
setTemplateConfigInfo(result); setTemplateConfigInfo(result);
}, },
......
import { IParameter } from "../Project/ProjectSubmitWork/interface"; import { IParameter } from "../Project/ProjectSubmitWork/interface";
export const getCustomTemplateParameterCheckResult = ( export const getCustomTemplateParameterCheckResult = (
parameter: IParameter, parameter: IParameter,
value: string
): { ): {
error: boolean; error: boolean;
helperText: string; helperText: string;
...@@ -12,12 +11,12 @@ export const getCustomTemplateParameterCheckResult = ( ...@@ -12,12 +11,12 @@ export const getCustomTemplateParameterCheckResult = (
if (parameter.required) { if (parameter.required) {
// 提交任务时不展示 // 提交任务时不展示
if (parameter.hidden) { if (parameter.hidden) {
if (Array.isArray(value)) { if (Array.isArray(parameter.defaultValue)) {
if (value.length === 0) { if (parameter.defaultValue.length === 0) {
error = true; error = true;
helperText = "该参数为必填,您必须为该参数赋予默认值"; helperText = "该参数为必填,您必须为该参数赋予默认值";
} }
} else if (value === "" || value === null || value === undefined) { } else if (parameter.defaultValue === "" || parameter.defaultValue === null || parameter.defaultValue === undefined) {
error = true; error = true;
helperText = "该参数为必填,您必须为该参数赋予默认值"; helperText = "该参数为必填,您必须为该参数赋予默认值";
} }
...@@ -32,7 +31,7 @@ export const getCustomTemplateParameterCheckResult = ( ...@@ -32,7 +31,7 @@ export const getCustomTemplateParameterCheckResult = (
if (parameter.validators.length > 0) { if (parameter.validators.length > 0) {
parameter.validators.forEach((validator) => { parameter.validators.forEach((validator) => {
const reg = new RegExp(validator.regex); const reg = new RegExp(validator.regex);
if (!reg.test(value)) { if (!reg.test(parameter.defaultValue)) {
error = true; error = true;
helperText = validator.message; helperText = validator.message;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment