jcjw-sdk
v1.0.4
Published
JCJW SDK
Downloads
18
Readme
集成吉文 web 调用 Flutter 的 API 介绍
通过 npm 安装
npm install jcjw-sdk
扫描二维码
import { scanBarcode } from 'jcjw-sdk'
try {
const res = await scanBarcode();
// 返回数据处理
} catch (error) {
// 异常
}
斑马打印机相关
开启监听获取打印机列表方法
import { discoveryPrinters } from 'jcjw-sdk'
discoveryPrinters()
获取打印机列表(蓝牙+wifi)
import { discoveryDevices } from 'jcjw-sdk'
discoveryDevices((res) => {
// 获取打印机列表,推荐在onMounted(以vue3为例)等生命周期里监听,防止重复监听
})
返回格式
{
status: 'success', // success成功,failed失败,none蓝牙列表获取中
deviceList: [
{
"id": ipAddress, // id地址
"name": name, // 名称
"isWifi": true // 是否wifi,否为蓝牙
}
]
};
开启监听获取打印机列表方法及获取打印机列表使用示例(以 vue3 为例)
onMounted(() => {
// 开启获取
discoveryPrinters();
// 打印机返回值监听
discoveryDevices((res) => {
// 列表返回值处理
res.deviceList...
if (res.status && res.status != "none") {
// 打印机获取完毕
}
});
});
监听蓝牙或者 wifi 网络权限授权结果回调
import { permissionStatus } from 'jcjw-sdk'
permissionStatus((res) => {
// 获取蓝牙或者wifi网络权限授权结果回调,推荐在onMounted(以vue3为例)等生命周期里监听,防止重复监听
// res返回内容
// {"status": "PermissionDeny"}
// 如果返回状态为PermissionDeny 则说明权限未开,正常不返回内容
})
连接
import { connectToPrinter } from 'jcjw-sdk'
try {
// 传入打印机id地址
const res = await connectToPrinter(address);
if (res.status == "success") {
// 成功
} else {
// 失败
}
} catch (error) {
// 其他异常
}
返回格式
{
status: 'success', // success成功,failed失败
};
断开连接
import { disconnect } from 'jcjw-sdk'
try {
const res = await disconnect();
if (res.status == "success") {
// 成功
} else {
// 失败
}
} catch (error) {
// 其他异常
}
返回格式
{
status: 'success', // success成功,failed失败
};
打印
import { zebraPrint } from 'jcjw-sdk'
try {
// 传入zpl指令
const res = await zebraPrint(zplStr);
if (res.status == "success") {
// 成功
} else {
// 失败
}
} catch (error) {
// 异常
}
返回格式
{
status: 'success', // success成功,failed失败
};
注:此处需发送 zpl 指令,指令格式可参考斑马官方文档
image 转 zpl 指令相关
image 转 zpl
import { convertImage } from 'jcjw-sdk'
try {
// 传入图片base64地址(必填),options为可配置对象
const res = await convertImage(base64, options);
// 返回zpl指令
} catch (error) {
// 异常
}
options 详解
| 参数 | 默认 | 描述 | 是否选填 | | ------ | ---- | --------------------------------------------------------------------------------------------------------------------------------------- | -------- | | black | 50 | 浓度(1 ~ 99) | 是 | | rot | 'N' | 旋转角度'N':不旋转'L':逆时针旋转 90 度'R':顺时针旋转 90 度'I':旋转 180 度'B':同'L',逆时针旋转 90 度 | 是 | | notrim | true | 不去边缘空白 | 是 |
其他方法
import { z64ToCanvas,rgbaToZ64, rgbaToACS, imageToZ64, imageToACS } from 'jcjw-sdk'
一般作为 image 转 zpl 的内置方法,具体使用可以查看https://github.com/metafloor/zpl-image
斑马扫码枪相关
扫码枪初始化(即连接)
import { initToPairing } from 'jcjw-sdk'
try {
const res = await initToPairing();
// 返回数据处理
} catch (error) {
// 异常
}
返回格式
{
status: 'success', // success成功,failed失败
};
扫码枪扫码
import { callBackScannerData } from 'jcjw-sdk'
callBackScannerData((res) => {
// 获取扫描内容,推荐在onMounted(以vue3为例)等生命周期里监听,防止重复监听
})
返回格式
{
text: '123123', // 内容
type: 'code128', // 码类型
};
扫码枪断开连接
import { disconnectScanner } from 'jcjw-sdk'
try {
const res = await disconnectScanner();
// 返回数据处理
} catch (error) {
// 异常
}
返回格式
{
status: 'success', // success成功,failed失败
};
扫码枪补充说明
注: 1:因扫码枪断开连接后 sdk 无法获取其返回状态,故扫码枪是否已连接状态要开发本地存储,sdk 无法提供方法查询当前状态。在遇到场景需要重连时由开发自行判断。 2:app 关闭时会自动断开扫码枪连接,且每次连接必须扫码匹配,无法直接无感连接,产品设计时需注意此项。