新增打印日志:订单复核的打印功能
This commit is contained in:
parent
f49411c428
commit
6c2f8895a6
@ -4,7 +4,7 @@
|
||||
<page-nav :title="title"></page-nav>
|
||||
|
||||
<view class="search-filter">
|
||||
<view class="search-box">
|
||||
<view class="search-box" @click="handleSearchBoxDebugTap">
|
||||
<view class="search-box-inner">
|
||||
<u-search
|
||||
v-model="keyword"
|
||||
@ -250,6 +250,10 @@
|
||||
taskId: '',
|
||||
scanPickerName: '',
|
||||
reviewedOrderIds: [],
|
||||
_debugClickCount: 0,
|
||||
_debugClickTimer: null,
|
||||
_debugMode: false,
|
||||
_debugLogs: [],
|
||||
_navigatedToDetail: false
|
||||
};
|
||||
},
|
||||
@ -329,6 +333,13 @@
|
||||
onUnload() {
|
||||
this.safeDispatchBroadcast('stop');
|
||||
uni.$off('orderInterceptCompleted', this.handleInterceptCompleted);
|
||||
if (this._debugMode) {
|
||||
this.flushDebugLogs();
|
||||
}
|
||||
if (this._debugClickTimer) {
|
||||
clearTimeout(this._debugClickTimer);
|
||||
this._debugClickTimer = null;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
buildBatchListParams(page = this.currentPage) {
|
||||
@ -792,6 +803,86 @@
|
||||
this.keyword = this.normalizeKeyword(this.keyword);
|
||||
this.requestScanOrder(this.keyword);
|
||||
},
|
||||
handleSearchBoxDebugTap() {
|
||||
this._debugClickCount += 1;
|
||||
// 超过2秒未继续点击则重置计数
|
||||
if (this._debugClickTimer) {
|
||||
clearTimeout(this._debugClickTimer);
|
||||
}
|
||||
this._debugClickTimer = setTimeout(() => {
|
||||
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 || '打印发送失败');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user