diff --git a/package.json b/package.json index e958a94f607062d97bb7251991ba500ff7ea508e..86a6ec278b34905f8634afe1770bd0b69cf8eabc 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "reflect-metadata": "^0.2.2", "type-fest": "^4.20.0", "umi-request": "^1.4.0", - "uuid": "^10.0.0" + "uuid": "^10.0.0", + "zustand": "^4.5.4" }, "devDependencies": { "@types/react": "^18.2.66", diff --git a/src/components/ArrowTag/index.module.css b/src/components/ArrowTag/index.module.css index 62131bcc280113d82c059cfd00cb4cbcd16e6193..ffd3c533ecf7e0be58ec26d18171564e9b40d39f 100644 --- a/src/components/ArrowTag/index.module.css +++ b/src/components/ArrowTag/index.module.css @@ -16,4 +16,5 @@ font-weight: 600; font-size: 16px; padding: 0 10px 0 5px; + transform: translateX(-1px); } diff --git a/src/components/BasicModal/index.tsx b/src/components/BasicModal/index.tsx index 9e6e54ae3ff62ae0bb6d9d29586189bb9d48b184..ee61a4f5350e92a7b31734ccc4f4ff74479b6723 100644 --- a/src/components/BasicModal/index.tsx +++ b/src/components/BasicModal/index.tsx @@ -28,7 +28,12 @@ const BasicModal: React.FC> = (props) => { } return ( -
+
e.stopPropagation()} + >
{ const componentsRegister = useMemo(() => { const composeProps = { ...newProps, ...config }; + switch (componentType) { case "TextInput": return ; + case "NumberInput": + return ; case "Branch": return ""; case "DatePicker": - return ; + return ( + { + console.log(str); + }} + > + ); case "TextAreaInput": return ; case "Radio": return ; case "Select": - return ; default: return ""; } diff --git a/src/config/dev.ts b/src/config/dev.ts new file mode 100644 index 0000000000000000000000000000000000000000..d81d7030d1c1d2bfa7effb79ed9e186a993c5641 --- /dev/null +++ b/src/config/dev.ts @@ -0,0 +1,3 @@ +export default { + imgHost: "http://192.168.2.24:9000", +}; diff --git a/src/config/util.ts b/src/config/util.ts new file mode 100644 index 0000000000000000000000000000000000000000..bf1bbcab8ad0c6346157ed1215179cca700bb754 --- /dev/null +++ b/src/config/util.ts @@ -0,0 +1,5 @@ +import dev from "./dev"; + +export function composeImgUrl(imgStr: string) { + return `${dev.imgHost}${imgStr}`; +} diff --git a/src/customForm/components/Checkbox/index.tsx b/src/customForm/components/Checkbox/index.tsx index 3aa5a41c6c77325c232c22b86f3611df0c75eaa1..466964f84ffc7602f27ffbfe28ae9a6b12a2ecf2 100644 --- a/src/customForm/components/Checkbox/index.tsx +++ b/src/customForm/components/Checkbox/index.tsx @@ -17,7 +17,7 @@ const Checkbox = ({ value, onChange, options }: CheckboxProps) => { const [selected, setSelected] = useState([]); useEffect(() => { - if (typeof value === "object" && isEqual(value, selected)) { + if (typeof value === "object" && !isEqual(value, selected)) { setSelected(value); } }, [value]); @@ -53,6 +53,9 @@ const Checkbox = ({ value, onChange, options }: CheckboxProps) => {
); } + if (options && options.length === 0) { + return
没有可供选择的选项
; + } return (
void; + value?: any; + isRange: boolean; +} + +const HnDatePicker: React.FC = (props) => { + const { isRange, value, picker, onChange } = props; + + if (isRange) { + return ( + + ); + } + return ( + + ); +}; + +export default HnDatePicker; diff --git a/src/customForm/components/FileUpload/index.tsx b/src/customForm/components/FileUpload/index.tsx index 84ac5c01d47e7a93da207ee80782c518d460152e..a7635f2609f6a57fdd8b4aab7cca6e60fc3f4754 100644 --- a/src/customForm/components/FileUpload/index.tsx +++ b/src/customForm/components/FileUpload/index.tsx @@ -1,37 +1,70 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import { InboxOutlined } from "@ant-design/icons"; import type { UploadProps } from "antd"; import { message, Upload } from "antd"; +import { isEqual } from "lodash"; const { Dragger } = Upload; -const props: UploadProps = { - name: "file", - multiple: true, - action: "https://660d2bd96ddfa2943b33731c.mockapi.io/api/upload", - onChange(info) { - const { status } = info.file; - if (status !== "uploading") { - console.log(info.file, info.fileList); - } - if (status === "done") { - message.success(`${info.file.name} file uploaded successfully.`); - } else if (status === "error") { - message.error(`${info.file.name} file upload failed.`); +interface FileUploadProps { + onChange: (params: string) => void; + value: string; + placeholder?: string; +} + +const FileUpload: React.FC = (props) => { + const { placeholder, value, onChange } = props; + const [fileList, setFilList] = useState([]); + useEffect(() => { + if (typeof value === "string") { + const list = value?.split(","); + if (list && list.length > 0 && isEqual(fileList, list)) { + setFilList(list); + } } - }, - onDrop(e) { - console.log("Dropped files", e.dataTransfer.files); - }, -}; + }, [value]); -const FileUpload: React.FC = () => ( - -

- -

-

单击或拖动文件到此区域进行上传

-
-); + const DraggerProps: UploadProps = { + name: "file", + multiple: true, + action: "/apis/oss/upload?bucketName=cgtf", + maxCount: 1, + accept: ".pdf", + onChange(info) { + const { status } = info.file; + if (status === "done") { + const imgStr = info.fileList.map((item) => { + return item.response.data; + }) as string[]; + setFilList(imgStr); + onChange(imgStr.join(",")); + message.success(`${info.file.name}上传成功.`); + } else if (status === "error") { + message.error(`${info.file.name}上传失败.`); + } + }, + defaultFileList: fileList.map((v, i) => { + return { + uid: (i + 1).toString(), + name: v, + status: "done", + url: v, + }; + }), + onDrop(e) { + console.log("Dropped files", e.dataTransfer.files); + }, + }; + return ( + +

+ +

+

+ {placeholder ?? "单击或拖动文件到此区域进行上传"} +

+
+ ); +}; export default FileUpload; diff --git a/src/customForm/components/List/index.tsx b/src/customForm/components/List/index.tsx index 1736ffa506461c3a146a556291fbc495fbfd82a5..96db624b2ac258670418943f03744cd3abcb7e14 100644 --- a/src/customForm/components/List/index.tsx +++ b/src/customForm/components/List/index.tsx @@ -1,33 +1,29 @@ import { MinusOutlined, PlusOutlined } from "@ant-design/icons"; -import { Button, Flex, Input, Space } from "antd"; -import { cloneDeep, isEqual } from "lodash"; +import { Button, Flex, Input } from "antd"; +import { cloneDeep } from "lodash"; import { useEffect, useState } from "react"; interface ListProps { - value: { label: string; value: string }[]; - onChange: (params: { label: string; value: string }[]) => void; + value: string[]; + onChange: (params: string[]) => void; } const List = (props: ListProps) => { const { value, onChange } = props; - const [data, setData] = useState([ - { - label: "", - value: "", - }, - ]); + const [data, setData] = useState([""]); useEffect(() => { - if (!value || isEqual(data, value)) { - return; - } else { + if (value && Array.isArray(value) && value.length > 0) { setData(value); + } else { + setData([""]); } + console.log(value); }, [value]); const add = (index: number) => { const temp = cloneDeep(data); - temp.splice(index + 1, 0, { label: "", value: "" }); + temp.splice(index + 1, 0, ""); setData(temp); }; @@ -39,9 +35,9 @@ const List = (props: ListProps) => { const LabelChange = (e: any, index: number) => { const v = e.target.value; const temp = cloneDeep(data); - temp[index].label = v; - temp[index].value = v; + temp[index] = v; setData(temp); + onChange(temp); }; return ( @@ -51,7 +47,7 @@ const List = (props: ListProps) => { LabelChange(e, i)} >