소스 검색

♻️ refactor(SilverWisdomDetailPage): 移除页面内冗余工具函数

- 删除handleShare、handleDownload等处理函数
- 移除getFileExtension、getFileIcon等工具方法
- 删除checkPdfSupport、getResponsivePreviewHeight等兼容性相关函数
- 清理getCompatibilityMessage、handlePdfPreview等PDF预览相关逻辑
yourname 7 달 전
부모
커밋
3bfef35f23
1개의 변경된 파일0개의 추가작업 그리고 127개의 파일을 삭제
  1. 0 127
      src/client/mobile/pages/SilverWisdomDetailPage.tsx

+ 0 - 127
src/client/mobile/pages/SilverWisdomDetailPage.tsx

@@ -257,53 +257,6 @@ const SilverWisdomDetailPage: React.FC = () => {
   // 解析标签
   const tags = knowledge.tags ? String(knowledge.tags).split(',').map(tag => tag.trim()).filter(tag => tag) : [];
 
-  const handleShare = async () => {
-    try {
-      if (navigator.share) {
-        await navigator.share({
-          title: knowledge.title,
-          text: knowledge.content.substring(0, 100) + '...',
-          url: window.location.href,
-        });
-      } else {
-        // 降级处理:复制到剪贴板
-        await navigator.clipboard.writeText(window.location.href);
-        alert('链接已复制到剪贴板');
-      }
-    } catch (error) {
-      console.error('分享失败:', error);
-    }
-  };
-
-  const handleDownload = () => {
-    if (knowledge.attachment) {
-      // 创建临时链接下载,避免直接打开可能的安全问题
-      const link = document.createElement('a');
-      link.href = knowledge.attachment;
-      link.download = knowledge.attachmentName || '附件';
-      link.target = '_blank';
-      link.rel = 'noopener noreferrer';
-      document.body.appendChild(link);
-      link.click();
-      document.body.removeChild(link);
-    }
-  };
-
-  // 获取兼容性提示信息
-  const getCompatibilityMessage = () => {
-    const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
-    const isWechat = /MicroMessenger/i.test(navigator.userAgent);
-    const isQQ = /QQ/i.test(navigator.userAgent);
-    
-    if (isWechat || isQQ) {
-      return '微信/QQ内置浏览器暂不支持PDF预览,请使用系统浏览器打开';
-    }
-    if (isIOS && !checkPdfSupport()) {
-      return '建议使用Safari浏览器获得最佳PDF预览体验';
-    }
-    return null;
-  };
-
   // 使用useEffect检查PDF支持并设置预览状态
   React.useEffect(() => {
     if (knowledge.attachment && getFileExtension(knowledge.attachmentName || '') === 'pdf') {
@@ -317,86 +270,6 @@ const SilverWisdomDetailPage: React.FC = () => {
     }
   }, [knowledge.attachment, knowledge.attachmentName]);
 
-  const getFileExtension = (filename: string) => {
-    return filename.split('.').pop()?.toLowerCase() || '';
-  };
-
-  const getFileIcon = (filename: string) => {
-    const ext = getFileExtension(filename);
-    switch (ext) {
-      case 'pdf':
-        return '📄';
-      case 'doc':
-      case 'docx':
-        return '📝';
-      case 'xls':
-      case 'xlsx':
-        return '📊';
-      case 'ppt':
-      case 'pptx':
-        return '📊';
-      case 'jpg':
-      case 'jpeg':
-      case 'png':
-      case 'gif':
-        return '🖼️';
-      default:
-        return '📎';
-    }
-  };
-
-  const formatDate = (date: string) => {
-    return dayjs(date).format('YYYY年MM月DD日 HH:mm');
-  };
-
-  const getReadTime = (content: string) => {
-    const wordsPerMinute = 200;
-    const wordCount = content.length;
-    return Math.ceil(wordCount / wordsPerMinute);
-  };
-
-  // 移动端PDF兼容性检测
-  const checkPdfSupport = () => {
-    const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
-    const isWechat = /MicroMessenger/i.test(navigator.userAgent);
-    const isQQ = /QQ/i.test(navigator.userAgent);
-    
-    // 禁用微信、QQ内置浏览器的PDF预览
-    if (isWechat || isQQ) {
-      return false;
-    }
-    
-    // iOS Safari支持较好,但部分版本有问题
-    if (isIOS) {
-      return navigator.userAgent.includes('Safari') &&
-             !navigator.userAgent.includes('CriOS') && // Chrome iOS
-             !navigator.userAgent.includes('FxiOS');   // Firefox iOS
-    }
-    
-    return true;
-  };
-
-  const getResponsivePreviewHeight = () => {
-    const screenHeight = window.innerHeight;
-    return Math.min(320, screenHeight * 0.35); // 35%屏幕高度,最大320px
-  };
-
-  const handlePdfPreview = () => {
-    if (!knowledge.attachment) return;
-    
-    const isSupported = checkPdfSupport();
-    if (!isSupported) {
-      // 不支持的浏览器直接提供下载
-      setShowPdfPreview(false);
-      handleDownload();
-      return;
-    }
-    
-    setShowPdfPreview(true);
-    setPdfLoading(true);
-    setPdfError(false);
-  };
-
   return (
     <div className="min-h-screen" style={{ backgroundColor: COLORS.ink.light }}>
       {/* 头部导航 */}