From f98dbd9a855c87cc546f73eae12413fa5a313b2a Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Fri, 7 Nov 2025 15:09:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Select?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Select/Basic/index.d.ts | 2 ++ components/Select/Basic/index.js | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/components/Select/Basic/index.d.ts b/components/Select/Basic/index.d.ts index b52f7e9..0e82c67 100644 --- a/components/Select/Basic/index.d.ts +++ b/components/Select/Basic/index.d.ts @@ -15,6 +15,8 @@ export interface BasicSelectProps extends SelectProps { placeholder?: string; /** 获取 label */ onGetLabel?: (label: string | string[]) => void; + /** 获取选中的项 */ + onGetOption?: (option: Record | Record[]) => void; /** 获取数据 */ onGetData?: (data: Record[]) => void; } diff --git a/components/Select/Basic/index.js b/components/Select/Basic/index.js index 1c85f09..f4233de 100644 --- a/components/Select/Basic/index.js +++ b/components/Select/Basic/index.js @@ -1,6 +1,5 @@ import { Select } from "antd"; import { useEffect } from "react"; -import { getLabelName } from "../../../utils"; /** * 基础下拉组件(不建议直接使用此组件,二次继承使用) @@ -10,6 +9,7 @@ function BasicSelect(props) { onGetData, onChange, onGetLabel, + onGetOption, placeholder = "", data = [], nameKey = "name", @@ -20,21 +20,33 @@ function BasicSelect(props) { const handleChange = (event, option) => { if (Array.isArray(event)) { if (event.length > 0) { - const name = []; + const findItems = []; + const names = []; event.forEach((item) => { - name.push(getLabelName({ list: data, status: item, idKey, nameKey })); + const findItem = data.find(dataItem => dataItem[idKey] === item); + if (findItem) { + findItems.push(findItem); + names.push(findItem[nameKey]); + } }); - onGetLabel?.(name); + onGetLabel?.(names); + onGetOption?.(findItems); } else { onGetLabel?.([]); + onGetOption?.([]); } } else { - if (event) - onGetLabel?.(getLabelName({ list: data, status: event, idKey, nameKey })); - else + if (event) { + const findItem = data.find(item => item[idKey] === event); + onGetLabel?.(findItem[nameKey]); + onGetOption?.(findItem); + } + else { onGetLabel?.(""); + onGetOption?.({}); + } } onChange?.(event, option); };