6 changed files with 128 additions and 40 deletions
@ -0,0 +1,55 @@
|
||||
import { setStore, getStore } from 'utils/store'; // 从 'utils/store' 导入 setStore 和 getStore 方法
|
||||
import { getLodop } from '@/utils/LodopFuncs'; |
||||
|
||||
const print = { |
||||
state: { |
||||
/** 本地打印机列表 */ |
||||
printList: [], |
||||
/** 打印机 -- 配送单类型 */ |
||||
deliveryPrintActiveIndex: 0, |
||||
/** 打印机 -- 标签打印机类型 */ |
||||
titlePrintActiveIndex: 0, |
||||
}, |
||||
mutations: { |
||||
/** 获取当前设备的打印机 */ |
||||
GET_PRINT_LIST(state) { |
||||
const timer = setTimeout(() => { |
||||
let LODOP = getLodop(); |
||||
const _count = LODOP.GET_PRINTER_COUNT(); |
||||
|
||||
const _name = LODOP.GET_PRINTER_NAME(-1); |
||||
|
||||
const _deliveryPrintActiveName = window.localStorage.getItem('deliveryPrintActiveName'); |
||||
const _titlePrintActiveName = window.localStorage.getItem('titlePrintActiveName'); |
||||
|
||||
for (let index = 0; index < _count; index++) { |
||||
const name = LODOP.GET_PRINTER_NAME(index); |
||||
|
||||
_deliveryPrintActiveName && |
||||
_deliveryPrintActiveName === name && |
||||
(state.deliveryPrintActiveIndex = index); |
||||
|
||||
_titlePrintActiveName && |
||||
_titlePrintActiveName === name && |
||||
(state.titlePrintActiveIndex = index); |
||||
|
||||
if (name === _name) { |
||||
!_deliveryPrintActiveName && (state.deliveryPrintActiveIndex = index); |
||||
!_titlePrintActiveName && (state.titlePrintActiveIndex = index); |
||||
} |
||||
state.printList.push({ label: name, value: index }); |
||||
} |
||||
clearTimeout(timer); |
||||
}, 2000); |
||||
}, |
||||
/** 设置打印机 */ |
||||
SET_PRINT_ACTIVE(state, action) { |
||||
state[action.type + 'ActiveIndex'] = action.activeIndex; |
||||
window.localStorage.setItem( |
||||
action.type + 'ActiveName', |
||||
state.printList[action.activeIndex].label |
||||
); |
||||
}, |
||||
}, |
||||
}; |
||||
export default print; |
Loading…
Reference in new issue