等待增加打印模板后端渲染
This commit is contained in:
parent
81515b035d
commit
0a2e1cc47b
@ -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;
|
||||
@ -176,8 +413,6 @@ Component({
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
const totalCodes = allValuesToPrint.length;
|
||||
let sentCodes = 0;
|
||||
let totalChunks = 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({
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<view class="page-section">
|
||||
<view class="page-section-demo">
|
||||
<text> v1.0.11 </text>
|
||||
<text> v1.0.12 </text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="nav-container">
|
||||
|
||||
@ -24,3 +24,12 @@
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
/* 让 rich-text 内的文字字体变小 */
|
||||
rich-text {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 让 textarea 内的文字字体变小 */
|
||||
textarea {
|
||||
font-size: 12px;
|
||||
}
|
||||
@ -2,7 +2,18 @@
|
||||
<view>
|
||||
<rich-text nodes="{{nodes}}" onTap="tap"></rich-text>
|
||||
</view>
|
||||
|
||||
<view class="page-section">
|
||||
<view class="page-section-title">TSPL指令集</view>
|
||||
<view class="page-section-demo">
|
||||
<textarea onBlur="bindTextAreaBlur" auto-height placeholder="Please input something" value="{{tspl.code}}" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="page-section">
|
||||
<view class="page-section-title">TSPL指令集</view>
|
||||
<view class="page-section-demo">
|
||||
<textarea onBlur="bindTextAreaBlur" auto-height placeholder="Please input something" value="{{tspl.currentCode}}" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="cart-bottom">
|
||||
<view class="cart-info">
|
||||
</view>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
|
||||
import jsonrpcFunc from '../../../../../../ulti/jsonrpc'
|
||||
Page({
|
||||
data: {
|
||||
nodes: [{
|
||||
@ -13,9 +14,24 @@ Page({
|
||||
text: 'Hello World! 拖拉设计打印模板待开发',
|
||||
}],
|
||||
}],
|
||||
tspl:{},
|
||||
loginInfo: '', //权限验证信息
|
||||
},
|
||||
onLoad(query) {
|
||||
// 页面加载
|
||||
const loginInfo = dd.getStorageSync({
|
||||
key: 'loginInfo'
|
||||
}).data;
|
||||
if (loginInfo && loginInfo.apiurl && loginInfo.databaseName && loginInfo.username && loginInfo.password && loginInfo.uid > 0) {
|
||||
this.setData({
|
||||
loginInfo
|
||||
});
|
||||
// console.log('销售页得到的本地信息', loginInfo);
|
||||
//执行获取销售订单第一页数据分页第一页默认
|
||||
this.fetchData(1);
|
||||
} else {
|
||||
// console.log('本地缓存中未获取到登录信息');
|
||||
}
|
||||
},
|
||||
onReady() {
|
||||
// 页面加载完成
|
||||
@ -51,4 +67,46 @@ Page({
|
||||
console.log('tap');
|
||||
},
|
||||
//
|
||||
fetchData(page) {
|
||||
const {
|
||||
loginInfo,
|
||||
} = this.data;
|
||||
// 调用 search_count 方法获取总记录数
|
||||
const tspl = {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "call",
|
||||
"id": 2,
|
||||
"params": {
|
||||
"service": "object",
|
||||
"method": "execute_kw",
|
||||
"args": [
|
||||
loginInfo.databaseName,
|
||||
loginInfo.uid,
|
||||
loginInfo.password,
|
||||
'sale.order',
|
||||
"tspl",
|
||||
[
|
||||
[]
|
||||
],
|
||||
{}
|
||||
]
|
||||
}
|
||||
};
|
||||
jsonrpcFunc(loginInfo, tspl)
|
||||
.then((response) => {
|
||||
// 保存数据到本地缓存
|
||||
dd.setStorageSync({
|
||||
key: 'tspl',
|
||||
data: response
|
||||
});
|
||||
this.setData({
|
||||
tspl: response
|
||||
});
|
||||
console.log("response", response)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("获取打印模板失败")
|
||||
// console.error('请求数据时出错:', error);
|
||||
});
|
||||
},
|
||||
});
|
||||
@ -48,7 +48,7 @@
|
||||
</form>
|
||||
<view class="page-section">
|
||||
<view class="page-section-demo">
|
||||
<text> v1.0.11 </text>
|
||||
<text> v1.0.12 </text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -1,3 +1,4 @@
|
||||
import jsonrpcFunc from '../ulti/jsonrpc'
|
||||
Page({
|
||||
data: {
|
||||
apiurl: '',
|
||||
@ -134,6 +135,7 @@ Page({
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
dd.httpRequest({
|
||||
url: `${apiurl}/jsonrpc`,
|
||||
@ -162,6 +164,38 @@ Page({
|
||||
password,
|
||||
databaseName
|
||||
};
|
||||
// const session_id = {
|
||||
// "jsonrpc": "2.0",
|
||||
// "method": "call",
|
||||
// "id": 2,
|
||||
// "params": {
|
||||
// "service": "object",
|
||||
// "method": "execute_kw",
|
||||
// "args": [
|
||||
// databaseName,
|
||||
// uid,
|
||||
// password,
|
||||
// "ir.http",
|
||||
// "session_info",
|
||||
// [],
|
||||
// {}
|
||||
// ]
|
||||
// }
|
||||
// };
|
||||
// jsonrpcFunc(loginInfo, session_id)
|
||||
// .then((response) => {
|
||||
// // 保存数据到本地缓存
|
||||
// dd.setStorageSync({
|
||||
// key: 'session_id',
|
||||
// data: response
|
||||
// });
|
||||
// console.log("response", response)
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.log("获取session_id失败")
|
||||
// // console.error('请求数据时出错:', error);
|
||||
// });
|
||||
//
|
||||
dd.setStorageSync({
|
||||
key: 'loginInfo',
|
||||
data: loginInfo
|
||||
@ -170,6 +204,7 @@ Page({
|
||||
reject(new Error(`保存登录信息到本地缓存失败: ${e.message}`));
|
||||
return;
|
||||
}
|
||||
|
||||
if (uid) {
|
||||
dd.switchTab({
|
||||
url: '/pages/deal/deal',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user