diff --git a/Cunkebao/src/components/DeviceSelection/data.ts b/Cunkebao/src/components/DeviceSelection/data.ts index d002905c..9f966a46 100644 --- a/Cunkebao/src/components/DeviceSelection/data.ts +++ b/Cunkebao/src/components/DeviceSelection/data.ts @@ -26,4 +26,5 @@ export interface DeviceSelectionProps { showSelectedList?: boolean; // 新增 readonly?: boolean; // 新增 deviceGroups?: any[]; // 传递设备组数据 + singleSelect?: boolean; // 新增,是否单选模式 } diff --git a/Cunkebao/src/components/DeviceSelection/index.tsx b/Cunkebao/src/components/DeviceSelection/index.tsx index ba6952cd..80d27c49 100644 --- a/Cunkebao/src/components/DeviceSelection/index.tsx +++ b/Cunkebao/src/components/DeviceSelection/index.tsx @@ -18,6 +18,7 @@ const DeviceSelection: React.FC = ({ showInput = true, showSelectedList = true, readonly = false, + singleSelect = false, }) => { // 弹窗控制 const [popupVisible, setPopupVisible] = useState(false); @@ -37,6 +38,9 @@ const DeviceSelection: React.FC = ({ // 获取显示文本 const getDisplayText = () => { if (selectedOptions.length === 0) return ""; + if (singleSelect && selectedOptions.length > 0) { + return selectedOptions[0].memo || selectedOptions[0].wechatId || "已选择设备"; + } return `已选择 ${selectedOptions.length} 个设备`; }; @@ -179,6 +183,7 @@ const DeviceSelection: React.FC = ({ onClose={() => setRealVisible(false)} selectedOptions={selectedOptions} onSelect={onSelect} + singleSelect={singleSelect} /> ); diff --git a/Cunkebao/src/components/DeviceSelection/selectionPopup.tsx b/Cunkebao/src/components/DeviceSelection/selectionPopup.tsx index 7a839f70..8dbac0ad 100644 --- a/Cunkebao/src/components/DeviceSelection/selectionPopup.tsx +++ b/Cunkebao/src/components/DeviceSelection/selectionPopup.tsx @@ -12,6 +12,7 @@ interface SelectionPopupProps { onClose: () => void; selectedOptions: DeviceSelectionItem[]; onSelect: (devices: DeviceSelectionItem[]) => void; + singleSelect?: boolean; } const PAGE_SIZE = 20; @@ -21,6 +22,7 @@ const SelectionPopup: React.FC = ({ onClose, selectedOptions, onSelect, + singleSelect = false, }) => { // 设备数据 const [devices, setDevices] = useState([]); @@ -110,13 +112,23 @@ const SelectionPopup: React.FC = ({ // 处理设备选择 const handleDeviceToggle = (device: DeviceSelectionItem) => { - if (tempSelectedOptions.some(v => v.id === device.id)) { - setTempSelectedOptions( - tempSelectedOptions.filter(v => v.id !== device.id), - ); + if (singleSelect) { + // 单选模式:如果已选中,则取消选择;否则替换为当前设备 + if (tempSelectedOptions.some(v => v.id === device.id)) { + setTempSelectedOptions([]); + } else { + setTempSelectedOptions([device]); + } } else { - const newSelectedOptions = [...tempSelectedOptions, device]; - setTempSelectedOptions(newSelectedOptions); + // 多选模式:原有的逻辑 + if (tempSelectedOptions.some(v => v.id === device.id)) { + setTempSelectedOptions( + tempSelectedOptions.filter(v => v.id !== device.id), + ); + } else { + const newSelectedOptions = [...tempSelectedOptions, device]; + setTempSelectedOptions(newSelectedOptions); + } } }; @@ -179,6 +191,7 @@ const SelectionPopup: React.FC = ({ totalPages={totalPages} loading={loading} selectedCount={tempSelectedOptions.length} + singleSelect={singleSelect} onPageChange={setCurrentPage} onCancel={onClose} onConfirm={() => { @@ -187,7 +200,7 @@ const SelectionPopup: React.FC = ({ onClose(); }} isAllSelected={isCurrentPageAllSelected} - onSelectAll={handleSelectAllCurrentPage} + onSelectAll={singleSelect ? undefined : handleSelectAllCurrentPage} /> } > diff --git a/Cunkebao/src/components/FriendSelection/index.tsx b/Cunkebao/src/components/FriendSelection/index.tsx index 8958681b..a3745eff 100644 --- a/Cunkebao/src/components/FriendSelection/index.tsx +++ b/Cunkebao/src/components/FriendSelection/index.tsx @@ -95,9 +95,9 @@ export default function FriendSelection({ {(selectedOptions || []).map(friend => (
- +
-
{friend.friendName}
+
{friend.nickname || friend.friendName}
{friend.wechatId}
{!readonly && ( diff --git a/Cunkebao/src/components/PopuLayout/footer.tsx b/Cunkebao/src/components/PopuLayout/footer.tsx index 60e562be..a9d09855 100644 --- a/Cunkebao/src/components/PopuLayout/footer.tsx +++ b/Cunkebao/src/components/PopuLayout/footer.tsx @@ -14,6 +14,7 @@ interface PopupFooterProps { // 全选功能相关 isAllSelected?: boolean; onSelectAll?: (checked: boolean) => void; + singleSelect?: boolean; } const PopupFooter: React.FC = ({ @@ -26,20 +27,23 @@ const PopupFooter: React.FC = ({ onConfirm, isAllSelected = false, onSelectAll, + singleSelect = false, }) => { return ( <> {/* 分页栏 */}
-
- onSelectAll(e.target.checked)} - className={style.selectAllCheckbox} - > - 全选当前页 - -
+ {onSelectAll && ( +
+ onSelectAll(e.target.checked)} + className={style.selectAllCheckbox} + > + 全选当前页 + +
+ )}
-
已选择 {selectedCount} 条记录
+
+ {singleSelect + ? selectedCount > 0 + ? "已选择设备" + : "未选择设备" + : `已选择 ${selectedCount} 条记录`} +