From 7972683f56368cd8ce7ef8bb7f1d087416f4a3e7 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期一, 02 二月 2026 13:23:35 +0800
Subject: [PATCH] 容器管理-编辑可入库区  选中数据排序  选择文字排序 兼容修改后的其他调用方法

---
 rsf-admin/src/page/components/DictionarySelect.jsx |   91 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 71 insertions(+), 20 deletions(-)

diff --git a/rsf-admin/src/page/components/DictionarySelect.jsx b/rsf-admin/src/page/components/DictionarySelect.jsx
index 2523c5d..41101ee 100644
--- a/rsf-admin/src/page/components/DictionarySelect.jsx
+++ b/rsf-admin/src/page/components/DictionarySelect.jsx
@@ -1,41 +1,92 @@
 import EditIcon from '@mui/icons-material/Edit';
-import { useState, useEffect } from 'react';
+import { useState, useEffect, useMemo } from 'react';
 import {
     Button, useListContext, SelectInput,
-    required,
+    required, SelectArrayInput,
     useTranslate, useNotify
 } from 'react-admin';
+import { useFormContext } from 'react-hook-form';
 import request from '@/utils/request';
 
 const DictionarySelect = (props) => {
-    const { dictTypeCode, name, ...parmas } = props;
+    const { 
+        dictTypeCode, 
+        name, 
+        group,
+        multiple = false, 
+        perPage = 100,  // 榛樿姣忛〉鏄剧ず100鏉℃暟鎹�
+        page = 1,       // 榛樿绗竴椤�
+        ...parmas 
+    } = props;
     const translate = useTranslate();
     const notify = useNotify();
-    const [list, setList] = useState([])
+    const { watch } = useFormContext();
+    const [list, setList] = useState([]);
+    const [loading, setLoading] = useState(false);
+    
+    // 鑾峰彇褰撳墠琛ㄥ崟鍊�
+    const currentValue = watch(name);
 
     useEffect(() => {
-        http()
-    }, [dictTypeCode]);
+        http();
+    }, [dictTypeCode, page, perPage]);
 
     const http = async () => {
-        const res = await request.post('/dictData/page', { dictTypeCode });
-        if (res?.data?.code === 200) {
-
-            setList(res.data.data.records.map((item) => {
-                return {
-                    id: item.value,
-                    name: item.label
-                }
-            }))
-        } else {
-            notify(res.data.msg);
+        setLoading(true);
+        try {
+            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 {
+                        id: item.value,
+                        name: item.label
+                    }
+                }));
+            } else {
+                notify(res.data.msg);
+            }
+        } catch (error) {
+            notify('鍔犺浇瀛楀吀鏁版嵁澶辫触', 'error');
+            console.error('鍔犺浇瀛楀吀鏁版嵁澶辫触:', error);
+        } finally {
+            setLoading(false);
         }
-    }
+    };
+
+    // 纭繚褰撳墠鍊煎湪閫夐」涓紝濡傛灉涓嶅湪涓旀鍦ㄥ姞杞斤紝娣诲姞鍗犱綅閫夐」
+    const choices = useMemo(() => {
+        if (!list || list.length === 0) {
+            // 濡傛灉鍒楄〃涓虹┖浣嗗綋鍓嶆湁鍊硷紝娣诲姞鍗犱綅閫夐」浠ラ伩鍏嶈鍛�
+            if (currentValue !== undefined && currentValue !== null && currentValue !== '') {
+                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) }];
+        }
+        
+        return list;
+    }, [list, currentValue]);
+
+    const InputComponent = multiple ? SelectArrayInput : SelectInput;
 
     return (
-        <SelectInput
+        <InputComponent
             source={name}
-            choices={list}
+            choices={choices}
+            isLoading={loading}
             {...parmas}
         />
     );

--
Gitblit v1.9.1