From 5b7b608a6acd3a6178687372cdb6b74198e23376 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期二, 03 三月 2026 13:52:44 +0800
Subject: [PATCH] #
---
rsf-admin/src/page/components/DictionarySelect.jsx | 50 +++++++++++++++++++++++++++++++++-----------------
1 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/rsf-admin/src/page/components/DictionarySelect.jsx b/rsf-admin/src/page/components/DictionarySelect.jsx
index 41101ee..e6934f9 100644
--- a/rsf-admin/src/page/components/DictionarySelect.jsx
+++ b/rsf-admin/src/page/components/DictionarySelect.jsx
@@ -9,21 +9,21 @@
import request from '@/utils/request';
const DictionarySelect = (props) => {
- const {
- dictTypeCode,
- name,
+ const {
+ dictTypeCode,
+ name,
group,
- multiple = false,
+ multiple = false,
perPage = 100, // 榛樿姣忛〉鏄剧ず100鏉℃暟鎹�
page = 1, // 榛樿绗竴椤�
- ...parmas
+ ...parmas
} = props;
const translate = useTranslate();
const notify = useNotify();
const { watch } = useFormContext();
const [list, setList] = useState([]);
const [loading, setLoading] = useState(false);
-
+
// 鑾峰彇褰撳墠琛ㄥ崟鍊�
const currentValue = watch(name);
@@ -34,13 +34,13 @@
const http = async () => {
setLoading(true);
try {
- const res = await request.post('/dictData/page', {
+ const res = await request.post('/dictData/page', {
dictTypeCode,
group,
current: page,
pageSize: perPage
});
-
+
if (res?.data?.code === 200) {
setList(res.data.data.records.map((item) => {
return {
@@ -64,21 +64,37 @@
if (!list || list.length === 0) {
// 濡傛灉鍒楄〃涓虹┖浣嗗綋鍓嶆湁鍊硷紝娣诲姞鍗犱綅閫夐」浠ラ伩鍏嶈鍛�
if (currentValue !== undefined && currentValue !== null && currentValue !== '') {
+ if (multiple && Array.isArray(currentValue)) {
+ return currentValue.map(v => ({ id: v, name: String(v) }));
+ }
return [{ id: currentValue, name: String(currentValue) }];
}
return [];
}
-
- // 妫�鏌ュ綋鍓嶅�兼槸鍚﹀湪閫夐」涓�
- const valueExists = list.some(item => String(item.id) === String(currentValue));
-
- // 濡傛灉褰撳墠鍊间笉鍦ㄩ�夐」涓紝娣诲姞瀹冿紙鍙兘鏄姞杞藉欢杩熷鑷寸殑锛�
- if (currentValue !== undefined && currentValue !== null && currentValue !== '' && !valueExists) {
- return [...list, { id: currentValue, name: String(currentValue) }];
+
+ if (currentValue !== undefined && currentValue !== null && currentValue !== '') {
+ if (multiple && Array.isArray(currentValue)) {
+ let newChoices = [...list];
+ currentValue.forEach(val => {
+ const exists = newChoices.some(item => String(item.id) === String(val));
+ if (!exists) {
+ newChoices.push({ id: val, name: String(val) });
+ }
+ });
+ return newChoices;
+ } else {
+ // 妫�鏌ュ綋鍓嶅�兼槸鍚﹀湪閫夐」涓�
+ const valueExists = list.some(item => String(item.id) === String(currentValue));
+
+ // 濡傛灉褰撳墠鍊间笉鍦ㄩ�夐」涓紝娣诲姞瀹冿紙鍙兘鏄姞杞藉欢杩熷鑷寸殑锛�
+ if (!valueExists) {
+ return [...list, { id: currentValue, name: String(currentValue) }];
+ }
+ }
}
-
+
return list;
- }, [list, currentValue]);
+ }, [list, currentValue, multiple]);
const InputComponent = multiple ? SelectArrayInput : SelectInput;
--
Gitblit v1.9.1