async function printContent() {
    return new Promise(resolve => {
        let canvas = document.createElement("canvas");
        let barCodeClone = "6954301173908";
        // 生成条形码
        JsBarcode(canvas, barCodeClone, {
            format: "EAN13",
            width: 3,
            height: 40,
            displayValue: false
        });
        let imageData = canvas.toDataURL("image/png", 1);
        let image = '<img src="' + imageData + '">';

        let str = barCodeClone + "";
        let str1 = str.substring(0, 1);
        let str2 = str.substring(1, 7);
        let str3 = str.substring(7, 14);

        //去空
        LODOP.ADD_PRINT_IMAGE(10, 24, 130, 32, image); // 添加图片
        LODOP.SET_PRINT_STYLEA(0, "Stretch", 1);
        //69文字
        LODOP.ADD_PRINT_TEXT(32, 22, 10, 10, `${str1}`);
        LODOP.ADD_PRINT_TEXT(32, 37, 74, 10, `${str2}`);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 4);
        LODOP.ADD_PRINT_TEXT(32, 95, 74, 10, `${str3}`);
        LODOP.SET_PRINT_STYLEA(0, "LetterSpacing", 4);
        LODOP.PREVIEW(); // 可以改成 LODOP.PRINT() 直接打印
        resolve();
    });
}

export const testPrint = async () => {
    const batchSize = 10; // 每批打印的数量
    const totalPrints = 1000; // 总打印数量

    for (let i = 0; i < totalPrints; i += batchSize) {
        const batchEnd = Math.min(i + batchSize, totalPrints);
        const batchPromises = [];

        for (let j = i; j < batchEnd; j++) {
            batchPromises.push(printContent());
        }

        // 使用 Promise.all 等待当前批次的所有打印任务完成
        await Promise.all(batchPromises);
    }

    console.log("All print jobs completed");
};
