| | |
| | | <view> |
| | | <!-- 蓝牙连接状态 MAC地址 --> |
| | | <view class="connection-status"> |
| | | <view>连接状态:</view> |
| | | <view style="display: flex; flex-direction: row; gap: 20rpx;padding: 20rpx;"> |
| | | <view style="width: 5rem;">连接设备: </view> |
| | | <view v-if="$printer.isConnected() === false">无</view> |
| | | <view v-else="$printer.isConnected() === true" |
| | | style="flex: 1;display: inline-flex;flex-direction: row;justify-content: space-between;"> |
| | | <view>{{ $printer.connectedDevice().name }}</view> |
| | | <view>{{ $printer.connectedDevice().address }}</view> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | <!-- 操作区 --> |
| | | <view class="buttons"> |
| | |
| | | FakeConnectedDevice, |
| | | WriteOptions, |
| | | } from '@psdk/frame-father'; |
| | | import { getAddress } from '../../utils/auth'; |
| | | export default { |
| | | name: "blueToothConnector", |
| | | data() { |
| | | return { |
| | | discoveredDevices: [], // 查询到的设备 |
| | | connectedDeviceId: "" |
| | | connectedDeviceId: "", |
| | | }; |
| | | }, |
| | | methods: { |
| | |
| | | } |
| | | } |
| | | }) |
| | | |
| | | }, |
| | | onDevice(device) { |
| | | console.log("监听寻找到新设备的事件---------------") |
| | |
| | | title: '连接中' |
| | | }); |
| | | bluetoothTool.connDevice(device.address, (result) => { |
| | | console.log(result) |
| | | console.log("设备MAC地址: ", device.address) |
| | | console.log("printer:",vm.$printer._connectedDevice) |
| | | uni.hideLoading() |
| | | if (result) { |
| | | // // console.log(result); |
| | |
| | | // console.log(vm.$printer) |
| | | vm.$printer.init(new FakeConnectedDevice()); |
| | | vm.connectedDeviceId = device.address; |
| | | vm.$printer._connectedDevice.address = device.address |
| | | vm.$printer._connectedDevice.name = device.name |
| | | console.log("printer:",vm.$printer._connectedDevice) |
| | | uni.showToast({ |
| | | icon: 'none', |
| | | title: '连接成功' |
| | | }) |
| | | |
| | | } else { |
| | | uni.showToast({ |
| | | icon: 'none', |
| | |
| | | if (vm.connectedDeviceId != '') { |
| | | bluetoothTool.closeBtSocket(); |
| | | vm.connectedDeviceId = ""; |
| | | vm.$printer._connectedDevice = null |
| | | |
| | | } |
| | | }, |
| | | labelPrint() { |
| | | // 打印 |
| | | // 检查蓝牙连接 |
| | | let btStatus = bluetoothTool.getBluetoothStatus() |
| | | if (btStatus != true) { |
| | | this.showToast("蓝牙连接异常!") |
| | | return |
| | | } |
| | | |
| | | // 检查是否连接设备 |
| | | let pairedDevices = bluetoothTool.getPairedDevices() |
| | | if (pairedDevices.length < 1) { |
| | | this.showToast("无设备连接!") |
| | | return |
| | | } |
| | | |
| | | // 检查表单项是否有空值 |
| | | for (var key in this.hform) { |
| | | if (this.hform[key] == "") { |
| | | // todo 提示表单项不能为空 |
| | | this.showToast("表单不能有空值!") |
| | | return |
| | | } |
| | | } |
| | | this.printWrite() |
| | | |
| | | |
| | | }, |
| | | showToast(msg, status = "none") { |
| | | uni.showToast({ |
| | | title: msg, |
| | | icon: status, |
| | | duration: 2000 |
| | | }); |
| | | }, |
| | | ///转成安卓有符号的 |
| | | uint8ArrayToSignedArray(uint8Array) { |
| | | let signedArray = new Array(uint8Array.length); |
| | | for (let i = 0; i < uint8Array.length; i++) { |
| | | if (uint8Array[i] >= 128) { |
| | | signedArray[i] = uint8Array[i] - 256; |
| | | } else { |
| | | signedArray[i] = uint8Array[i]; |
| | | } |
| | | } |
| | | return signedArray; |
| | | }, |
| | | async printWrite(type = "cpcl") { |
| | | const vm = this; |
| | | console.log("开始打印------------------") |
| | | switch (type) { |
| | | case "cpcl": |
| | | await vm.writeCpclModel(); |
| | | break; |
| | | } |
| | | }, |
| | | async writeCpclModel() { |
| | | const vm = this; |
| | | try { |
| | | const cpcl = await vm.$printer.cpcl().clear() |
| | | .page(new CPage({ |
| | | width: 608, |
| | | height: 260 |
| | | })) |
| | | .text(new CText({ |
| | | x: 54, |
| | | y: 40, |
| | | content: "物料代码: " + vm.hform.HMaterCode, |
| | | font: CFont.TSS24 |
| | | })) |
| | | .text(new CText({ |
| | | x: 54, |
| | | y: 80, |
| | | content: "名 称: " + vm.hform.HMaterName, |
| | | font: CFont.TSS24 |
| | | })) |
| | | .text(new CText({ |
| | | x: 54, |
| | | y: 120, |
| | | content: "规格型号: " + vm.hform.HMaterType, |
| | | font: CFont.TSS24 |
| | | })) |
| | | .text(new CText({ |
| | | x: 54, |
| | | y: 160, |
| | | content: "数 量: " + vm.hform.HNumber, |
| | | font: CFont.TSS24 |
| | | })) |
| | | .bar(new CBar({ |
| | | x: 120, |
| | | y: 200, |
| | | lineWidth: 1, |
| | | height: 80, |
| | | content: vm.hform.HBarCode, |
| | | codeRotation: CCodeRotation.ROTATION_0, |
| | | codeType: CCodeType.CODE128 |
| | | })) |
| | | .form(new CForm()) //标签纸需要加定位指令 |
| | | .print(); |
| | | console.log(cpcl.command().string()); |
| | | var binary = cpcl.command().binary(); |
| | | await this.sendMessage(Array.from(this.uint8ArrayToSignedArray(binary))); |
| | | } catch (e) { |
| | | console.error(e); |
| | | uni.showToast({ |
| | | title: '失败', |
| | | }); |
| | | } |
| | | }, |
| | | async sendMessage(cmd) { |
| | | console.log(cmd); |
| | | const result = bluetoothTool.sendByteData(cmd); |
| | | uni.showToast({ |
| | | icon: 'none', |
| | | title: result ? '发送成功!' : '发送失败...' |
| | | }) |
| | | }, |
| | | }, |
| | | async mounted() { |
| | | //#ifdef APP-PLUS |
| | | // 蓝牙 |
| | | console.log("蓝牙初始化") |
| | | bluetoothTool.init({ |
| | | listenBTStatusCallback: (state) => { |
| | | if (state == 'STATE_ON') { |
| | |
| | | } |
| | | }); |
| | | |
| | | // 查看连接设备 |
| | | let pariedDevices = bluetoothTool.getPairedDevices() |
| | | console("已配对设备", pariedDevices) |
| | | console.log(this.$printer) |
| | | if(this.$printer.isConnected()){ |
| | | this.connectedDeviceId = this.$printer.connectedDevice().address |
| | | } |
| | | //#endif |
| | | }, |
| | | } |
| | |
| | | import App from './App' |
| | | |
| | | import Printer from './plugins/printer' |
| | | Vue.use(Printer); |
| | | // 生产环境 |
| | | // Vue.prototype.serverUrl = "https://qqyapi.xinlinsoft.cn/qqy-api"; |
| | | // 开发环境 |
| | |
| | | { |
| | | "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages |
| | | "pages" : [ |
| | | //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages |
| | | { |
| | | "path": "pages/index/login", |
| | | |
| | | "style": { |
| | | "navigationBarTitleText": "登录", |
| | | "navigationStyle": "custom" |
| | |
| | | "navigationBarTitleText": "首件检验单", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | },{ |
| | | }, |
| | | { |
| | | "path": "pages/gongxuIn/form", |
| | | "style": { |
| | | "navigationBarTitleText": "工序进站接收单" |
| | |
| | | "navigationBarTitleText": "工序进站接收单", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | },{ |
| | | }, |
| | | { |
| | | "path": "pages/gongxuOut/form", |
| | | "style": { |
| | | "navigationBarTitleText": "工序出站汇报单" |
| | |
| | | }, |
| | | { |
| | | "path" : "pages/mujvzhuangtai/mujvzhuangtai", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "模具状态分布", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/mujvzhuangtai/detail", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "模具状态详情" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/tiaomachaima/tiaomachaima", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "条码拆码" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/wuliaosaoma/wuliaosaoma", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "物料清单" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/wuliaosaoma/detail", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "条码档案" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/caigouruku/table", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "采购入库", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/caigouruku/form", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "采购入库单" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/caigoutuiliao/table", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "采购退料", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/caigoutuiliao/form", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "采购退料单" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/xiaoshouchuku/table", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "销售出库", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/xiaoshouchuku/form", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "销售出库单" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/xiaoshoutuihuo/table", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "销售退货", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/xiaoshoutuihuo/form", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "销售退货单" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/qitachuku/qitachuku", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "其他出库", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/qitachuku/form", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "其他出库单" |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/qitaruku/qitaruku", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "其他入库", |
| | | "enablePullDownRefresh": true |
| | | } |
| | | }, |
| | | { |
| | | "path" : "pages/qitaruku/form", |
| | | "style" : |
| | | { |
| | | "style" : { |
| | | "navigationBarTitleText" : "其他入库单" |
| | | } |
| | | } |
| | |
| | | "selectedColor": "#2d7dee", //tab 上的文字选中时的颜色,仅支持十六进制颜色 |
| | | "borderStyle": "black", //tabbar上边框的颜色, 仅支持 black / white |
| | | "backgroundColor": "#ffffff", //tab 的背景色,仅支持十六进制颜色 |
| | | "list": [{ |
| | | "list" : [ |
| | | { |
| | | "pagePath": "pages/index/index", |
| | | "iconPath":"static/tabBar/home.png", |
| | | "selectedIconPath":"static/tabBar/home-default.png", |
| | |
| | | "iconPath":"static/tabBar/user.png", |
| | | "selectedIconPath":"static/tabBar/user-default.png", |
| | | "text": "我的" |
| | | }] |
| | | } |
| | | ] |
| | | }, |
| | | "globalStyle": { |
| | | "navigationBarTextStyle": "white", |
| | |
| | | "backgroundColor": "#F8F8F8", |
| | | "pageOrientation": "default" |
| | | }, |
| | | "uniIdRouter": {} |
| | | "uniIdRouter" : {}, |
| | | "condition" : { //模式配置,仅开发期间生效 |
| | | "current": 0, //当前激活的模式(list 的索引项) |
| | | "list": [ |
| | | { |
| | | "name": "", //模式名称 |
| | | "path": "", //启动页面,必选 |
| | | "query": "" //启动参数,在页面的onLoad函数里面得到 |
| | | } |
| | | ] |
| | | } |
| | | } |