Commit 0e478a9a by 施宇

111

parent 0128049e
{"ignoreds":["node_modules/**/*","**/node_modules/**","**/.git/**",".git/**/*","**/.svn/**",".svn/**/*",".DS_Store","**/.DS_Store"],"folderInfo":{"./":{"mtimeMs":1587538189371.3574,"children":["app.js","app.json","app.wxss","project.config.json","sitemap.json"]},"pages/":{"mtimeMs":1587639531953.152,"children":[]},"res/":{"mtimeMs":1587468629426.3813,"children":[]},"res/css/":{"mtimeMs":1587468648224.7944,"children":["res/css/base.wxss"]},"res/img/":{"mtimeMs":1587643440799.6272,"children":["res/img/arrow-left.png","res/img/arrow-right.png","res/img/ck-icon-a.png","res/img/ck-icon.png","res/img/close-icon.png","res/img/kc-icon-a.png","res/img/kc-icon.png","res/img/login-img.png","res/img/login-text.png","res/img/nav-arrow-down.png","res/img/question-icon.png","res/img/search-icon.png","res/img/sh-icon-a.png","res/img/sj-icon-a.png","res/img/sj-icon.png","res/img/sz-icon-a.png","res/img/sz-icon.png","res/img/warn-icon.png"]},"utils/":{"mtimeMs":1587468231280.8867,"children":["utils/util.js"]},".git/":{"mtimeMs":1587643097947.4,"children":[]},".wechatide/":{"mtimeMs":1587519550088.0625,"children":[".wechatide/fileCache.cfg"]},"pages/home/":{"mtimeMs":1587536014892.4702,"children":["pages/home/home.js","pages/home/home.json","pages/home/home.wxml","pages/home/home.wxss"]},"pages/login/":{"mtimeMs":1587535974795.0686,"children":["pages/login/login.js","pages/login/login.json","pages/login/login.wxml","pages/login/login.wxss"]},"components/":{"mtimeMs":1587538211879.0247,"children":[]},"components/navC/":{"mtimeMs":1587538221287.4016,"children":["components/navC/navC.js","components/navC/navC.json","components/navC/navC.wxml","components/navC/navC.wxss"]},"pages/receivinggoods/":{"mtimeMs":1587538742321.587,"children":["pages/receivinggoods/receivinggoods.js","pages/receivinggoods/receivinggoods.json","pages/receivinggoods/receivinggoods.wxml","pages/receivinggoods/receivinggoods.wxss"]},"pages/upperShelf/":{"mtimeMs":1587622056930.153,"children":["pages/upperShelf/upperShelf.js","pages/upperShelf/upperShelf.json","pages/upperShelf/upperShelf.wxml","pages/upperShelf/upperShelf.wxss"]},"pages/outbound/":{"mtimeMs":1587626008346.8442,"children":["pages/outbound/outbound.js","pages/outbound/outbound.json","pages/outbound/outbound.wxml","pages/outbound/outbound.wxss"]},"pages/scanDelivery/":{"mtimeMs":1587627596586.3196,"children":["pages/scanDelivery/scanDelivery.js","pages/scanDelivery/scanDelivery.json","pages/scanDelivery/scanDelivery.wxml","pages/scanDelivery/scanDelivery.wxss"]},"pages/picking/":{"mtimeMs":1587631234329.3645,"children":["pages/picking/picking.js","pages/picking/picking.json","pages/picking/picking.wxml","pages/picking/picking.wxss"]},"pages/cardBoard/":{"mtimeMs":1587632724321.1174,"children":["pages/cardBoard/cardBoard.js","pages/cardBoard/cardBoard.json","pages/cardBoard/cardBoard.wxml","pages/cardBoard/cardBoard.wxss"]},"pages/changeWarehouse/":{"mtimeMs":1587635396534.957,"children":["pages/changeWarehouse/changeWarehouse.js","pages/changeWarehouse/changeWarehouse.json","pages/changeWarehouse/changeWarehouse.wxml","pages/changeWarehouse/changeWarehouse.wxss"]},"pages/systemSettings/":{"mtimeMs":1587637181028.4365,"children":["pages/systemSettings/systemSettings.js","pages/systemSettings/systemSettings.json","pages/systemSettings/systemSettings.wxml","pages/systemSettings/systemSettings.wxss"]},"pages/printer/":{"mtimeMs":1587637593187.5686,"children":["pages/printer/printer.js","pages/printer/printer.json","pages/printer/printer.wxml","pages/printer/printer.wxss"]},"pages/inventoryQuery/":{"mtimeMs":1587639536186.8396,"children":["pages/inventoryQuery/inventoryQuery.js","pages/inventoryQuery/inventoryQuery.json","pages/inventoryQuery/inventoryQuery.wxml","pages/inventoryQuery/inventoryQuery.wxss"]}},"cacheVersion":1} {"ignoreds":["node_modules/**/*","**/node_modules/**","**/.git/**",".git/**/*","**/.svn/**",".svn/**/*",".DS_Store","**/.DS_Store"],"folderInfo":{"./":{"mtimeMs":1587696289558.8054,"children":["app.js","app.json","app.wxss","project.config.json","sitemap.json"]},"pages/":{"mtimeMs":1587696395511.2776,"children":[]},"res/":{"mtimeMs":1587468629426.3813,"children":[]},"res/css/":{"mtimeMs":1587468648224.7944,"children":["res/css/base.wxss"]},"res/img/":{"mtimeMs":1587693859514.1584,"children":["res/img/arrow-left.png","res/img/arrow-right.png","res/img/ck-icon-a.png","res/img/ck-icon.png","res/img/close-icon.png","res/img/kc-icon-a.png","res/img/kc-icon.png","res/img/login-img.png","res/img/login-text.png","res/img/nav-arrow-down.png","res/img/question-icon.png","res/img/search-icon.png","res/img/sh-icon-a.png","res/img/sh-icon.png","res/img/sj-icon-a.png","res/img/sj-icon.png","res/img/sz-icon-a.png","res/img/sz-icon.png","res/img/warn-icon.png"]},"utils/":{"mtimeMs":1587468231280.8867,"children":["utils/util.js"]},".git/":{"mtimeMs":1587696329501.2468,"children":[]},".wechatide/":{"mtimeMs":1587519550088.0625,"children":[".wechatide/fileCache.cfg"]},"pages/home/":{"mtimeMs":1587536014892.4702,"children":["pages/home/home.js","pages/home/home.json","pages/home/home.wxml","pages/home/home.wxss"]},"pages/login/":{"mtimeMs":1587535974795.0686,"children":["pages/login/login.js","pages/login/login.json","pages/login/login.wxml","pages/login/login.wxss"]},"components/":{"mtimeMs":1587538211879.0247,"children":[]},"components/navC/":{"mtimeMs":1587538221287.4016,"children":["components/navC/navC.js","components/navC/navC.json","components/navC/navC.wxml","components/navC/navC.wxss"]},"pages/receivinggoods/":{"mtimeMs":1587538742321.587,"children":["pages/receivinggoods/receivinggoods.js","pages/receivinggoods/receivinggoods.json","pages/receivinggoods/receivinggoods.wxml","pages/receivinggoods/receivinggoods.wxss"]},"pages/upperShelf/":{"mtimeMs":1587622056930.153,"children":["pages/upperShelf/upperShelf.js","pages/upperShelf/upperShelf.json","pages/upperShelf/upperShelf.wxml","pages/upperShelf/upperShelf.wxss"]},"pages/outbound/":{"mtimeMs":1587626008346.8442,"children":["pages/outbound/outbound.js","pages/outbound/outbound.json","pages/outbound/outbound.wxml","pages/outbound/outbound.wxss"]},"pages/scanDelivery/":{"mtimeMs":1587627596586.3196,"children":["pages/scanDelivery/scanDelivery.js","pages/scanDelivery/scanDelivery.json","pages/scanDelivery/scanDelivery.wxml","pages/scanDelivery/scanDelivery.wxss"]},"pages/picking/":{"mtimeMs":1587631234329.3645,"children":["pages/picking/picking.js","pages/picking/picking.json","pages/picking/picking.wxml","pages/picking/picking.wxss"]},"pages/cardBoard/":{"mtimeMs":1587632724321.1174,"children":["pages/cardBoard/cardBoard.js","pages/cardBoard/cardBoard.json","pages/cardBoard/cardBoard.wxml","pages/cardBoard/cardBoard.wxss"]},"pages/changeWarehouse/":{"mtimeMs":1587635396534.957,"children":["pages/changeWarehouse/changeWarehouse.js","pages/changeWarehouse/changeWarehouse.json","pages/changeWarehouse/changeWarehouse.wxml","pages/changeWarehouse/changeWarehouse.wxss"]},"pages/systemSettings/":{"mtimeMs":1587637181028.4365,"children":["pages/systemSettings/systemSettings.js","pages/systemSettings/systemSettings.json","pages/systemSettings/systemSettings.wxml","pages/systemSettings/systemSettings.wxss"]},"pages/printer/":{"mtimeMs":1587637593187.5686,"children":["pages/printer/printer.js","pages/printer/printer.json","pages/printer/printer.wxml","pages/printer/printer.wxss"]},"pages/inventoryQuery/":{"mtimeMs":1587639536186.8396,"children":["pages/inventoryQuery/inventoryQuery.js","pages/inventoryQuery/inventoryQuery.json","pages/inventoryQuery/inventoryQuery.wxml","pages/inventoryQuery/inventoryQuery.wxss"]},"miniprogram_npm/":{"mtimeMs":1587696277856.0212,"children":[]},"miniprogram_npm/text-encoding/":{"mtimeMs":1587696277883.9749,"children":["miniprogram_npm/text-encoding/index.js","miniprogram_npm/text-encoding/index.js.map"]},"printer/":{"mtimeMs":1587696289579.8447,"children":["printer/commands.js","printer/printerjobs.js","printer/printerutil.js"]},"pages/index/":{"mtimeMs":1587696395532.241,"children":["pages/index/index.js","pages/index/index.json","pages/index/index.wxml","pages/index/index.wxss"]}},"cacheVersion":1}
\ No newline at end of file \ No newline at end of file
{ {
"pages": [ "pages": [
"pages/index/index",
"pages/inventoryQuery/inventoryQuery", "pages/inventoryQuery/inventoryQuery",
"pages/receivinggoods/receivinggoods", "pages/receivinggoods/receivinggoods",
"pages/printer/printer", "pages/printer/printer",
...@@ -17,8 +18,7 @@ ...@@ -17,8 +18,7 @@
"backgroundTextStyle": "light", "backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "", "navigationBarTitleText": "",
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black"
"navigationStyle": "custom"
}, },
"style": "v2", "style": "v2",
"sitemapLocation": "sitemap.json" "sitemapLocation": "sitemap.json"
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<image class="arrow-down" src="../../res/img/nav-arrow-down.png"></image> <image class="arrow-down" src="../../res/img/nav-arrow-down.png"></image>
<view class="drop-down2 borderBox"> <view class="drop-down2 borderBox">
<view class="item Bflex aic"> <view class="item Bflex aic">
<image src="../../res/img/sh-icon-a.png" class="icon icon1"></image> <image src="../../res/img/sh-icon.png" class="icon icon1"></image>
<image src="../../res/img/sh-icon-a.png" class="icon icon2"></image> <image src="../../res/img/sh-icon-a.png" class="icon icon2"></image>
<text>收货管理</text> <text>收货管理</text>
</view> </view>
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
text-align: center; text-align: center;
right: -23px; right: -23px;
top: 20px; top: 20px;
/* display: none; */ display: none;
} }
.drop-down1 .item { .drop-down1 .item {
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
padding-left: 17px; padding-left: 17px;
top:20px; top:20px;
right:-60px; right:-60px;
display: none;
} }
.drop-down2 .item { .drop-down2 .item {
......
This diff could not be displayed because it is too large.
{
"navigationBarTitleText": "蓝牙打印"
}
\ No newline at end of file
<wxs module="utils">
module.exports.max = function(n1, n2) {
return Math.max(n1, n2)
}
module.exports.len = function(arr) {
arr = arr || [];
return arr.length;
}
</wxs>
<view class="container">
<view class="page-section">
<view class="devices-summary">已发现 {{devices.length}} 个外围设备:</view>
<scroll-view class="device-list" scroll-y scroll-with-animation>
<view wx:for="{{devices}}" wx:key="index" data-device-id="{{item.deviceId}}" data-name="{{item.name || item.localName}}" bindtap="createBLEConnection" class="device-item" hover-class="device-item-hover">
<view style="font-size: 16px; color: #333;">{{item.name}}</view>
<view style="font-size: 10px">信号强度: {{item.RSSI}}dBm ({{utils.max(0, item.RSSI + 100)}}%)</view>
<view style="font-size: 10px">UUID: {{item.deviceId}}</view>
<view style="font-size: 10px">Service数量: {{utils.len(item.advertisServiceUUIDs)}}</view>
</view>
</scroll-view>
<view class="btn-area">
<button type="primary" bindtap="openBluetoothAdapter">开始扫描</button>
<button bindtap="stopBluetoothDevicesDiscovery" style="margin-top: 10px;">停止扫描</button>
</view>
</view>
<view class="page-section connected-area" wx:if="{{lastDevice}}">
<text style="font-size: 30rpx">最近连接的设备</text>
<view>{{lastDevice}}</view>
<view class="btn-area">
<button type="primary" bindtap="createBLEConnectionWithDeviceId">直接连接</button>
</view>
</view>
<view class="page-section connected-area" wx:if="{{connected}}">
<view class="connected-info">
<text style="font-size: 30rpx">已连接到 {{name}}</text>
<view wx:for="{{chs}}" wx:key="index">
<view>特性UUID: {{item.uuid}}</view>
<view>特性值: {{item.value}}</view>
</view>
</view>
<view class="btn-area">
<button wx:if="{{canWrite}}" type="primary" bindtap="writeBLECharacteristicValue" style="margin-bottom: 10px;">
写数据
</button>
<button bindtap="closeBLEConnection">断开连接</button>
</view>
</view>
</view>
\ No newline at end of file
.page-section {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
box-sizing: border-box;
border-bottom: 2rpx solid #EEE;
padding: 30rpx 0;
}
.devices-summary {
padding: 10rpx;
font-size: 30rpx;
}
.device-list {
height: 300rpx;
}
.device-item {
border-bottom: 1rpx solid #EEE;
padding: 10rpx;
color: #666;
}
.device-item-hover {
background-color: rgba(0, 0, 0, .1);
}
.btn-area {
box-sizing: border-box;
width: 100%;
padding: 0 30rpx;
margin: 30rpx 0;
}
.connected-area {
font-size: 22rpx;
}
.connected-info {}
.input-area {
background: #fff;
margin-top: 10rpx;
width: 100%;
}
.input {
font-size: 28rpx;
height: 2.58823529em;
min-height: 2.58823529em;
line-height: 2.58823529em;
padding: 10rpx;
}
\ No newline at end of file
/**
* 修改自https://github.com/song940/node-escpos/blob/master/commands.js
* ESC/POS _ (Constants)
*/
var _ = {
LF: [0x0a],
FS: [0x1c],
FF: [0x0c],
GS: [0x1d],
DLE: [0x10],
EOT: [0x04],
NUL: [0x00],
ESC: [0x1b],
EOL: '\n',
};
/**
* [FEED_CONTROL_SEQUENCES Feed control sequences]
* @type {Object}
*/
_.FEED_CONTROL_SEQUENCES = {
CTL_LF: [0x0a], // Print and line feed
CTL_GLF: [0x4a, 0x00], // Print and feed paper (without spaces between lines)
CTL_FF: [0x0c], // Form feed
CTL_CR: [0x0d], // Carriage return
CTL_HT: [0x09], // Horizontal tab
CTL_VT: [0x0b], // Vertical tab
};
_.CHARACTER_SPACING = {
CS_DEFAULT: [0x1b, 0x20, 0x00],
CS_SET: [0x1b, 0x20]
};
_.LINE_SPACING = {
LS_DEFAULT: [0x1b, 0x32],
LS_SET: [0x1b, 0x33]
};
/**
* [HARDWARE Printer hardware]
* @type {Object}
*/
_.HARDWARE = {
HW_INIT: [0x1b, 0x40], // Clear data in buffer and reset modes
HW_SELECT: [0x1b, 0x3d, 0x01], // Printer select
HW_RESET: [0x1b, 0x3f, 0x0a, 0x00], // Reset printer hardware
};
/**
* [CASH_DRAWER Cash Drawer]
* @type {Object}
*/
_.CASH_DRAWER = {
CD_KICK_2: [0x1b, 0x70, 0x00], // Sends a pulse to pin 2 []
CD_KICK_5: [0x1b, 0x70, 0x01], // Sends a pulse to pin 5 []
};
/**
* [MARGINS Margins sizes]
* @type {Object}
*/
_.MARGINS = {
BOTTOM: [0x1b, 0x4f], // Fix bottom size
LEFT: [0x1b, 0x6c], // Fix left size
RIGHT: [0x1b, 0x51], // Fix right size
};
/**
* [PAPER Paper]
* @type {Object}
*/
_.PAPER = {
PAPER_FULL_CUT: [0x1d, 0x56, 0x00], // Full cut paper
PAPER_PART_CUT: [0x1d, 0x56, 0x01], // Partial cut paper
PAPER_CUT_A: [0x1d, 0x56, 0x41], // Partial cut paper
PAPER_CUT_B: [0x1d, 0x56, 0x42], // Partial cut paper
};
/**
* [TEXT_FORMAT Text format]
* @type {Object}
*/
_.TEXT_FORMAT = {
TXT_NORMAL: [0x1b, 0x21, 0x00], // Normal text
TXT_2HEIGHT: [0x1b, 0x21, 0x10], // Double height text
TXT_2WIDTH: [0x1b, 0x21, 0x20], // Double width text
TXT_4SQUARE: [0x1b, 0x21, 0x30], // Double width & height text
TXT_UNDERL_OFF: [0x1b, 0x2d, 0x00], // Underline font OFF
TXT_UNDERL_ON: [0x1b, 0x2d, 0x01], // Underline font 1-dot ON
TXT_UNDERL2_ON: [0x1b, 0x2d, 0x02], // Underline font 2-dot ON
TXT_BOLD_OFF: [0x1b, 0x45, 0x00], // Bold font OFF
TXT_BOLD_ON: [0x1b, 0x45, 0x01], // Bold font ON
TXT_ITALIC_OFF: [0x1b, 0x35], // Italic font ON
TXT_ITALIC_ON: [0x1b, 0x34], // Italic font ON
TXT_FONT_A: [0x1b, 0x4d, 0x00], // Font type A
TXT_FONT_B: [0x1b, 0x4d, 0x01], // Font type B
TXT_FONT_C: [0x1b, 0x4d, 0x02], // Font type C
TXT_ALIGN_LT: [0x1b, 0x61, 0x00], // Left justification
TXT_ALIGN_CT: [0x1b, 0x61, 0x01], // Centering
TXT_ALIGN_RT: [0x1b, 0x61, 0x02], // Right justification
};
/**
* [BARCODE_FORMAT Barcode format]
* @type {Object}
*/
_.BARCODE_FORMAT = {
BARCODE_TXT_OFF: [0x1d, 0x48, 0x00], // HRI barcode chars OFF
BARCODE_TXT_ABV: [0x1d, 0x48, 0x01], // HRI barcode chars above
BARCODE_TXT_BLW: [0x1d, 0x48, 0x02], // HRI barcode chars below
BARCODE_TXT_BTH: [0x1d, 0x48, 0x03], // HRI barcode chars both above and below
BARCODE_FONT_A: [0x1d, 0x66, 0x00], // Font type A for HRI barcode chars
BARCODE_FONT_B: [0x1d, 0x66, 0x01], // Font type B for HRI barcode chars
BARCODE_HEIGHT: function (height) { // Barcode Height [1-255]
return [0x1d, 0x68, height];
},
BARCODE_WIDTH: function (width) { // Barcode Width [2-6]
return [0x1d, 0x77, width];
},
BARCODE_HEIGHT_DEFAULT: [0x1d, 0x68, 0x64], // Barcode height default:100
BARCODE_WIDTH_DEFAULT: [0x1d, 0x77, 0x01], // Barcode width default:1
BARCODE_UPC_A: [0x1d, 0x6b, 0x00], // Barcode type UPC-A
BARCODE_UPC_E: [0x1d, 0x6b, 0x01], // Barcode type UPC-E
BARCODE_EAN13: [0x1d, 0x6b, 0x02], // Barcode type EAN13
BARCODE_EAN8: [0x1d, 0x6b, 0x03], // Barcode type EAN8
BARCODE_CODE39: [0x1d, 0x6b, 0x04], // Barcode type CODE39
BARCODE_ITF: [0x1d, 0x6b, 0x05], // Barcode type ITF
BARCODE_NW7: [0x1d, 0x6b, 0x06], // Barcode type NW7
BARCODE_CODE93: [0x1d, 0x6b, 0x48], // Barcode type CODE93
BARCODE_CODE128: [0x1d, 0x6b, 0x49], // Barcode type CODE128
};
/**
* [IMAGE_FORMAT Image format]
* @type {Object}
*/
_.IMAGE_FORMAT = {
S_RASTER_N: [0x1d, 0x76, 0x30, 0x00], // Set raster image normal size
S_RASTER_2W: [0x1d, 0x76, 0x30, 0x01], // Set raster image double width
S_RASTER_2H: [0x1d, 0x76, 0x30, 0x02], // Set raster image double height
S_RASTER_Q: [0x1d, 0x76, 0x30, 0x03], // Set raster image quadruple
};
/**
* [BITMAP_FORMAT description]
* @type {Object}
*/
_.BITMAP_FORMAT = {
BITMAP_S8: [0x1b, 0x2a, 0x00],
BITMAP_D8: [0x1b, 0x2a, 0x01],
BITMAP_S24: [0x1b, 0x2a, 0x20],
BITMAP_D24: [0x1b, 0x2a, 0x21]
};
/**
* [GSV0_FORMAT description]
* @type {Object}
*/
_.GSV0_FORMAT = {
GSV0_NORMAL: [0x1d, 0x76, 0x30, 0x00],
GSV0_DW: [0x1d, 0x76, 0x30, 0x01],
GSV0_DH: [0x1d, 0x76, 0x30, 0x02],
GSV0_DWDH: [0x1d, 0x76, 0x30, 0x03]
};
/**
* [BEEP description]
* @type {string}
*/
_.BEEP = [0x1b, 0x42]; // Printer Buzzer pre hex
/**
* [COLOR description]
* @type {Object}
*/
_.COLOR = {
0: [0x1b, 0x72, 0x00], // black
1: [0x1b, 0x72, 0x01] // red
};
/**
* [exports description]
* @type {[type]}
*/
module.exports = _;
\ No newline at end of file
const commands = require('commands');
const TextEncoder = require('text-encoding/index').TextEncoder;
const printerJobs = function () {
this._queue = Array.from(commands.HARDWARE.HW_INIT);
this._encoder = new TextEncoder("gb2312", {NONSTANDARD_allowLegacyEncoding: true});
this._enqueue = function (cmd) {
this._queue.push.apply(this._queue, cmd);
}
};
/**
* 增加打印内容
* @param {string} content 文字内容
*/
printerJobs.prototype.text = function (content) {
if (content) {
let uint8Array = this._encoder.encode(content);
let encoded = Array.from(uint8Array);
this._enqueue(encoded);
}
return this;
};
/**
* 打印文字
* @param {string} content 文字内容
*/
printerJobs.prototype.print = function (content) {
this.text(content);
this._enqueue(commands.LF);
return this;
};
/**
* 打印文字并换行
* @param {string} content 文字内容
*/
printerJobs.prototype.println = function (content = '') {
return this.print(content + commands.EOL);
};
/**
* 设置对齐方式
* @param {string} align 对齐方式 LT/CT/RT
*/
printerJobs.prototype.setAlign = function (align) {
this._enqueue(commands.TEXT_FORMAT['TXT_ALIGN_' + align.toUpperCase()]);
return this;
};
/**
* 设置字体
* @param {string} family A/B/C
*/
printerJobs.prototype.setFont = function (family) {
this._enqueue(commands.TEXT_FORMAT['TXT_FONT_' + family.toUpperCase()]);
return this;
};
/**
* 设定字体尺寸
* @param {number} width 字体宽度 1~2
* @param {number} height 字体高度 1~2
*/
printerJobs.prototype.setSize = function (width, height) {
if (2 >= width && 2 >= height) {
this._enqueue(commands.TEXT_FORMAT.TXT_NORMAL);
if (2 === width && 2 === height) {
this._enqueue(commands.TEXT_FORMAT.TXT_4SQUARE);
} else if (1 === width && 2 === height) {
this._enqueue(commands.TEXT_FORMAT.TXT_2HEIGHT);
} else if (2 === width && 1 === height) {
this._enqueue(commands.TEXT_FORMAT.TXT_2WIDTH);
}
}
return this;
};
/**
* 设定字体是否加粗
* @param {boolean} bold
*/
printerJobs.prototype.setBold = function (bold) {
if (typeof bold !== 'boolean') {
bold = true;
}
this._enqueue(bold ? commands.TEXT_FORMAT.TXT_BOLD_ON : commands.TEXT_FORMAT.TXT_BOLD_OFF);
return this;
};
/**
* 设定是否开启下划线
* @param {boolean} underline
*/
printerJobs.prototype.setUnderline = function (underline) {
if (typeof underline !== 'boolean') {
underline = true;
}
this._enqueue(underline ? commands.TEXT_FORMAT.TXT_UNDERL_ON : commands.TEXT_FORMAT.TXT_UNDERL_OFF);
return this;
};
/**
* 设置行间距为 n 点行,默认值行间距是 30 点
* @param {number} n 0≤n≤255
*/
printerJobs.prototype.setLineSpacing = function (n) {
if (n === undefined || n === null) {
this._enqueue(commands.LINE_SPACING.LS_DEFAULT);
} else {
this._enqueue(commands.LINE_SPACING.LS_SET);
this._enqueue([n]);
}
return this;
};
/**
* 打印空行
* @param {number} n
*/
printerJobs.prototype.lineFeed = function (n = 1) {
return this.print(new Array(n).fill(commands.EOL).join(''));
};
/**
* 设置字体颜色,需要打印机支持
* @param {number} color - 0 默认颜色黑色 1 红色
*/
printerJobs.prototype.setColor = function (color) {
this._enqueue(commands.COLOR[color === 1 ? 1 : 0]);
return this;
};
/**
* https://support.loyverse.com/hardware/printers/use-the-beeper-in-a-escpos-printers
* 蜂鸣警报,需要打印机支持
* @param {number} n 蜂鸣次数,1-9
* @param {number} t 蜂鸣长短,1-9
*/
printerJobs.prototype.beep = function (n, t) {
this._enqueue(commands.BEEP);
this._enqueue([n, t]);
return this;
};
/**
* 清空任务
*/
printerJobs.prototype.clear = function () {
this._queue = Array.from(commands.HARDWARE.HW_INIT);
return this;
};
/**
* 返回ArrayBuffer
*/
printerJobs.prototype.buffer = function () {
return new Uint8Array(this._queue).buffer;
};
module.exports = printerJobs;
\ No newline at end of file
// 打印机纸宽58mm,页的宽度384,字符宽度为1,每行最多盛放32个字符
const PAGE_WIDTH = 384;
const MAX_CHAR_COUNT_EACH_LINE = 32;
/**
* @param str
* @returns {boolean} str是否全是中文
*/
function isChinese(str) {
return /^[\u4e00-\u9fa5]$/.test(str);
}
/**
* 返回字符串宽度(1个中文=2个英文字符)
* @param str
* @returns {number}
*/
function getStringWidth(str) {
let width = 0;
for (let i = 0, len = str.length; i < len; i++) {
width += isChinese(str.charAt(i)) ? 2 : 1;
}
return width;
}
/**
* 同一行输出str1, str2,str1居左, str2居右
* @param {string} str1 内容1
* @param {string} str2 内容2
* @param {number} fontWidth 字符宽度 1/2
* @param {string} fillWith str1 str2之间的填充字符
*
*/
function inline(str1, str2, fillWith = ' ', fontWidth = 1) {
const lineWidth = MAX_CHAR_COUNT_EACH_LINE / fontWidth;
// 需要填充的字符数量
let fillCount = lineWidth - (getStringWidth(str1) + getStringWidth(str2)) % lineWidth;
let fillStr = new Array(fillCount).fill(fillWith.charAt(0)).join('');
return str1 + fillStr + str2;
}
/**
* 用字符填充一整行
* @param {string} fillWith 填充字符
* @param {number} fontWidth 字符宽度 1/2
*/
function fillLine(fillWith = '-', fontWidth = 1) {
const lineWidth = MAX_CHAR_COUNT_EACH_LINE / fontWidth;
return new Array(lineWidth).fill(fillWith.charAt(0)).join('');
}
/**
* 文字内容居中,左右用字符填充
* @param {string} str 文字内容
* @param {number} fontWidth 字符宽度 1/2
* @param {string} fillWith str1 str2之间的填充字符
*/
function fillAround(str, fillWith = '-', fontWidth = 1) {
const lineWidth = MAX_CHAR_COUNT_EACH_LINE / fontWidth;
let strWidth = getStringWidth(str);
// 内容已经超过一行了,没必要填充
if (strWidth >= lineWidth) {
return str;
}
// 需要填充的字符数量
let fillCount = lineWidth - strWidth;
// 左侧填充的字符数量
let leftCount = Math.round(fillCount / 2);
// 两侧的填充字符,需要考虑左边需要填充,右边不需要填充的情况
let fillStr = new Array(leftCount).fill(fillWith.charAt(0)).join('');
return fillStr + str + fillStr.substr(0, fillCount - leftCount);
}
module.exports = {
inline: inline,
fillLine: fillLine,
fillAround: fillAround,
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment