小票打印机

This commit is contained in:
jjLv 2025-09-11 15:54:17 +08:00
parent cdfa2ec3da
commit 85d1909fd7
2 changed files with 60 additions and 48 deletions

View File

@ -1,7 +1,7 @@
var port = 18080; var port = 18080;
var connectionMode = "ws:"; var connectionMode = "ws:";
var wsPrint = null; var wsPrint = null;
let wsGetPrinterList = null; var wsGetPrinterList = null;
var CHUNK_SIZE = 1024 * 64; var CHUNK_SIZE = 1024 * 64;
const WebSocketPrint = function (serverURL, strPrinterName, request, callback) { const WebSocketPrint = function (serverURL, strPrinterName, request, callback) {
@ -187,6 +187,7 @@ export {
requestPrint, requestPrint,
getPrinterList, getPrinterList,
wsPrint, wsPrint,
wsGetPrinterList,
WebSocketPrint, WebSocketPrint,
WebSocketGetPrinterList WebSocketGetPrinterList
} }

View File

@ -117,14 +117,16 @@
</el-cascader> </el-cascader>
</el-form-item> </el-form-item>
<!-- <el-form-item label="小票打印机" prop="deptIdList">--> <!-- <el-form-item label="小票打印机" prop="deptIdList">-->
<!-- <el-select v-model="printerName" clearable collapse-tags style="width: 220px">--> <!-- <el-input v-model="printerName" placeholder="请输入订单号" maxlength="20" clearable-->
<!-- <el-option--> <!-- style="width: 220px"/>-->
<!-- v-for="item in printList"--> <!--&lt;!&ndash; <el-select v-model="printerName" placeholder="请选择小票打印机" clearable collapse-tags style="width: 220px">&ndash;&gt;-->
<!-- :key="item.value"--> <!--&lt;!&ndash; <el-option&ndash;&gt;-->
<!-- :label="item.name"--> <!--&lt;!&ndash; v-for="item in printList"&ndash;&gt;-->
<!-- :value="item.value"--> <!--&lt;!&ndash; :key="item.value"&ndash;&gt;-->
<!-- />--> <!--&lt;!&ndash; :label="item.name"&ndash;&gt;-->
<!-- </el-select>--> <!--&lt;!&ndash; :value="item.value">&ndash;&gt;-->
<!--&lt;!&ndash; </el-option>&ndash;&gt;-->
<!--&lt;!&ndash; </el-select>&ndash;&gt;-->
<!-- </el-form-item>--> <!-- </el-form-item>-->
@ -537,16 +539,16 @@
<!-- 提醒对话框 --> <!-- 提醒对话框 -->
<el-dialog :title="handleType+'提醒'" :visible.sync="openRemind" width="40%" append-to-body> <el-dialog :title="handleType+'提醒'" :visible.sync="openRemind" width="40%" append-to-body>
<div> <!-- <div>-->
<el-select v-model="printerName" clearable collapse-tags style="width: 220px"> <!-- <el-select v-model="printerName" clearable collapse-tags style="width: 220px">-->
<el-option <!-- <el-option-->
v-for="item in printList" <!-- v-for="item in printList"-->
:key="item.value" <!-- :key="item.value"-->
:label="item.name" <!-- :label="item.name"-->
:value="item.value" <!-- :value="item.value"-->
/> <!-- />-->
</el-select> <!-- </el-select>-->
</div> <!-- </div>-->
<div class="remind-question">请问是否对以下可{{ handleType }}订单进行{{ handleType }}操作</div> <div class="remind-question">请问是否对以下可{{ handleType }}订单进行{{ handleType }}操作</div>
<div class="remind-title">{{ handleType }}订单 {{ ableList.length }} </div> <div class="remind-title">{{ handleType }}订单 {{ ableList.length }} </div>
<div v-for="(item,index) in ableList" :key="item.orderId">{{ (index + 1) }}. <div v-for="(item,index) in ableList" :key="item.orderId">{{ (index + 1) }}.
@ -694,38 +696,46 @@ export default {
created() { created() {
// this.printerName = '' // this.printerName = ''
// this.printList = [] // this.printList = []
this.PosPrinter = new WebSDK.EscPosCommand()
this.refreshPrinterList()
this.getAreaTreeData() this.getAreaTreeData()
this.getDeptTree() this.getDeptTree()
this.getList() this.getList()
}, },
mounted() { mounted() {
this.PosPrinter = new WebSDK.EscPosCommand()
this.refreshPrinterList()
}, },
methods: { methods: {
refreshPrinterList() { refreshPrinterList() {
setPort(18080) setPort(18080)
const category = { 'category': 1 } getPrinterList({ 'category': 1 },(printer) =>{
getPrinterList(category, this.updatePrinterList) this.updatePrinterList(printer)
})
}, },
updatePrinterList(printers) { updatePrinterList(printers) {
// this.printList = printers console.log("Printers from getPrinterList:", printers)
// console.log(this.printList) if (!Array.isArray(printers)) {
// if (!Array.isArray(printers)) { console.error('Expected an array of printers, but got:', typeof printers)
// console.error('Expected an array of printers, but got:', typeof printers) return
// return
// }
// console.log('Available printers:', this.printList)
this.printList = printers.map(item => ({
name: item.logicalName,
value: item.logicalName
}))
console.log('Available printers:', this.printList)
if (this.printList.length > 0) {
this.printerName = this.printList[0].name
} }
this.printList = Array.isArray(printers)
? printers.map((item, index) => ({
name: item.logicalName,
value: index,
}))
: []
console.log('Available printers:', this.printList)
console.log('Available printers size:', this.printList.length)
if (this.printList.length > 0) {
console.log('Setting default printer to:', this.printList[0].value)
this.printerName = this.printList[0].value
}
console.log('this.printerName:', this.printerName)
console.log('this.printList:', this.printList)
this.$nextTick(() => {
//
this.$forceUpdate()
})
}, },
// //
getAreaTreeData() { getAreaTreeData() {
@ -1046,14 +1056,14 @@ export default {
this.$modal.msgSuccess('批量核销完成') this.$modal.msgSuccess('批量核销完成')
} }
if (this.handleType == '打印小票') { if (this.handleType == '打印小票') {
if (this.printList.length === 0) { // if (this.printList.length === 0) {
this.$modal.msgWarning('请先开启小票打印机服务!') // this.$modal.msgWarning(',,')
return // return
} // }
if (this.printerName === '') { // if (this.printerName === '') {
this.$modal.msgWarning('请先选择小票打印机!') // this.$modal.msgWarning('')
return // return
} // }
const _titles = ['菜品名称', '数量', '单价', '总价'] const _titles = ['菜品名称', '数量', '单价', '总价']
const _columnWidths = [20, 10, 10, 8] const _columnWidths = [20, 10, 10, 8]
console.log(this.ableList) console.log(this.ableList)
@ -1082,7 +1092,8 @@ export default {
}) // : 277 -> Total: 277; : 277 -> Amount Due: 277; : 1234567891011 -> Flow Number: 1234567891011; -> Thank you for your visit! Welcome again next time! }) // : 277 -> Total: 277; : 277 -> Amount Due: 277; : 1234567891011 -> Flow Number: 1234567891011; -> Thank you for your visit! Welcome again next time!
.printAndFeed(2) .printAndFeed(2)
.feedAndCut(50) .feedAndCut(50)
this.prepareAndPrint(this.printerName) //TODO
this.prepareAndPrint('Printer1')
}) })
this.$modal.msgSuccess('打印小票完成') this.$modal.msgSuccess('打印小票完成')