Compare commits
7 Commits
d9a28d0345
...
ceafd10b72
Author | SHA1 | Date | |
---|---|---|---|
ceafd10b72 | |||
6b4d47828e | |||
6650334525 | |||
958a74101e | |||
1ed6ca4828 | |||
e39356bbe0 | |||
5eea3a0fff |
2
App.vue
2
App.vue
@ -5,7 +5,7 @@
|
||||
export default {
|
||||
|
||||
onLaunch: function() {
|
||||
uni.clearStorageSync();
|
||||
|
||||
var ble = bleTool.getBleTool();
|
||||
},
|
||||
onShow: function() {
|
||||
|
198
components/global-loading/global-loading.vue
Normal file
198
components/global-loading/global-loading.vue
Normal file
@ -0,0 +1,198 @@
|
||||
<template>
|
||||
<view v-if="visible" class="loading-container" @touchmove.stop.prevent="handleTouchMove">
|
||||
<view class="loading-content">
|
||||
<!-- 刻度点容器 -->
|
||||
<view class="clock-container">
|
||||
<view v-for="(dot, index) in dots" :key="index" class="clock-dot" :style="{
|
||||
transform: `rotate(${index * angle}deg) translateY(-${radius}px)`,
|
||||
backgroundColor: getDotColor(index),
|
||||
animationDuration: `${duration}ms`,
|
||||
animationDelay: `${index * (duration / dotsCount)}ms`
|
||||
}"></view>
|
||||
</view>
|
||||
|
||||
<!-- 提示文本 -->
|
||||
<text class="loading-text" :class="text?'':'displayNone'" :style="{ color: textColor }">{{ text }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
dotsCount: 12,
|
||||
dotColors: ['#CEF231c2'],
|
||||
text: '请稍候...',//文本文字
|
||||
textColor: '#FFFFFFde',//文本颜色
|
||||
radius: 50,//圆的半径
|
||||
duration: 1200,//动画的播放速度
|
||||
colorIndex: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 计算每个点之间的角度
|
||||
angle() {
|
||||
return 360 / this.dotsCount
|
||||
},
|
||||
// 生成刻度点数组
|
||||
dots() {
|
||||
return Array.from({
|
||||
length: this.dotsCount
|
||||
})
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 获取刻度点颜色(实现无限循环变色)
|
||||
getDotColor(index) {
|
||||
// 根据当前颜色索引和刻度点位置计算颜色
|
||||
const colorIndex = (index + this.colorIndex) % this.dotColors.length
|
||||
return this.dotColors[colorIndex]
|
||||
},
|
||||
|
||||
// 更新颜色索引(实现循环变色)
|
||||
updateColorIndex() {
|
||||
this.colorIndex = (this.colorIndex + 1) % this.dotColors.length
|
||||
},
|
||||
|
||||
// 显示loading
|
||||
show(options) {
|
||||
|
||||
if(!options){
|
||||
options={};
|
||||
}
|
||||
|
||||
this.update(options)
|
||||
this.visible = true
|
||||
|
||||
// 启动颜色循环
|
||||
if (!this.colorTimer) {
|
||||
this.colorTimer = setInterval(() => {
|
||||
this.updateColorIndex()
|
||||
}, this.duration / this.dotColors.length)
|
||||
}
|
||||
},
|
||||
|
||||
// 隐藏loading
|
||||
hide() {
|
||||
|
||||
this.visible = false
|
||||
// 清除颜色循环定时器
|
||||
if (this.colorTimer) {
|
||||
clearInterval(this.colorTimer)
|
||||
this.colorTimer = null
|
||||
}
|
||||
},
|
||||
|
||||
// 更新loading配置
|
||||
update(options) {
|
||||
if(!options){
|
||||
options={a:1};
|
||||
}
|
||||
Object.keys(options).forEach(key => {
|
||||
if (this[key] !== undefined) {
|
||||
this[key] = options[key]
|
||||
}
|
||||
})
|
||||
|
||||
// 如果更新了颜色数组,重置颜色索引
|
||||
if (options.dotColors) {
|
||||
this.colorIndex = 0
|
||||
}
|
||||
},
|
||||
|
||||
// 阻止触摸移动事件
|
||||
handleTouchMove() {}
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
// 组件销毁前清除定时器
|
||||
if (this.colorTimer) {
|
||||
clearInterval(this.colorTimer)
|
||||
this.colorTimer = null
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 全屏遮罩层 */
|
||||
.loading-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #000000c2;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 99999999999;
|
||||
pointer-events: auto;
|
||||
|
||||
}
|
||||
|
||||
/* 内容居中 */
|
||||
.loading-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transform: translateZ(0);
|
||||
/* 启用GPU加速 */
|
||||
margin-top: -150rpx;
|
||||
}
|
||||
|
||||
/* 刻度容器 */
|
||||
.clock-container {
|
||||
position: relative;
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
/* 单个刻度点 */
|
||||
.clock-dot {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 14rpx;
|
||||
height: 52rpx;
|
||||
border-radius: 12rpx;
|
||||
/* margin-top: -4rpx;
|
||||
margin-left: -4rpx; */
|
||||
transform-origin: 0 0;
|
||||
animation: colorScale infinite ease-in-out;
|
||||
box-shadow: 0 0 8rpx rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
/* 刻度点动画 - 颜色和大小变化 */
|
||||
@keyframes colorScale {
|
||||
0% {
|
||||
opacity: 0.05;
|
||||
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* 提示文本 */
|
||||
.loading-text {
|
||||
font-size: 32rpx;
|
||||
font-weight: 400;
|
||||
letter-spacing: 1.4rpx;
|
||||
text-align: center;
|
||||
max-width: 80vw;
|
||||
padding: 0 20px;
|
||||
line-height: 1.5;
|
||||
font-family: 'PingFang SC';
|
||||
}
|
||||
|
||||
.displayNone{
|
||||
display: none !important;
|
||||
}
|
||||
</style>
|
6
main.js
6
main.js
@ -2,14 +2,14 @@ import App from './App'
|
||||
|
||||
// 引入 uView UI
|
||||
import uView from 'vk-uview-ui';
|
||||
import bleTool from '@/store/BLETools.js';
|
||||
|
||||
|
||||
// #ifndef VUE3
|
||||
import Vue from 'vue'
|
||||
import store from './store/store';
|
||||
import './uni.promisify.adaptor'
|
||||
Vue.config.productionTip = false
|
||||
Vue.prototype.$bleTool = bleTool;
|
||||
|
||||
App.mpType = 'app'
|
||||
const app = new Vue({
|
||||
store,
|
||||
@ -25,7 +25,7 @@ import {
|
||||
} from 'vue'
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
app.config.globalProperties.$bleTool = bleTool;
|
||||
|
||||
// 使用 uView UI
|
||||
app.use(uView)
|
||||
return {
|
||||
|
@ -247,12 +247,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
ble.removeReceiveCallback(this);
|
||||
},
|
||||
onLoad: function() {
|
||||
var these = this;
|
||||
let eventChannel = this.getOpenerEventChannel();
|
||||
|
||||
//eventChannel.on('detailData', function(data) {
|
||||
//eventChannel.on('deviceControl', function(data) {
|
||||
|
||||
let data = {
|
||||
data: {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,33 +1,227 @@
|
||||
<template>
|
||||
<view>
|
||||
<view class="content">
|
||||
<view class="deviceDetail">
|
||||
<view class="imgContent">
|
||||
<image src="/static/images/BLEAdd/addBleDevice.png" class="titleIco" mode="aspectFit">
|
||||
</image>
|
||||
</view>
|
||||
<view class="deviceName">
|
||||
设备名:{{device.deviceName}}
|
||||
</view>
|
||||
<view class="deviceId">
|
||||
ID:{{device.deviceId}}
|
||||
</view>
|
||||
<view class="bound" v-bind:class="boundStatu">
|
||||
{{Statu.boundRemark}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="btnLink" @click="Link()">
|
||||
连接
|
||||
</view>
|
||||
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
var these=null;
|
||||
var eventChannel =null;
|
||||
import request from '@/utils/request.js';
|
||||
import bleTool from '@/utils/BleHelper.js'
|
||||
var these = null;
|
||||
var eventChannel = null;
|
||||
var ble=null;
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
Statu: {
|
||||
bound: null
|
||||
},
|
||||
device: {
|
||||
"deviceId": "",
|
||||
"name": "",
|
||||
"deviceName": "",
|
||||
"RSSI": -37,
|
||||
"localName": "",
|
||||
"advertisServiceUUIDs": [
|
||||
|
||||
],
|
||||
"linkStatu": false,
|
||||
"macAddress": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
boundStatu: function() {
|
||||
if (this.Statu.bound === null) {
|
||||
return "displayNone"
|
||||
}
|
||||
if (this.Statu.bound) {
|
||||
return "green"
|
||||
} else {
|
||||
return "red";
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
these=this;
|
||||
eventChannel= this.getOpenerEventChannel();
|
||||
|
||||
these = this;
|
||||
ble=bleTool.getBleTool();
|
||||
eventChannel = this.getOpenerEventChannel();
|
||||
eventChannel.on('LinkItem', function(data) {
|
||||
console.log("收到父页面的参数了,",data)
|
||||
eventChannel.emit("Linked",data);
|
||||
let f=ble.data.LinkedList.find((v)=>{
|
||||
return v.deviceId=data.deviceId;
|
||||
});
|
||||
if(f){
|
||||
these.device = f;
|
||||
console.log("获取到设备",f);
|
||||
these.initDevice();
|
||||
}else{
|
||||
console.log("未获取到设备");
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
initDevice: function() {
|
||||
request({
|
||||
url: 'app/device/getDeviceInfoByDeviceMac',
|
||||
method: 'GET',
|
||||
data: {
|
||||
deviceMac: these.device.macAddress
|
||||
}
|
||||
}).then(res=>{
|
||||
console.log("获取设备信息",res);
|
||||
}).catch((ex)=>{
|
||||
console.log("获取设备出现异常:",ex);
|
||||
});
|
||||
},
|
||||
Link() {
|
||||
// 调用绑定设备接口
|
||||
|
||||
let f=ble.data.LinkedList.find((v)=>{
|
||||
return v.deviceId=these.device.deviceId;
|
||||
});
|
||||
if(!f){
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = "蓝牙连接不成功";
|
||||
return;
|
||||
}
|
||||
if(!f.macAddress){
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = "获取设备Mac地址异常";
|
||||
return;
|
||||
}
|
||||
these.Statu.bound = null;
|
||||
these.Statu.boundRemark = "";
|
||||
uni.showLoading({
|
||||
mask: true,
|
||||
title: "连接中..."
|
||||
})
|
||||
let promise = request({
|
||||
url: '/app/device/bind',
|
||||
method: 'POST',
|
||||
data: {
|
||||
deviceImei: '',
|
||||
deviceMac: these.device.macAddress,
|
||||
communicationMode: '1', //0是4g,1是蓝牙
|
||||
}
|
||||
});
|
||||
promise.then((res) => {
|
||||
console.log("1111" + JSON.stringify(res));
|
||||
if (res.code == 200) {
|
||||
these.Statu.bound = true;
|
||||
these.Statu.boundRemark = "设备绑定成功!";
|
||||
uni.$emit("refreshDeviceList");
|
||||
setTimeout(()=>{
|
||||
uni.switchTab({
|
||||
url:"/pages/common/index/index"
|
||||
});
|
||||
},500);
|
||||
} else {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = res.msg;
|
||||
}
|
||||
}).catch((ex) => {
|
||||
these.Statu.bound = false;
|
||||
these.Statu.boundRemark = '出现了未知的异常,操作失败';
|
||||
}).finally(() => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
background-color: #1d1d1d;
|
||||
color: #ffffffde;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
min-height: 100vh;
|
||||
height: auto;
|
||||
font-family: "PingFang SC";
|
||||
}
|
||||
|
||||
.deviceDetail {
|
||||
margin: 200rpx auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.imgContent,
|
||||
.titleIco {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
}
|
||||
|
||||
.deviceId {
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
font-size: 32rpx;
|
||||
|
||||
line-height: 44rpx;
|
||||
letter-spacing: 0.14rpx;
|
||||
margin-top: 5rpx;
|
||||
}
|
||||
|
||||
.btnLink {
|
||||
position: fixed;
|
||||
bottom: 30rpx;
|
||||
left: 30rpx;
|
||||
right: 30rpx;
|
||||
width: calc(100% - 60rpx);
|
||||
border-radius: 91px;
|
||||
height: 90rpx;
|
||||
background: rgba(187, 230, 0, 1);
|
||||
color: rgba(35, 35, 35, 1);
|
||||
|
||||
|
||||
font-size: 32rpx;
|
||||
line-height: 90rpx;
|
||||
letter-spacing: 12rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.bound,
|
||||
.deviceName {
|
||||
font-size: 32rpx;
|
||||
font-weight: 400;
|
||||
line-height: 44rpx;
|
||||
letter-spacing: 0.14rpx;
|
||||
margin-top: 5rpx;
|
||||
}
|
||||
|
||||
.displayNone {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.green {
|
||||
color: rgba(187, 230, 0, 1);
|
||||
}
|
||||
|
||||
.red {
|
||||
color: rgba(245, 80, 80, 1);
|
||||
}
|
||||
</style>
|
@ -228,19 +228,7 @@
|
||||
ble.showBlueSetting(false);
|
||||
},
|
||||
Link: function(item, index) {
|
||||
ble.StopSearch();
|
||||
uni.navigateTo({
|
||||
url:"/pages/common/addBLE/LinkBle",
|
||||
events:{
|
||||
Linked:function(data ){
|
||||
console.log("收到数据了",data);
|
||||
}
|
||||
},
|
||||
success(res) {
|
||||
res.eventChannel.emit('LinkItem', item)
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
||||
uni.showLoading({
|
||||
title: "正在连接",
|
||||
mask: true
|
||||
@ -258,6 +246,15 @@
|
||||
|
||||
these.PairEquip.push(item);
|
||||
}
|
||||
uni.navigateTo({
|
||||
url:"/pages/common/addBLE/LinkBle",
|
||||
events:{
|
||||
|
||||
},
|
||||
success(res) {
|
||||
res.eventChannel.emit('LinkItem', item)
|
||||
}
|
||||
});
|
||||
|
||||
}).catch((ex) => {
|
||||
console.log("ex=",ex)
|
||||
|
@ -477,6 +477,7 @@
|
||||
},
|
||||
handleFile(item) {
|
||||
// communicationMode 0是4G 1是蓝牙,考虑多个4g设备
|
||||
console.log("item=",item);
|
||||
if (item.typeName == 'BJQ6170') {
|
||||
uni.navigateTo({
|
||||
url: "/pages/6170/deviceControl/index",
|
||||
@ -509,14 +510,27 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
if (item.typeName == '6155') {
|
||||
else if (item.typeName == '6155') {
|
||||
uni.navigateTo({
|
||||
url: "/pages/6155/deviceDetail",
|
||||
events: {
|
||||
ack: function(data) {}
|
||||
},
|
||||
success: (res) => {
|
||||
res.eventChannel.emit('detailData', {
|
||||
res.eventChannel.emit('deviceControl', {
|
||||
data: item
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
else if (item.typeName == '650') {
|
||||
uni.navigateTo({
|
||||
url: "/pages/650/HBY650",
|
||||
events: {
|
||||
ack: function(data) {}
|
||||
},
|
||||
success: (res) => {
|
||||
res.eventChannel.emit('deviceControl', {
|
||||
data: item
|
||||
});
|
||||
}
|
||||
|
BIN
static/images/6155/DeviceDetail/warnning.png
Normal file
BIN
static/images/6155/DeviceDetail/warnning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
static/images/BLEAdd/addBleDevice.png
Normal file
BIN
static/images/BLEAdd/addBleDevice.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 867 B |
@ -53,23 +53,23 @@ class BleHelper {
|
||||
},
|
||||
{
|
||||
key: '10003',
|
||||
remark: '连接失败'
|
||||
remark: '蓝牙设备连接失败'
|
||||
},
|
||||
{
|
||||
key: '10004',
|
||||
remark: '没有找到指定服务'
|
||||
remark: '蓝牙设备没有找到指定服务'
|
||||
},
|
||||
{
|
||||
key: '10005',
|
||||
remark: '没有找到指定特征值'
|
||||
remark: '蓝牙设备没有找到指定特征值'
|
||||
},
|
||||
{
|
||||
key: '10006',
|
||||
remark: '当前连接已断开'
|
||||
remark: '蓝牙连接已断开'
|
||||
},
|
||||
{
|
||||
key: '10007',
|
||||
remark: '当前特征值不支持此操作'
|
||||
remark: '蓝牙设备当前特征值不支持此操作'
|
||||
},
|
||||
{
|
||||
key: '10008',
|
||||
@ -77,7 +77,7 @@ class BleHelper {
|
||||
},
|
||||
{
|
||||
key: '10009',
|
||||
remark: '系统不支持 BLE低功耗蓝牙'
|
||||
remark: '蓝牙设备不支持BLE低功耗蓝牙'
|
||||
},
|
||||
{
|
||||
key: '10010',
|
||||
@ -85,11 +85,11 @@ class BleHelper {
|
||||
},
|
||||
{
|
||||
key: '10011',
|
||||
remark: '配对设备需要配对码'
|
||||
remark: '蓝牙设备配对设备需要配对码'
|
||||
},
|
||||
{
|
||||
key: '10012',
|
||||
remark: '连接超时'
|
||||
remark: '蓝牙设备连接超时'
|
||||
},
|
||||
{
|
||||
key: '10013',
|
||||
@ -119,18 +119,22 @@ class BleHelper {
|
||||
const pages = getCurrentPages();
|
||||
|
||||
if (pages.length === 0) {
|
||||
return '';
|
||||
return "";
|
||||
}
|
||||
|
||||
const currentPage = pages[pages.length - 1];
|
||||
|
||||
console.log("currentPage=",currentPage.route);
|
||||
return currentPage.route;
|
||||
}
|
||||
|
||||
//设置发现新设备的回调
|
||||
addDeviceFound(callback) {
|
||||
let key = this.getCurrentPagePath();
|
||||
if(!key){
|
||||
key=new Date().getTime();
|
||||
}
|
||||
if (key) {
|
||||
console.log("key="+key);
|
||||
let f = this.cfg.onDeviceFound.findIndex((v) => {
|
||||
return v.key == key;
|
||||
});
|
||||
@ -148,19 +152,29 @@ class BleHelper {
|
||||
//移除发现新设备的回调
|
||||
removeDeviceFound() {
|
||||
let key = this.getCurrentPagePath();
|
||||
|
||||
if (key) {
|
||||
console.log("key="+key);
|
||||
let f = this.cfg.onDeviceFound.findIndex((v) => {
|
||||
return v.key == key;
|
||||
});
|
||||
if (f > -1) {
|
||||
this.cfg.onDeviceFound.splice(f, 1);
|
||||
}
|
||||
}else{
|
||||
if(this.cfg.onDeviceFound.length>0){
|
||||
this.cfg.onDeviceFound.splice(this.cfg.onDeviceFound.length-1, 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//添加接收到数据的回调
|
||||
addReceiveCallback(callback) {
|
||||
let key = this.getCurrentPagePath();
|
||||
if(!key){
|
||||
key=new Date().getTime();
|
||||
}
|
||||
if (key) {
|
||||
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
||||
return v.key == key;
|
||||
@ -179,9 +193,10 @@ class BleHelper {
|
||||
|
||||
|
||||
//设置接收到数据的回调
|
||||
removeReceiveCallback() {
|
||||
removeReceiveCallback(ev) {
|
||||
let key = this.getCurrentPagePath();
|
||||
if (key) {
|
||||
console.log("key="+key);
|
||||
let f = this.cfg.receivDataCallback.findIndex((v) => {
|
||||
return v.key == key;
|
||||
});
|
||||
@ -190,6 +205,10 @@ class BleHelper {
|
||||
this.cfg.receivDataCallback.splice(f, 1);
|
||||
}
|
||||
|
||||
}else{
|
||||
if(this.cfg.receivDataCallback.length>0){
|
||||
this.cfg.receivDataCallback.splice(this.cfg.receivDataCallback.length-1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,12 +451,13 @@ class BleHelper {
|
||||
this.data.LinkedList.find((v) => {
|
||||
if (v.deviceId == receive.deviceId) {
|
||||
v.macAddress = str.replace(header,"");
|
||||
console.log("收到mac地址:", str)
|
||||
}
|
||||
});
|
||||
uni.setStorageSync(this.StorageKey, this.data
|
||||
.LinkedList);
|
||||
}
|
||||
//////console.log("收到的字符串:", str)
|
||||
|
||||
|
||||
} catch (ex) {
|
||||
////console.log("将数据转文本失败", ex);
|
||||
@ -854,7 +874,7 @@ class BleHelper {
|
||||
|
||||
//连接某个设备
|
||||
LinkBlue(deviceId, targetServiceId, writeCharId, notifyCharId) {
|
||||
this.StopSearch();
|
||||
|
||||
|
||||
if (!writeCharId) {
|
||||
writeCharId = "xxxx"; // "FFE1";
|
||||
@ -890,7 +910,7 @@ class BleHelper {
|
||||
console.log("正在连接" + deviceId);
|
||||
uni.createBLEConnection({
|
||||
deviceId: deviceId,
|
||||
timeout: 5000,
|
||||
timeout: 3000,
|
||||
success: (info) => {
|
||||
|
||||
console.log("新连接成功", this.data.LinkedList);
|
||||
@ -955,7 +975,7 @@ class BleHelper {
|
||||
}).then((res) => {
|
||||
////console.log("11111111");
|
||||
if (res) { //新连接
|
||||
console.log("开始获取服务")
|
||||
console.log("开始获取服务",targetServiceId)
|
||||
return this.getService(deviceId, targetServiceId, writeCharId,
|
||||
notifyCharId); //获取服务
|
||||
} else { //已连接过,直接订阅消息
|
||||
@ -969,7 +989,9 @@ class BleHelper {
|
||||
}).then(() => {
|
||||
|
||||
|
||||
return resolve();
|
||||
setTimeout(()=>{
|
||||
resolve();
|
||||
},500);
|
||||
}).catch((ex) => {
|
||||
////console.log("出现异常", ex);
|
||||
reject(ex);
|
||||
@ -1041,8 +1063,8 @@ class BleHelper {
|
||||
//向蓝牙设备发送数据,如果没连接将自动连接后再发
|
||||
sendData(deviceid, buffer, writeServiceId, wirteCharactId, ms) {
|
||||
|
||||
console.log("deviceid=" + deviceid + ",writeServiceId=" + writeServiceId + ",wirteCharactId=" +
|
||||
wirteCharactId + ",timeout=" + ms)
|
||||
// console.log("deviceid=" + deviceid + ",writeServiceId=" + writeServiceId + ",wirteCharactId=" +
|
||||
// wirteCharactId + ",timeout=" + ms)
|
||||
if (ms === undefined) {
|
||||
ms = 50;
|
||||
}
|
||||
@ -1080,7 +1102,7 @@ class BleHelper {
|
||||
})); //没有找到指定设备
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("device=",device);
|
||||
uni.writeBLECharacteristicValue({
|
||||
deviceId: device.deviceId,
|
||||
serviceId: device.writeServiceId,
|
||||
@ -1114,7 +1136,7 @@ class BleHelper {
|
||||
Promise.race([timeOut(ms), promise]).then(resolve).catch((ex) => {
|
||||
console.log("ex=", ex);
|
||||
if (ex.code == -1) {
|
||||
resolve();
|
||||
resolve(ex);
|
||||
} else {
|
||||
reject(ex);
|
||||
}
|
||||
@ -1129,12 +1151,19 @@ class BleHelper {
|
||||
|
||||
}
|
||||
if (c.Linked) {
|
||||
console.log("蓝牙已连接,直接发送");
|
||||
// console.log("蓝牙已连接,直接发送");
|
||||
return sendBuffer();
|
||||
} else {
|
||||
console.log("先连接蓝牙再发送");
|
||||
// console.log("先连接蓝牙再发送");
|
||||
return new Promise((resolve, reject) => {
|
||||
this.LinkBlue(deviceid).then((res) => {
|
||||
let f=this.data.LinkedList.find((v)=>{
|
||||
return v.deviceId==deviceid;
|
||||
});
|
||||
if(!f){
|
||||
reject({code:'-9',msg:'蓝牙未连接过此设备,请重新使用蓝牙添加该设备'});
|
||||
retrn;
|
||||
}
|
||||
this.LinkBlue(f.deviceId,f.writeServiceId,f.wirteCharactId,f.notifyCharactId).then((res) => {
|
||||
console.log("连接成功");
|
||||
return sendBuffer();
|
||||
}).then(() => {
|
||||
@ -1178,7 +1207,7 @@ export default {
|
||||
getBleTool: function(found, receive) {
|
||||
if (!instance) {
|
||||
instance = new BleHelper();
|
||||
////console.log("第一次初始化");
|
||||
|
||||
} else {
|
||||
////console.log("调用现有实例");
|
||||
}
|
||||
|
38
utils/loading.js
Normal file
38
utils/loading.js
Normal file
@ -0,0 +1,38 @@
|
||||
// utils/loading.js
|
||||
|
||||
// 显示loading
|
||||
export const showLoading = (ev,options) => {
|
||||
if(!ev){
|
||||
return;
|
||||
}
|
||||
|
||||
if(!options){
|
||||
options={a:1};
|
||||
}
|
||||
ev.$refs.loading.show(options)
|
||||
|
||||
}
|
||||
|
||||
// 隐藏loading
|
||||
export const hideLoading = (ev) => {
|
||||
|
||||
if(!ev){
|
||||
return;
|
||||
}
|
||||
console.log("hide.....")
|
||||
ev.$refs.loading.hide();
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 更新loading配置
|
||||
export const updateLoading = (ev,options) => {
|
||||
if(!ev){
|
||||
return;
|
||||
}
|
||||
if(!options){
|
||||
options={a:1};
|
||||
}
|
||||
ev.$refs.loading.update(options)
|
||||
|
||||
}
|
Reference in New Issue
Block a user