#
zhou zhou
昨天 5b7b608a6acd3a6178687372cdb6b74198e23376
rsf-admin/src/page/components/DictionarySelect.jsx
@@ -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 [];
        }
        
        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 (currentValue !== undefined && currentValue !== null && currentValue !== '' && !valueExists) {
                if (!valueExists) {
            return [...list, { id: currentValue, name: String(currentValue) }];
                }
            }
        }
        
        return list;
    }, [list, currentValue]);
    }, [list, currentValue, multiple]);
    const InputComponent = multiple ? SelectArrayInput : SelectInput;