From 4db5e0facc9b710dd1c8a7e9ee517589fbfd1c23 Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Wed, 10 Apr 2024 20:30:35 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=96=B0=E5=A2=9E=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=9C=89=E6=95=88=E6=9C=9F=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/keyDelay/index.jsx | 139 +++++++++++++++++++++++++++++ src/components/keyDelay/index.less | 15 ++++ 2 files changed, 154 insertions(+) create mode 100644 src/components/keyDelay/index.jsx create mode 100644 src/components/keyDelay/index.less diff --git a/src/components/keyDelay/index.jsx b/src/components/keyDelay/index.jsx new file mode 100644 index 00000000..46927467 --- /dev/null +++ b/src/components/keyDelay/index.jsx @@ -0,0 +1,139 @@ +import FormItem from "@/components/form-item/main" +import Form from "@/components/form/main" +import { useSetState } from "ahooks" +import moment from "moment" +import { useRef } from "react" +import "./index.less" +import { Button, DateRangePicker, Input, Notify, Radio } from "zent" +export default ({ data, onColes }) => { + const ref = useRef() + const [model, setModel] = useSetState({ + expiration_type: "1", + expiration_value: "" + }) + + function submit() { + if (model.expiration_type == 2 && model.expiration_value.length < 1) { + return Notify.error("请选择固定时间段") + } + if (model.expiration_type == 3 && !model.expiration_value) { + return Notify.error("请输入接口调取后有效期") + } + + console.log(data) + } + + function onDisabledRange(date, type) { + let step1 = JSON.parse(sessionStorage.getItem("knockGold_effectDate")) + let isdisabled = false + let str = moment(date).format("YYYY-MM-DD HH:mm:ss") + let isDay = moment(step1.end_time).format("HH:mm:ss") + if (type == "start") { + if (isDay < "23:59:59") { + isdisabled = + moment(str).isBefore(step1.begin_time) || + moment(str).subtract(1, "days").isAfter(step1.end_time) + } else { + isdisabled = moment(str).isBefore(step1.begin_time) || moment(str).isAfter(step1.end_time) + } + } + + if (type == "end") { + isdisabled = + moment(str).add(1, "days").isBefore(step1.begin_time) || moment(str).isAfter(step1.end_time) + } + return isdisabled + } + + return ( + <> +
+ + { + setModel({ + expiration_value: "", + expiration_type: e.target.value + }) + }} + > + 不设置 + 固定时间段 + 接口调取后有效期 + + + + {model.expiration_type === "2" ? ( + + { + setModel({ + expiration_value: e + }) + }} + disabledDate={onDisabledRange} + /> + + ) : null} + + {model.expiration_type === "3" ? ( + + { + let time = sessionStorage.getItem("knockGold_effectDate") + if (time) { + time = JSON.parse(time) + + // 开始时间和结束时间 + let begin_time = new Date(time.begin_time) + let end_time = new Date(time.end_time) + + // 计算毫秒数差异 + let timeDiff = end_time.getTime() - begin_time.getTime() + + // 将毫秒数差异转换为天数 + let daysDiff = Math.ceil(timeDiff / (1000 * 60 * 60 * 24)) + + // 输入的天数必须小于等于天数 + if (daysDiff >= Number(e.target.value)) { + setModel({ + expiration_value: e.target.value + }) + } else { + Notify.clear() + Notify.error(`key码有效期不能超过计划有效期(${daysDiff}天)`) + return + } + } + }} + /> + + ) : null} +

+ + +

+
+ + ) +} diff --git a/src/components/keyDelay/index.less b/src/components/keyDelay/index.less new file mode 100644 index 00000000..49b00bb9 --- /dev/null +++ b/src/components/keyDelay/index.less @@ -0,0 +1,15 @@ + .form { + #keyDelay { + margin-bottom: 20px; + } + + #keyDelay .form-compontent { + padding-top: 0 !important; + } + + .keyDelay-but { + display: flex; + justify-content: flex-end; + margin-top: 40px; + } + } \ No newline at end of file