diff --git a/Touchkebao/src/pages/pc/ckbox/weChat/components/ChatWindow/components/MessageRecord/components/SmallProgramMessage/index.tsx b/Touchkebao/src/pages/pc/ckbox/weChat/components/ChatWindow/components/MessageRecord/components/SmallProgramMessage/index.tsx index 44787540..51711685 100644 --- a/Touchkebao/src/pages/pc/ckbox/weChat/components/ChatWindow/components/MessageRecord/components/SmallProgramMessage/index.tsx +++ b/Touchkebao/src/pages/pc/ckbox/weChat/components/ChatWindow/components/MessageRecord/components/SmallProgramMessage/index.tsx @@ -26,7 +26,7 @@ const SmallProgramMessage: React.FC = ({ const messageData = JSON.parse(trimmedContent); // 处理文章类型消息 - if (messageData.type === "link" && messageData.title && messageData.url) { + if (messageData.type === "link") { const { title, desc, thumbPath, url } = messageData; return ( @@ -68,7 +68,7 @@ const SmallProgramMessage: React.FC = ({ } // 处理小程序消息 - 统一使用parseWeappMsgStr解析 - if (messageData.type === "miniprogram" && messageData.contentXml) { + if (messageData.type === "miniprogram") { try { const parsedData = parseWeappMsgStr(trimmedContent); @@ -144,109 +144,115 @@ const SmallProgramMessage: React.FC = ({ } } - // 验证传统JSON格式的小程序数据结构 - if ( - messageData && - typeof messageData === "object" && - (messageData.title || messageData.appName) - ) { - return ( -
-
- {messageData.thumb && ( - 小程序缩略图 { - const target = e.target as HTMLImageElement; - target.style.display = "none"; - }} - /> - )} -
-
- {messageData.title || "小程序消息"} -
- {messageData.appName && ( -
- {messageData.appName} + //处理文档类型消息 + + if (messageData.type === "file") { + const { url, title } = messageData; + // 增强的文件消息处理 + const isFileUrl = + url.startsWith("http") || + url.startsWith("https") || + url.startsWith("file://") || + /\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|zip|rar|7z)$/i.test(url); + + if (isFileUrl) { + // 尝试从URL中提取文件名 + const fileName = + title || url.split("/").pop()?.split("?")[0] || "文件"; + const fileExtension = fileName.split(".").pop()?.toLowerCase(); + + // 根据文件类型选择图标 + let fileIcon = "📄"; + if (fileExtension) { + const iconMap: { [key: string]: string } = { + pdf: "📕", + doc: "📘", + docx: "📘", + xls: "📗", + xlsx: "📗", + ppt: "📙", + pptx: "📙", + txt: "📝", + zip: "🗜️", + rar: "🗜️", + "7z": "🗜️", + jpg: "🖼️", + jpeg: "🖼️", + png: "🖼️", + gif: "🖼️", + mp4: "🎬", + avi: "🎬", + mov: "🎬", + mp3: "🎵", + wav: "🎵", + flac: "🎵", + }; + fileIcon = iconMap[fileExtension] || "📄"; + } + + return ( +
+
+
{fileIcon}
+
+
+ {fileName.length > 20 + ? fileName.substring(0, 20) + "..." + : fileName}
- )} +
{ + try { + window.open(messageData.url, "_blank"); + } catch (e) { + console.error("文件打开失败:", e); + } + }} + > + 点击查看 +
+
-
- ); - } - } - - // 增强的文件消息处理 - const isFileUrl = - content.startsWith("http") || - content.startsWith("https") || - content.startsWith("file://") || - /\.(pdf|doc|docx|xls|xlsx|ppt|pptx|txt|zip|rar|7z)$/i.test(content); - - if (isFileUrl) { - // 尝试从URL中提取文件名 - const fileName = content.split("/").pop()?.split("?")[0] || "文件"; - const fileExtension = fileName.split(".").pop()?.toLowerCase(); - - // 根据文件类型选择图标 - let fileIcon = "📄"; - if (fileExtension) { - const iconMap: { [key: string]: string } = { - pdf: "📕", - doc: "📘", - docx: "📘", - xls: "📗", - xlsx: "📗", - ppt: "📙", - pptx: "📙", - txt: "📝", - zip: "🗜️", - rar: "🗜️", - "7z": "🗜️", - jpg: "🖼️", - jpeg: "🖼️", - png: "🖼️", - gif: "🖼️", - mp4: "🎬", - avi: "🎬", - mov: "🎬", - mp3: "🎵", - wav: "🎵", - flac: "🎵", - }; - fileIcon = iconMap[fileExtension] || "📄"; + ); + } } - return ( -
-
-
{fileIcon}
-
-
- {fileName.length > 20 - ? fileName.substring(0, 20) + "..." - : fileName} -
-
{ - try { - window.open(content, "_blank"); - } catch (e) { - console.error("文件打开失败:", e); - } - }} - > - 点击查看 -
-
-
-
- ); + // 验证传统JSON格式的小程序数据结构 + // if ( + // messageData && + // typeof messageData === "object" && + // (messageData.title || messageData.appName) + // ) { + // return ( + //
+ //
+ // {messageData.thumb && ( + // 小程序缩略图 { + // const target = e.target as HTMLImageElement; + // target.style.display = "none"; + // }} + // /> + // )} + //
+ //
+ // {messageData.title || "小程序消息"} + //
+ // {messageData.appName && ( + //
+ // {messageData.appName} + //
+ // )} + //
+ //
+ //
+ // ); + // } } return renderErrorMessage("[小程序/文件消息]");