Showing
3 changed files
with
71 additions
and
46 deletions
| ... | @@ -52,6 +52,7 @@ pnpm lint | ... | @@ -52,6 +52,7 @@ pnpm lint |
| 52 | - 黄色背景表示"生成中"状态 | 52 | - 黄色背景表示"生成中"状态 |
| 53 | - 绿色背景表示"已完成"状态 | 53 | - 绿色背景表示"已完成"状态 |
| 54 | - 使用条件类名动态切换样式 | 54 | - 使用条件类名动态切换样式 |
| 55 | +- ✅ **查看状态更新** - 仅在预览成功后标记为已查看,返回列表不刷新位置 | ||
| 55 | - ✅ **提交跳转体验** - 提交后先关闭并重置弹框,再无固定延迟跳转结果页 | 56 | - ✅ **提交跳转体验** - 提交后先关闭并重置弹框,再无固定延迟跳转结果页 |
| 56 | - ✅ **返回重置体验** - 结果页返回后表单不保留旧数据 | 57 | - ✅ **返回重置体验** - 结果页返回后表单不保留旧数据 |
| 57 | 58 | ... | ... |
| ... | @@ -63,12 +63,14 @@ export function useFileOperation() { | ... | @@ -63,12 +63,14 @@ export function useFileOperation() { |
| 63 | }) | 63 | }) |
| 64 | 64 | ||
| 65 | try { | 65 | try { |
| 66 | + let openResult = false | ||
| 66 | await openDocument({ | 67 | await openDocument({ |
| 67 | filePath: filePath, | 68 | filePath: filePath, |
| 68 | showMenu: true, // 显示右上角菜单,用户可以转发、保存等 | 69 | showMenu: true, // 显示右上角菜单,用户可以转发、保存等 |
| 69 | success: () => { | 70 | success: () => { |
| 70 | // 记录成功回调 | 71 | // 记录成功回调 |
| 71 | console.log('[文件操作] ✅ openDocument success 回调触发 - 文件已打开') | 72 | console.log('[文件操作] ✅ openDocument success 回调触发 - 文件已打开') |
| 73 | + openResult = true | ||
| 72 | 74 | ||
| 73 | // 文件打开后,延迟提示用户如果看不到内容该如何操作 | 75 | // 文件打开后,延迟提示用户如果看不到内容该如何操作 |
| 74 | // 使用统一的扩展名提取函数 | 76 | // 使用统一的扩展名提取函数 |
| ... | @@ -94,6 +96,7 @@ export function useFileOperation() { | ... | @@ -94,6 +96,7 @@ export function useFileOperation() { |
| 94 | errMsg: err.errMsg, | 96 | errMsg: err.errMsg, |
| 95 | errorCode: err.errCode | 97 | errorCode: err.errCode |
| 96 | }) | 98 | }) |
| 99 | + openResult = false | ||
| 97 | 100 | ||
| 98 | // 获取文件扩展名(使用统一的扩展名提取函数) | 101 | // 获取文件扩展名(使用统一的扩展名提取函数) |
| 99 | const fileExt = extractExtensionFromFile(item) | 102 | const fileExt = extractExtensionFromFile(item) |
| ... | @@ -169,6 +172,7 @@ export function useFileOperation() { | ... | @@ -169,6 +172,7 @@ export function useFileOperation() { |
| 169 | }) | 172 | }) |
| 170 | } | 173 | } |
| 171 | }) | 174 | }) |
| 175 | + return openResult | ||
| 172 | } catch (error) { | 176 | } catch (error) { |
| 173 | // 记录异常(Promise rejection) | 177 | // 记录异常(Promise rejection) |
| 174 | console.log('[文件操作] ❌ openDocument 异常捕获:', error) | 178 | console.log('[文件操作] ❌ openDocument 异常捕获:', error) |
| ... | @@ -177,6 +181,7 @@ export function useFileOperation() { | ... | @@ -177,6 +181,7 @@ export function useFileOperation() { |
| 177 | icon: 'none', | 181 | icon: 'none', |
| 178 | duration: 2000 | 182 | duration: 2000 |
| 179 | }) | 183 | }) |
| 184 | + return false | ||
| 180 | } | 185 | } |
| 181 | } | 186 | } |
| 182 | 187 | ||
| ... | @@ -246,32 +251,38 @@ export function useFileOperation() { | ... | @@ -246,32 +251,38 @@ export function useFileOperation() { |
| 246 | // 首次打开 Office 文档,显示提示 | 251 | // 首次打开 Office 文档,显示提示 |
| 247 | console.log('[文件操作] 首次打开 Office 文档,显示提示') | 252 | console.log('[文件操作] 首次打开 Office 文档,显示提示') |
| 248 | 253 | ||
| 249 | - showModal({ | 254 | + return await new Promise((resolve) => { |
| 250 | - title: '预览提示', | 255 | + showModal({ |
| 251 | - content: `小程序对 ${fileExt.toUpperCase()} 文档的预览支持有限,如果显示为空白,请点击右上角"..."菜单,选择"发送给朋友"后在电脑或其他应用中打开。\n\n是否继续预览?`, | 256 | + title: '预览提示', |
| 252 | - confirmText: '继续预览', | 257 | + content: `小程序对 ${fileExt.toUpperCase()} 文档的预览支持有限,如果显示为空白,请点击右上角"..."菜单,选择"发送给朋友"后在电脑或其他应用中打开。\n\n是否继续预览?`, |
| 253 | - cancelText: '取消', | 258 | + confirmText: '继续预览', |
| 254 | - success: (modalRes) => { | 259 | + cancelText: '取消', |
| 255 | - console.log('[文件操作] 用户选择:', modalRes.confirm ? '继续预览' : '取消') | 260 | + success: async (modalRes) => { |
| 256 | - | 261 | + console.log('[文件操作] 用户选择:', modalRes.confirm ? '继续预览' : '取消') |
| 257 | - if (modalRes.confirm) { | 262 | + |
| 258 | - // 记录用户选择,下次不再提示 | 263 | + if (modalRes.confirm) { |
| 259 | - try { | 264 | + // 记录用户选择,下次不再提示 |
| 260 | - Taro.setStorageSync(dontShowAgainKey, true) | 265 | + try { |
| 261 | - console.log('[文件操作] ✅ 已保存"不再提醒"设置') | 266 | + Taro.setStorageSync(dontShowAgainKey, true) |
| 262 | - } catch (storageErr) { | 267 | + console.log('[文件操作] ✅ 已保存"不再提醒"设置') |
| 263 | - console.log('[文件操作] ❌ 保存设置失败:', storageErr) | 268 | + } catch (storageErr) { |
| 269 | + console.log('[文件操作] ❌ 保存设置失败:', storageErr) | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + const openResult = await openFile(downloadResult.tempFilePath, item) | ||
| 273 | + resolve(openResult) | ||
| 274 | + return | ||
| 264 | } | 275 | } |
| 265 | 276 | ||
| 266 | - // 打开文件 | 277 | + resolve(false) |
| 267 | - openFile(downloadResult.tempFilePath, item) | ||
| 268 | } | 278 | } |
| 269 | - } | 279 | + }) |
| 270 | }) | 280 | }) |
| 271 | } else { | 281 | } else { |
| 272 | // 用户已选择"不再提醒"或非 Office 文档,直接打开 | 282 | // 用户已选择"不再提醒"或非 Office 文档,直接打开 |
| 273 | console.log('[文件操作] 直接打开文件(已选择不再提醒 或 非 Office 文档)') | 283 | console.log('[文件操作] 直接打开文件(已选择不再提醒 或 非 Office 文档)') |
| 274 | - await openFile(downloadResult.tempFilePath, item) | 284 | + const openResult = await openFile(downloadResult.tempFilePath, item) |
| 285 | + return openResult | ||
| 275 | } | 286 | } |
| 276 | } catch (error) { | 287 | } catch (error) { |
| 277 | // 确保隐藏加载提示 | 288 | // 确保隐藏加载提示 |
| ... | @@ -292,6 +303,7 @@ export function useFileOperation() { | ... | @@ -292,6 +303,7 @@ export function useFileOperation() { |
| 292 | icon: 'none', | 303 | icon: 'none', |
| 293 | duration: 2000 | 304 | duration: 2000 |
| 294 | }) | 305 | }) |
| 306 | + return false | ||
| 295 | } | 307 | } |
| 296 | } | 308 | } |
| 297 | 309 | ||
| ... | @@ -328,7 +340,7 @@ export function useFileOperation() { | ... | @@ -328,7 +340,7 @@ export function useFileOperation() { |
| 328 | icon: 'none', | 340 | icon: 'none', |
| 329 | duration: 2000 | 341 | duration: 2000 |
| 330 | }) | 342 | }) |
| 331 | - return | 343 | + return false |
| 332 | } | 344 | } |
| 333 | 345 | ||
| 334 | // 判断是否为图片文件(优先使用 extension 字段) | 346 | // 判断是否为图片文件(优先使用 extension 字段) |
| ... | @@ -340,6 +352,7 @@ export function useFileOperation() { | ... | @@ -340,6 +352,7 @@ export function useFileOperation() { |
| 340 | urls: [item.downloadUrl], | 352 | urls: [item.downloadUrl], |
| 341 | current: item.downloadUrl | 353 | current: item.downloadUrl |
| 342 | }) | 354 | }) |
| 355 | + return true | ||
| 343 | } catch (error) { | 356 | } catch (error) { |
| 344 | console.error('[文件操作] 图片预览失败:', error) | 357 | console.error('[文件操作] 图片预览失败:', error) |
| 345 | showToast({ | 358 | showToast({ |
| ... | @@ -347,17 +360,27 @@ export function useFileOperation() { | ... | @@ -347,17 +360,27 @@ export function useFileOperation() { |
| 347 | icon: 'none', | 360 | icon: 'none', |
| 348 | duration: 2000 | 361 | duration: 2000 |
| 349 | }) | 362 | }) |
| 363 | + return false | ||
| 350 | } | 364 | } |
| 351 | - return | ||
| 352 | } | 365 | } |
| 353 | 366 | ||
| 354 | // 判断是否为视频文件(优先使用 extension 字段) | 367 | // 判断是否为视频文件(优先使用 extension 字段) |
| 355 | if (isVideoFile(item)) { | 368 | if (isVideoFile(item)) { |
| 356 | // 视频文件:跳转到视频播放页面 | 369 | // 视频文件:跳转到视频播放页面 |
| 357 | - Taro.navigateTo({ | 370 | + try { |
| 358 | - url: `/pages/video-player/index?url=${encodeURIComponent(item.downloadUrl)}&title=${encodeURIComponent(item.title || item.fileName)}` | 371 | + await Taro.navigateTo({ |
| 359 | - }) | 372 | + url: `/pages/video-player/index?url=${encodeURIComponent(item.downloadUrl)}&title=${encodeURIComponent(item.title || item.fileName)}` |
| 360 | - return | 373 | + }) |
| 374 | + return true | ||
| 375 | + } catch (error) { | ||
| 376 | + console.error('[文件操作] 视频打开失败:', error) | ||
| 377 | + showToast({ | ||
| 378 | + title: '视频打开失败', | ||
| 379 | + icon: 'none', | ||
| 380 | + duration: 2000 | ||
| 381 | + }) | ||
| 382 | + return false | ||
| 383 | + } | ||
| 361 | } | 384 | } |
| 362 | 385 | ||
| 363 | // 非视频文件:下载并打开 | 386 | // 非视频文件:下载并打开 |
| ... | @@ -368,7 +391,8 @@ export function useFileOperation() { | ... | @@ -368,7 +391,8 @@ export function useFileOperation() { |
| 368 | }) | 391 | }) |
| 369 | 392 | ||
| 370 | // 下载并打开文件 | 393 | // 下载并打开文件 |
| 371 | - await downloadAndOpenFile(item) | 394 | + const openResult = await downloadAndOpenFile(item) |
| 395 | + return openResult | ||
| 372 | } | 396 | } |
| 373 | 397 | ||
| 374 | return { | 398 | return { | ... | ... |
| ... | @@ -477,30 +477,30 @@ const onView = async (item) => { | ... | @@ -477,30 +477,30 @@ const onView = async (item) => { |
| 477 | */ | 477 | */ |
| 478 | const handleFileView = async (file) => { | 478 | const handleFileView = async (file) => { |
| 479 | try { | 479 | try { |
| 480 | - // 调用 viewAPI 标记为已查看 | 480 | + const previewSuccess = await viewFile({ |
| 481 | - const viewRes = await viewAPI({ i: item.id }) | 481 | + downloadUrl: file.file_url, |
| 482 | - | 482 | + fileName: file.file_name |
| 483 | - if (viewRes.code === 1) { | 483 | + }) |
| 484 | - // 更新本地状态为"已查看" | 484 | + |
| 485 | - item.status = 'viewed' | 485 | + if (!previewSuccess) { |
| 486 | - | 486 | + return |
| 487 | - // 显示提示 | 487 | + } |
| 488 | - Taro.showToast({ | 488 | + |
| 489 | - title: '已标记为查看', | 489 | + if (item.status !== 'viewed') { |
| 490 | - icon: 'success', | 490 | + const viewRes = await viewAPI({ i: item.id }) |
| 491 | - duration: 1000 | 491 | + |
| 492 | - }) | 492 | + if (viewRes.code === 1) { |
| 493 | + item.status = 'viewed' | ||
| 494 | + Taro.showToast({ | ||
| 495 | + title: '已标记为查看', | ||
| 496 | + icon: 'success', | ||
| 497 | + duration: 1000 | ||
| 498 | + }) | ||
| 499 | + } | ||
| 493 | } | 500 | } |
| 494 | } catch (error) { | 501 | } catch (error) { |
| 495 | console.error('标记查看失败:', error) | 502 | console.error('标记查看失败:', error) |
| 496 | - // 即使标记失败,也继续查看文档 | ||
| 497 | } | 503 | } |
| 498 | - | ||
| 499 | - // 使用 useFileOperation 查看文档 | ||
| 500 | - await viewFile({ | ||
| 501 | - downloadUrl: file.file_url, | ||
| 502 | - fileName: file.file_name | ||
| 503 | - }) | ||
| 504 | } | 504 | } |
| 505 | 505 | ||
| 506 | // 如果只有一个文件,直接查看 | 506 | // 如果只有一个文件,直接查看 | ... | ... |
-
Please register or login to post a comment