From e4114251fbdd55c0eca6cd29c1b5798e72b8e252 Mon Sep 17 00:00:00 2001 From: XiaoJia Chen <441785369@qq.com> Date: Tue, 15 Apr 2025 04:00:02 +0800 Subject: [PATCH] blue ui --- pages/components/bluetooth/bluetooth.acss | 7 + pages/components/bluetooth/bluetooth.axml | 122 +++++------ pages/components/bluetooth/bluetooth.js | 204 +++++++++--------- pages/components/bluetooth/bluetooth.json | 10 +- pages/deal/deal.axml | 1 - .../printTemplate/bluetooth/bluetooth.axml | 2 +- .../printTemplate/bluetooth/bluetooth.js | 48 +---- 7 files changed, 183 insertions(+), 211 deletions(-) diff --git a/pages/components/bluetooth/bluetooth.acss b/pages/components/bluetooth/bluetooth.acss index e69de29..602d8d6 100644 --- a/pages/components/bluetooth/bluetooth.acss +++ b/pages/components/bluetooth/bluetooth.acss @@ -0,0 +1,7 @@ +.space-between { + margin-bottom: 10px; +} + +.text-space { + margin-left: 10px; /* 这里添加了左侧间距,你可以根据需要调整值 */ +} \ No newline at end of file diff --git a/pages/components/bluetooth/bluetooth.axml b/pages/components/bluetooth/bluetooth.axml index c155db6..80b4837 100644 --- a/pages/components/bluetooth/bluetooth.axml +++ b/pages/components/bluetooth/bluetooth.axml @@ -1,80 +1,62 @@ - - - - 开关 - - - - - + + + + + + + + + {{selectedDevice.name}} + {{discovering}} + {{available}} - - - - 是否正在搜索设备{{discovering}} - 蓝牙模块是否可用需支持 BLE 并且蓝牙是打开状态{{available}} - - - 开关 - - - - - - - + - 图标 + - Type - - - - - {{item}} + +
+ + + + - + + + + + + +
- - 单选框 - - -
- - - - - - - - - - - -
+
+ + + + 启动 + + 搜索 + + + + + + + + + 指令集选择 + 当前选择:{{array[index]}} - + - 指令集选择 下拉选择框 - - 蓝牙选择框+选择+打印+清空查找更多蓝牙 devices 单选列表框 - - - - 已经连接蓝牙名名称文本 文本 状态一行 - 获取蓝牙状态 有两个标识 打勾 状态一行 -
\ No newline at end of file +
diff --git a/pages/components/bluetooth/bluetooth.js b/pages/components/bluetooth/bluetooth.js index 1ce2f22..e589c58 100644 --- a/pages/components/bluetooth/bluetooth.js +++ b/pages/components/bluetooth/bluetooth.js @@ -1,6 +1,9 @@ Component({ mixins: [], data: { + printdata: {}, + array: ['TSPL', 'ZPL', 'CPCL', 'ESC/POS'], + index: 0, // 初始化蓝牙的开关状态,false 表示关闭,true 表示打开 switchswitchopenBluetoothAdapter: false, // 搜索蓝牙设备的开关状态,false 表示停止搜索,true 表示开始搜索 @@ -13,7 +16,6 @@ Component({ deviceslist: [], // 选择的保持连接的蓝牙对象 devices: [], - devices: {}, selectedDevice: {}, // 存储设备名称,可根据需求调整 devicesName: [], @@ -35,7 +37,12 @@ Component({ // 存储所有服务及其特征值 allServicesAndCharacteristics: {} }, - props: {}, + props: { + printdata: { + type: Object, + default: () => ({}) + } + }, didMount() { // 获取本机蓝牙模块的状态 this.getBluetoothAdapterState(); @@ -90,10 +97,10 @@ Component({ fail: (res) => { console.log('获取本机蓝牙模块状态失败,错误码:', res.errorCode); if (res.errorCode === 10000) { - dd.showToast({ - title: '请先打开蓝牙开关', - icon: 'none' - }); + // dd.showToast({ + // title: '请先打开蓝牙开关', + // icon: 'none' + // }); } else { // dd.showToast({ // title: `获取本机蓝牙模块状态失败,错误码: ${res.errorCode}`, @@ -107,8 +114,10 @@ Component({ }); }, switchopenBluetoothAdapter(e) { + console.log('Data updated:', this.props.printdata); console.log('switchopenBluetoothAdapter 发生 change 事件,携带值为', e.detail.value); // 更新组件数据,将开关的新状态存储到 data 中 + console.log('Received printdata:', this.data.printdata); this.setData({ switchswitchopenBluetoothAdapter: e.detail.value, }); @@ -120,10 +129,10 @@ Component({ autoClose: true, success: (res) => { console.log('蓝牙模块初始化成功,是否支持 BLE:', res.isSupportBLE); - dd.showToast({ - title: '蓝牙模块初始化成功', - icon: 'success' - }); + // dd.showToast({ + // title: '蓝牙模块初始化成功', + // icon: 'success' + // }); // 监听手机蓝牙状态的改变 dd.onBluetoothAdapterStateChange((res) => { console.log('蓝牙适配器状态改变:', res); @@ -169,10 +178,10 @@ Component({ dd.closeBluetoothAdapter({ success: () => { console.log('蓝牙模块已关闭'); - dd.showToast({ - title: '蓝牙模块已关闭', - icon: 'success' - }); + // dd.showToast({ + // title: '蓝牙模块已关闭', + // icon: 'success' + // }); }, fail: (res) => { console.error('关闭蓝牙模块失败,错误码:', res.errorCode); @@ -205,10 +214,10 @@ Component({ // services: ['fff0'], success: (res) => { console.log(res); - dd.showToast({ - title: '开始搜索蓝牙设备', - icon: 'success' - }); + // dd.showToast({ + // title: '开始搜索蓝牙设备', + // icon: 'success' + // }); // 开始搜索后获取已发现设备 this.getDiscoveredDevices(); }, @@ -233,10 +242,10 @@ Component({ dd.stopBluetoothDevicesDiscovery({ success: (res) => { console.log(res); - dd.showToast({ - title: '停止搜索蓝牙设备', - icon: 'success' - }); + // dd.showToast({ + // title: '停止搜索蓝牙设备', + // icon: 'success' + // }); }, fail: (res) => { console.error('停止搜寻蓝牙设备失败,错误码:', res.errorCode); @@ -349,12 +358,7 @@ Component({ deviceId, success: (res) => { console.log('连接蓝牙设备成功', res); - this.setData({ - isConnected: true, - iconType: [ - 'success', - ], - }); + // const title = '蓝牙设备连接成功'; // if (title) { // dd.showToast({ @@ -364,6 +368,12 @@ Component({ // } // 获取设备的服务列表 this.getBLEDeviceServices(deviceId); + this.setData({ + isConnected: true, + iconType: [ + 'success', + ], + }); }, fail: (res) => { console.error('连接蓝牙设备失败,错误码:', res.errorCode); @@ -382,12 +392,12 @@ Component({ } else { console.log('请先选择要连接的蓝牙设备'); const title = '请先选择要连接的蓝牙设备'; - if (title) { - dd.showToast({ - title, - icon: 'none' - }); - } + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } } }, /** @@ -407,34 +417,34 @@ Component({ } else { console.error('服务的 UUID 和 serviceId 均为空,无法获取特征值。服务详情:', service); const title = '服务 UUID 和 serviceId 均为空,无法获取特征值'; - if (title) { - dd.showToast({ - title, - icon: 'none' - }); - } + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } } }); } else { console.error('未获取到服务列表'); - const title = '未获取到服务列表'; - if (title) { - dd.showToast({ - title, - icon: 'none' - }); - } + // const title = '未获取到服务列表'; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } } }, fail: (serviceErr) => { console.error('获取服务失败', serviceErr); - const title = '获取服务失败'; - if (title) { - dd.showToast({ - title, - icon: 'none' - }); - } + // const title = '获取服务失败'; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } } }); }, @@ -470,23 +480,23 @@ Component({ writableCharacteristics: [...this.data.writableCharacteristics, ...writable] }); console.log('获取特征值成功', characteristicRes); - const title = '获取特征值成功'; - if (title) { - dd.showToast({ - title, - icon: 'success' - }); - } + // const title = '获取特征值成功'; + // if (title) { + // dd.showToast({ + // title, + // icon: 'success' + // }); + // } }, fail: (characteristicErr) => { console.error('获取特征值失败', characteristicErr); - const title = '获取特征值失败'; - if (title) { - dd.showToast({ - title, - icon: 'none' - }); - } + // const title = '获取特征值失败'; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } } }); }, @@ -518,13 +528,13 @@ Component({ }, fail: (res) => { console.error('重新连接蓝牙设备失败,错误码:', res.errorCode); - const title = `重新连接蓝牙设备失败,错误码: ${res.errorCode}`; - if (title) { - dd.showToast({ - title, - icon: 'none' - }); - } + // const title = `重新连接蓝牙设备失败,错误码: ${res.errorCode}`; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } this.reconnectBluetoothDevice(); }, complete: (res) => { @@ -563,13 +573,13 @@ Component({ }, fail: (res) => { console.error('关闭蓝牙连接失败,错误码:', res.errorCode); - const title = `关闭蓝牙连接失败,错误码: ${res.errorCode}`; - if (title) { - dd.showToast({ - title, - icon: 'none' - }); - } + // const title = `关闭蓝牙连接失败,错误码: ${res.errorCode}`; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } }, complete: (res) => { console.log('关闭蓝牙连接调用结束', res); @@ -598,13 +608,13 @@ Component({ } = res; if (connected) { console.log(`蓝牙设备 ${deviceId} 连接成功`); - const title = `蓝牙设备 ${deviceId} 连接成功`; - if (title) { - dd.showToast({ - title, - icon: 'success' - }); - } + // const title = `蓝牙设备 ${deviceId} 连接成功`; + // if (title) { + // dd.showToast({ + // title, + // icon: 'success' + // }); + // } this.setData({ isConnected: true, iconType: [ @@ -613,13 +623,13 @@ Component({ }); } else { console.log(`蓝牙设备 ${deviceId} 连接断开,尝试重新连接`); - const title = `蓝牙设备 ${deviceId} 连接断开,尝试重新连接`; - if (title) { - dd.showToast({ - title, - icon: 'none' - }); - } + // const title = `蓝牙设备 ${deviceId} 连接断开,尝试重新连接`; + // if (title) { + // dd.showToast({ + // title, + // icon: 'none' + // }); + // } this.setData({ isConnected: false, iconType: [ @@ -762,5 +772,5 @@ Component({ sendPrintCode(0); } - } + }, }); \ No newline at end of file diff --git a/pages/components/bluetooth/bluetooth.json b/pages/components/bluetooth/bluetooth.json index 467ce29..ec70dea 100644 --- a/pages/components/bluetooth/bluetooth.json +++ b/pages/components/bluetooth/bluetooth.json @@ -1,3 +1,9 @@ { - "component": true -} + "component": true, + "properties": { + "printdata": { + "type": "Object", + "value": {} + } + } +} \ No newline at end of file diff --git a/pages/deal/deal.axml b/pages/deal/deal.axml index 93a3a67..afb0b3e 100644 --- a/pages/deal/deal.axml +++ b/pages/deal/deal.axml @@ -1,5 +1,4 @@ 销售 - \ No newline at end of file diff --git a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.axml b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.axml index 7f1dc3b..b971fab 100644 --- a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.axml +++ b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.axml @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.js b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.js index c2e565d..a0f1c41 100644 --- a/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.js +++ b/pages/deal/saleOrder/kanban/from/printTag/printTemplate/bluetooth/bluetooth.js @@ -1,46 +1,15 @@ Page({ data: { - switch1: '', - switch2: '', - switch3: '', - switch4: '', - iconType: [ - 'cancel', - ], - // 'success',连接成功打勾 - // 'info', 感叹号 - // 'warn', 黄色感叹号 - // 'waiting',时钟 - // 'clear',打叉 - // 'success_no_circle',打勾 - // 'download',下载 - // 'cancel',打叉 - // 'search',搜索 - array: ['TSPL', 'ZPL', 'CPCL', 'ESC/POS'], - value: {}, printdata: {}, - blueoptions: [], - deviceId: '', - connected: false, - devices: [], - showDeviceList: false, - currentDeviceServices: [], - currentDeviceCharacteristics: [], - hasLocation: false, - location: {}, - deviceCount: 0, - targetDeviceId: 'DC:0D:30:63:9E:0E', - isSearching: true, - printFormat: 'TSPL', - maxAllowedLength: 1024, - delayTime: 5000, // 默认延迟 5 秒,单位:毫秒 - paperSize: { - width: 80, // 默认宽度 80mm - height: 60 // 默认高度 60mm - }, - index: 0 //指令集默认选择 + // printFormat: 'TSPL', + // maxAllowedLength: 1024, + // delayTime: 5000, // 默认延迟 5 秒,单位:毫秒 + // paperSize: { + // width: 80, // 默认宽度 80mm + // height: 60 // 默认高度 60mm + // }, + // index: 0 //指令集默认选择 }, - onLoad() { const selectedSaleOrderLines = dd.getStorageSync({ key: 'selectedSaleOrderLines' @@ -50,5 +19,4 @@ Page({ printdata }); }, - }); \ No newline at end of file