import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { Spin } from "antd"; import { LoadingOutlined } from "@ant-design/icons"; import { useRule } from "./PackagingOperation/hooks" const btnTyps = [ { type: "primary", color: "#0185FF" }, { type: "danger", color: "#F5222D" }, { type: "warning", color: "#FAAB0C" }, { type: "success", color: "#85C700" }, { type: "info", color: "#26c1e1" }, { type: "default", color: "rgba(0,0,0,.85)" }, ]; export const Button = React.memo((props) => { const { visible = true, enable = true, title, type = "primary", ghost = false, size, onClick = () => { }, ruleCode, } = props; const rule = useRule(ruleCode); // useEffect(() => { // console.log("rule", rule) // }, [rule]) const types = useRef(btnTyps.map(({ type }) => type)); const sizes = useRef(["large"]); const className = useMemo(() => { let res = "client-btn"; if (type && types.current.includes(type)) res += ` btn-${type}`; if (ghost === true) res += ` btn-ghost`; if (size && sizes.current.includes(size)) res += ` btn-${size}`; if (enable === false) res += ` btn-disabled`; return res; }, [type, ghost, size, enable]); const [loading, setLoading] = useState(false); const handleClick = useCallback(() => { if (enable && !loading) { let res = onClick(); if (res && typeof res.then == "function" && typeof res.finally == "function") { setLoading(true); res.finally(() => setLoading(false)) } } }, [enable, onClick, loading]); if (!rule) return null; if (!visible) return null; return (