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({
/**
* 获取文档图标 URL
*
* @description 优先使用 extension 字段,其次从 fileName 解析
* @description 优先使用 extension 字段,其次从 fileName、src、downloadUrl 解析
* @returns {string} 图标 URL
*/
const iconUrl = getDocumentIcon({
extension: props.extension,
fileName: props.fileName
fileName: props.fileName,
downloadUrl: props.downloadUrl
});
/**
* 获取文档类型标签
*
* @description 优先使用 extension 字段,其次从 fileName 解析
* @description 优先使用 extension 字段,其次从 fileName、src、downloadUrl 解析
* @returns {string} 文档类型标签
*/
const docTypeLabel = getDocumentLabel({
extension: props.extension,
fileName: props.fileName
fileName: props.fileName,
downloadUrl: props.downloadUrl
});
/**
......
......@@ -227,16 +227,16 @@ export function useFileOperation() {
console.log('[文件操作] "不再提醒"设置状态:', dontShowAgain)
if (unsupportedFormats.includes(fileExt) && !dontShowAgain) {
// 首次打开 Office 文档,显示提示(带"不再提醒"选项)
// 首次打开 Office 文档,显示提示
console.log('[文件操作] 首次打开 Office 文档,显示提示')
showModal({
title: '预览提示',
content: `小程序对 ${fileExt.toUpperCase()} 文档的预览支持有限,如果显示为空白,请点击右上角"..."菜单,选择"发送给朋友"后在电脑或其他应用中打开。\n\n是否继续预览?`,
confirmText: '继续,不再提醒',
confirmText: '继续预览',
cancelText: '取消',
success: (modalRes) => {
console.log('[文件操作] 用户选择:', modalRes.confirm ? '继续,不再提醒' : '取消')
console.log('[文件操作] 用户选择:', modalRes.confirm ? '继续预览' : '取消')
if (modalRes.confirm) {
// 记录用户选择,下次不再提示
......
......@@ -133,16 +133,15 @@ const fetchWeekHotList = async (params = {}, isLoadMore = false) => {
// 处理列表数据
if (res.data.list?.length) {
// 直接映射为 MaterialCard 需要的格式
// 注意:extension 字段可以让 extractExtensionFromFile 函数自动从 URL 解析
const listData = res.data.list.map(item => {
const fileName = item.name || '未命名文件'
const extension = item.extension || fileName.split('.').pop()?.toLowerCase() || ''
return {
meta_id: item.meta_id,
name: fileName,
name: item.name || '未命名文件',
size: item.size || '',
downloadUrl: item.src,
extension: extension,
// extension 可以为空,MaterialCard 会使用 extractExtensionFromFile 从 src 解析
extension: item.extension || '',
collected: item.is_favorite === '1' || item.is_favorite === 1 || item.is_favorite === true,
read_people_count: item.read_people_count,
read_people_percent: item.read_people_percent
......