guoyuji
2024-10-12 acaf8ca38cd32bc474bb46b593db2a8d75b9bfdd
north-glass-erp/northglass-erp/src/hook/queue.js
New file
@@ -0,0 +1,34 @@
/**
 * Queue hook
 * 打印队列方法
 */
export default function QueuePrinter(list,hiprintTemplate,columnsNum){
    const queue = JSON.parse(JSON.stringify(list));
    // 添加打印任务
    this.printJob = function(job) {
        queue.push(job);
    };
    // 模拟打印
    this.tick = setInterval(()=>{
                if(typeof queue === 'object' && Array.isArray(queue)){
                    if (queue.length > 0) {
                        hiprintTemplate.value.print2(queue[0])
                        queue.shift(); // 打印任务,并从队列中移除
                    }else{
                        clearInterval(this.tick)
                    }
                }else{
                    if (queue.table.length > 0) {
                        hiprintTemplate.value.print2({table:queue.table.slice(0, columnsNum)})
                        queue.table.splice(0, columnsNum);
                    }else{
                        clearInterval(this.tick)
                    }
                }
        },
        5000)
};