diff --git a/pages/work/order/order-review.vue b/pages/work/order/order-review.vue index 1f39dd0..d89ba7f 100644 --- a/pages/work/order/order-review.vue +++ b/pages/work/order/order-review.vue @@ -4,7 +4,7 @@ - + { + this._debugClickCount = 0; + }, 2000); + if (this._debugClickCount >= 10) { + this._debugClickCount = 0; + if (this._debugClickTimer) { + clearTimeout(this._debugClickTimer); + this._debugClickTimer = null; + } + this._debugMode = !this._debugMode; + if (this._debugMode) { + // 清空旧日志 + this._debugLogs = []; + this.debugLog('调试模式', '已开启'); + // #ifdef APP-PLUS + const filePath = '_doc/print_debug_log.txt'; + uni.showToast({ + title: `调试模式已开启,日志文件:${filePath}`, + icon: 'none', + duration: 3000 + }); + // #endif + // #ifndef APP-PLUS + uni.showToast({ + title: '调试模式已开启(仅App端可写入文件)', + icon: 'none', + duration: 2000 + }); + // #endif + } else { + this.flushDebugLogs(); + uni.showToast({ + title: '调试模式已关闭', + icon: 'none' + }); + } + } + }, + debugLog(label, data) { + if (!this._debugMode) return; + const timestamp = new Date().toLocaleString(); + const text = `[${timestamp}][${label}] ${typeof data === 'string' ? data : JSON.stringify(data, null, 2)}`; + this._debugLogs.push(text); + // 每10条写入一次文件 + if (this._debugLogs.length >= 10) { + this.flushDebugLogs(); + } + }, + flushDebugLogs() { + if (!this._debugLogs.length) return; + const content = this._debugLogs.join('\n') + '\n'; + this._debugLogs = []; + // #ifdef APP-PLUS + try { + plus.io.requestFileSystem(plus.io.PRIVATE_DOC, fs => { + fs.root.getFile('print_debug_log.txt', { create: true }, fileEntry => { + fileEntry.file(file => { + const reader = new plus.io.FileReader(); + reader.onloadend = e => { + const existing = e.target.result || ''; + fileEntry.createWriter(writer => { + writer.seek(file.size); + writer.write(content); + }); + }; + reader.readAsText(file); + }); + }); + }); + } catch (e) { + console.warn('[debugLog] 写入文件失败:', e); + } + // #endif + }, handleCameraScan() { uni.scanCode({ onlyFromCamera: true, @@ -1418,6 +1509,7 @@ } const params = this.buildPrintSendParams(); + this.debugLog('print.send 请求参数', params); const effectivePrintCount = Number(this.pendingPrintCount || 0) > 0 ? Number(this.pendingPrintCount || 0) : this.printWaveGroups.length; @@ -1426,6 +1518,7 @@ }); try { const response = await this.$http('print.send', params); + this.debugLog('print.send 返回数据', response); const success = response?.flag !== 'failure' && response?.code !== '500' && response?.code !== 500; if (!success) { throw new Error(response?.message || response?.msg || '打印失败'); @@ -1516,7 +1609,9 @@ waveGroups } }; + this.debugLog('print.send 请求参数', sendParams); const sendResponse = await this.$http('print.send', sendParams); + this.debugLog('print.send 返回数据', sendResponse); const success = sendResponse?.flag !== 'failure' && sendResponse?.code !== '500' && sendResponse?.code !== 500; if (!success) { throw new Error(sendResponse?.message || sendResponse?.msg || '打印发送失败');