Commit ca93d0f2 authored by chenshouchao's avatar chenshouchao

feat: 代码整理

parent 2489ece8
......@@ -21,7 +21,6 @@ const theme = createTheme({
MuiMenu: {
styleOverrides: {
root: {
// maxHeight: "260px",
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 { ReactNode, useMemo } from "react";
......
......@@ -83,7 +83,7 @@ export type IValidator = {
};
export interface IChoice {
key: string;
label: string;
value: boolean | string | number;
}
......
......@@ -151,7 +151,7 @@ const templateConfigInfoMock = [
name: "senior",
required: true,
defaultValue: "",
domType: "select",
domType: "checkbox",
classType: "STRING",
classTypeName: "String",
value: "",
......@@ -168,7 +168,20 @@ const templateConfigInfoMock = [
regex: "^.[s][m][i]$",
},
],
choices: [],
choices: [
{
label: "123",
value: "123",
},
{
label: "456",
value: "456",
},
{
label: "789",
value: "789",
},
],
parameterGroup: "senior",
},
{
......@@ -177,7 +190,7 @@ const templateConfigInfoMock = [
name: "hardware",
required: true,
defaultValue: "",
domType: "select",
domType: "radio",
classType: "STRING",
classTypeName: "String",
value: "",
......@@ -194,7 +207,20 @@ const templateConfigInfoMock = [
regex: "^.[s][m][i]$",
},
],
choices: [],
choices: [
{
label: "123",
value: "123",
},
{
label: "456",
value: "456",
},
{
label: "789",
value: "789",
},
],
parameterGroup: "hardware",
},
],
......@@ -251,18 +277,21 @@ const ParameterSetting = (props: IParameterSettingProps) => {
return item.id === taskId;
});
if (taskIndex !== -1) {
let isCheck = true;
result[taskIndex].parameters.forEach((parameter) => {
if (parameter.id === parameterId) {
console.log(e.target.checked);
parameter.hidden = !e.target.checked;
const checkResult = getCustomTemplateParameterCheckResult(
parameter,
parameter.defaultValue
);
const checkResult =
getCustomTemplateParameterCheckResult(parameter);
parameter.error = checkResult.error;
parameter.helperText = checkResult.helperText;
}
if (getCustomTemplateParameterCheckResult(parameter).error === true) {
isCheck = false;
}
});
result[taskIndex].isCheck = isCheck;
}
setTemplateConfigInfo(result);
},
......@@ -271,24 +300,25 @@ const ParameterSetting = (props: IParameterSettingProps) => {
const handleParameterChange = useCallback(
(e: any, parameterId: string) => {
console.log(e.target.value, taskId, parameterId);
const result: ITask[] = _.cloneDeep(templateConfigInfo);
console.log(result);
const taskIndex = result.findIndex((item) => {
return item.id === taskId;
});
if (taskIndex !== -1) {
let isCheck = true;
result[taskIndex].parameters.forEach((parameter) => {
if (parameter.id === parameterId) {
parameter.defaultValue = e.target.value;
const checkResult = getCustomTemplateParameterCheckResult(
parameter,
e.target.value
);
const checkResult =
getCustomTemplateParameterCheckResult(parameter);
parameter.error = checkResult.error;
parameter.helperText = checkResult.helperText;
}
if (getCustomTemplateParameterCheckResult(parameter).error === true) {
isCheck = false;
}
});
result[taskIndex].isCheck = isCheck;
}
setTemplateConfigInfo(result);
},
......
import { IParameter } from "../Project/ProjectSubmitWork/interface";
export const getCustomTemplateParameterCheckResult = (
parameter: IParameter,
value: string
): {
error: boolean;
helperText: string;
......@@ -12,12 +11,12 @@ export const getCustomTemplateParameterCheckResult = (
if (parameter.required) {
// 提交任务时不展示
if (parameter.hidden) {
if (Array.isArray(value)) {
if (value.length === 0) {
if (Array.isArray(parameter.defaultValue)) {
if (parameter.defaultValue.length === 0) {
error = true;
helperText = "该参数为必填,您必须为该参数赋予默认值";
}
} else if (value === "" || value === null || value === undefined) {
} else if (parameter.defaultValue === "" || parameter.defaultValue === null || parameter.defaultValue === undefined) {
error = true;
helperText = "该参数为必填,您必须为该参数赋予默认值";
}
......@@ -32,7 +31,7 @@ export const getCustomTemplateParameterCheckResult = (
if (parameter.validators.length > 0) {
parameter.validators.forEach((validator) => {
const reg = new RegExp(validator.regex);
if (!reg.test(value)) {
if (!reg.test(parameter.defaultValue)) {
error = true;
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