From 0a2e1cc47bd8e2d6c27becc80e3b8852a9a31b17 Mon Sep 17 00:00:00 2001 From: XiaoJia Chen <441785369@qq.com> Date: Sun, 20 Apr 2025 01:24:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=89=E5=BE=85=E5=A2=9E=E5=8A=A0=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=A8=A1=E6=9D=BF=E5=90=8E=E7=AB=AF=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/components/bluetooth/bluetooth.js | 329 +++++++++++++++--- pages/deal/deal.axml | 2 +- .../printTag/printTemplate/printTemplate.acss | 11 +- .../printTag/printTemplate/printTemplate.axml | 13 +- .../printTag/printTemplate/printTemplate.js | 58 +++ pages/index/index.axml | 2 +- pages/index/index.js | 35 ++ 7 files changed, 389 insertions(+), 61 deletions(-) diff --git a/pages/components/bluetooth/bluetooth.js b/pages/components/bluetooth/bluetooth.js index d5fcb0f..f20a8fc 100644 --- a/pages/components/bluetooth/bluetooth.js +++ b/pages/components/bluetooth/bluetooth.js @@ -38,7 +38,8 @@ Component({ // 存储获取到的可写特征值列表 writableCharacteristics: [], // 存储所有服务及其特征值 - allServicesAndCharacteristics: {} + allServicesAndCharacteristics: {}, + tspl: {} }, props: { printdata: { @@ -84,7 +85,243 @@ Component({ } }, methods: { + // onSubmit() { + // const tspl = dd.getStorageSync({ + // key: 'tspl' + // }).data; + // if (tspl) { + // this.setData({ + // tspl + // }); + // console.log('tspl', tspl); + // } else { + // // console.log('本地缓存中未获取到登录信息'); + // } + // const selectedDevice = this.data.selectedDevice; + // console.log('selectedDevice', selectedDevice); + // const isConnected = this.data.isConnected; + // // 检查蓝牙设备是否已连接 + // if (!selectedDevice || !isConnected) { + // console.log('请先连接蓝牙设备'); + // const title = '请先连接蓝牙设备'; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } + // return; + // } + + // // 从可写特征值列表中获取第一个可写特征值(这里假设只有一个可写特征值,你可以根据实际情况调整) + // const writableCharacteristic = this.data.writableCharacteristics[0]; + // console.log('writableCharacteristics', this.data.writableCharacteristics); + // if (!writableCharacteristic) { + // console.log('未找到可写特征值'); + // const title = '未找到可写特征值'; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } + // return; + // } + + // const serviceId = writableCharacteristic.serviceId; + // const characteristicId = writableCharacteristic.characteristicId; + // const deviceId = selectedDevice.deviceId; + + // // 检查参数完整性 + // if (!deviceId || !serviceId || !characteristicId) { + // console.error('缺少必要参数:', { + // deviceId, + // serviceId, + // characteristicId + // }); + // const title = '缺少必要参数,请检查连接'; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } + // return; + // } + // //打印数据处理 + // const selectedSaleOrderLines = dd.getStorageSync({ + // key: 'selectedSaleOrderLines' + // }).data; + // const printdata = selectedSaleOrderLines || {}; + // this.setData({ + // printdata + // }); + + // const allValuesToPrint = []; + // // 检查打印数据是否存在,并且 selectedItems 是一个数组 + // if (printdata && printdata.selectedItems && Array.isArray(printdata.selectedItems)) { + // // 遍历 selectedItems 数组 + // printdata.selectedItems.forEach((item) => { + // // 输出当前遍历的 item + // console.log('每个订单行数据item:', item); + // // 检查 item 的 fineCode3Names 是否存在,并且是一个数组 + // if (item.fineCode3Names && Array.isArray(item.fineCode3Names)) { + // // 遍历 fineCode3Names 数组 + // item.fineCode3Names.forEach((value) => { + // // 将可能的浮点数转换为文本 + // const nameValue = typeof item.name === 'number'? item.name.toString() : item.name; + // const colorValue = typeof item.color_id_2[1] === 'number'? item.color_id_2[1].toString() : item.color_id_2[1]; + // const codeValue = typeof value === 'number'? value.toString() : value; + // // 去除中文和[]符号 + // const nameValuereplace = nameValue.replace(/[\u4e00-\u9fa5\[\]]/g, ''); + // // 拼接要打印的内容 + // value = `货号: ${nameValuereplace}.色号: ${colorValue}.细码: ${codeValue}`; + + // // allValuesToPrint.push(value); + // allValuesToPrint.push({ + // name: `货号: ${nameValuereplace}`, + // color: `色号: ${colorValue}`, + // code: `细码: ${codeValue}` + // }); + // }); + // } + // }); + // } + + + + // const totalCodes = allValuesToPrint.length; + // let sentCodes = 0; + // let totalChunks = 0; + // let sentChunks = 0; + + // // 计算总的数据块数量 + // allValuesToPrint.forEach((code) => { + // const command = ` + // SIZE 75 mm,60 mm + // GAP 2,0 + // CLS + // QRCODE 20,150,H,5,A,0,"${code.name} ${code.color} ${code.code} 020-89061189" + // TEXT 200,100,"TSS32.BF2",0,1,1,"${code.name}" + // TEXT 200,200,"TSS32.BF2",0,1,1,"${code.color}" + // TEXT 200,300,"TSS32.BF2",0,1,1,"${code.code}" + // TEXT 20,400,"TSS24.BF2",0,1,1,"备注:如经裁剪或加工后本布行概不负责" + // PRINT 1,1 + // `; + + // // const encoder = new TextEncoder('utf-8'); + // // const commandBuffer = encoder.encode(command); + // // const commandBuffer = Buffer.from(command, 'utf8'); + // const commandBuffer = iconv.encode(command, 'GB18030'); + // const hexValue = Array.from(commandBuffer) + // .map(byte => byte.toString(16).padStart(2, '0')) + // .join(''); + // const chunkSize = 40; + // const chunks = []; + // for (let i = 0; i < hexValue.length; i += chunkSize) { + // chunks.push(hexValue.slice(i, i + chunkSize)); + // } + // totalChunks += chunks.length; + // }); + + // const sendPrintCode = (index) => { + // if (index >= allValuesToPrint.length) { + // console.log('所有 printcode 数据发送完成'); + // this.setData({ + // percent: '100', + // }); + // return; + // } + + // const currentCode = allValuesToPrint[index]; + // const command = ` + // SIZE 75 mm,60 mm + // GAP 2,0 + // CLS + // QRCODE 20,150,H,5,A,0,"${currentCode.name} ${currentCode.color} ${currentCode.code} 020-89061189" + // TEXT 200,100,"TSS32.BF2",0,1,1,"${currentCode.name}" + // TEXT 200,200,"TSS32.BF2",0,1,1,"${currentCode.color}" + // TEXT 200,300,"TSS32.BF2",0,1,1,"${currentCode.code}" + // TEXT 20,400,"TSS24.BF2",0,1,1,"备注:如经裁剪或加工后本布行概不负责" + // PRINT 1,1 + // `; + + // // const encoder = new TextEncoder('utf-8'); + // // const commandBuffer = encoder.encode(command); + // console.log("command",command) + // // const commandBuffer = Buffer.from(command, 'utf8'); + // const commandBuffer = iconv.encode(command, 'GB18030'); + // // 将二进制数据转换为 hex 编码 + // const hexValue = Array.from(commandBuffer) + // .map(byte => byte.toString(16).padStart(2, '0')) + // .join(''); + + // // 分段发送数据 + // const chunkSize = 40; // 每个分段的长度,20 字节 = 40 个十六进制字符 + // const chunks = []; + // for (let i = 0; i < hexValue.length; i += chunkSize) { + // chunks.push(hexValue.slice(i, i + chunkSize)); + // } + + // const sendNextChunk = (chunkIndex) => { + // if (chunkIndex >= chunks.length) { + // console.log(`printcode ${currentCode} 的所有数据分段发送完成`); + // sentCodes++; + // sendPrintCode(index + 1); + // return; + // } + + // const currentChunk = chunks[chunkIndex]; + // console.log(`准备发送 printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段,长度: ${currentChunk.length}`, currentChunk); + // dd.writeBLECharacteristicValue({ + // deviceId, + // serviceId, + // characteristicId, + // value: currentChunk, + // success: (res) => { + // console.log(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送成功`, res); + // sentChunks++; + // const percent = ((sentChunks / totalChunks) * 100).toFixed(0); + // this.setData({ + // percent: percent, + // }); + // sendNextChunk(chunkIndex + 1); + // }, + // fail: (res) => { + // console.error(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送失败,错误码:`, res.errorCode); + // const title = `printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送失败,错误码: ${res.errorCode}`; + // if (title) { + // dd.showToast({ + // title: title, + // icon: 'none' + // }); + // } + // }, + // complete: (res) => { + // console.log(`printcode ${currentCode} 的第 ${chunkIndex + 1} 个数据分段发送调用结束`, res); + // } + // }); + // }; + + // sendNextChunk(0); + // }; + + // sendPrintCode(0); + // }, onSubmit() { + const tspl = dd.getStorageSync({ + key: 'tspl' + }).data; + if (tspl) { + this.setData({ + tspl + }); + console.log('tspl', tspl); + } else { + // console.log('本地缓存中未获取到登录信息'); + return; + } + const selectedDevice = this.data.selectedDevice; console.log('selectedDevice', selectedDevice); const isConnected = this.data.isConnected; @@ -136,7 +373,7 @@ Component({ } return; } - //打印数据处理 + // 打印数据处理 const selectedSaleOrderLines = dd.getStorageSync({ key: 'selectedSaleOrderLines' }).data; @@ -150,33 +387,31 @@ Component({ if (printdata && printdata.selectedItems && Array.isArray(printdata.selectedItems)) { // 遍历 selectedItems 数组 printdata.selectedItems.forEach((item) => { - // 输出当前遍历的 item - console.log('每个订单行数据item:', item); - // 检查 item 的 fineCode3Names 是否存在,并且是一个数组 - if (item.fineCode3Names && Array.isArray(item.fineCode3Names)) { - // 遍历 fineCode3Names 数组 - item.fineCode3Names.forEach((value) => { - // 将可能的浮点数转换为文本 - const nameValue = typeof item.name === 'number'? item.name.toString() : item.name; - const colorValue = typeof item.color_id_2[1] === 'number'? item.color_id_2[1].toString() : item.color_id_2[1]; - const codeValue = typeof value === 'number'? value.toString() : value; - // 去除中文和[]符号 - const nameValuereplace = nameValue.replace(/[\u4e00-\u9fa5\[\]]/g, ''); - // 拼接要打印的内容 - value = `货号: ${nameValuereplace}.色号: ${colorValue}.细码: ${codeValue}`; + // 输出当前遍历的 item + console.log('每个订单行数据item:', item); + // 检查 item 的 fineCode3Names 是否存在,并且是一个数组 + if (item.fineCode3Names && Array.isArray(item.fineCode3Names)) { + // 遍历 fineCode3Names 数组 + item.fineCode3Names.forEach((value) => { + // 将可能的浮点数转换为文本 + const nameValue = typeof item.name === 'number' ? item.name.toString() : item.name; + const colorValue = typeof item.color_id_2[1] === 'number' ? item.color_id_2[1].toString() : item.color_id_2[1]; + const codeValue = typeof value === 'number' ? value.toString() : value; + // 去除中文和[]符号 + const nameValuereplace = nameValue.replace(/[\u4e00-\u9fa5\[\]]/g, ''); + // 拼接要打印的内容 + value = `货号: ${nameValuereplace}.色号: ${colorValue}.细码: ${codeValue}`; - // allValuesToPrint.push(value); - allValuesToPrint.push({ - name: `货号: ${nameValuereplace}`, - color: `色号: ${colorValue}`, - code: `细码: ${codeValue}` - }); - }); - } + // allValuesToPrint.push(value); + allValuesToPrint.push({ + name: `货号: ${nameValuereplace}`, + color: `色号: ${colorValue}`, + code: `细码: ${codeValue}` + }); + }); + } }); - } - - + } const totalCodes = allValuesToPrint.length; let sentCodes = 0; @@ -185,21 +420,12 @@ Component({ // 计算总的数据块数量 allValuesToPrint.forEach((code) => { - const command = ` - SIZE 75 mm,60 mm - GAP 2,0 - CLS - QRCODE 20,150,H,5,A,0,"${code.name} ${code.color} ${code.code} 020-89061189" - TEXT 200,100,"TSS32.BF2",0,1,1,"${code.name}" - TEXT 200,200,"TSS32.BF2",0,1,1,"${code.color}" - TEXT 200,300,"TSS32.BF2",0,1,1,"${code.code}" - TEXT 20,400,"TSS24.BF2",0,1,1,"备注:如经裁剪或加工后本布行概不负责" - PRINT 1,1 - `; + // 使用 tspl 模板,并替换其中的值 + let command = tspl.code; + command = command.replace('{{name}}', code.name) + .replace('{{color}}', code.color) + .replace('{{code}}', code.code); - // const encoder = new TextEncoder('utf-8'); - // const commandBuffer = encoder.encode(command); - // const commandBuffer = Buffer.from(command, 'utf8'); const commandBuffer = iconv.encode(command, 'GB18030'); const hexValue = Array.from(commandBuffer) .map(byte => byte.toString(16).padStart(2, '0')) @@ -222,22 +448,12 @@ Component({ } const currentCode = allValuesToPrint[index]; - const command = ` - SIZE 75 mm,60 mm - GAP 2,0 - CLS - QRCODE 20,150,H,5,A,0,"${currentCode.name} ${currentCode.color} ${currentCode.code} 020-89061189" - TEXT 200,100,"TSS32.BF2",0,1,1,"${currentCode.name}" - TEXT 200,200,"TSS32.BF2",0,1,1,"${currentCode.color}" - TEXT 200,300,"TSS32.BF2",0,1,1,"${currentCode.code}" - TEXT 20,400,"TSS24.BF2",0,1,1,"备注:如经裁剪或加工后本布行概不负责" - PRINT 1,1 - `; - - // const encoder = new TextEncoder('utf-8'); - // const commandBuffer = encoder.encode(command); + // 使用 tspl 模板,并替换其中的值 + let command = tspl.code; + command = command.replace('{{name}}', currentCode.name) + .replace('{{color}}', currentCode.color) + .replace('{{code}}', currentCode.code); console.log("command",command) - // const commandBuffer = Buffer.from(command, 'utf8'); const commandBuffer = iconv.encode(command, 'GB18030'); // 将二进制数据转换为 hex 编码 const hexValue = Array.from(commandBuffer) @@ -297,7 +513,6 @@ Component({ sendPrintCode(0); }, - getBluetoothAdapterState() { // 调用 dd.getBluetoothAdapterState 方法获取本机蓝牙模块的状态 dd.getBluetoothAdapterState({ diff --git a/pages/deal/deal.axml b/pages/deal/deal.axml index e87bf60..648cdde 100644 --- a/pages/deal/deal.axml +++ b/pages/deal/deal.axml @@ -1,6 +1,6 @@ - v1.0.11 + v1.0.12 diff --git a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/printTemplate.acss b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/printTemplate.acss index 9366157..c351ccd 100644 --- a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/printTemplate.acss +++ b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/printTemplate.acss @@ -23,4 +23,13 @@ border: none; border-radius: 5px; } - \ No newline at end of file + +/* 让 rich-text 内的文字字体变小 */ +rich-text { + font-size: 12px; +} + +/* 让 textarea 内的文字字体变小 */ +textarea { + font-size: 12px; +} \ No newline at end of file diff --git a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/printTemplate.axml b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/printTemplate.axml index f1e100b..0b3a60e 100644 --- a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/printTemplate.axml +++ b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/printTemplate.axml @@ -2,7 +2,18 @@ - + + TSPL指令集 + +