diff --git a/mobile/src/pages/xg/xsjcxx/xsqj/leaveEdit/index.vue b/mobile/src/pages/xg/xsjcxx/xsqj/leaveEdit/index.vue index 84d3d4cd..51862ed9 100644 --- a/mobile/src/pages/xg/xsjcxx/xsqj/leaveEdit/index.vue +++ b/mobile/src/pages/xg/xsjcxx/xsqj/leaveEdit/index.vue @@ -31,81 +31,6 @@ - - - - 微信SDK调试 - - - {{ wechatInitializing ? '初始化中' : '重新初始化' }} - - - {{ debugMode ? '关闭调试' : '开启调试' }} - - 清空日志 - - - - - - - 微信环境: - - {{ isWechatBrowser ? '是' : '否' }} - - - - SDK状态: - - {{ wechatSDK.isInitialized ? '已初始化' : '未初始化' }} - - - - 版本信息: - {{ wechatSDK.getVersion() }} - - - 可用API: - {{ wechatSDK.getAvailableApis() }} - - - - - - - - {{ log.time }} - {{ log.message }} - - {{ log.detail }} - - - - 暂无调试日志 - - - - - - - - - - item.leaveTypeName)]; - console.log('leaveTypeOptions: 格式化后的数据', options); return options; }, @@ -780,44 +700,26 @@ export default { // 检查微信环境并自动初始化SDK async checkWechatEnvironment() { - this.addWechatLog('开始检查微信环境...', 'info'); - try { // 检查是否在微信浏览器中 this.isWechatBrowser = this.wechatSDK.isWeChatBrowser(); - this.addWechatLog( - `微信环境检测结果: ${this.isWechatBrowser ? '是' : '否'}`, - this.isWechatBrowser ? 'success' : 'warning', - ); if (this.isWechatBrowser) { // 在微信环境中,自动初始化SDK - this.addWechatLog('检测到微信环境,开始自动初始化SDK...', 'info'); await this.initWechatSDK(); - } else { - this.addWechatLog('非微信环境,跳过SDK初始化', 'warning'); - } - - // 在开发环境或微信环境中默认开启调试模式 - if (process.env.NODE_ENV === 'development' || this.isWechatBrowser) { - this.debugMode = false; // 默认关闭,用户可手动开启 - this.addWechatLog('调试模式已准备就绪', 'info'); } } catch (error) { console.error('微信环境检查失败:', error); - this.addWechatLog(`微信环境检查失败: ${error.message}`, 'error'); } }, // 初始化微信SDK async initWechatSDK() { if (this.wechatInitializing) { - this.addWechatLog('SDK正在初始化中,请等待...', 'warning'); return; } this.wechatInitializing = true; - this.addWechatLog('开始初始化微信SDK...', 'info'); try { // 使用微信SDK工具类进行初始化 @@ -826,34 +728,17 @@ export default { jsApiList: ['chooseImage', 'previewImage', 'getLocation', 'openLocation'], }); - this.addWechatLog('微信SDK初始化成功', 'success'); - this.addWechatLog(`SDK版本: ${this.wechatSDK.getVersion()}`, 'info'); - this.addWechatLog(`可用API: ${this.wechatSDK.getAvailableApis()}`, 'info'); - // 检查关键API支持情况 try { const apiCheckResult = await this.wechatSDK.checkJsApi([ 'chooseImage', 'getLocation', ]); - this.addWechatLog( - `API支持检查完成`, - 'success', - JSON.stringify(apiCheckResult, null, 2), - ); } catch (apiError) { - this.addWechatLog(`API支持检查失败: ${apiError.message}`, 'warning'); + console.warn('API支持检查失败:', apiError.message); } } catch (error) { console.error('微信SDK初始化失败:', error); - this.addWechatLog(`微信SDK初始化失败: ${error.message}`, 'error'); - - // 显示用户友好的错误提示 - if (error.message.includes('invalid signature')) { - this.addWechatLog('可能原因: 签名验证失败,请检查域名配置', 'error'); - } else if (error.message.includes('invalid url domain')) { - this.addWechatLog('可能原因: 当前域名未在微信公众平台配置', 'error'); - } } finally { this.wechatInitializing = false; } @@ -861,62 +746,10 @@ export default { // 重新初始化微信SDK async reinitWechatSDK() { - this.addWechatLog('用户触发重新初始化SDK...', 'info'); this.wechatSDK.isInitialized = false; await this.initWechatSDK(); }, - // 添加调试日志 - addWechatLog(message, type = 'info', detail = '') { - const log = { - time: new Date().toLocaleTimeString(), - message: message, - type: type, // 'info', 'success', 'warning', 'error' - detail: detail, - }; - - this.wechatLogs.push(log); - - // 控制日志数量,避免内存溢出 - if (this.wechatLogs.length > 100) { - this.wechatLogs.shift(); - } - - // 更新最新日志ID,用于自动滚动 - this.latestLogId = `wechat-log-${this.wechatLogs.length - 1}`; - - // 同时输出到控制台 - const consoleMethod = - { - info: 'log', - success: 'log', - warning: 'warn', - error: 'error', - }[type] || 'log'; - - console[consoleMethod](`[微信SDK] ${message}`, detail ? detail : ''); - }, - - // 清空调试日志 - clearWechatLogs() { - this.wechatLogs = []; - this.latestLogId = ''; - this.addWechatLog('调试日志已清空', 'info'); - }, - - // 切换调试模式 - toggleDebugMode() { - this.debugMode = !this.debugMode; - this.addWechatLog(`调试模式已${this.debugMode ? '开启' : '关闭'}`, 'info'); - - if (this.debugMode) { - uni.showToast({ - title: '调试模式已开启', - icon: 'success', - }); - } - }, - // 微信选择图片 // async chooseWechatImage() { // if (!this.isWechatBrowser) { @@ -990,11 +823,9 @@ export default { // 上传微信图片到OSS(参考stuMsgDialog.vue的实现) async uploadWechatImageToOSS(localId) { try { - this.addWechatLog('🚀 开始上传微信图片到OSS...', 'info'); this.uploadProgress = 10; // 步骤1:上传到微信服务器(20%进度) - this.addWechatLog('📤 正在上传到微信服务器...', 'info'); const wxUploadRes = await this.wechatSDK.uploadImage(localId); if (!wxUploadRes.serverId) { @@ -1003,11 +834,9 @@ export default { const mediaId = wxUploadRes.serverId; this.uploadProgress = 30; - this.addWechatLog(`✅ 微信服务器上传成功,mediaId: ${mediaId}`, 'success'); // 步骤2:保存到OSS(80%进度) this.uploadProgress = 50; - this.addWechatLog('💾 正在保存到云端存储...', 'info'); const ossResponse = await request({ url: '/system/wechat/downloadToOss', @@ -1022,12 +851,6 @@ export default { const ossResult = ossResponse.data; this.uploadProgress = 90; - this.addWechatLog( - '🎉 图片保存成功!', - 'success', - `文件名: ${ossResult.fileName}\nOSS ID: ${ossResult.ossId}`, - ); - this.uploadProgress = 100; return { ossId: ossResult.ossId, @@ -1040,7 +863,6 @@ export default { } } catch (error) { console.error('上传微信图片失败:', error); - this.addWechatLog(`❌ 图片上传失败: ${error.message}`, 'error'); // 上传失败时重置进度 this.uploadProgress = 0; @@ -1209,7 +1031,6 @@ export default { if (this.isWechatBrowser && this.wechatSDK.isInitialized) { try { - this.addWechatLog('使用微信打开地图...', 'info'); await this.wechatSDK.openLocation({ latitude: latitude, longitude: longitude, @@ -1217,9 +1038,8 @@ export default { address: this.form.leaveLocation || '当前位置', scale: 16, }); - this.addWechatLog('微信地图打开成功', 'success'); } catch (error) { - this.addWechatLog(`微信地图打开失败: ${error.message}`, 'error'); + console.error('微信地图打开失败:', error); this.fallbackOpenMap(latitude, longitude); } } else { @@ -1261,7 +1081,6 @@ export default { await this.getLeaveTypeList(); // 检查请假类型数据是否获取成功 - console.log('初始化完成,请假类型数量:', this.leaveTypeList.length); if (this.leaveTypeList.length === 0) { console.warn('请假类型列表为空,可能影响picker显示'); } @@ -1319,7 +1138,6 @@ export default { if (response.code === 200) { this.leaveTypeList = response.rows || []; - console.log('获取请假类型成功,数据量:', this.leaveTypeList.length); // 如果API返回数据为空,使用测试数据 if (this.leaveTypeList.length === 0) { @@ -1336,7 +1154,6 @@ export default { } catch (error) { console.error('获取请假类型失败:', error); // 网络错误时使用测试数据 - console.log('已设置测试数据,数据量:', this.leaveTypeList.length); uni.showToast({ title: '网络错误,已加载默认数据', icon: 'none', @@ -1423,14 +1240,11 @@ export default { // 获取附件文件 async getAttachmentFiles(ossIds) { try { - console.log('=== 获取附件文件 ===', ossIds); const response = await request({ url: `/resource/oss/listByIds/${ossIds}`, method: 'GET', }); - console.log('获取附件响应:', response); - if (response.code === 200 && response.data) { const attachmentFiles = response.data.map((item, index) => { // 使用fileSuffix字段判断文件类型 @@ -1445,7 +1259,6 @@ export default { if (isImage && item.url && item.url.startsWith('/resource/')) { // 图片文件需要添加/api前缀 processedUrl = `/api${item.url}`; - console.log(`图片URL处理: ${item.url} -> ${processedUrl}`); } // 构造完整的文件名(包含扩展名) @@ -1478,30 +1291,16 @@ export default { }, }; - console.log(`附件 ${index + 1} 处理结果:`, { - 原始文件名: item.originalName, - 文件后缀: item.fileSuffix, - 完整文件名: fullFileName, - 文件类型: fileType, - 是否为图片: isImage, - 图片URL: item.url, - 完整对象: fileObj, - }); - return fileObj; }); this.attachmentList = attachmentFiles; - console.log('设置附件列表成功:', this.attachmentList); - console.log('图片文件数量:', this.imageFiles.length); - console.log('非图片文件数量:', this.nonImageFiles.length); // 为图片文件获取blob数据以确保正确显示 await this.processImageFiles(); // 强制刷新组件显示 this.$nextTick(() => { - console.log('强制刷新图片组件显示'); // 预加载图片以确保能正确显示 this.preloadImages(); }); @@ -1616,15 +1415,11 @@ export default { script.async = true; script.src = sdkUrls[currentUrlIndex]; - console.log(`🔄 尝试加载微信JS-SDK: ${script.src}`); - script.onload = () => { // 检查wx对象是否正确加载 if (typeof wx !== 'undefined' && wx.config && wx.ready) { - console.log('✅ 微信JS-SDK加载成功'); resolve(); } else { - console.log('❌ 微信JS-SDK加载失败,wx对象不完整'); currentUrlIndex++; if (currentUrlIndex < sdkUrls.length) { // 移除失败的脚本 @@ -1637,12 +1432,8 @@ export default { }; script.onerror = (error) => { - console.log( - `❌ 微信JS-SDK CDN[${currentUrlIndex}] 加载失败: ${script.src}`, - ); currentUrlIndex++; if (currentUrlIndex < sdkUrls.length) { - console.log(`🔄 切换到备用CDN: ${sdkUrls[currentUrlIndex]}`); // 移除失败的脚本 document.head.removeChild(script); setTimeout(tryLoadScript, 1000); @@ -1656,7 +1447,6 @@ export default { // 设置超时时间 setTimeout(() => { if (typeof wx === 'undefined' || !wx.config) { - console.log('❌ 微信JS-SDK加载超时,尝试下一个CDN'); currentUrlIndex++; if (currentUrlIndex < sdkUrls.length) { document.head.removeChild(script); @@ -1772,9 +1562,6 @@ export default { duration: 2000, }); - console.log( - `H5定位结果: 纬度=${latitude}, 经度=${longitude}, 精度=${accuracy}米`, - ); resolve(true); }, (error) => { @@ -1796,8 +1583,6 @@ export default { break; } - console.log(`H5定位错误详情: ${errorMessage} (错误码: ${error.code})`); - // 显示友好的错误提示 uni.showModal({ title: '定位失败', @@ -1831,7 +1616,6 @@ export default { async handleGetLocation() { try { uni.showLoading({ title: '定位中...', mask: true }); - this.addWechatLog('开始智能定位...', 'info'); const envInfo = { isWechatBrowser: this.isWechatBrowser, @@ -1840,66 +1624,48 @@ export default { isBrowserGeolocationSupported: this.isBrowserGeolocationSupported(), }; - this.addWechatLog('当前环境检测结果', 'info', JSON.stringify(envInfo, null, 2)); - // 优先级1:微信SDK定位(如果在微信环境且SDK已就绪) if (this.isWechatBrowser && this.wechatSDK.isInitialized) { - this.addWechatLog('尝试微信SDK定位...', 'info'); const wxLocationSuccess = await this.tryWeChatLocationWithSDK(); if (wxLocationSuccess) { - this.addWechatLog('微信SDK定位成功', 'success'); return; } - this.addWechatLog('微信SDK定位失败,尝试下一种方式...', 'warning'); } // 优先级2:微信环境但SDK未就绪,尝试初始化后重试 if (this.isWechatBrowser && !this.wechatSDK.isInitialized) { - this.addWechatLog('微信SDK未初始化,尝试快速初始化...', 'warning'); try { await this.initWechatSDK(); if (this.wechatSDK.isInitialized) { const wxLocationSuccess = await this.tryWeChatLocationWithSDK(); if (wxLocationSuccess) { - this.addWechatLog('微信SDK初始化并定位成功', 'success'); return; } } } catch (error) { - this.addWechatLog(`微信SDK初始化失败: ${error.message}`, 'error'); + console.error('微信SDK初始化失败:', error); } } // 优先级3:H5 web端原生定位 if (this.isH5Web() && this.isBrowserGeolocationSupported()) { - this.addWechatLog('尝试H5浏览器原生定位...', 'info'); const h5LocationSuccess = await this.handleH5WebLocation(); if (h5LocationSuccess) { - this.addWechatLog('H5原生定位成功', 'success'); return; } - this.addWechatLog('H5原生定位失败,尝试最后的备用方案...', 'warning'); } // 优先级4:uni-app通用定位(最后的回退方案) - this.addWechatLog('尝试uni-app通用定位...', 'info'); await this.handleFallbackLocation(); } catch (error) { console.error('智能定位流程出错:', error); - this.addWechatLog(`智能定位流程异常: ${error.message}`, 'error'); uni.hideLoading(); uni.showModal({ title: '定位失败', - content: '定位功能暂时不可用,您可以手动输入位置信息。是否查看详细错误信息?', - showCancel: true, - cancelText: '取消', - confirmText: '查看详情', - success: (res) => { - if (res.confirm && this.isWechatBrowser) { - this.debugMode = true; // 自动开启调试模式以查看详情 - } - }, + content: '定位功能暂时不可用,您可以手动输入位置信息。', + showCancel: false, + confirmText: '确定', }); } }, @@ -1907,18 +1673,10 @@ export default { // 使用微信SDK进行定位(新版本,集成调试日志) async tryWeChatLocationWithSDK() { try { - this.addWechatLog('开始微信SDK定位...', 'info'); - const result = await this.wechatSDK.getLocation({ type: 'gcj02', // 火星坐标系,适合国内地图 }); - this.addWechatLog( - '微信定位API调用成功', - 'success', - JSON.stringify(result, null, 2), - ); - if (result.latitude && result.longitude) { this.geoLatitude = parseFloat(result.latitude); this.geoLongitude = parseFloat(result.longitude); @@ -1929,12 +1687,6 @@ export default { )}`; this.form.leaveLocation = locationStr; - this.addWechatLog( - `定位成功 - 纬度: ${this.geoLatitude}, 经度: ${this.geoLongitude}`, - 'success', - ); - this.addWechatLog(`位置精度: ${result.accuracy || '未知'}米`, 'info'); - uni.hideLoading(); uni.showToast({ title: '微信定位成功', @@ -1944,30 +1696,19 @@ export default { return true; } else { - this.addWechatLog( - '微信定位返回数据异常', - 'error', - JSON.stringify(result, null, 2), - ); return false; } } catch (error) { console.error('微信SDK定位失败:', error); - this.addWechatLog(`微信SDK定位失败: ${error.message}`, 'error'); // 根据错误类型提供更友好的提示 if (error.message && error.message.includes('denied')) { - this.addWechatLog('用户拒绝了位置权限请求', 'warning'); uni.showModal({ title: '定位权限', content: '需要获取位置信息来记录请假地点,请在微信中允许位置权限。', showCancel: false, confirmText: '知道了', }); - } else if (error.message && error.message.includes('unavailable')) { - this.addWechatLog('位置服务不可用,可能是设备问题', 'warning'); - } else if (error.message && error.message.includes('timeout')) { - this.addWechatLog('定位超时,网络或信号问题', 'warning'); } return false; @@ -2010,15 +1751,8 @@ export default { // 请假类型点击事件 (uview2) handleLeaveTypeClick() { - console.log('=== 请假类型点击事件触发 ==='); - console.log('请假类型输入框被点击,数据数量:', this.leaveTypeList.length); - console.log('当前选中的请假类型:', this.form.leaveTypeName); - console.log('当前选中的类型编码:', this.form.leaveTypeCode); - console.log('当前选中索引:', this.currentLeaveTypeIndex); - if (this.leaveTypeList.length === 0) { // 尝试重新获取数据 - console.log('数据为空,尝试重新获取...'); uni.showLoading({ title: '加载中...', }); @@ -2026,7 +1760,6 @@ export default { this.getLeaveTypeList() .then(() => { uni.hideLoading(); - console.log('重新获取后的数据量:', this.leaveTypeList.length); if (this.leaveTypeList.length > 0) { this.showLeaveTypePicker = true; uni.showToast({ @@ -2053,31 +1786,13 @@ export default { // uview2的picker需要设置为true来显示 this.showLeaveTypePicker = true; - console.log('显示picker选择器(uview2),状态:', this.showLeaveTypePicker); - console.log('leaveTypeOptions:', this.leaveTypeOptions); - console.log('默认索引:', [this.currentLeaveTypeIndex]); - - // 使用nextTick确保DOM更新 - this.$nextTick(() => { - console.log('nextTick后的picker状态:', this.showLeaveTypePicker); - console.log('nextTick后的leaveTypeOptions:', this.leaveTypeOptions); - if (this.leaveTypeOptions[0]) { - console.log('leaveTypeOptions第一列数据:', this.leaveTypeOptions[0]); - console.log('第一列数据长度:', this.leaveTypeOptions[0].length); - } - }); }, // 请假类型确认 (uview2格式) handleLeaveTypeConfirm(e) { - console.log('=== picker确认事件(uview2) ===', e); - console.log('事件完整参数:', JSON.stringify(e, null, 2)); - try { // uView2的picker确认事件:e.value是数组,包含选中的值(不是索引) const selectedValue = e.value[0]; // 获取选中的值(请假类型名称) - console.log('选中的值:', selectedValue); - console.log('值的类型:', typeof selectedValue); // 验证选中的值 if (!selectedValue) { @@ -2093,40 +1808,13 @@ export default { const selectedType = this.leaveTypeList.find( (item) => item.leaveTypeName === selectedValue, ); - console.log('查找条件 - selectedValue:', selectedValue); - console.log( - 'leaveTypeList:', - this.leaveTypeList.map((item) => ({ - name: item.leaveTypeName, - code: item.leaveTypeCode, - })), - ); - console.log('找到的请假类型对象:', selectedType); if (selectedType) { // 同时更新名称和编码 this.form.leaveTypeName = selectedType.leaveTypeName; this.form.leaveTypeCode = selectedType.leaveTypeCode; - - console.log('更新后的表单数据:'); - console.log('- 请假类型名称:', this.form.leaveTypeName); - console.log('- 请假类型编码:', this.form.leaveTypeCode); - - // 显示选择成功的提示 - // uni.showToast({ - // title: `已选择: ${selectedType.leaveTypeName}`, - // icon: 'success', - // duration: 1500, - // }); } else { console.error('未找到对应的请假类型对象'); - console.error('可能的原因:数据不匹配或字段名错误'); - - // 显示所有可用的请假类型名称用于调试 - const availableNames = this.leaveTypeList.map((item) => item.leaveTypeName); - console.error('可用的请假类型名称:', availableNames); - console.error('是否包含选中值:', availableNames.includes(selectedValue)); - uni.showToast({ title: '请假类型数据异常,请重试', icon: 'none', @@ -2140,56 +1828,35 @@ export default { }); } finally { this.showLeaveTypePicker = false; - console.log('关闭picker,当前表单状态:', { - leaveTypeName: this.form.leaveTypeName, - leaveTypeCode: this.form.leaveTypeCode, - }); } }, // 开始时间输入框点击事件 handleStartTimeClick() { - console.log('=== 开始时间点击事件 ==='); - console.log('当前startTimeValue:', this.startTimeValue); - console.log('minDate:', this.minDate, 'maxDate:', this.maxDate); - console.log('当前showStartTimePicker状态:', this.showStartTimePicker); - this.showStartTimePicker = true; - console.log('设置showStartTimePicker为true'); // 确保时间值正确 if (!this.startTimeValue || this.startTimeValue === '') { this.startTimeValue = new Date().getTime(); - console.log('重置startTimeValue为当前时间:', this.startTimeValue); } }, // 结束时间输入框点击事件 handleEndTimeClick() { - console.log('=== 结束时间点击事件 ==='); - console.log('当前endTimeValue:', this.endTimeValue); - console.log('minDate:', this.minDate, 'maxDate:', this.maxDate); - console.log('当前showEndTimePicker状态:', this.showEndTimePicker); - this.showEndTimePicker = true; - console.log('设置showEndTimePicker为true'); // 确保时间值正确 if (!this.endTimeValue || this.endTimeValue === '') { this.endTimeValue = new Date().getTime(); - console.log('重置endTimeValue为当前时间:', this.endTimeValue); } }, // 开始时间选择器确认 handleStartTimeConfirm(e) { - console.log('开始时间选择确认:', e); const timestamp = e.value; - console.log('选中的时间戳:', timestamp); // 格式化时间字符串 const dateStr = this.formatTimestamp(timestamp); - console.log('格式化后的时间字符串:', dateStr); this.form.startTime = dateStr; this.startTimeValue = timestamp; @@ -2199,13 +1866,10 @@ export default { // 结束时间选择器确认 handleEndTimeConfirm(e) { - console.log('结束时间选择确认:', e); const timestamp = e.value; - console.log('选中的时间戳:', timestamp); // 格式化时间字符串 const dateStr = this.formatTimestamp(timestamp); - console.log('格式化后的时间字符串:', dateStr); this.form.endTime = dateStr; this.endTimeValue = timestamp; @@ -2241,9 +1905,7 @@ export default { this.form.leaveDuration = diffDays.toFixed(2); } - console.log( - `请假天数计算: 开始时间=${this.form.startTime}, 结束时间=${this.form.endTime}, 天数=${this.form.leaveDuration}`, - ); + } }, @@ -2265,8 +1927,6 @@ export default { // 图片预览 handleImagePreview(image, index) { - console.log('图片预览:', image); - if (image.status !== 'success') { uni.showToast({ title: '图片尚未上传完成', @@ -2296,7 +1956,7 @@ export default { urls: imageUrls, current: currentIndex >= 0 ? currentIndex : 0, success: () => { - console.log('图片预览成功'); + // 预览成功 }, fail: (error) => { console.error('图片预览失败:', error); @@ -2310,28 +1970,9 @@ export default { // 图片下载(带重试机制) async handleImageDownload(image, event, retryCount = 0) { - this.addWechatLog('=== 图片下载方法开始执行 ===', 'info'); - this.addWechatLog( - '图片信息', - 'info', - JSON.stringify( - { - uid: image.uid, - ossId: image.ossId, - name: image.name, - url: image.url, - status: image.status, - retryCount: retryCount, - }, - null, - 2, - ), - ); - // 事件阻止已由handleImageDownloadClick方法处理 if (image.status !== 'success') { - this.addWechatLog('⚠️ 图片尚未上传完成,无法下载', 'warning'); uni.showToast({ title: '图片尚未上传完成', icon: 'none', @@ -2339,8 +1980,6 @@ export default { return; } - this.addWechatLog('📤 开始准备下载图片...', 'info'); - // 显示下载进度提示 uni.showLoading({ title: '正在下载图片...', @@ -2351,7 +1990,6 @@ export default { // 如果有ossId,通过API下载 if (image.ossId) { const downloadUrl = `/resource/oss/download/${image.ossId}`; - this.addWechatLog(`📥 使用API下载图片,URL: ${downloadUrl}`, 'info'); // 调用下载接口并等待完成 const response = await downloadFile(downloadUrl, image.name); @@ -2374,154 +2012,15 @@ export default { }, }); } - // 添加短暂延迟确保下载完成(特别是H5环境) - // await new Promise((resolve) => setTimeout(resolve, 500)); - - // this.addWechatLog('✅ 图片下载完成', 'success'); - - // 隐藏loading并显示成功提示 - - // uni.showToast({ - // title: '下载完成', - // icon: 'success', - // duration: 2000, - // }); - - // // 在H5环境中,使用blob数据创建下载链接 - // // #ifdef H5 - // const blob = new Blob([response], { type: 'application/octet-stream' }); - // const blobUrl = URL.createObjectURL(blob); - // const link = document.createElement('a'); - // link.href = blobUrl; - // link.download = image.name || 'image.jpg'; - // document.body.appendChild(link); - // link.click(); - // document.body.removeChild(link); - - // // 释放blob URL - // URL.revokeObjectURL(blobUrl); - - // this.addWechatLog('✅ H5环境图片下载已开始', 'success'); - // uni.hideLoading(); - // uni.showToast({ - // title: '下载已开始', - // icon: 'success', - // }); - // // #endif - - // // #ifndef H5 - // // 在小程序或App中,使用downloadFile - // uni.downloadFile({ - // url: downloadUrl, - // success: (res) => { - // if (res.statusCode === 200) { - // uni.saveImageToPhotosAlbum({ - // filePath: res.tempFilePath, - // success: () => { - // uni.showToast({ - // title: '保存成功', - // icon: 'success', - // }); - // }, - // fail: () => { - // uni.showToast({ - // title: '保存失败', - // icon: 'none', - // }); - // }, - // }); - // } - // }, - // fail: (error) => { - // this.addWechatLog( - // '❌ 图片下载失败', - // 'error', - // error.message || error.toString(), - // ); - // uni.showToast({ - // title: '下载失败', - // icon: 'none', - // }); - // }, - // complete: () => { - // uni.hideLoading(); - // }, - // }); - // // #endif } - // else { - // // 没有ossId的情况,直接使用图片URL - // const imageUrl = image.blobUrl || image.url; - // if (imageUrl) { - // // #ifdef H5 - // const link = document.createElement('a'); - // link.href = imageUrl; - // link.download = image.name || 'image.jpg'; - // document.body.appendChild(link); - // link.click(); - // document.body.removeChild(link); - - // uni.hideLoading(); - // uni.showToast({ - // title: '下载已开始', - // icon: 'success', - // }); - // // #endif - - // // #ifndef H5 - // uni.downloadFile({ - // url: imageUrl, - // success: (res) => { - // if (res.statusCode === 200) { - // uni.saveImageToPhotosAlbum({ - // filePath: res.tempFilePath, - // success: () => { - // uni.showToast({ - // title: '保存成功', - // icon: 'success', - // }); - // }, - // fail: () => { - // uni.showToast({ - // title: '保存失败', - // icon: 'none', - // }); - // }, - // }); - // } - // }, - // fail: (error) => { - // this.addWechatLog( - // '❌ 图片下载失败', - // 'error', - // error.message || error.toString(), - // ); - // uni.showToast({ - // title: '下载失败', - // icon: 'none', - // }); - // }, - // complete: () => { - // uni.hideLoading(); - // }, - // }); - // // #endif - // } - // } } catch (error) { - this.addWechatLog( - '❌ 图片下载过程出错', - 'error', - error.message || error.toString(), - ); + console.error('图片下载过程出错:', error); // 确保隐藏loading状态 uni.hideLoading(); // 重试机制(最多重试2次) if (retryCount < 2) { - this.addWechatLog(`🔄 准备进行第${retryCount + 1}次重试...`, 'warning'); - // 显示重试提示 uni.showToast({ title: `下载失败,正在重试(${retryCount + 1}/2)...`, @@ -2549,7 +2048,6 @@ export default { duration: 3000, }); } - this.addWechatLog('=== 图片下载方法执行完成 ===', 'success'); }, // 图片点击处理(智能判断是预览还是操作按钮) @@ -2584,18 +2082,11 @@ export default { // 图片下载按钮点击处理(更强的事件处理) handleImageDownloadClick(image, event) { - this.addWechatLog('🔽 图片下载按钮被点击', 'info'); - this.addWechatLog(`图片信息: ${JSON.stringify(image)}`, 'info'); - // 强制阻止事件冒泡和默认行为 if (event) { event.stopPropagation(); event.preventDefault(); event.stopImmediatePropagation(); - this.addWechatLog( - '✅ 事件冒泡已阻止 (stopPropagation + preventDefault + stopImmediatePropagation)', - 'success', - ); } // 调用实际的下载方法 @@ -2604,45 +2095,18 @@ export default { // 图片删除 handleImageDelete(image, index, event) { - this.addWechatLog('=== 图片删除方法开始执行 ===', 'info'); - this.addWechatLog(`删除图片参数 - 索引: ${index}`, 'info'); - this.addWechatLog( - '图片信息', - 'info', - JSON.stringify( - { - uid: image.uid, - ossId: image.ossId, - name: image.name, - url: image.url, - status: image.status, - }, - null, - 2, - ), - ); - this.addWechatLog(`当前附件列表数量: ${this.attachmentList.length}`, 'info'); - // 强制阻止事件冒泡和默认行为 if (event) { - this.addWechatLog('阻止事件冒泡和默认行为', 'info'); event.stopPropagation(); event.preventDefault(); } - this.addWechatLog('准备显示删除确认对话框', 'info'); uni.showModal({ title: '确认删除', content: '确定要删除这张图片吗?删除后无法恢复。', confirmColor: '#ff5722', success: (res) => { - this.addWechatLog( - `删除确认对话框回调 - 用户选择: ${res.confirm ? '确认' : '取消'}`, - 'info', - ); if (res.confirm) { - this.addWechatLog('用户确认删除,开始执行删除操作', 'success'); - // 从附件列表中删除 const attachmentIndex = this.attachmentList.findIndex( (file) => @@ -2651,44 +2115,12 @@ export default { (file.url && file.url === image.url), ); - this.addWechatLog(`查找到的附件索引: ${attachmentIndex}`, 'info'); - this.addWechatLog( - '匹配条件', - 'info', - `uid: ${image.uid}, ossId: ${image.ossId}, url: ${image.url}`, - ); - if (attachmentIndex >= 0) { - this.addWechatLog( - '删除前附件列表', - 'info', - JSON.stringify( - this.attachmentList.map((f) => ({ uid: f.uid, name: f.name })), - null, - 2, - ), - ); this.attachmentList.splice(attachmentIndex, 1); - this.addWechatLog( - '删除后附件列表', - 'info', - JSON.stringify( - this.attachmentList.map((f) => ({ uid: f.uid, name: f.name })), - null, - 2, - ), - ); - this.addWechatLog('✅ 图片从附件列表中删除成功', 'success'); - } else { - this.addWechatLog( - '⚠️ 警告:未找到要删除的附件,可能已被删除或索引错误', - 'warning', - ); } // 清理blob URL,防止内存泄漏 if (image.blobUrl && image.blobUrl.startsWith('blob:')) { - this.addWechatLog(`清理blob URL: ${image.blobUrl}`, 'info'); URL.revokeObjectURL(image.blobUrl); } @@ -2696,22 +2128,10 @@ export default { title: '删除成功', icon: 'success', }); - - this.addWechatLog( - `图片删除完成,当前附件数量: ${this.attachmentList.length}`, - 'success', - ); - this.addWechatLog('=== 图片删除方法执行完成 ===', 'success'); - } else { - this.addWechatLog('用户取消删除操作', 'warning'); } }, fail: (err) => { - this.addWechatLog( - '❌ 删除确认对话框显示失败', - 'error', - err.message || err.toString(), - ); + console.error('删除确认对话框显示失败:', err); }, }); }, @@ -3339,18 +2759,11 @@ export default { // 文件下载按钮点击处理(更强的事件处理) handleDownloadFileClick(file, event) { - this.addWechatLog('📁 文件下载按钮被点击', 'info'); - this.addWechatLog(`文件信息: ${JSON.stringify(file)}`, 'info'); - // 强制阻止事件冒泡和默认行为 if (event) { event.stopPropagation(); event.preventDefault(); event.stopImmediatePropagation(); - this.addWechatLog( - '✅ 事件冒泡已阻止 (stopPropagation + preventDefault + stopImmediatePropagation)', - 'success', - ); } // 调用实际的下载方法 @@ -3359,35 +2772,9 @@ export default { // 文件下载(微信小程序专用版本) async handleDownloadFile(file, event) { - this.addWechatLog('=== 文件下载方法开始执行 ===', 'info'); - this.addWechatLog('文件信息', 'info', JSON.stringify(file, null, 2)); - this.addWechatLog(`当前时间: ${new Date().toISOString()}`, 'info'); - // 事件阻止已由handleDownloadFileClick方法处理 - // 检查环境信息 - const systemInfo = uni.getSystemInfoSync(); - this.addWechatLog( - '运行环境信息', - 'info', - JSON.stringify( - { - platform: systemInfo.platform, - version: systemInfo.version, - model: systemInfo.model, - brand: systemInfo.brand, - }, - null, - 2, - ), - ); - if (!file.ossId) { - this.addWechatLog( - '❌ 下载失败:文件ossId为空', - 'warning', - JSON.stringify(file, null, 2), - ); uni.showToast({ title: '文件未上传完成', icon: 'none', @@ -3396,7 +2783,6 @@ export default { } try { - this.addWechatLog('📤 开始显示下载Loading...', 'info'); uni.showLoading({ title: `正在下载${file.name}...`, mask: true, @@ -3404,29 +2790,16 @@ export default { // 构建下载URL const downloadUrl = `/resource/oss/download/${file.ossId}`; - this.addWechatLog(`下载URL: ${downloadUrl}`, 'info'); - - // 根据文件类型选择处理方式 - this.addWechatLog( - `🔍 检查文件类型: ${file.name}, 是否为图片: ${this.isImageFile(file)}`, - 'info', - ); if (this.isImageFile(file)) { // 图片文件:下载并保存到相册 - this.addWechatLog('🖼️ 图片文件,下载并保存到相册', 'info'); await this.downloadAndSaveImage(downloadUrl, file.name); } else { // 非图片文件:下载并直接打开预览 - this.addWechatLog('📄 非图片文件,下载并打开预览', 'info'); await this.downloadAndOpenDocument(downloadUrl, file.name); } } catch (error) { - this.addWechatLog( - '❌ 下载过程发生异常', - 'error', - error.message || error.toString(), - ); + console.error('下载过程发生异常:', error); uni.hideLoading(); let errorMsg = '下载失败,请重试'; @@ -3453,8 +2826,6 @@ export default { }, }); } - - this.addWechatLog('=== 文件下载方法执行完成 ===', 'success'); }, // 下载图片并保存到相册 @@ -3525,7 +2896,6 @@ export default { // H5环境:直接使用浏览器下载 // this.downloadFileInBrowser(downloadUrl, fileName); // const downloadUrl = `/resource/oss/download/${image.ossId}`; - this.addWechatLog(`📥 使用API下载图片,URL: ${downloadUrl}`, 'info'); // 调用下载接口并等待完成 const response = await downloadFile(downloadUrl, fileName);