From 6d8ce0c7005370c10f5508e965e4385dd7d42671 Mon Sep 17 00:00:00 2001 From: Linzp Date: Mon, 12 Jan 2026 11:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9TypeDate=E6=8A=A5=E9=94=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- .../TypeDateRangePickerField/index.js | 118 +++++------- src/components/Enum/index.js | 174 +++++------------- 3 files changed, 92 insertions(+), 202 deletions(-) diff --git a/package.json b/package.json index 0d2c7462..fe60d31f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kne-components/components-core", - "version": "0.4.49", + "version": "0.4.50", "files": [ "build" ], diff --git a/src/common/components/TypeDateRangePickerField/index.js b/src/common/components/TypeDateRangePickerField/index.js index 6a180552..1ea0182f 100644 --- a/src/common/components/TypeDateRangePickerField/index.js +++ b/src/common/components/TypeDateRangePickerField/index.js @@ -1,81 +1,49 @@ -import { DatePicker, Select, Space } from "antd"; +import {DatePicker, Select, Space} from "antd"; import useControlValue from "@kne/use-control-value"; import dayjs from "dayjs"; import importMessages from "../locale"; -import { createWithIntl, useIntl } from "@components/Intl"; +import {createWithIntl, useIntl} from "@components/Intl"; -const TypeDatePickerField = ({ ...props }) => { - const { formatMessage } = useIntl({ moduleName: "Common" }); - const typeList = new Map([ - ["date", formatMessage({ id: "customTime" })], - ["month", formatMessage({ id: "monthly" })], - ["week", formatMessage({ id: "weekly" })], - ]); - const [value, onChange] = useControlValue(props); - return ( - - { + onChange((value) => { + if (!value?.value?.length) { + return {value: null, type: typeValue || "date"}; + } + const startTime = dayjs(value.value[0]), endTime = dayjs(value.value[1]); + return { + value: [startTime.isValid() ? startTime.startOf(typeValue || "date") : null, endTime.isValid() ? endTime.endOf(typeValue || "date") : null], + type: typeValue || "date", + }; + }); + }} + options={Array.from(typeList).map(([value, label]) => ({ + label, value, + }))} + /> + item && dayjs(item))} + onChange={(dateValue) => { + onChange((value) => { + console.log(Object.assign({type: "date"}, value, { + value: dateValue && [dateValue[0] && new Date(dateValue[0].startOf(value?.type || "date").valueOf()), dateValue[1] && new Date(dateValue[1].endOf(value?.type || "date").valueOf()),], + })); + return Object.assign({type: "date"}, value, { + value: dateValue && [dateValue[0] && new Date(dateValue[0].startOf(value?.type || "date").valueOf()), dateValue[1] && new Date(dateValue[1].endOf(value?.type || "date").valueOf()),], + }); + }); + }} + /> + ); }; -export default createWithIntl({ importMessages, moduleName: "Common" })( - TypeDatePickerField -); +export default createWithIntl({importMessages, moduleName: "Common"})(TypeDatePickerField); diff --git a/src/components/Enum/index.js b/src/components/Enum/index.js index 5c2c6f2b..5ec7e6fb 100644 --- a/src/components/Enum/index.js +++ b/src/components/Enum/index.js @@ -1,132 +1,54 @@ -import { preset } from "@kne/react-enum"; +import {preset} from "@kne/react-enum"; import transform from "lodash/transform"; -const baseLoaders = [ - [ - "gender", - () => [ - { value: "M", description: "男" }, - { - value: "F", - description: "女", - }, - ], - ], - [ - "marital", - () => [ - { description: "已婚", value: "Y" }, - { - description: "未婚", - value: "N", - }, - ], - ], - [ - "confirm", - () => [ - { description: "是", value: "Y" }, - { - description: "否", - value: "N", - }, - ], - ], - [ - "political", - () => [ - { description: "中共党员", value: "中共党员" }, - { - description: "共青团员", - value: "共青团员", - }, - { description: "群众", value: "群众" }, - { - description: "其他党派", - value: "其他党派", - }, - ], - ], - [ - "phoneStateEnum", - () => [ - { - value: 0, - description: "空号", - }, - { - value: 1, - description: "实号", - }, - { - value: 2, - description: "停机", - }, - { - value: 3, - description: "库无", - }, - { - value: 4, - description: "沉默号", - }, - { - value: 5, - description: "风险号", - }, - ], - ], - [ - "degreeEnum", - () => [ - { - description: "初中", - value: 10, - }, - { - description: "中专", - value: 20, - }, - { - description: "高中", - value: 30, - }, - { - description: "大专", - value: 40, - }, - { - description: "本科", - value: 50, - }, - { - description: "硕士研究生", - value: 60, - }, - { - description: "博士研究生", - value: 70, - }, - { - description: "博士后", - value: 75, - }, - { - description: "学历不限", - value: 999, - }, - ], - ], -]; +const baseLoaders = [['commonStatus', () => [{value: 'open', description: '开启', type: 'success',}, { + value: 'close', description: '关闭', type: 'danger' +}]], ["gender", () => [{value: "M", description: "男"}, { + value: "F", description: "女", +},],], ["marital", () => [{description: "已婚", value: "Y"}, { + description: "未婚", value: "N", +},],], ["confirm", () => [{description: "是", value: "Y"}, { + description: "否", value: "N", +},],], ["political", () => [{description: "中共党员", value: "中共党员"}, { + description: "共青团员", value: "共青团员", +}, {description: "群众", value: "群众"}, { + description: "其他党派", value: "其他党派", +},],], ["phoneStateEnum", () => [{ + value: 0, description: "空号", +}, { + value: 1, description: "实号", +}, { + value: 2, description: "停机", +}, { + value: 3, description: "库无", +}, { + value: 4, description: "沉默号", +}, { + value: 5, description: "风险号", +},],], ["degreeEnum", () => [{ + description: "初中", value: 10, +}, { + description: "中专", value: 20, +}, { + description: "高中", value: 30, +}, { + description: "大专", value: 40, +}, { + description: "本科", value: 50, +}, { + description: "硕士研究生", value: 60, +}, { + description: "博士研究生", value: 70, +}, { + description: "博士后", value: 75, +}, { + description: "学历不限", value: 999, +},],],]; preset({ - base: transform( - baseLoaders, - (result, value) => { - result[value[0]] = value[1]; - }, - {} - ), + base: transform(baseLoaders, (result, value) => { + result[value[0]] = value[1]; + }, {}), }); -export { default } from "@kne/react-enum"; +export {default} from "@kne/react-enum";