diff --git a/src/components/CopyButton.tsx b/src/components/CopyButton.tsx index 64b5314..971e6c2 100644 --- a/src/components/CopyButton.tsx +++ b/src/components/CopyButton.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState } from 'react'; import { Check, Copy } from 'lucide-react'; import { copyTextToClipboard } from '@/utils/clipboard'; import { Button, type ButtonProps } from '@/components/ui/button'; +import { cn } from '@/lib/utils'; import { toast } from 'sonner'; interface CopyButtonProps extends Omit { @@ -53,7 +54,7 @@ export const CopyButton: React.FC = ({ aria-label={tooltip ?? '复制'} variant={variant} size={size} - className={className} + className={cn(className, copied && 'text-emerald-500')} {...props} > {copied ? ( diff --git a/src/utils/ruleStorage.ts b/src/utils/ruleStorage.ts index d39c107..7ba95ce 100644 --- a/src/utils/ruleStorage.ts +++ b/src/utils/ruleStorage.ts @@ -78,7 +78,7 @@ export function save( useCount: 0, }; rules.unshift(newRule); - setAll(rules); + if (!setAll(rules)) return null; return newRule; } @@ -95,7 +95,7 @@ export function save( updatedAt: now, }; rules[index] = updatedRule; - setAll(rules); + if (!setAll(rules)) return null; return updatedRule; } @@ -117,7 +117,7 @@ export function update(id: string, updates: Partial): DataRule | null updatedAt: Date.now(), }; rules[index] = updatedRule; - setAll(rules); + if (!setAll(rules)) return null; return updatedRule; } @@ -132,7 +132,7 @@ export function deleteRule(id: string): boolean { return false; } rules.splice(index, 1); - setAll(rules); + if (!setAll(rules)) return false; return true; } @@ -267,11 +267,13 @@ export function clear(): void { /** * 保存所有规则到存储 */ -function setAll(rules: DataRule[]): void { +function setAll(rules: DataRule[]): boolean { try { localStorage.setItem(STORAGE_KEY, JSON.stringify(rules)); + return true; } catch (error) { console.error('[ruleStorage] 保存规则失败:', error); + return false; } }