You need to sign in or sign up before continuing.
hookehuyr

fix(material): 优化文件扩展名解析和预览提示

- MaterialCard: 增强 downloadUrl 字段传递,支持从 CDN URL 解析扩展名
- useFileOperation: 修复 Office 文档预览提示按钮文本(小程序限制 4 字符)
- week-hot-material: 简化数据映射,依赖组件内部自动解析扩展名

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
...@@ -128,23 +128,25 @@ const emit = defineEmits({ ...@@ -128,23 +128,25 @@ const emit = defineEmits({
128 /** 128 /**
129 * 获取文档图标 URL 129 * 获取文档图标 URL
130 * 130 *
131 - * @description 优先使用 extension 字段,其次从 fileName 解析 131 + * @description 优先使用 extension 字段,其次从 fileName、src、downloadUrl 解析
132 * @returns {string} 图标 URL 132 * @returns {string} 图标 URL
133 */ 133 */
134 const iconUrl = getDocumentIcon({ 134 const iconUrl = getDocumentIcon({
135 extension: props.extension, 135 extension: props.extension,
136 - fileName: props.fileName 136 + fileName: props.fileName,
137 + downloadUrl: props.downloadUrl
137 }); 138 });
138 139
139 /** 140 /**
140 * 获取文档类型标签 141 * 获取文档类型标签
141 * 142 *
142 - * @description 优先使用 extension 字段,其次从 fileName 解析 143 + * @description 优先使用 extension 字段,其次从 fileName、src、downloadUrl 解析
143 * @returns {string} 文档类型标签 144 * @returns {string} 文档类型标签
144 */ 145 */
145 const docTypeLabel = getDocumentLabel({ 146 const docTypeLabel = getDocumentLabel({
146 extension: props.extension, 147 extension: props.extension,
147 - fileName: props.fileName 148 + fileName: props.fileName,
149 + downloadUrl: props.downloadUrl
148 }); 150 });
149 151
150 /** 152 /**
......
...@@ -227,16 +227,16 @@ export function useFileOperation() { ...@@ -227,16 +227,16 @@ export function useFileOperation() {
227 console.log('[文件操作] "不再提醒"设置状态:', dontShowAgain) 227 console.log('[文件操作] "不再提醒"设置状态:', dontShowAgain)
228 228
229 if (unsupportedFormats.includes(fileExt) && !dontShowAgain) { 229 if (unsupportedFormats.includes(fileExt) && !dontShowAgain) {
230 - // 首次打开 Office 文档,显示提示(带"不再提醒"选项) 230 + // 首次打开 Office 文档,显示提示
231 console.log('[文件操作] 首次打开 Office 文档,显示提示') 231 console.log('[文件操作] 首次打开 Office 文档,显示提示')
232 232
233 showModal({ 233 showModal({
234 title: '预览提示', 234 title: '预览提示',
235 content: `小程序对 ${fileExt.toUpperCase()} 文档的预览支持有限,如果显示为空白,请点击右上角"..."菜单,选择"发送给朋友"后在电脑或其他应用中打开。\n\n是否继续预览?`, 235 content: `小程序对 ${fileExt.toUpperCase()} 文档的预览支持有限,如果显示为空白,请点击右上角"..."菜单,选择"发送给朋友"后在电脑或其他应用中打开。\n\n是否继续预览?`,
236 - confirmText: '继续,不再提醒', 236 + confirmText: '继续预览',
237 cancelText: '取消', 237 cancelText: '取消',
238 success: (modalRes) => { 238 success: (modalRes) => {
239 - console.log('[文件操作] 用户选择:', modalRes.confirm ? '继续,不再提醒' : '取消') 239 + console.log('[文件操作] 用户选择:', modalRes.confirm ? '继续预览' : '取消')
240 240
241 if (modalRes.confirm) { 241 if (modalRes.confirm) {
242 // 记录用户选择,下次不再提示 242 // 记录用户选择,下次不再提示
......
...@@ -133,16 +133,15 @@ const fetchWeekHotList = async (params = {}, isLoadMore = false) => { ...@@ -133,16 +133,15 @@ const fetchWeekHotList = async (params = {}, isLoadMore = false) => {
133 // 处理列表数据 133 // 处理列表数据
134 if (res.data.list?.length) { 134 if (res.data.list?.length) {
135 // 直接映射为 MaterialCard 需要的格式 135 // 直接映射为 MaterialCard 需要的格式
136 + // 注意:extension 字段可以让 extractExtensionFromFile 函数自动从 URL 解析
136 const listData = res.data.list.map(item => { 137 const listData = res.data.list.map(item => {
137 - const fileName = item.name || '未命名文件'
138 - const extension = item.extension || fileName.split('.').pop()?.toLowerCase() || ''
139 -
140 return { 138 return {
141 meta_id: item.meta_id, 139 meta_id: item.meta_id,
142 - name: fileName, 140 + name: item.name || '未命名文件',
143 size: item.size || '', 141 size: item.size || '',
144 downloadUrl: item.src, 142 downloadUrl: item.src,
145 - extension: extension, 143 + // extension 可以为空,MaterialCard 会使用 extractExtensionFromFile 从 src 解析
144 + extension: item.extension || '',
146 collected: item.is_favorite === '1' || item.is_favorite === 1 || item.is_favorite === true, 145 collected: item.is_favorite === '1' || item.is_favorite === 1 || item.is_favorite === true,
147 read_people_count: item.read_people_count, 146 read_people_count: item.read_people_count,
148 read_people_percent: item.read_people_percent 147 read_people_percent: item.read_people_percent
......